public function SocialContentInstagram::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/
instagram/ social_content_instagram.class.inc, line 364 - Social Content Instagram class.
Class
- SocialContentInstagram
- @file Social Content Instagram class.
Code
public function prepareRow($row) {
$settings = $this->settings['instance'];
if (!empty($settings['include']['image']) && !isset($row->images->standard_resolution->url)) {
watchdog('social_content_instagram', 'Missing image URL on Instagram Import', array(), WATCHDOG_WARNING);
}
if (!empty($settings['include']['video']) && empty($settings['include']['image']) && !isset($row->videos)) {
// No point in continuing if we are only meant to import videos but the
// current record does not have any videos.
watchdog('social_content_instagram', 'Missing video URL on Instagram Import', array(), WATCHDOG_WARNING);
return FALSE;
}
$mappings = $this
->getFieldMappings();
$row->created = $row->created_time;
$row->user_id = $row->user->id;
$row->hashtag = $row->tags;
$row->user_name = $row->user->username;
$row->user_link = 'http://instagram.com/' . $row->user_name;
$row->caption = isset($row->caption) ? $row->caption->text : '';
if (parent::prepareRow($row) === FALSE) {
return FALSE;
}
// Save the picture if we need to.
if ($mappings['picture']) {
$validators = array();
if (!empty($settings['min_resolution'])) {
$validators = array(
'file_validate_image_resolution' => array(
0,
$settings['min_resolution'],
),
);
}
$picture = $this
->saveExternalFile($row->images->standard_resolution->url, $mappings['picture'], $validators);
$row->picture = !empty($picture) ? $picture : NULL;
}
// Save the video if we need to.
if (isset($row->videos) && $mappings['video']) {
$video_url = isset($row->videos->standard_resolution) ? $row->videos->standard_resolution->url : $row->videos->low_resolution->url;
$video = $this
->saveExternalFile($video_url, $mappings['video']);
$row->video = !empty($video) ? $video : NULL;
}
// Save the video if we need to.
if (isset($row->videos) && $mappings['video_url']) {
$row->video_url = isset($row->videos->standard_resolution) ? $row->videos->standard_resolution->url : $row->videos->low_resolution->url;
}
}