X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=ae0ce8f0e738fa6204b12fbfca3b1ef99b403391;hb=50142efd1b4b826f60b1e5673dba5ccbe26e0108;hp=e1516d37d15d806728c06071fff8b46748fbef68;hpb=fd7d84616d53486c3a276a42da869390e1d7f5eb;p=github%2Fshaarli%2FShaarli.git diff --git a/index.php b/index.php index e1516d37..ae0ce8f0 100644 --- a/index.php +++ b/index.php @@ -436,7 +436,7 @@ if (isset($_POST['login'])) else { ban_loginFailed($conf); - $redir = '&username='. $_POST['login']; + $redir = '&username='. urlencode($_POST['login']); if (isset($_GET['post'])) { $redir .= '&post=' . urlencode($_GET['post']); foreach (array('description', 'source', 'title', 'tags') as $param) { @@ -526,7 +526,11 @@ function showDailyRSS($conf) { // We pre-format some fields for proper output. foreach ($links as &$link) { - $link['formatedDescription'] = format_description($link['description'], $conf->get('redirector.url')); + $link['formatedDescription'] = format_description( + $link['description'], + $conf->get('redirector.url'), + $conf->get('redirector.encode_url') + ); $link['thumbnail'] = thumbnail($conf, $link['url']); $link['timestamp'] = $link['created']->getTimestamp(); if (startsWith($link['url'], '?')) { @@ -598,11 +602,29 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager) $taglist = explode(' ',$link['tags']); uasort($taglist, 'strcasecmp'); $linksToDisplay[$key]['taglist']=$taglist; - $linksToDisplay[$key]['formatedDescription'] = format_description($link['description'], $conf->get('redirector.url')); + $linksToDisplay[$key]['formatedDescription'] = format_description( + $link['description'], + $conf->get('redirector.url'), + $conf->get('redirector.encode_url') + ); $linksToDisplay[$key]['thumbnail'] = thumbnail($conf, $link['url']); $linksToDisplay[$key]['timestamp'] = $link['created']->getTimestamp(); } + $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); + $data = array( + 'pagetitle' => $conf->get('general.title') .' - '. format_date($dayDate, false), + 'linksToDisplay' => $linksToDisplay, + 'day' => $dayDate->getTimestamp(), + 'dayDate' => $dayDate, + 'previousday' => $previousday, + 'nextday' => $nextday, + ); + + /* Hook is called before column construction so that plugins don't have + to deal with columns. */ + $pluginManager->executeHooks('render_daily', $data, array('loggedin' => isLoggedIn())); + /* We need to spread the articles on 3 columns. I did not want to use a JavaScript lib like http://masonry.desandro.com/ so I manually spread entries with a simple method: I roughly evaluate the @@ -610,7 +632,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager) */ $columns = array(array(), array(), array()); // Entries to display, for each column. $fill = array(0, 0, 0); // Rough estimate of columns fill. - foreach($linksToDisplay as $key => $link) { + foreach($data['linksToDisplay'] as $key => $link) { // Roughly estimate length of entry (by counting characters) // Title: 30 chars = 1 line. 1 line is 30 pixels height. // Description: 836 characters gives roughly 342 pixel height. @@ -626,18 +648,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager) $fill[$index] += $length; } - $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); - $data = array( - 'pagetitle' => $conf->get('general.title') .' - '. format_date($dayDate, false), - 'linksToDisplay' => $linksToDisplay, - 'cols' => $columns, - 'day' => $dayDate->getTimestamp(), - 'dayDate' => $dayDate, - 'previousday' => $previousday, - 'nextday' => $nextday, - ); - - $pluginManager->executeHooks('render_daily', $data, array('loggedin' => isLoggedIn())); + $data['cols'] = $columns; foreach ($data as $key => $value) { $pageBuilder->assign($key, $value); @@ -1417,16 +1428,10 @@ 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) { // Short timeout to keep the application responsive - list($headers, $content) = get_http_response($url, 4); - if (strpos($headers[0], '200 OK') !== false) { - // Retrieve charset. - $charset = get_charset($headers, $content); - // Extract title. - $title = html_extract_title($content); - // Re-encode title in utf-8 if necessary. - if (! empty($title) && strtolower($charset) != 'utf-8') { - $title = mb_convert_encoding($title, 'utf-8', $charset); - } + // The callback will fill $charset and $title with data from the downloaded page. + get_http_response($url, 25, 4194304, get_curl_download_callback($charset, $title)); + if (! empty($title) && strtolower($charset) != 'utf-8') { + $title = mb_convert_encoding($title, 'utf-8', $charset); } } @@ -1688,7 +1693,11 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) while ($i<$end && $iget('redirector.url')); + $link['description'] = format_description( + $link['description'], + $conf->get('redirector.url'), + $conf->get('redirector.encode_url') + ); $classLi = ($i % 2) != 0 ? '' : 'publicLinkHightLight'; $link['class'] = $link['private'] == 0 ? $classLi : 'private'; $link['timestamp'] = $link['created']->getTimestamp();