public function SocialContentTumblr::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/
tumblr/ social_content_tumblr.class.inc, line 196 - Social Content Tumblr class.
Class
- SocialContentTumblr
- @file Social Content Tumblr class.
Code
public function prepareRow($row) {
if (parent::prepareRow($row) === FALSE) {
return FALSE;
}
$row->created = $row->timestamp;
$row->blog_link = 'http://' . $this->settings['instance']['host_name'];
if ($row->type == 'text') {
// Try to get an image from the body.
$mappings = $this
->getFieldMappings();
$doc = new DOMDocument();
@$doc
->loadHTML($row->body);
$tags = $doc
->getElementsByTagName('img');
foreach ($tags as $tag) {
$picture = $this
->saveExternalFile($tag
->getAttribute('src'), $mappings['picture']);
continue;
}
$row->picture = !empty($picture) ? $picture : NULL;
$filter = filter_format_exists('tumblr') ? 'tumblr' : 'filtered_html';
$row->body = array(
'value' => $row->body,
'format' => $filter,
);
}
else {
if ($row->type == 'photo') {
// Save first photo only for now.
foreach ($row->photos as $photo) {
$mappings = $this
->getFieldMappings();
$picture = $this
->saveExternalFile($photo->original_size->url, $mappings['picture']);
continue;
}
$row->picture = !empty($picture) ? $picture : NULL;
// Put the caption field to the body.
$filter = filter_format_exists('tumblr') ? 'tumblr' : 'filtered_html';
$row->body = array(
'value' => $row->caption,
'format' => $filter,
);
}
else {
if ($row->type == 'video') {
// Save the video thumbnail.
$mappings = $this
->getFieldMappings();
$picture = $this
->saveExternalFile($row->thumbnail_url, $mappings['picture']);
$row->picture = !empty($picture) ? $picture : NULL;
// Put the caption field to the body.
$filter = filter_format_exists('tumblr') ? 'tumblr' : 'filtered_html';
$row->body = array(
'value' => $row->caption,
'format' => $filter,
);
// Get video embed URL.
$row->video_embed = NULL;
$player = end($row->player);
if ($player && isset($player->embed_code)) {
$doc = new DOMDocument();
@$doc
->loadHTML($player->embed_code);
$tags = $doc
->getElementsByTagName('iframe');
foreach ($tags as $tag) {
$row->video_embed = $tag
->getAttribute('src');
continue;
}
}
}
}
}
return TRUE;
}