X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=9e473936ab0ab76cc3d5d23dfb6cffc6c13c2468;hb=refs%2Ftags%2Fv0.11.0;hp=a14616edc3bf546fb66cc41b5c09c5c4dbff8bfb;hpb=bd231539e93649bf623bb91703131682ad0b0db7;p=github%2Fshaarli%2FShaarli.git diff --git a/index.php b/index.php index a14616ed..9e473936 100644 --- a/index.php +++ b/index.php @@ -1015,6 +1015,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, $conf->set('general.timezone', $tz); $conf->set('general.title', escape($_POST['title'])); $conf->set('general.header_link', escape($_POST['titleLink'])); + $conf->set('general.retrieve_description', !empty($_POST['retrieveDescription'])); $conf->set('resource.theme', escape($_POST['theme'])); $conf->set('security.session_protection_disabled', !empty($_POST['disablesessionprotection'])); $conf->set('privacy.default_private_links', !empty($_POST['privateLinkByDefault'])); @@ -1063,6 +1064,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, ); $PAGE->assign('continents', $continents); $PAGE->assign('cities', $cities); + $PAGE->assign('retrieve_description', $conf->get('general.retrieve_description')); $PAGE->assign('private_links_default', $conf->get('privacy.default_private_links', false)); $PAGE->assign('session_protection_disabled', $conf->get('security.session_protection_disabled', false)); $PAGE->assign('enable_rss_permalinks', $conf->get('feed.rss_permalinks', false)); @@ -1124,22 +1126,24 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, // lf_id should only be present if the link exists. $id = isset($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : $LINKSDB->getNextId(); + $link['id'] = $id; // Linkdate is kept here to: // - use the same permalink for notes as they're displayed when creating them // - let users hack creation date of their posts // See: https://shaarli.readthedocs.io/en/master/guides/various-hacks/#changing-the-timestamp-for-a-shaare $linkdate = escape($_POST['lf_linkdate']); + $link['created'] = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate); if (isset($LINKSDB[$id])) { // Edit - $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate); - $updated = new DateTime(); - $shortUrl = $LINKSDB[$id]['shorturl']; + $link['updated'] = new DateTime(); + $link['shorturl'] = $LINKSDB[$id]['shorturl']; + $link['sticky'] = isset($LINKSDB[$id]['sticky']) ? $LINKSDB[$id]['sticky'] : false; $new = false; } else { // New link - $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate); - $updated = null; - $shortUrl = link_small_hash($created, $id); + $link['updated'] = null; + $link['shorturl'] = link_small_hash($link['created'], $id); + $link['sticky'] = false; $new = true; } @@ -1155,17 +1159,13 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, } $url = whitelist_protocols(trim($_POST['lf_url']), $conf->get('security.allowed_protocols')); - $link = array( - 'id' => $id, + $link = array_merge($link, [ 'title' => trim($_POST['lf_title']), 'url' => $url, 'description' => $_POST['lf_description'], 'private' => (isset($_POST['lf_private']) ? 1 : 0), - 'created' => $created, - 'updated' => $updated, 'tags' => str_replace(',', ' ', $tags), - 'shorturl' => $shortUrl, - ); + ]); // If title is empty, use the URL as title. if ($link['title'] == '') { @@ -1179,8 +1179,6 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, $link['thumbnail'] = $thumbnailer->get($url); } - $link['sticky'] = isset($link['sticky']) ? $link['sticky'] : false; - $pluginManager->executeHooks('save_link', $link); $LINKSDB[$id] = $link; @@ -1364,13 +1362,14 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, // 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) + get_curl_download_callback($charset, $title, $description, $tags, $retrieveDescription) ); if (! empty($title) && strtolower($charset) != 'utf-8') { $title = mb_convert_encoding($title, 'utf-8', $charset); @@ -1564,6 +1563,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, if ($targetPage == Router::$PAGE_SAVE_PLUGINSADMIN) { try { if (isset($_POST['parameters_form'])) { + $pluginManager->executeHooks('save_plugin_parameters', $_POST); unset($_POST['parameters_form']); foreach ($_POST as $param => $value) { $conf->set('plugins.'. $param, escape($value));