Browse Source

New CSS for statusmessage
added video and photo buttons for form
fixed StatusTwitter parsing to get user picture

logicp 7 years ago
parent
commit
20f4374aaf
5 changed files with 86 additions and 6 deletions
  1. 42 0
      css/statusmessage.css
  2. 4 0
      js/statusmessage.js
  3. 16 0
      src/Form/StatusForm.php
  4. 21 6
      src/StatusTwitter.php
  5. 3 0
      statusmessage.libraries.yml

+ 42 - 0
css/statusmessage.css

@@ -0,0 +1,42 @@
+/*Main Feed Form*/
+
+#edit-mediatabs input[type="radio"] {
+  -webkit-appearance: none;
+  display: inline-block;
+}
+
+#edit-mediatabs .form-item-mediatabs {
+  display: inline-block;
+  position: relative;
+  border-right: 1px solid white;
+
+}
+#edit-mediatabs input.form-radio {
+  background: #928f8e;
+  min-width: 100%;
+  margin-bottom:0;
+  padding: 0em 6em 2.5em 0em;
+  font-weight: 700;
+  display: inline-block;
+}
+
+#edit-mediatabs input.form-radio:hover {
+  background: #500005;
+}
+
+
+#edit-mediatabs input[type="radio"]:checked {
+  background: #003b08;
+}
+
+#edit-mediatabs label {
+  font-size: 1rem;
+  font-weight: 700;
+  color: white;
+  position: absolute;
+  /* left: 50%; */
+  display: inline-block;
+  width: auto;
+  padding-left: 20%;
+  transform: translate(5%, -150%);
+}

+ 4 - 0
js/statusmessage.js

@@ -76,6 +76,9 @@
         console.dir(previewImage.src);
         var outer = document.createElement('div');
         outer.className = 'statusmessage-preview';
+        // var closeButton = document.createElement('button');
+        // closeButton.className('statusmessage-preview-close');
+        // closeButton.innerHTML('✖');
         var titlemarkup = document.createElement('h4');
         titlemarkup.innerHTML = title.innerHTML;
         var descmarkup = document.createElement('p');
@@ -88,6 +91,7 @@
         wrapper.appendChild(titlemarkup);
         wrapper.appendChild(descmarkup);
         wrapper.appendChild(imgmarkup);
+        // wrapper.appendChild(closeButton);
 
         return wrapper;
       }

+ 16 - 0
src/Form/StatusForm.php

@@ -28,6 +28,8 @@ class StatusForm extends FormBase {
 
   protected $previewGenerator;
 
+  private $mediaTabs;
+
   /**
    * {@inheritdoc}
    */
@@ -47,6 +49,7 @@ class StatusForm extends FormBase {
     $this->statusTypeService = $status_type_service;
     $this->statusService = $status_service;
     $this->previewGenerator = $preview_generator;
+    $this->mediaTabs = ['Photo', 'Video'];
   }
 
   /**
@@ -80,6 +83,19 @@ class StatusForm extends FormBase {
       ],
     );
 
+    $form['mediatabs'] = [
+      '#type' => 'radios',
+//      '#description' => $this->t('User selectable feeds'),
+      '#options' => $this->mediaTabs,
+//      '#ajax' => [
+//        'callback' => '::updateFeed',
+////        'event' => 'onclick',
+//        'progress' => array(
+//          'type' => 'none',
+////        'message' => t('Fetching feed'),
+//        ),
+      ];
+
 
     $form['post'] = array(
       '#type' => 'submit',

+ 21 - 6
src/StatusTwitter.php

@@ -134,6 +134,10 @@ class StatusTwitter {
         $tweetNode->set('field_tweet_video', $media->video);
       }
 
+      if ($media->userImage) {
+        $tweetNode->set('field_user_image', $media->userImage);
+      }
+
 
       if ($tweetNode->save()) {
         return $tweetNode->id();
@@ -154,8 +158,6 @@ class StatusTwitter {
     $user = \Drupal::currentUser();
     $ip =  \Drupal::request()->getClientIp();//get user's IP
 
-    $tags = [];
-    $users = [];
     $links = [];
 
     $terms = $this->processTerms($data);
@@ -195,8 +197,17 @@ class StatusTwitter {
 
 
   private function getTweetMedia($data) {
+
     $media = new \stdClass();
+    $images = [];
+    $video = null;
+    $userImage = null;
 
+    if ($data->user->profile_image_url_https) {
+      $userImage = file_get_contents($data->user->profile_image_url_https);
+      $file = file_save_data($userImage);
+      $userImage = $file->id();
+    }
     foreach($data->extended_entities->media as $media)  {
       $image = file_get_contents($media->media_url);
       $file = file_save_data($image);
@@ -221,15 +232,19 @@ class StatusTwitter {
 
       if ($bitrate->index !== null) {
         $data->extended_entities->media[0]->video_info->variants[$bitrate->index]->url;
-        $video = system_retrieve_file($vidUrl, null, TRUE);
-        $file = File::create([
-          'id' => 'id',
-        ])->save();
+//        $video = system_retrieve_file($vidUrl, null, TRUE);
+//        $file = File::create([
+//          'id' => 'id',
+//        ])->save();
+        $video = file_get_contents($data->extended_entities->media[0]->video_info->variants[$bitrate->index]->url);
+        $file = file_save_data($video);
+        $video = $file->id();
       }
     }
 
     $media->images = $images;
     $media->video = $video;
+    $media->userImage = $userImage;
 
     return $media;
   }

+ 3 - 0
statusmessage.libraries.yml

@@ -1,5 +1,8 @@
 status:
   version: 1.x
+  css:
+      theme:
+        css/statusmessage.css: {}
   js:
     js/statusmessage.js: {}
   dependencies: