- $url = cleanup_url($_GET['post']);
-
- $link_is_new = false;
- // Check if URL is not already in database (in this case, we will edit the existing link)
- $bookmark = $bookmarkService->findByUrl($url);
- if (! $bookmark) {
- $link_is_new = true;
- // Get title if it was provided in URL (by the bookmarklet).
- $title = empty($_GET['title']) ? '' : escape($_GET['title']);
- // Get description if it was provided in URL (by the bookmarklet). [Bronco added that]
- $description = empty($_GET['description']) ? '' : escape($_GET['description']);
- $tags = empty($_GET['tags']) ? '' : escape($_GET['tags']);
- $private = !empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0;
-
- // If this is an HTTP(S) link, we try go get the page to extract
- // the title (otherwise we will to straight to the edit form.)
- if (empty($title) && strpos(get_url_scheme($url), 'http') !== false) {
- $retrieveDescription = $conf->get('general.retrieve_description');
- // Short timeout to keep the application responsive
- // The callback will fill $charset and $title with data from the downloaded page.
- get_http_response(
- $url,
- $conf->get('general.download_timeout', 30),
- $conf->get('general.download_max_size', 4194304),
- get_curl_download_callback($charset, $title, $description, $tags, $retrieveDescription)
- );
- if (! empty($title) && strtolower($charset) != 'utf-8') {
- $title = mb_convert_encoding($title, 'utf-8', $charset);
- }
- }
-
- if ($url == '') {
- $title = $conf->get('general.default_note_title', t('Note: '));
- }
- $url = escape($url);
- $title = escape($title);
-
- $link = [
- 'title' => $title,
- 'url' => $url,
- 'description' => $description,
- 'tags' => $tags,
- 'private' => $private,
- ];
- } else {
- $factory = new FormatterFactory($conf, $loginManager->isLoggedIn());
- $formatter = $factory->getFormatter('raw');
- $link = $formatter->format($bookmark);
- }
-
- $tags = $bookmarkService->bookmarksCountPerTag();
- if ($conf->get('formatter') === 'markdown') {
- $tags[BookmarkMarkdownFormatter::NO_MD_TAG] = 1;
- }
- $data = [
- 'link' => $link,
- 'link_is_new' => $link_is_new,
- 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
- 'source' => (isset($_GET['source']) ? $_GET['source'] : ''),
- 'tags' => $tags,
- 'default_private_links' => $conf->get('privacy.default_private_links', false),
- ];
- $pluginManager->executeHooks('render_editlink', $data);
-
- foreach ($data as $key => $value) {
- $PAGE->assign($key, $value);
- }
-
- $PAGE->assign('pagetitle', t('Shaare') .' - '. $conf->get('general.title', 'Shaarli'));
- $PAGE->renderPage('editlink');