Skip to content
Snippets Groups Projects

Resolve #3450880 "Add checks for"

1 file
+ 45
0
Compare changes
  • Side-by-side
  • Inline
@@ -130,6 +130,16 @@ class HootsuitePostManager implements HootsuitePostManagerInterface {
@@ -130,6 +130,16 @@ class HootsuitePostManager implements HootsuitePostManagerInterface {
$image = File::load($imageId);
$image = File::load($imageId);
if ($image != NULL) {
if ($image != NULL) {
 
// Check if image is square for instagram.
 
$profile_meta_data = $this->getProfileMetadata($assignment);
 
if (stripos($profile_meta_data['type'], 'instagram') !== FALSE && !$this->checkImageSquare($image)) {
 
$this->messenger->addError(
 
$this->t('Post for @profile could not be posted as the image needs to be square for instagram.',
 
['@profile' => $assignment->field_hs_profile_name->value])
 
);
 
return;
 
}
 
// Upload image to aws.
// Upload image to aws.
if (($id = $this->uploadImage($image)) !== FALSE) {
if (($id = $this->uploadImage($image)) !== FALSE) {
$requestBody['media'] = [['id' => $id]];
$requestBody['media'] = [['id' => $id]];
@@ -399,4 +409,39 @@ class HootsuitePostManager implements HootsuitePostManagerInterface {
@@ -399,4 +409,39 @@ class HootsuitePostManager implements HootsuitePostManagerInterface {
return TRUE;
return TRUE;
}
}
 
/**
 
* Check if image is square.
 
*
 
* @param \Drupal\file\Entity\File $image
 
* The image to check.
 
*
 
* @return bool
 
* Whether the image is square.
 
*/
 
protected function checkImageSquare(File $image) {
 
$imageUri = $image->getFileUri();
 
$imageInfo = getimagesize($imageUri);
 
if ($imageInfo[0] === $imageInfo[1]) {
 
return TRUE;
 
}
 
return FALSE;
 
}
 
 
/**
 
* {@inheritdoc}
 
*/
 
public function getProfileMetadata(Assignment $assignment): array {
 
// Get meta data of profile.
 
$endpoint = $this->config->get('url_social_profiles_endpoint') . '/' . $assignment->field_hs_profile_id->value;
 
$response = $this->hootsuiteClient->connect('get', $endpoint);
 
if (empty($response)) {
 
return [];
 
}
 
$data = Json::decode($response);
 
if (!empty($data['data'])) {
 
return $data['data'];
 
}
 
return [];
 
}
 
}
}
Loading