data['url']; $hash = md5($url); $date = now(); $path = sprintf('%s/%s/%s', static::$section, $date->format('Y/m/d'), $hash); $bundle = new Bundle($path, $this->disk); if ($bundle->exists()) { throw new BundleAlreadyExists( sprintf('A bundle already exists in %s', $path) ); } $browser = new Browser($url); $browser->go(); $screenshot = $browser->getScreenshot(); $title = $browser->getTitle(); $description = $browser->getDescription(); $ref = $bundle->attachments(AttachmentsManager::Images)->addToHistory('screenshot', [ 'contents' => $screenshot, 'filename' => sprintf('screenshot-%s.jpg', now()->format('Y-m-d')), ]); $bundle->metadata()->setMany([ 'title' => $title, 'date' => $date->toIso8601String(), 'cover' => $ref, ]); $bundle->metadata('metadata')->set('links.Page originale', [$url]); $bundle->markdown()->set('> ' . $description . "\n\n"); $bundle->save(); return $path; } /** * Return a boolean value indicating if the creator can actually make the * bundle using known data. */ public function canCreateBundle(): bool { return !empty($this->data['url']); } /** * Return an array describing what kind of data the creator needs in * addition to the one it already has */ public function formSpecs(): ?array { $specs = []; if (empty($this->data['url'])) { $specs['url'] = fn () => text('Interesting link URL', '', '', true, [ 'url' => 'url', ]); } return $specs; } /** * Return a boolean value indicating if this creator in particular can * create bundles for specified section */ public static function handles(string $section, ?array $data = []): bool { return $section === static::$section; } }