private static function response() { try { $api = new API(self::$url, false); $xml = simplexml_load_string(utf8_decode($api->response())); if ($xml) { $response = $xml->concerts->children(); $response2 = $xml->concerts_later->children(); } else { $response = array(); } $return = array(); foreach ($response as $r) { //withpic true signifie avec les photos, sinon false. cela depend de la date de concerts <= 30 ou pas $return[] = array('withpic' => "true", 'group' => (string) $r->nom_groupe, 'link_group' => (string) $r->lien_nom_groupe, 'place' => (string) $r->nom_salle, 'link_place' => (string) $r->lien_nom_salle, 'date' => (string) $r->date, 'price' => (string) $r->prix . ' euro', 'pict' => (string) $r->img_groupe, 'link_pict' => (string) $r->lien_img_groupe); } foreach ($response2 as $r) { //withpic true signifie avec les photos, sinon false. cela depend de la date de concerts <= 30 ou pas $return[] = array('withpic' => "false", 'group' => (string) $r->nom_groupe, 'link_group' => (string) $r->lien_nom_groupe, 'place' => (string) $r->nom_salle, 'link_place' => (string) $r->lien_nom_salle, 'date' => (string) $r->date, 'price' => (string) $r->prix . ' euro', 'pict' => (string) $r->img_groupe, 'link_pict' => (string) $r->lien_img_groupe); } return $return; } catch (Exception $e) { return array(); } }
function __construct($city_code = 'Palaiseau', $lang = 'fr') { $prefix_images = 'https://www.google.com/'; $url = 'http://www.google.com/ig/api?weather=' . urlencode($city_code) . '&hl=' . $lang; $api = new API($url); $xml = simplexml_load_string($api->response()); if ($xml === false) { throw new Exception("Unable to read Google Weather data"); } if (isset($xml->weather->problem_cause)) { throw new Exception($xml->weather->problem_cause); } if (isset($xml->weather->current_conditions)) { $current_conditions = $xml->weather->current_conditions; $this->today = new WeatherConditions(); $this->today->label = isset($current_conditions->condition) ? $this->getAttrData($current_conditions->condition) : null; $this->today->temperature = isset($current_conditions->temp_c) ? $this->getAttrData($current_conditions->temp_c) : null; $icon = isset($current_conditions->icon) ? $this->getAttrData($current_conditions->icon) : null; $this->today->icon = $icon ? $prefix_images . $icon : null; } else { $this->today = null; } $this->forecasts = array(); foreach ($xml->weather->forecast_conditions as $aforecast) { $forecast = new WeatherConditions(); $forecast->label = isset($aforecast->condition) ? $this->getAttrData($aforecast->condition) : null; $forecast->low = isset($aforecast->low) ? $this->getAttrData($aforecast->low) : null; $forecast->high = isset($aforecast->high) ? $this->getAttrData($aforecast->high) : null; $icon = isset($current_conditions->icon) ? $this->getAttrData($current_conditions->icon) : null; $forecast->icon = $icon ? $prefix_images . $icon : null; $forecast->day = isset($aforecast->day_of_week) ? $this->getAttrData($aforecast->day_of_week) : null; $this->forecasts[] = $forecast; } }
protected function loadFile($url) { $api = new API($url, false); $photos = simplexml_load_string(utf8_decode($api->response())); //charset fix $res = array(); foreach ($photos as $photo) { $res[] = array("urlPage" => "http://pix/photo/" . $photo->id, "imgThumb" => "http://pix/media/photo/thumb/" . $photo->author->id . "/" . $photo->link, "imgFull" => "http://pix/media/photo/view/" . $photo->author->id . "/" . $photo->link, "title" => htmlspecialchars($photo->title . " par " . $photo->author->name . " " . $photo->author->surname), "text" => htmlspecialchars($photo->title . " par " . $photo->author->name . " " . $photo->author->surname) . "<br/><a href='http://pix/photo/" . $photo->id . "'>voir dans piX</a>"); } return $res; }
public function run() { global $globals; if (!PlCache::hasGlobal('ik')) { $ikapi = new API('http://ik.frankiz.net/ajax/last', false); $json = json_decode($ikapi->response(), true); if (isset($json['ik']['id']) && $json['ik']['id'] != '') { $json = $json['ik']; $filename = $globals->spoolroot . '/htdocs/data/ik/' . $json['id'] . '.jpg'; file_put_contents($filename, base64_decode($json['base64'])); $ik = array('id' => $json['id'], 'title' => $json['title'], 'url' => $json['url']); PlCache::setGlobal('ik', $ik, $globals->cache->ik); } } $this->assign('ik', PlCache::getGlobal('ik')); }
private static function response($destination) { try { $api = new API(self::$urls[$destination]); $xml = simplexml_load_string(utf8_decode($api->response())); if ($xml && isset($xml->schedules->schedule->liste)) { $response = $xml->schedules->schedule->liste->children(); } else { $response = array(); } $return = array(); foreach ($response as $r) { if (preg_match('![0-9]{2}:[0-9]{2}!', (string) $r->texte2)) { $return[] = array('name' => (string) $r->texte3, 'desc' => self::destination((string) $r->texte1), 'time' => (string) $r->texte2); } } return $return; } catch (Exception $e) { return array(); } }
private static function response() { static $url = "http://www.pointgamma.com/moduleFKZ/generation_xml.php"; try { $api = new API($url, true); $xml = simplexml_load_string(utf8_decode($api->response())); if ($xml) { $response = $xml->bars->children(); $response2 = $xml->annonces->children(); $response3 = $xml->preventes->children(); } else { $response = array(); $response2 = array(); $response3 = array(); } $return = array(); $bar = array(); $annonce = array(); $prevente = array(); foreach ($response as $r) { $bar[] = array('classement' => (string) $r->numero_bar, 'bars' => (string) $r->nom_bar, 'score' => (string) $r->score_bar); } foreach ($response2 as $r) { $annonce[] = array('numero' => (string) $r->numero_annonce, 'titre' => (string) $r->titre_annonce, 'time' => (string) $r->time_annonce, 'text' => (string) $r->text_annonce); } foreach ($response3 as $r) { $prevente[] = array('ecole' => (string) $r->ecole_prevente, 'time' => (string) $r->time_prevente); } $return[0] = $bar; $return[1] = $annonce; $return[2] = $prevente; return $return; } catch (Exception $e) { return array(); } }
/** * Store an error into the API result, display it and stop script execution * * @version 1.0 * @param string $http_response HTTP Error code to send with JSON * @param string $code Error code * @param string $message Error message * @result void */ public static function error($http_response, $code, $message) { // we store error data self::$success = false; self::$response = $http_response; self::$errors[] = array('status' => $http_response, 'code' => $code, 'title' => $message); // we parse JSON self::parsing(); // we load JSON result to client self::result(); // we stop script execution exit; }
/** * Delete field. */ public function action_delete($id) { // Find field $field = CustomField::find($id); // Verify project if ($field->project_id != $this->project->id) { return $this->show_no_permission(); } // Delete and redirect $field->delete(); if ($this->is_api) { return \API::response(1); } else { Request::redirectTo($this->project->href('settings/custom_fields')); } }
/** * Return informations about an interaction * * @version 1.0 * @param int $contact Contact ID * @param int $id Interaction ID * @return void */ public function interaction($contact, $id) { // we search interaction data $query = API::query('contact_interaction'); $query->bindParam(':event', $id, PDO::PARAM_INT); $query->bindParam(':contact', $contact, PDO::PARAM_INT); $query->execute(); // we check if wa have an answer if ($query->rowCount() == 1) { // Yay! we have a contact detail! API::response(200); // we load contact informations $data = $query->fetch(PDO::FETCH_ASSOC); // we put contact into links section $data['links']['contact'] = $data['contact']; API::link('interactions', 'contact', 'contact'); unset($data['contact']); // we put directory data into links section, if exists if (!is_null($data['dossier'])) { $data['links']['dossier'] = $data['dossier']; API::link('interactions', 'dossier', 'dossier'); unset($data['dossier']); } else { unset($data['dossier']); } // we put user data into links section $data['links']['utilisateur'] = $data['utilisateur']; API::link('interactions', 'utilisateur', 'utilisateur'); unset($data['utilisateur']); // we add contact information to JSON response API::add('interactions', $data); } else { // we display an error API::error(404, 'EventUnknown', 'L\'élément d\'historique demandé n\'existe pas.'); } }
<?php echo API::response(1);
public function run() { global $globals; // google calendar pour la prochaine émission // MAJ 1x/jour $gc = "http://www.google.com/calendar/feeds/binet.radio.xray%40gmail.com/public/full?alt=json&orderby=starttime&max-results=50&singleevents=true&sortorder=ascending&futureevents=true"; // Check if cache needs to be refreshed : if emission < now or if last check was 12h ago if (PlCache::hasGlobal('xray_calendar')) { $xray_calendar = PlCache::getGlobal('xray_calendar'); if (!isset($xray_calendar['time']) || !isset($xray_calendar['next_time']) || time() > min($xray_calendar['next_time'], $xray_calendar['time'] + 43200)) { PlCache::invalidateGlobal('xray_calendar'); } } if (!PlCache::hasGlobal('xray_calendar')) { $calendar_api = new API($gc, true); $json_calendar = json_decode($calendar_api->response(), true); // First emission $feed = $json_calendar['feed']['entry']; $next_show = "surprise !"; // Update no-emission every minute $next_time = time() + 60; for ($i = 0; $i < count($feed); $i++) { $entry = $feed[$i]; $title = $entry['title']['$t']; if ($title[0] == '_') { $name = substr($title, 1); $start = new DateTime($entry['gd$when'][0]['startTime']); $next_show = $name . " à " . strftime('%Hh, %A', $start->getTimestamp()); $next_time = $start->getTimestamp(); break; } } $xray_calendar = array('emission' => $next_show, 'next_time' => $next_time, 'time' => time()); PlCache::setGlobal('xray_calendar', $xray_calendar, $globals->cache->xray_calendar); } /* // feed x-ray pour le dernier podcast // MAJ 1x/jour $podcasts_xml = "http://x-ray/blog/?feed=podcast"; if (!PlCache::hasGlobal('xray_podcast')) { $podcast_api = new API($podcasts_xml, false); $podcasts = $this->xml2array($podcast_api->response()); $last_podcast = $podcasts['rss']['channel']['item'][0]; $xray_podcast = array('titre' => utf8_decode($last_podcast['title']), 'url' => $last_podcast['link'], 'description' => utf8_decode($last_podcast['itunes:subtitle'])); PlCache::setGlobal('xray_podcast', $xray_podcast, $globals->cache->xray_podcast); } */ // titre en cours // MAJ toutes les 2 mn $nowplaying_xml = "http://x-ray/cache/info.xml"; if (!PlCache::hasGlobal('xray_nowplaying')) { $nowplaying_api = new API($nowplaying_xml, false); $nowplaying = $this->xml2array($nowplaying_api->response()); if (isset($nowplaying['info'])) { $song = $nowplaying['info']; $xray_nowplaying = array('title' => $song['title'], 'artist' => $song['artist'], 'album' => $song['album'], 'cover' => $song['cover']); PlCache::setGlobal('xray_nowplaying', $xray_nowplaying, $globals->cache->xray_nowplaying); } } $this->assign('xray_calendar', PlCache::getGlobal('xray_calendar')); //$this->assign('xray_podcast', PlCache::getGlobal('xray_podcast')); $this->assign('xray_nowplaying', PlCache::getGlobal('xray_nowplaying')); }
private function incidence() { //check the current status $user_status = $this->status(null, true); if ($user_status->status != 'checkin') { //the user is not checkedin return API::response(array('timestamp' => NULL)); } //incidence $incidence = new stdClass(); $incidence->userid = $this->get_userid($this->_token); $incidence->action = 'incidence'; $incidence->timestamp = time(); $indicence->computed = 0; //store the incidence $in_status = DB::putRecord('presence_activity', $incidence); //checkout the user $checkout = clone $incidence; $checkout->action = 'checkout'; $ch_status = DB::putRecord('presence_activity', $checkout); if ($in_status && $ch_status) { return API::response(array('timestamp' => $checkout->timestamp)); } else { return API::response(array('timestamp' => NULL)); } }
<?php echo API::response(0, array('errors' => $field->errors));
public function validateToken() { return \API::response()->array(['status' => 'success'])->statusCode(200); }