Beispiel #1
0
 /**
  * Fetch and parse results as though they were a json string.
  *
  * @param String $url    API URL
  * @param Array  $params Array of parameters for the API request
  *
  * @return Array $parts Array of return values
  */
 protected function get_json_results($url, $params = [])
 {
     $this->curl->set_option('CURLOPT_FAILONERROR', FALSE);
     $response = $this->curl->get_request($url . '?' . http_build_query($params));
     $result = json_decode($response->get_result(), TRUE);
     if ($response->http_code !== 200) {
         $context = ['message' => $result['message'], 'request' => $url, 'id' => $result['sys']['id']];
         $this->logger->warning('Contentful API Request ({request}) failed with id "{id}": {message}', $context);
         $result['total'] = 0;
     }
     unset($response);
     return $result;
 }
Beispiel #2
0
 /**
  * Push the notification.
  *
  * @return GCMResponse $return Response object
  */
 public function push()
 {
     $this->curl->set_option('CURLOPT_HEADER', TRUE);
     $this->curl->set_http_headers(['Content-Type:application/json', 'Authorization: key=' . $this->auth_token]);
     $tmp_payload = json_decode($this->payload, TRUE);
     $tmp_payload['registration_ids'] = [$this->endpoint];
     $tmp_payload['priority'] = $this->priority;
     $this->payload = json_encode($tmp_payload);
     $response = $this->curl->post_request(self::GOOGLE_SEND_URL, $this->payload);
     $res = new GCMResponse($response, $this->logger, $this->endpoint);
     $this->endpoint = '';
     $this->payload = '';
     return $res;
 }
Beispiel #3
0
 /**
  * Fetch and parse results as though they were a query string.
  *
  * @param String $url    API URL
  * @param Array  $params Array of parameters for the API request
  * @param String $method Request method to use, either 'get' or 'post'
  *
  * @return Array $parts Array of return values
  */
 protected function get_json_results($url, $params = [], $method = 'get')
 {
     $this->curl->set_option('CURLOPT_FAILONERROR', FALSE);
     if (strtolower($method) === 'get') {
         $response = $this->curl->get_request($url . '?' . http_build_query($params));
     } else {
         $response = $this->curl->post_request($url, $params);
     }
     $result = json_decode($response->get_result(), TRUE);
     if ($response->http_code !== 200) {
         $error = $result['error'];
         $result = [];
         $context = ['message' => $error['message'], 'code' => $error['code'], 'type' => $error['type'], 'request' => $url];
         $this->logger->error('Facebook API Request ({request}) failed, {type} ({code}): {message}', $context);
     }
     unset($response);
     return $result;
 }
Beispiel #4
0
 /**
  * Push the notification.
  *
  * @return PAPResponse $return Response object
  */
 public function push()
 {
     // construct PAP URL
     $pap_url = "https://cp{$this->cid}.pushapi.na.blackberry.com/mss/PD_pushRequest";
     $pap_data = $this->construct_pap_data();
     $this->curl->set_option('CURLOPT_URL', $pap_url);
     $this->curl->set_option('CURLOPT_HEADER', FALSE);
     $this->curl->set_option('CURLOPT_HTTP_VERSION', CURL_HTTP_VERSION_1_1);
     $this->curl->set_option('CURLOPT_HTTPAUTH', CURLAUTH_BASIC);
     $this->curl->set_option('CURLOPT_USERPWD', $this->auth_token . ':' . $this->password);
     $this->curl->set_option('CURLOPT_RETURNTRANSFER', TRUE);
     $this->curl->set_http_header('Content-Type: multipart/related; boundary=' . self::PAP_BOUNDARY . '; type=application/xml');
     $this->curl->set_http_header('Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2');
     $this->curl->set_http_header('Connection: keep-alive');
     $response = $this->curl->post_request($pap_url, $pap_data);
     $res = new PAPResponse($response, $this->logger, $this->endpoint);
     $this->endpoint = '';
     $this->push_id = '';
     $this->payload = '';
     $this->deliverbefore = '';
     return $res;
 }
 function getEnrichment($notice_id, $source_id, $type = "", $enrich_params = array())
 {
     global $charset;
     $params = $this->get_source_params($source_id);
     if ($params["PARAMETERS"]) {
         //Affichage du formulaire avec $params["PARAMETERS"]
         $vars = unserialize($params["PARAMETERS"]);
     }
     $enrichment = array();
     switch ($type) {
         case "artevod":
         default:
             $perso_params = new parametres_perso("notices");
             $perso_params->get_values($notice_id);
             $values = $perso_params->values;
             $link = "http://www.mediatheque-numerique.com/ws/films/" . $values[$vars['cp_field']][0];
             $infos = unserialize($this->parameters);
             $curl = new Curl();
             if (isset($infos['accesskey']) && $infos['accesskey']) {
                 $curl->set_option("CURLOPT_USERPWD", $infos['accesskey'] . ":" . $infos['secretkey']);
             }
             $result = $curl->get($link);
             $result = _parser_text_no_function_($result->body, "WSOBJECTQUERY");
             $content = "";
             $film = array();
             // Titre
             $film['title'] = $result['FILM'][0]['EDITORIAL'][0]['TITLE'][0]['value'];
             $film['original_title'] = $result['FILM'][0]['EDITORIAL'][0]['ORIGINAL_TITLE'][0]['value'];
             // Genres
             $film['genres'] = array();
             foreach ($result['FILM'][0]['EDITORIAL'][0]['GENRE'] as $genre) {
                 foreach ($genre['LABEL'] as $label) {
                     if ($label['LANG'] == 'fr') {
                         $film['genres'][] = $label['value'];
                     }
                 }
             }
             // Sous-genres
             $film['subgenres'] = array();
             foreach ($result['FILM'][0]['EDITORIAL'][0]['SUB_GENRE'] as $genre) {
                 foreach ($genre['LABEL'] as $label) {
                     if ($label['LANG'] == 'fr') {
                         $film['subgenres'][] = $label['value'];
                     }
                 }
             }
             // Auteurs
             $film['authors'] = array();
             foreach ($result['FILM'][0]['STAFF'][0]['AUTHORS'][0]['PERSON'] as $author) {
                 if ($author['FULL_NAME'][0]['value']) {
                     $film['authors'][] = $author['FULL_NAME'][0]['value'];
                 } else {
                     $film['authors'][] = $author['FIRST_NAME'][0]['value'] . " " . $author['LAST_NAME'][0]['value'];
                 }
             }
             // Acteurs
             $film['actors'] = array();
             foreach ($result['FILM'][0]['STAFF'][0]['ACTORS'][0]['PERSON'] as $actor) {
                 if ($actor['FULL_NAME'][0]['value']) {
                     $film['actors'][] = $actor['FULL_NAME'][0]['value'];
                 } else {
                     $film['actors'][] = $actor['FIRST_NAME'][0]['value'] . " " . $actor['LAST_NAME'][0]['value'];
                 }
             }
             // Couverture
             $film['poster'] = $result['FILM'][0]['MEDIA'][0]['POSTERS'][0]['MEDIA'][0]['SRC'];
             // Durée
             $film['duration'] = array('raw_value' => $result['FILM'][0]['TECHNICAL'][0]['DURATION'][0]['value'], 'format_value' => floor($result['FILM'][0]['TECHNICAL'][0]['DURATION'][0]['value'] / 60) . ":" . str_pad($result['FILM'][0]['TECHNICAL'][0]['DURATION'][0]['value'] % 60, 2, '0', STR_PAD_LEFT));
             // Description
             $film['description'] = $result['FILM'][0]['EDITORIAL'][0]['DESCRIPTION'][0]['value'];
             // Résumé
             $film['body'] = $result['FILM'][0]['EDITORIAL'][0]['BODY'][0]['value'];
             // Extraits
             $film['trailers'] = array();
             foreach ($result['FILM'][0]['MEDIA'][0]['TRAILERS'][0]['MEDIA'] as $trailer) {
                 $film['trailers'][] = $trailer['SRC'];
             }
             // Photos
             $film['photos'] = array();
             foreach ($result['FILM'][0]['MEDIA'][0]['PHOTOS'][0]['MEDIA'] as $photo) {
                 $film['photos'][] = $photo['SRC'];
             }
             // Public
             $film['target_audience'] = $result['FILM'][0]['TECHNICAL'][0]['TARGET_AUDIENCE'][0]['LABEL'][0]['value'];
             // Année de production
             $film['production_year'] = $result['FILM'][0]['TECHNICAL'][0]['PRODUCTION_YEAR'][0]['value'];
             // Pays de production
             $film['production_countries'] = array();
             foreach ($result['FILM'][0]['TECHNICAL'][0]['PRODUCTION_COUNTRIES'][0]['COUNTRY'] as $country) {
                 foreach ($country['LABEL'] as $label) {
                     if ($label['LANG'] == 'fr') {
                         $film['production_countries'] = $label['value'];
                     }
                 }
             }
             // Langues
             $film['languages'] = array();
             foreach ($result['FILM'][0]['TECHNICAL'][0]['LANGUAGES'][0]['LANGUAGE'] as $language) {
                 foreach ($language['LABEL'] as $label) {
                     if ($label['LANG'] == 'fr') {
                         $film['languages'] = $label['value'];
                     }
                 }
             }
             // Lien externe
             if ($result['FILM'][0]['EXTERNALURI'][0]['value']) {
                 $film['externaluri'] = $result['FILM'][0]['EXTERNALURI'][0]['value'];
                 if ($_SESSION['user_code'] && isset($infos['privatekey'])) {
                     global $empr_cb, $empr_nom, $empr_prenom, $empr_mail, $empr_year;
                     $id_encrypted = hash('sha256', $empr_cb . $infos['privatekey']);
                     $film['externaluri'] .= "?sso_id=mednum&id=" . $empr_cb . "&email=" . $empr_mail . "&nom=" . strtolower($empr_nom) . "&prenom=" . strtolower($empr_prenom) . "&dnaiss=" . $empr_year . "&id_encrypted=" . $id_encrypted;
                 }
             }
             $enrichment[$type]['content'] = H2o::parseString(stripslashes($vars['enrichment_template']))->render(array("film" => $film));
             break;
     }
     $enrichment['source_label'] = $this->msg['artevod_enrichment_source'];
     return $enrichment;
 }