Explorar el Código

Fixing reload of Heartbeat Block
Preventing duplicate images in HeartPost nodes

logicp hace 7 años
padre
commit
d7542289f8
Se han modificado 2 ficheros con 26 adiciones y 9 borrados
  1. 5 2
      src/Form/StatusForm.php
  2. 21 7
      src/StatusHeartPost.php

+ 5 - 2
src/Form/StatusForm.php

@@ -256,9 +256,12 @@ class StatusForm extends FormBase {
 
       if (\Drupal::service('module_handler')
           ->moduleExists('heartbeat') && ($nid !== NULL || $statusEntity !== NULL)) {
-//              $configManager = \Drupal::service('config.manager');
+        //these config settings provide the chosen "Feed" with which to reload the stream
+        //earlier in development, the implementation was centered around selectable feed
+        //types rather than filtering a single feed
+        //TODO decide on the use of feed selections
+        
         $feedConfig = \Drupal::config('heartbeat_feed.settings');
-//              $feedConfig = $feedConfig = $configManager->get('heartbeat_feed.settings');
         $response = new AjaxResponse();
         $response->addCommand(new SelectFeedCommand($feedConfig->get('message')));
         $response->addCommand(new ClearPreviewCommand(true));

+ 21 - 7
src/StatusHeartPost.php

@@ -9,6 +9,7 @@
 namespace Drupal\statusmessage;
 
 
+use Drupal\Component\Utility\UrlHelper;
 use Drupal\node\Entity\Node;
 use Drupal\taxonomy\Entity\Term;
 use Drupal\heartbeat\Entity\Heartbeat;
@@ -117,13 +118,23 @@ class StatusHeartPost implements SharedContentInterface {
   }
 
 
-  private function getMedia()
-  {
-
+  private function getMedia() {
     $fids = array();
 
     if ($images = $this->generator->getImages()) {
-      for ($i = 0; $i < 10; $i++) {
+      $num = count($images) > 10 ? 10 : count($images);
+
+      for ($i = 0; $i < $num; $i++) {
+
+        if ( // Try to skip iterating over duplicate images
+          $i > 0 &&
+          $images[$i]['width'] === $images[$i - 1]['width'] &&
+          $images[$i]['height'] === $images[$i - 1]['height'] &&
+          $images[$i]['size'] === $images[$i - 1]['size']
+        ) {
+          continue;
+        }
+
         if (count($fids) < 6 && $images[$i]['width'] > 400) {
           $ext = strtolower(pathinfo($images[$i]['url'], PATHINFO_EXTENSION));
 
@@ -134,9 +145,12 @@ class StatusHeartPost implements SharedContentInterface {
           $ext = strpos($ext, '?') ? substr($ext, 0, strpos($ext, '?')) : $ext;
           $fileName = strlen($ext) > 0 ? substr($images[$i]['url'], 0, strpos($images[$i]['url'], $ext)) . $ext : $images[$i]['url'];
 
-          $data = file_get_contents($images[$i]['url']);
-          $file = file_save_data($data, 'public://' . substr($fileName, strrpos($fileName, '/') + 1), FILE_EXISTS_REPLACE);
-          $fids[] = $file->id();
+          if (UrlHelper::isValid($images[$i]['url'])) {
+
+            $data = file_get_contents($images[$i]['url']);
+            $file = file_save_data($data, 'public://' . substr($fileName, strrpos($fileName, '/') + 1), FILE_EXISTS_REPLACE);
+            $fids[] = $file->id();
+          }
         }
       }
     } else {