From e54c5ad3cd7ad705a1838c59b41ceba816b2a3a5 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Wed, 3 Mar 2021 14:48:40 +0100 Subject: [PATCH] Fix codestyle --- .../lib/data/unfurl/url/UnfurlUrl.class.php | 48 ++++++++++--------- .../data/unfurl/url/UnfurlUrlAction.class.php | 28 +++++------ .../data/unfurl/url/UnfurlUrlEditor.class.php | 12 ++--- .../data/unfurl/url/UnfurlUrlList.class.php | 16 +++---- ...s.php => UnfurlUrlBackgroundJob.class.php} | 39 +++++++-------- .../node/HtmlInputNodeProcessor.class.php | 1 - .../html/node/HtmlNodeUnfurlLink.class.php | 8 ++-- .../node/HtmlOutputUnfurlUrlNode.class.php | 12 +++-- .../UnfurlUrlEmbeddedObjectHandler.class.php | 16 +++---- .../files/lib/util/UnfurlUrlUtil.class.php | 34 ++++++------- .../install/files/style/ui/unfurlUrl.scss | 34 ++++++------- 11 files changed, 127 insertions(+), 121 deletions(-) rename wcfsetup/install/files/lib/system/background/job/{UnfurlUrlJob.class.php => UnfurlUrlBackgroundJob.class.php} (91%) diff --git a/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrl.class.php b/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrl.class.php index 3c9215a3c7..0ee207b4a1 100644 --- a/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrl.class.php +++ b/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrl.class.php @@ -11,11 +11,11 @@ use wcf\util\Url; /** * Represents an unfurl url object in the database. * - * @author Joshua Ruesweg + * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH - * @license GNU Lesser General Public License - * @package WoltLabSuite\Core\Data\Unfurl\Url - * @since 5.4 + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Data\Unfurl\Url + * @since 5.4 * * @property-read string $url * @property-read string $urlHash @@ -27,51 +27,55 @@ use wcf\util\Url; */ class UnfurlUrl extends DatabaseObject { - public const IMAGE_SQUARED = "SQUARED"; - public const IMAGE_COVER = "COVER"; - public const IMAGE_NO_IMAGE = "NOIMAGE"; + public const IMAGE_SQUARED = "SQUARED"; - public const STATUS_PENDING = "PENDING"; - public const STATUS_SUCCESSFUL = "SUCCESSFUL"; - public const STATUS_REJECTED = "REJECTED"; + public const IMAGE_COVER = "COVER"; + + public const IMAGE_NO_IMAGE = "NOIMAGE"; + + public const STATUS_PENDING = "PENDING"; + + public const STATUS_SUCCESSFUL = "SUCCESSFUL"; + + public const STATUS_REJECTED = "REJECTED"; /** * Renders the unfurl url card and returns the template. * * @return string */ - public function render() : string + public function render(): string { return WCF::getTPL()->fetch('unfurlUrl', 'wcf', [ 'object' => $this, ]); } - + /** * Returns the hostname of the url. * * @return string */ - public function getHost() : string + public function getHost(): string { $url = Url::parse($this->url); - + return $url['host']; } - + /** * Returns the image url for the url. * * @throws \wcf\system\exception\SystemException */ - public function getImageUrl() : ?string + public function getImageUrl(): ?string { if (!empty($this->imageHash)) { return WCF::getPath() . 'images/unfurlUrl/' . \substr($this->imageHash, 0, 2) . '/' . $this->imageHash; } elseif (!empty($this->imageUrl)) { if (MODULE_IMAGE_PROXY) { $key = CryptoUtil::createSignedString($this->imageUrl); - + return LinkHandler::getInstance()->getLink('ImageProxy', [ 'key' => $key, ]); @@ -80,20 +84,20 @@ class UnfurlUrl extends DatabaseObject } } - return null; + return null; } - + /** * Returns the unfurl url object for a given url. * * @throws \InvalidArgumentException If the given URL is invalid. */ - public static function getByUrl(string $url) : UnfurlUrl + public static function getByUrl(string $url): self { if (!Url::is($url)) { throw new \InvalidArgumentException("Given URL is not a valid URL."); } - + $sql = "SELECT unfurl_url.* FROM wcf" . WCF_N . "_unfurl_url unfurl_url WHERE unfurl_url.urlHash = ?"; @@ -103,7 +107,7 @@ class UnfurlUrl extends DatabaseObject if (!$row) { $row = []; } - + return new self(null, $row); } } diff --git a/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlAction.class.php b/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlAction.class.php index 749a31bf0e..206fb74d07 100644 --- a/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlAction.class.php +++ b/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlAction.class.php @@ -4,19 +4,19 @@ namespace wcf\data\unfurl\url; use wcf\data\AbstractDatabaseObjectAction; use wcf\system\background\BackgroundQueueHandler; -use wcf\system\background\job\UnfurlURLJob; +use wcf\system\background\job\UnfurlUrlBackgroundJob; /** * Contains all dbo actions for unfurl url objects. * - * @author Joshua Ruesweg + * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH - * @license GNU Lesser General Public License - * @package WoltLabSuite\Core\Data\Unfurl\Url - * @since 5.4 + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Data\Unfurl\Url + * @since 5.4 * - * @method UnfurlUrlEditor[] getObjects() - * @method UnfurlUrlEditor getSingleObject() + * @method UnfurlUrlEditor[] getObjects() + * @method UnfurlUrlEditor getSingleObject() */ class UnfurlUrlAction extends AbstractDatabaseObjectAction { @@ -27,16 +27,16 @@ class UnfurlUrlAction extends AbstractDatabaseObjectAction { /** @var UnfurlUrl $object */ $object = parent::create(); - + BackgroundQueueHandler::getInstance()->enqueueIn([ - new UnfurlURLJob($object), + new UnfurlUrlBackgroundJob($object), ]); BackgroundQueueHandler::getInstance()->forceCheck(); - + return $object; } - + /** * Returns the unfurl url object to a given url. * @@ -45,7 +45,7 @@ class UnfurlUrlAction extends AbstractDatabaseObjectAction public function findOrCreate() { $object = UnfurlUrl::getByUrl($this->parameters['data']['url']); - + if (!$object->urlID) { $returnValues = (new self([], 'create', [ 'data' => [ @@ -53,10 +53,10 @@ class UnfurlUrlAction extends AbstractDatabaseObjectAction 'urlHash' => \sha1($this->parameters['data']['url']), ], ]))->executeAction(); - + return $returnValues['returnValues']; } - + return $object; } } diff --git a/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlEditor.class.php b/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlEditor.class.php index e1aedcac45..c1e42f079d 100644 --- a/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlEditor.class.php +++ b/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlEditor.class.php @@ -7,14 +7,14 @@ use wcf\data\DatabaseObjectEditor; /** * Provide functions to edit an unfurl url. * - * @author Joshua Ruesweg + * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH - * @license GNU Lesser General Public License - * @package WoltLabSuite\Core\Data\Unfurl\Url - * @since 5.4 + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Data\Unfurl\Url + * @since 5.4 * - * @method UnfurlUrl getDecoratedObject() - * @mixin UnfurlUrl + * @method UnfurlUrl getDecoratedObject() + * @mixin UnfurlUrl */ class UnfurlUrlEditor extends DatabaseObjectEditor { diff --git a/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlList.class.php b/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlList.class.php index a561b5f22d..d2e7b9901a 100644 --- a/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlList.class.php +++ b/wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrlList.class.php @@ -7,16 +7,16 @@ use wcf\data\DatabaseObjectList; /** * Represents a list of unfurled urls. * - * @author Joshua Ruesweg + * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH - * @license GNU Lesser General Public License - * @package WoltLabSuite\Core\Data\Unfurl\Url - * @since 5.4 + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Data\Unfurl\Url + * @since 5.4 * - * @method UnfurlUrl current() - * @method UnfurlUrl[] getObjects() - * @method UnfurlUrl|null search($objectID) - * @property UnfurlUrl[] $objects + * @method UnfurlUrl current() + * @method UnfurlUrl[] getObjects() + * @method UnfurlUrl|null search($objectID) + * @property UnfurlUrl[] $objects */ class UnfurlUrlList extends DatabaseObjectList { diff --git a/wcfsetup/install/files/lib/system/background/job/UnfurlUrlJob.class.php b/wcfsetup/install/files/lib/system/background/job/UnfurlUrlBackgroundJob.class.php similarity index 91% rename from wcfsetup/install/files/lib/system/background/job/UnfurlUrlJob.class.php rename to wcfsetup/install/files/lib/system/background/job/UnfurlUrlBackgroundJob.class.php index db088ca2bd..954f6d4f05 100644 --- a/wcfsetup/install/files/lib/system/background/job/UnfurlUrlJob.class.php +++ b/wcfsetup/install/files/lib/system/background/job/UnfurlUrlBackgroundJob.class.php @@ -4,7 +4,6 @@ namespace wcf\system\background\job; use wcf\data\unfurl\url\UnfurlUrl; use wcf\data\unfurl\url\UnfurlUrlAction; -use function wcf\functions\exception\logThrowable; use wcf\util\FileUtil; use wcf\util\StringUtil; use wcf\util\UnfurlUrlUtil; @@ -18,13 +17,13 @@ use wcf\util\UnfurlUrlUtil; * @package WoltLabSuite\Core\System\Background\Job * @since 5.4 */ -class UnfurlURLJob extends AbstractBackgroundJob +class UnfurlUrlBackgroundJob extends AbstractBackgroundJob { /** * @var UnfurlUrl */ private $url; - + /** * UnfurlURLJob constructor. * @@ -34,7 +33,7 @@ class UnfurlURLJob extends AbstractBackgroundJob { $this->url = $url; } - + /** * @inheritDoc */ @@ -52,7 +51,7 @@ class UnfurlURLJob extends AbstractBackgroundJob return 2 * 60 * 60; } } - + /** * @inheritDoc */ @@ -60,7 +59,7 @@ class UnfurlURLJob extends AbstractBackgroundJob { try { $url = new UnfurlUrlUtil($this->url->url); - + if (empty(StringUtil::trim($url->getTitle()))) { $urlAction = new UnfurlUrlAction([$this->url], 'update', [ 'data' => [ @@ -78,17 +77,19 @@ class UnfurlURLJob extends AbstractBackgroundJob 'description' => $description !== null ? StringUtil::truncate($description, 500) : '', 'status' => UnfurlUrl::STATUS_SUCCESSFUL, ]; - + if ($url->getImageUrl()) { $image = UnfurlUrlUtil::downloadImageFromUrl($url->getImageUrl()); if ($image !== null) { $imageData = @\getimagesizefromstring($image); - + // filter images which are too large or too small $isSquared = $imageData[0] === $imageData[1]; - if ((!$isSquared && ($imageData[0] < 300 && $imageData[1] < 150)) - || \min($imageData[0], $imageData[1]) < 50) { + if ( + (!$isSquared && ($imageData[0] < 300 && $imageData[1] < 150)) + || \min($imageData[0], $imageData[1]) < 50 + ) { $data['imageType'] = UnfurlUrl::IMAGE_NO_IMAGE; } else { if ($imageData[0] === $imageData[1]) { @@ -98,7 +99,7 @@ class UnfurlURLJob extends AbstractBackgroundJob $data['imageUrl'] = $url->getImageUrl(); $data['imageType'] = UnfurlUrl::IMAGE_COVER; } - + // Download image, if there is no image proxy or external source images allowed. if (!(MODULE_IMAGE_PROXY || IMAGE_ALLOW_EXTERNAL_SOURCE)) { if (isset($data['imageType'])) { @@ -115,33 +116,33 @@ class UnfurlURLJob extends AbstractBackgroundJob default: throw new \RuntimeException(); } - + $data['imageHash'] = \sha1($image) . '.' . $extension; - + $path = WCF_DIR . 'images/unfurlUrl/' . \substr($data['imageHash'], 0, 2); FileUtil::makePath($path); - + $fileLocation = $path . '/' . $data['imageHash']; - + \file_put_contents($fileLocation, $image); - + @\touch($fileLocation); } } } } } - + $urlAction = new UnfurlUrlAction([$this->url], 'update', [ 'data' => $data, ]); $urlAction->executeAction(); } } catch (\InvalidArgumentException $e) { - logThrowable($e); + \wcf\functions\exception\logThrowable($e); } } - + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php index 9ac6dbba61..b0a715355b 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php @@ -2,7 +2,6 @@ namespace wcf\system\html\input\node; -use wcf\data\unfurl\url\UnfurlUrlAction; use wcf\system\bbcode\BBCodeHandler; use wcf\system\event\EventHandler; use wcf\system\html\node\AbstractHtmlNodeProcessor; diff --git a/wcfsetup/install/files/lib/system/html/node/HtmlNodeUnfurlLink.class.php b/wcfsetup/install/files/lib/system/html/node/HtmlNodeUnfurlLink.class.php index 74ff262b9d..af4173d15e 100644 --- a/wcfsetup/install/files/lib/system/html/node/HtmlNodeUnfurlLink.class.php +++ b/wcfsetup/install/files/lib/system/html/node/HtmlNodeUnfurlLink.class.php @@ -7,11 +7,11 @@ use wcf\data\unfurl\url\UnfurlUrlAction; /** * Helper class to unfurl link objects. * - * @author Joshua Ruesweg + * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH - * @license GNU Lesser General Public License - * @package WoltLabSuite\Core\System\Html\Node - * @since 5.4 + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\System\Html\Node + * @since 5.4 */ class HtmlNodeUnfurlLink extends HtmlNodePlainLink { diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputUnfurlUrlNode.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputUnfurlUrlNode.class.php index 4a82c63b62..cc48a352cd 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputUnfurlUrlNode.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputUnfurlUrlNode.class.php @@ -22,7 +22,7 @@ class HtmlOutputUnfurlUrlNode extends AbstractHtmlOutputNode * @inheritDoc */ protected $tagName = 'a'; - + /** * @inheritDoc */ @@ -31,17 +31,19 @@ class HtmlOutputUnfurlUrlNode extends AbstractHtmlOutputNode /** @var \DOMElement $element */ foreach ($elements as $element) { $attribute = $element->getAttribute(HtmlNodeUnfurlLink::UNFURL_URL_ID_ATTRIBUTE_NAME); - if ($this->outputType === 'text/html' + if ( + $this->outputType === 'text/html' && !empty($attribute) - && MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.unfurlUrl', $attribute) !== null) { + && MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.unfurlUrl', $attribute) !== null + ) { $nodeIdentifier = StringUtil::getRandomID(); $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, ['urlId' => $attribute]); - + $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier); } } } - + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/message/embedded/object/UnfurlUrlEmbeddedObjectHandler.class.php b/wcfsetup/install/files/lib/system/message/embedded/object/UnfurlUrlEmbeddedObjectHandler.class.php index b5c30ee503..8ca51145de 100644 --- a/wcfsetup/install/files/lib/system/message/embedded/object/UnfurlUrlEmbeddedObjectHandler.class.php +++ b/wcfsetup/install/files/lib/system/message/embedded/object/UnfurlUrlEmbeddedObjectHandler.class.php @@ -9,11 +9,11 @@ use wcf\system\html\node\HtmlNodeUnfurlLink; /** * Represents the unfurl url embedded object handlers. * - * @author Joshua Ruesweg + * @author Joshua Ruesweg * @copyright 2001-2021 WoltLab GmbH - * @license GNU Lesser General Public License - * @package WoltLabSuite\Core\System\Message\Embedded\Object - * @since 5.4 + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\System\Message\Embedded\Object + * @since 5.4 */ class UnfurlUrlEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandler { @@ -28,7 +28,7 @@ class UnfurlUrlEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandle return $urlList->getObjects(); } - + /** * @inheritDoc */ @@ -37,13 +37,13 @@ class UnfurlUrlEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandle $unfurlUrlIDs = []; foreach ($htmlInputProcessor->getHtmlInputNodeProcessor()->getDocument()->getElementsByTagName('a') as $element) { /** @var \DOMElement $element */ - $id = intval($element->getAttribute(HtmlNodeUnfurlLink::UNFURL_URL_ID_ATTRIBUTE_NAME)); - + $id = \intval($element->getAttribute(HtmlNodeUnfurlLink::UNFURL_URL_ID_ATTRIBUTE_NAME)); + if (!empty($id)) { $unfurlUrlIDs[] = $id; } } - + return $unfurlUrlIDs; } } diff --git a/wcfsetup/install/files/lib/util/UnfurlUrlUtil.class.php b/wcfsetup/install/files/lib/util/UnfurlUrlUtil.class.php index 6814d68e0d..faf446d38e 100644 --- a/wcfsetup/install/files/lib/util/UnfurlUrlUtil.class.php +++ b/wcfsetup/install/files/lib/util/UnfurlUrlUtil.class.php @@ -34,28 +34,28 @@ final class UnfurlUrlUtil * @var string */ private $url; - + /** * @var string */ private $body; - + /** * @var \DOMDocument */ private $domDocument; - + public function __construct(string $url) { if (!Url::is($url)) { throw new \InvalidArgumentException('Given URL "' . $url . '" is not a valid URL.'); } - + $this->url = $url; - + $this->fetchUrl(); } - + /** * Fetches the body of the given url and converts the body to utf-8. */ @@ -70,7 +70,7 @@ final class UnfurlUrlUtil 'range' => \sprintf('bytes=%d-%d', 0, self::MAX_SIZE - 1), ]); $response = $client->send($request); - + $this->body = ""; while (!$response->getBody()->eof()) { $this->body .= $response->getBody()->read(8192); @@ -80,7 +80,7 @@ final class UnfurlUrlUtil } } $response->getBody()->close(); - + if (\mb_detect_encoding($this->body) !== 'UTF-8') { $this->body = StringUtil::convertEncoding(\mb_detect_encoding($this->body), 'UTF-8', $this->body); } @@ -88,7 +88,7 @@ final class UnfurlUrlUtil // Ignore these exceptions. } } - + /** * Returns the dom document of the website. */ @@ -99,10 +99,10 @@ final class UnfurlUrlUtil $this->domDocument = new \DOMDocument(); $this->domDocument->loadHTML('' . $this->body); } - + return $this->domDocument; } - + /** * Determines the title of the website. */ @@ -110,7 +110,7 @@ final class UnfurlUrlUtil { if (!empty($this->body)) { $metaTags = $this->getDomDocument()->getElementsByTagName('meta'); - + // og foreach ($metaTags as $metaTag) { foreach ($metaTag->attributes as $attr) { @@ -123,7 +123,7 @@ final class UnfurlUrlUtil } } } - + // title tag $title = $this->getDomDocument()->getElementsByTagName('title'); if ($title->length) { @@ -133,7 +133,7 @@ final class UnfurlUrlUtil return null; } - + /** * Determines the description of the website. */ @@ -158,7 +158,7 @@ final class UnfurlUrlUtil return null; } - + /** * Returns the image url for the current url. */ @@ -166,7 +166,7 @@ final class UnfurlUrlUtil { if (!empty($this->body)) { $metaTags = $this->getDomDocument()->getElementsByTagName('meta'); - + // og:image foreach ($metaTags as $metaTag) { foreach ($metaTag->attributes as $attr) { @@ -183,7 +183,7 @@ final class UnfurlUrlUtil return null; } - + /** * Downloads the image from a url and returns the image body. */ diff --git a/wcfsetup/install/files/style/ui/unfurlUrl.scss b/wcfsetup/install/files/style/ui/unfurlUrl.scss index 69c8db0367..655fbc0149 100644 --- a/wcfsetup/install/files/style/ui/unfurlUrl.scss +++ b/wcfsetup/install/files/style/ui/unfurlUrl.scss @@ -1,38 +1,38 @@ .unfurlCard { background-color: $wcfContentBackground; - box-shadow: 0 0 3px rgba(0, 0, 0, .12), 0 1px 2px rgba(0, 0, 0, .24); + box-shadow: 0 0 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24); display: inline-block; margin: 20px 0; white-space: nowrap; - + @include screen-md-up { max-width: 700px; } - + @include screen-sm-down { max-width: 100%; } - + > a { color: $wcfContentText; - + .unfurlInformation { position: relative; padding: 10px 20px 20px; } - + .urlTitle { display: block; overflow: hidden; text-overflow: ellipsis; - + @include wcfFontHeadline; } - + .urlDescription { white-space: normal; } - + .urlHost { @include wcfFontSmall; float: right; @@ -40,16 +40,16 @@ bottom: 5px; position: absolute; right: 5px; - + img { height: 12px !important; } } } - + &.unfurlLargeContentImage { min-width: 300px; - + > a > :first-child:not(:last-child) { min-height: 150px; background-position: center; @@ -58,11 +58,11 @@ position: relative; } } - + &.unfurlSquaredContentImage { > a { display: flex; - + > :first-child:not(:last-child) { flex: 0 0 auto; height: 128px !important; @@ -73,13 +73,13 @@ background-size: cover; position: relative; } - + > :last-child { flex: 1 1 auto; overflow: hidden; padding-left: 10px; } - + @include screen-sm-down { > :first-child:not(:last-child) { display: none; @@ -87,4 +87,4 @@ } } } -} \ No newline at end of file +} -- 2.20.1