You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.3 KiB

  1. <?php
  2. /*
  3. * SPDX-FileCopyrightText: 2010 Jaussoin Timothée
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Movim;
  7. class EmbedLight
  8. {
  9. public string $title;
  10. public ?string $description;
  11. public string $url;
  12. public string $type = 'text';
  13. public ?string $contentType;
  14. public array $tags = [];
  15. public array $images = [];
  16. public ?string $authorName;
  17. public ?string $authorUrl;
  18. public ?string $providerIcon;
  19. public ?string $providerName;
  20. public ?string $providerUrl;
  21. public ?string $license;
  22. public ?string $publishedTime;
  23. public function __construct($embed)
  24. {
  25. $this->title = $embed->title ? (string)$embed->title : (string)$embed->url;
  26. $this->description = $embed->description;
  27. $this->url = (string)$embed->url;
  28. $this->type = $embed->type;
  29. $this->contentType = $embed->contentType;
  30. $this->tags = (array)$embed->keywords;
  31. $this->authorName = $embed->authorName ? (string)$embed->authorName : null;
  32. $this->authorUrl = $embed->authorUrl ? (string)$embed->authorUrl : null;
  33. $this->providerIcon = $embed->icon ? (string)$embed->icon : null;
  34. $this->providerName = $embed->providerName;
  35. $this->providerUrl = $embed->providerUrl ? (string)$embed->providerUrl : null;
  36. $this->publishedTime = $embed->publishedTime;
  37. // Images
  38. $this->images = [];
  39. if ($this->type == 'image') {
  40. $this->images = [
  41. [
  42. 'url' => (string)$embed->url,
  43. 'size' => $embed->contentLength
  44. ]
  45. ];
  46. } elseif ($embed->image) {
  47. $this->images = [
  48. [
  49. 'url' => (string)$embed->image,
  50. 'size' => 0
  51. ]
  52. ];
  53. } elseif($embed->images) {
  54. foreach ($embed->images as $key => $image) {
  55. $this->images[$key] = [
  56. 'url' => (string)$key,
  57. 'size' => 0
  58. ];
  59. }
  60. }
  61. // Reset the keys
  62. $this->images = array_values($this->images);
  63. return $this;
  64. }
  65. }