You are here

public function SocialContentPinterest::prepareRow in Social Content 7.2

Do the uploads and attach expected fields to a row about to be imported.

Overrides SocialContent::prepareRow

File

modules/pinterest/social_content_pinterest.class.inc, line 150
Social Content Pinterest class.

Class

SocialContentPinterest
@file Social Content Pinterest class.

Code

public function prepareRow($row) {
  $row->created = strtotime($row->pubDate);
  $filter = filter_format_exists('pinterest') ? 'pinterest' : 'filtered_html';
  $row->body = array(
    'value' => $row->description,
    'format' => $filter,
  );
  $id = str_replace('https://www.pinterest.com/pin/', '', $row->guid);
  $id = str_replace('/', '', $id);
  $row->id = $id;
  if (parent::prepareRow($row) === FALSE) {
    return FALSE;
  }
  $doc = new DOMDocument();
  @$doc
    ->loadHTML($row->description);
  $tags = $doc
    ->getElementsByTagName('img');
  $mappings = $this
    ->getFieldMappings();
  if ($img = $tags
    ->item(0)) {
    $src = $img
      ->getAttribute('src');
    $picture = $this
      ->saveExternalFile($src, $mappings['picture']);
    $row->picture = $picture ? $picture : NULL;
  }
  return TRUE;
}