Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
chore(autoloader): Dump autoloader
Signed-off-by: nextcloud-command <[email protected]>
  • Loading branch information
nextcloud-command committed Jul 14, 2025
commit 95126e94a2f02c24cefd8818482ff8b756b13d6e
71 changes: 38 additions & 33 deletions composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -958,37 +958,42 @@
},
{
"name": "fusonic/opengraph",
"version": "v2.3.0",
"version_normalized": "2.3.0.0",
"version": "v3.0.0",
"version_normalized": "3.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/fusonic/opengraph.git",
"reference": "09dca70b04b4221c9dc664e1689e876a3faa50c2"
"reference": "2daa6dce84f23b1bb6d66bf03b3e9371c39cd378"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fusonic/opengraph/zipball/09dca70b04b4221c9dc664e1689e876a3faa50c2",
"reference": "09dca70b04b4221c9dc664e1689e876a3faa50c2",
"url": "https://api.github.com/repos/fusonic/opengraph/zipball/2daa6dce84f23b1bb6d66bf03b3e9371c39cd378",
"reference": "2daa6dce84f23b1bb6d66bf03b3e9371c39cd378",
"shasum": ""
},
"require": {
"ext-dom": "*",
"php": "^7.4|^8.0",
"php": "^8.1",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"symfony/css-selector": "^3.0|^4.0|^5.0|^6.0",
"symfony/dom-crawler": "^3.0|^4.0|^5.0|^6.0"
"symfony/css-selector": "^5.4 || ^6.4 || ^7.1",
"symfony/dom-crawler": "^5.4 || ^6.4 || ^7.1"
},
"require-dev": {
"nyholm/psr7": "^1.2",
"phpunit/phpunit": "^9.0",
"symfony/http-client": "^6.0"
"friendsofphp/php-cs-fixer": "^3.65",
"nyholm/psr7": "^1.8",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^10.5 || ^11.4",
"symfony/http-client": "^5.4 || ^6.4 || ^7.1"
},
"suggest": {
"nyholm/psr7": "^1.2",
"symfony/http-client": "^5.0"
"nyholm/psr7": "^1.8",
"symfony/http-client": "^5.4 || ^6.4 || ^7.1"
},
"time": "2023-12-05T14:26:51+00:00",
"time": "2025-01-13T07:23:24+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
Expand All @@ -1007,13 +1012,13 @@
}
],
"description": "PHP library for consuming and publishing Open Graph resources.",
"homepage": "https://github.com/fusonic/fusonic-opengraph",
"homepage": "https://github.com/fusonic/opengraph",
"keywords": [
"opengraph"
],
"support": {
"issues": "https://github.com/fusonic/opengraph/issues",
"source": "https://github.com/fusonic/opengraph/tree/v2.3.0"
"source": "https://github.com/fusonic/opengraph/tree/v3.0.0"
},
"install-path": "../fusonic/opengraph"
},
Expand Down Expand Up @@ -4513,23 +4518,23 @@
},
{
"name": "symfony/css-selector",
"version": "v6.4.3",
"version_normalized": "6.4.3.0",
"version": "v6.4.13",
"version_normalized": "6.4.13.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/css-selector.git",
"reference": "ee0f7ed5cf298cc019431bb3b3977ebc52b86229"
"reference": "cb23e97813c5837a041b73a6d63a9ddff0778f5e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/ee0f7ed5cf298cc019431bb3b3977ebc52b86229",
"reference": "ee0f7ed5cf298cc019431bb3b3977ebc52b86229",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/cb23e97813c5837a041b73a6d63a9ddff0778f5e",
"reference": "cb23e97813c5837a041b73a6d63a9ddff0778f5e",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"time": "2024-01-23T14:51:35+00:00",
"time": "2024-09-25T14:18:03+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
Expand Down Expand Up @@ -4561,7 +4566,7 @@
"description": "Converts CSS selectors to XPath expressions",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/css-selector/tree/v6.4.3"
"source": "https://github.com/symfony/css-selector/tree/v6.4.13"
},
"funding": [
{
Expand Down Expand Up @@ -4651,17 +4656,17 @@
},
{
"name": "symfony/dom-crawler",
"version": "v6.4.4",
"version_normalized": "6.4.4.0",
"version": "v6.4.23",
"version_normalized": "6.4.23.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/dom-crawler.git",
"reference": "f0e7ec3fa17000e2d0cb4557b4b47c88a6a63531"
"reference": "22210aacb35dbadd772325d759d17bce2374a84d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/f0e7ec3fa17000e2d0cb4557b4b47c88a6a63531",
"reference": "f0e7ec3fa17000e2d0cb4557b4b47c88a6a63531",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/22210aacb35dbadd772325d759d17bce2374a84d",
"reference": "22210aacb35dbadd772325d759d17bce2374a84d",
"shasum": ""
},
"require": {
Expand All @@ -4673,7 +4678,7 @@
"require-dev": {
"symfony/css-selector": "^5.4|^6.0|^7.0"
},
"time": "2024-02-07T09:17:57+00:00",
"time": "2025-06-13T12:10:00+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
Expand Down Expand Up @@ -4701,7 +4706,7 @@
"description": "Eases DOM navigation for HTML and XML documents",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/dom-crawler/tree/v6.4.4"
"source": "https://github.com/symfony/dom-crawler/tree/v6.4.23"
},
"funding": [
{
Expand Down Expand Up @@ -5134,8 +5139,8 @@
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.31.0",
"version_normalized": "1.31.0.0",
"version": "v1.32.0",
"version_normalized": "1.32.0.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
Expand Down Expand Up @@ -5196,7 +5201,7 @@
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.32.0"
},
"funding": [
{
Expand Down
22 changes: 11 additions & 11 deletions composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@
'dev_requirement' => false,
),
'fusonic/opengraph' => array(
'pretty_version' => 'v2.3.0',
'version' => '2.3.0.0',
'reference' => '09dca70b04b4221c9dc664e1689e876a3faa50c2',
'pretty_version' => 'v3.0.0',
'version' => '3.0.0.0',
'reference' => '2daa6dce84f23b1bb6d66bf03b3e9371c39cd378',
'type' => 'library',
'install_path' => __DIR__ . '/../fusonic/opengraph',
'aliases' => array(),
Expand Down Expand Up @@ -662,9 +662,9 @@
'dev_requirement' => false,
),
'symfony/css-selector' => array(
'pretty_version' => 'v6.4.3',
'version' => '6.4.3.0',
'reference' => 'ee0f7ed5cf298cc019431bb3b3977ebc52b86229',
'pretty_version' => 'v6.4.13',
'version' => '6.4.13.0',
'reference' => 'cb23e97813c5837a041b73a6d63a9ddff0778f5e',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/css-selector',
'aliases' => array(),
Expand All @@ -680,9 +680,9 @@
'dev_requirement' => false,
),
'symfony/dom-crawler' => array(
'pretty_version' => 'v6.4.4',
'version' => '6.4.4.0',
'reference' => 'f0e7ec3fa17000e2d0cb4557b4b47c88a6a63531',
'pretty_version' => 'v6.4.23',
'version' => '6.4.23.0',
'reference' => '22210aacb35dbadd772325d759d17bce2374a84d',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/dom-crawler',
'aliases' => array(),
Expand Down Expand Up @@ -740,8 +740,8 @@
'dev_requirement' => false,
),
'symfony/polyfill-ctype' => array(
'pretty_version' => 'v1.31.0',
'version' => '1.31.0.0',
'pretty_version' => 'v1.32.0',
'version' => '1.32.0.0',
'reference' => 'a3cc8b044a6ea513310cbd48ef7333b384945638',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-ctype',
Expand Down
2 changes: 1 addition & 1 deletion fusonic/opengraph/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 Fusonic GmbH (http://www.fusonic.net)
Copyright (c) 2014-2024 Fusonic GmbH (https://www.fusonic.net)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
72 changes: 36 additions & 36 deletions fusonic/opengraph/src/Consumer.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
<?php

/*
* Copyright (c) Fusonic GmbH. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/

declare(strict_types=1);

namespace Fusonic\OpenGraph;

use Fusonic\OpenGraph\Objects\ObjectBase;
use Fusonic\OpenGraph\Objects\Website;
use LogicException;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Symfony\Component\DomCrawler\Crawler;

/**
* Consumer that extracts Open Graph data from either a URL or a HTML string.
* Consumer that extracts Open Graph data from either a URL or an HTML string.
*/
class Consumer
{
private ?ClientInterface $client;
private ?RequestFactoryInterface $requestFactory;

/**
* When enabled, crawler will read content of title and meta description if no
* Open Graph data is provided by target page.
Expand All @@ -31,33 +34,31 @@ class Consumer
public bool $debug = false;

/**
* @param ClientInterface|null $client A PSR-18 ClientInterface implementation.
* @param RequestFactoryInterface|null $requestFactory A PSR-17 RequestFactoryInterface implementation.
* @param ClientInterface|null $client a PSR-18 ClientInterface implementation
* @param RequestFactoryInterface|null $requestFactory a PSR-17 RequestFactoryInterface implementation
*/
public function __construct(?ClientInterface $client = null, ?RequestFactoryInterface $requestFactory = null)
{
$this->client = $client;
$this->requestFactory = $requestFactory;
public function __construct(
private ?ClientInterface $client = null,
private ?RequestFactoryInterface $requestFactory = null,
) {
}

/**
* Fetches HTML content from the given URL and then crawls it for Open Graph data.
*
* @param string $url URL to be crawled.
*
* @return ObjectBase
* @param string $url URL to be crawled
*
* @throws ClientExceptionInterface
*/
public function loadUrl(string $url): ObjectBase
{
if ($this->client === null) {
throw new LogicException(
"To use loadUrl() you must provide \$client and \$requestFactory when instantiating the consumer."
if (null === $this->client || null === $this->requestFactory) {
throw new \LogicException(
'To use loadUrl() you must provide $client and $requestFactory when instantiating the consumer.'
);
}

$request = $this->requestFactory->createRequest("GET", $url);
$request = $this->requestFactory->createRequest('GET', $url);
$response = $this->client->sendRequest($request);

return $this->loadHtml($response->getBody()->getContents(), $url);
Expand All @@ -66,18 +67,16 @@ public function loadUrl(string $url): ObjectBase
/**
* Crawls the given HTML string for OpenGraph data.
*
* @param string $html HTML string, usually whole content of crawled web resource.
* @param string $fallbackUrl URL to use when fallback mode is enabled.
*
* @return ObjectBase
* @param string $html HTML string, usually whole content of crawled web resource
* @param string|null $fallbackUrl URL to use when fallback mode is enabled
*/
public function loadHtml(string $html, string $fallbackUrl = null): ObjectBase
public function loadHtml(string $html, ?string $fallbackUrl = null): ObjectBase
{
// Extract all data that can be found
$page = $this->extractOpenGraphData($html);

// Use the user's URL as fallback
if ($this->useFallbackMode && $page->url === null) {
if ($this->useFallbackMode && null === $page->url) {
$page->url = $fallbackUrl;
}

Expand All @@ -87,53 +86,54 @@ public function loadHtml(string $html, string $fallbackUrl = null): ObjectBase

private function extractOpenGraphData(string $content): ObjectBase
{
$crawler = new Crawler;
$crawler->addHTMLContent($content, 'UTF-8');
$crawler = new Crawler();
$crawler->addHtmlContent(content: $content);

$properties = [];
foreach(['name', 'property'] as $t)
{
foreach (['name', 'property'] as $t) {
// Get all meta-tags starting with "og:"
$ogMetaTags = $crawler->filter("meta[{$t}^='og:']");

// Create clean property array
$props = [];

/** @var \DOMElement $tag */
foreach ($ogMetaTags as $tag) {
$name = strtolower(trim($tag->getAttribute($t)));
$value = trim($tag->getAttribute("content"));
$value = trim($tag->getAttribute('content'));
$props[] = new Property($name, $value);
}

$properties = array_merge($properties, $props);
}

// Create new object
$object = new Website();

// Assign all properties to the object
$object->assignProperties($properties, $this->debug);

// Fallback for url
if ($this->useFallbackMode && !$object->url) {
if ($this->useFallbackMode && null === $object->url) {
$urlElement = $crawler->filter("link[rel='canonical']")->first();
if ($urlElement->count() > 0) {
$object->url = trim($urlElement->attr("href"));
$object->url = trim($urlElement->attr('href') ?? '');
}
}

// Fallback for title
if ($this->useFallbackMode && !$object->title) {
$titleElement = $crawler->filter("title")->first();
if ($this->useFallbackMode && null === $object->title) {
$titleElement = $crawler->filter('title')->first();
if ($titleElement->count() > 0) {
$object->title = trim($titleElement->text());
}
}

// Fallback for description
if ($this->useFallbackMode && !$object->description) {
if ($this->useFallbackMode && null === $object->description) {
$descriptionElement = $crawler->filter("meta[property='description']")->first();
if ($descriptionElement->count() > 0) {
$object->description = trim($descriptionElement->attr("content"));
$object->description = trim($descriptionElement->attr('content') ?? '');
}
}

Expand Down
Loading