You are here

private function StatusInstagram::setNodeData in Heartbeat 8

1 call to StatusInstagram::setNodeData()
StatusInstagram::sendRequest in modules/statusmessage/src/StatusInstagram.php

File

modules/statusmessage/src/StatusInstagram.php, line 155

Class

StatusInstagram

Namespace

Drupal\statusmessage

Code

private function setNodeData($data) {

  //Create datetime object for title, media file path and content date field
  $nowTime = new \DateTime();
  $posted = date('Y-m-d\\TH:i:s', strtotime($data->created_at));
  $user = \Drupal::currentUser();
  $ip = \Drupal::request()
    ->getClientIp();

  //get user's IP
  $links = [];
  $terms = $this
    ->processTerms($data);
  if (!empty($data->entities->urls)) {
    foreach ($data->entities->urls as $url) {
      $links[] = !strpos($url->display_url, 'http') ? 'http://' . $url->display_url : $url->display_url;
    }
  }

  //Check for attached media and create a directory for saving
  if (isset($data->extended_entities->media)) {
    $media = $this
      ->getTweetMedia($data);
  }
  if ($data->user->profile_image_url_https) {

    //TODO get profile image
  }
  $node = Node::create([
    'type' => 'tweet',
    'title' => $data->user->screen_name . '_' . $nowTime
      ->format('Y.m.d.Hi'),
    'uid' => $user
      ->id(),
    'field_tags' => $terms->tags,
    'field_tweet_url' => $this->parameter,
    'field_twit_id' => $data->id,
    'field_post_date' => [
      $posted,
    ],
    'field_username' => $terms->username,
    'field_users' => $terms->users,
    'field_links' => $links,
    'status' => 1,
  ]);
  $node
    ->set('body', [
    'value' => '<div class="created-date"> ' . $data->created_at . '</div>' . $data->full_text,
    'format' => 'full_html',
  ]);
  return $node;
}