Browse Source

Major updates

logicp 7 years ago
parent
commit
3b4ebe80c0

+ 4 - 4
config/schema/statusmessage.schema.yml

@@ -19,12 +19,12 @@ instagram_api.config:
   type: config_object
   label: 'Credentials to authenticate with Instagram API'
   mapping:
-    client_id:
+    oauth_access_token:
           type: text
-          label: 'Client ID'
-    client_secret:
+          label: 'Access Token'
+    oauth_access_token_secret:
           type: text
-          label: 'Client Secret'
+          label: 'Access Token Secret'
     consumer_key:
           type: text
           label: 'Consumer key'

+ 3 - 0
css/preview.css

@@ -0,0 +1,3 @@
+img.statusmessage-image {
+  max-height: 320px;
+}

+ 5 - 0
js/statusmessage.js

@@ -35,11 +35,16 @@
                   oldPreviewIframe.parentNode.removeChild(oldPreviewIframe);
 
                 }
+                var cssLink = document.createElement("link")
+                cssLink.href = "/modules/statusmessage/css/preview.css";
+                cssLink .rel = "stylesheet";
+                cssLink .type = "text/css";
                 previewIframe = document.createElement('iframe');
                 previewIframe.classList.add('statusmessage-preview-iframe');
                 statusTextBox.parentNode.appendChild(previewIframe);
                 previewIframe.contentWindow.document.open();
                 previewIframe.contentWindow.document.appendChild(markup);
+                previewIframe.contentWindow.document.documentElement.appendChild(cssLink);
                 previewIframe.contentWindow.document.close();
               }
             }

+ 132 - 0
src/Controller/ContentController.php

@@ -0,0 +1,132 @@
+<?php
+
+namespace Drupal\statusmessage\Controller;
+
+use Drupal\Core\Controller\ControllerBase;
+use Drupal\statusmessage\Entity\Status;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Core\Entity\EntityTypeManager;
+use Drupal\Core\Entity\Query\QueryFactory;
+use Drupal\statusmessage\StatusService;
+use Drupal\statusmessage\StatusTypeService;
+
+/**
+ * Class ContentController.
+ */
+class ContentController extends ControllerBase {
+
+  /**
+   * Drupal\Core\Entity\EntityTypeManager definition.
+   *
+   * @var \Drupal\Core\Entity\EntityTypeManager
+   */
+  protected $entityTypeManager;
+  /**
+   * Drupal\Core\Entity\Query\QueryFactory definition.
+   *
+   * @var \Drupal\Core\Entity\Query\QueryFactory
+   */
+  protected $entityQuery;
+  /**
+   * Drupal\statusmessage\StatusService definition.
+   *
+   * @var \Drupal\statusmessage\StatusService
+   */
+  protected $statusService;
+  /**
+   * Drupal\statusmessage\StatusTypeService definition.
+   *
+   * @var \Drupal\statusmessage\StatusTypeService
+   */
+  protected $statusTypeService;
+
+  /**
+   * Constructs a new ContentController object.
+   */
+  public function __construct(EntityTypeManager $entity_type_manager, QueryFactory $entity_query, StatusService $statusservice, StatusTypeService $status_type_service) {
+    $this->entityTypeManager = $entity_type_manager;
+    $this->entityQuery = $entity_query;
+    $this->statusService = $statusservice;
+    $this->statusTypeService = $status_type_service;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('entity_type.manager'),
+      $container->get('entity.query'),
+      $container->get('statusservice'),
+      $container->get('status_type_service')
+    );
+  }
+
+  /**
+   * Info.
+   *
+   * @return string
+   *   Return Hello string.
+   */
+  public function info() {
+    return [
+      '#type' => 'markup',
+      '#markup' => $this->t('Implement method: info')
+    ];
+  }
+
+  public function getStatusMessages() {
+
+    $data = file_get_contents("public://statusmessages.dat");
+    $statusmessages = unserialize($data);
+    $errors = false;
+    if (is_array($statusmessages)) {
+      $statusmessages = array_reverse($statusmessages);
+      foreach ($statusmessages as $statusMessage) {
+
+        if ($statusMessage instanceof \Drupal\statusmessage\Entity\Status) {
+//          try {
+//            $heartbeat->save();
+//          } catch (\Exception $e) {
+//            $message = $e->getMessage();
+//          }
+//        }
+
+
+          $status = Status::create([
+//            'uid' => $heartbeat->getOwnerId(),
+//            'nid' => $heartbeat->getNid()->getValue()[0]['target_id'],
+//            'name' => $title,
+//            'type' => $heartbeat->getType(),
+//            'message' => $heartbeat->getMessage()->getValue()[0]['value']
+          ]);
+
+          if (!$status->save()) {
+            $errors = true;
+          }
+        }
+      }
+    }
+    $result = $errors ? 'Error restoring statusmessages' : 'statusmessages restored';
+
+    return [
+      '#type' => 'markup',
+      '#markup' => $this->t($result),
+    ];
+
+  }
+//
+  public function deleteStatusMessages() {
+    $entities = \Drupal::service("entity.query")->get("status")->execute();
+    foreach($entities as $entity) {
+      $status = $this->entityTypeManager()->getStorage("status")->load($entity);
+      $status->delete();
+    }
+
+    return [
+      '#type' => 'markup',
+      '#markup' => $this->t('Deleting them statusmessages')
+    ];
+  }
+
+}

+ 0 - 1
src/Entity/Status.php

@@ -256,7 +256,6 @@ class Status extends ContentEntityBase implements StatusInterface {
       ->setRevisionable(TRUE)
       ->setDisplayOptions('view', array(
         'label' => 'above',
-        'type' => 'full_html',
         'weight' => -4,
       ));
 

+ 25 - 32
src/Form/StatusForm.php

@@ -129,7 +129,6 @@ class StatusForm extends FormBase {
       ]
 
     );
-$stophere = null;
     return $form;
   }
 
@@ -206,17 +205,13 @@ $stophere = null;
       preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $message, $match);
 
       if ($this->markupgenerator !== NULL && !empty($match) && array_values($match)[0] !== NULL) {
-
         $url = is_array(array_values($match)[0]) ? array_values(array_values($match)[0])[0] : array_values($match)[0];
 
         if (strpos($message, 'twitter')) {
-
-
           $statusTwitter = new StatusTwitter($url);
           $nid = $statusTwitter->sendRequest();
 
         } else if (strpos($message, 'youtube') || strpos($message, 'youtu.be')) {
-
           $statusYoutube = new StatusYoutube($url, $message);
           $nid = $statusYoutube->generateNode();
 
@@ -225,43 +220,41 @@ $stophere = null;
           $nid = $statusHeartPost->sendRequest();
 
         }
-
       }
 
       if ($nid === NULL && !empty($this->statusTypeService)) {
-        $statusCreated = false;
+        $sTypes = $this->statusTypeService->loadAll();
         foreach ($this->statusTypeService->loadAll() as $type) {
-          if (!$statusCreated && !$type->getMedia()) {
-
-            $userViewed = \Drupal::routeMatch()
-              ->getParameters()
-              ->get('user') === NULL ? \Drupal::currentUser()
-              ->id() : \Drupal::routeMatch()
-              ->getParameters()
-              ->get('user')
-              ->id();
-
-            if ($userViewed !== NULL) {
-
-              $statusEntity = Status::create([
-                'type' => $type->id(),
-                'uid' => \Drupal::currentUser()->id(),
-                'recipient' => $userViewed
-              ]);
-
-              $statusEntity->setMessage($message);
-              if ($statusEntity->save()) {
-                $statusCreated = TRUE;
-              }
+          $userViewed = \Drupal::routeMatch()
+            ->getParameters()
+            ->get('user') === NULL ? \Drupal::currentUser()
+            ->id() : \Drupal::routeMatch()
+            ->getParameters()
+            ->get('user')
+            ->id();
+
+          if ($userViewed !== NULL) {
+            $statusEntity = Status::create([
+              'type' => $type->id(),
+              'uid' => \Drupal::currentUser()->id(),
+              'recipient' => $userViewed
+            ]);
+
+            if ($type->getMedia() && $file !== null) {
+              $statusEntity->set('field_image', array_values($file)[0]);
             }
+            $statusEntity->setMessage($message);
+          }
+
+          if (!empty($statusEntity) && $statusEntity->save()) {
+            //TODO Log or error report
+            $statusCreated = TRUE;
           }
         }
       }
 
       if (\Drupal::service('module_handler')
-          ->moduleExists('heartbeat') && ($nid !== NULL || $statusEntity !== NULL)
-      ) {
-
+          ->moduleExists('heartbeat') && ($nid !== NULL || $statusEntity !== NULL)) {
 //              $configManager = \Drupal::service('config.manager');
         $feedConfig = \Drupal::config('heartbeat_feed.settings');
 //              $feedConfig = $feedConfig = $configManager->get('heartbeat_feed.settings');

+ 1 - 0
src/StatusTwitter.php

@@ -209,6 +209,7 @@ class StatusTwitter {
       $userImage = file_get_contents($data->user->profile_image_url_https);
       $file = file_save_data($userImage, 'public://' . substr($data->user->profile_image_url_https, strrpos($data->user->profile_image_url_https, '/') + 1), FILE_EXISTS_REPLACE);
 
+
       $userImage = $file->id();
     }
     foreach($data->extended_entities->media as $media)  {

+ 22 - 0
statusmessage.module

@@ -38,9 +38,31 @@ function statusmessage_theme() {
     'variables' => ['content' => NULL],
     'file' => 'status.page.inc',
   ];
+//  $theme['status-form'] = [
+//    'variables' => array(
+//      'messages' => NULL,
+//      'zilla' => 2,
+//    )
+//  ];
+//  $theme['status-form-element'] = [
+//    'render element' => 'element'
+//  ];
+//    'template' => 'status-form',
+
+
   return $theme;
 }
 
+/**
+ * Implements hook_form_alter().
+ */
+//function statusmessage_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
+//  if ($form_id == 'status_form') {
+//    $form['#theme'] = ['status-form'];
+//  }
+//
+//}
+
 /**
 * Implements hook_theme_suggestions_HOOK().
 */

+ 17 - 0
statusmessage.routing.yml

@@ -40,3 +40,20 @@ statusmessage.instagram_api_form:
   requirements:
     _access: 'TRUE'
 
+
+statusmessage.content_controller_info:
+  path: '/statusmessage/info'
+  defaults:
+    _controller: '\Drupal\statusmessage\Controller\ContentController::info'
+    _title: 'info'
+  requirements:
+    _permission: 'access content'
+
+
+statusmessage.delete:
+  path: '/statusmessage/delete'
+  defaults:
+    _controller: '\Drupal\statusmessage\Controller\ContentController::deleteStatusMessages'
+    _title: 'info'
+  requirements:
+    _permission: 'access content'

+ 95 - 0
templates/status-form-element.html.twig

@@ -0,0 +1,95 @@
+{#
+/**
+ * @file
+ * Theme override for a form element.
+ *
+ * Available variables:
+ * - attributes: HTML attributes for the containing element.
+ * - errors: (optional) Any errors for this form element, may not be set.
+ * - prefix: (optional) The form element prefix, may not be set.
+ * - suffix: (optional) The form element suffix, may not be set.
+ * - required: The required marker, or empty if the associated form element is
+ *   not required.
+ * - type: The type of the element.
+ * - name: The name of the element.
+ * - label: A rendered label element.
+ * - label_display: Label display setting. It can have these values:
+ *   - before: The label is output before the element. This is the default.
+ *     The label includes the #title and the required marker, if #required.
+ *   - after: The label is output after the element. For example, this is used
+ *     for radio and checkbox #type elements. If the #title is empty but the
+ *     field is #required, the label will contain only the required marker.
+ *   - invisible: Labels are critical for screen readers to enable them to
+ *     properly navigate through forms but can be visually distracting. This
+ *     property hides the label for everyone except screen readers.
+ *   - attribute: Set the title attribute on the element to create a tooltip but
+ *     output no label element. This is supported only for checkboxes and radios
+ *     in \Drupal\Core\Render\Element\CompositeFormElementTrait::preRenderCompositeFormElement().
+ *     It is used where a visual label is not needed, such as a table of
+ *     checkboxes where the row and column provide the context. The tooltip will
+ *     include the title and required marker.
+ * - description: (optional) A list of description properties containing:
+ *    - content: A description of the form element, may not be set.
+ *    - attributes: (optional) A list of HTML attributes to apply to the
+ *      description content wrapper. Will only be set when description is set.
+ * - description_display: Description display setting. It can have these values:
+ *   - before: The description is output before the element.
+ *   - after: The description is output after the element. This is the default
+ *     value.
+ *   - invisible: The description is output after the element, hidden visually
+ *     but available to screen readers.
+ * - disabled: True if the element is disabled.
+ * - title_display: Title display setting.
+ *
+ * @see template_preprocess_form_element()
+ */
+#}
+{%
+set classes = [
+'js-form-item',
+'form-item',
+'js-form-type-' ~ type|clean_class,
+'form-type-' ~ type|clean_class,
+'js-form-item-' ~ name|clean_class,
+'form-item-' ~ name|clean_class,
+title_display not in ['after', 'before'] ? 'form-no-label',
+disabled == 'disabled' ? 'form-disabled',
+errors ? 'form-item--error',
+]
+%}
+{%
+set description_classes = [
+'description',
+description_display == 'invisible' ? 'visually-hidden',
+]
+%}
+<div{{ attributes.addClass(classes) }}>
+  {% if label_display in ['before', 'invisible'] %}
+    {{ label }}
+  {% endif %}
+  {% if prefix is not empty %}
+    <span class="field-prefix">{{ prefix }}</span>
+  {% endif %}
+  {% if description_display == 'before' and description.content %}
+    <div{{ description.attributes }}>
+      {{ description.content }}
+    </div>
+  {% endif %}
+  {{ children }}
+  {% if suffix is not empty %}
+    <span class="field-suffix">{{ suffix }}</span>
+  {% endif %}
+  {% if label_display == 'after' %}
+    {{ label }}
+  {% endif %}
+  {% if errors %}
+    <div class="form-item--error-message">
+      <strong>{{ errors }}</strong>
+    </div>
+  {% endif %}
+  {% if description_display in ['after', 'invisible'] and description.content %}
+    <div{{ description.attributes.addClass(description_classes) }}>
+      {{ description.content }}
+    </div>
+  {% endif %}
+</div>

+ 15 - 0
templates/status-form.html.twig

@@ -0,0 +1,15 @@
+{#
+/**
+ * @file
+ * Theme override for a 'form' element.
+ *
+ * Available variables
+ * - attributes: A list of HTML attributes for the wrapper element.
+ * - children: The child elements of the form.
+ *
+ * @see template_preprocess_form()
+ */
+#}
+<form{{ attributes }}>
+  {{ children }}
+</form>