From: Arthur Date: Thu, 5 May 2016 11:21:36 +0000 (+0200) Subject: Merge pull request #551 from ArthurHoaro/hotfix/timezone X-Git-Tag: v0.7.0~10 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=86deafe0ff5a22a37255546cf82325e89bf272b1;hp=-c;p=github%2Fshaarli%2FShaarli.git Merge pull request #551 from ArthurHoaro/hotfix/timezone Use correct 'UTC' timezone --- 86deafe0ff5a22a37255546cf82325e89bf272b1 diff --combined index.php index e9b0bf40,01122ebf..47bae6e8 --- a/index.php +++ b/index.php @@@ -161,7 -161,6 +161,7 @@@ require_once 'application/HttpUtils.php require_once 'application/LinkDB.php'; require_once 'application/LinkFilter.php'; require_once 'application/LinkUtils.php'; +require_once 'application/NetscapeBookmarkUtils.php'; require_once 'application/TimeZone.php'; require_once 'application/Url.php'; require_once 'application/Utils.php'; @@@ -1277,11 -1276,15 +1277,15 @@@ function renderPage( { if (!empty($_POST['title']) ) { - if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away! + if (!tokenOk($_POST['token'])) { + die('Wrong token.'); // Go away! + } $tz = 'UTC'; - if (!empty($_POST['continent']) && !empty($_POST['city'])) - if (isTimeZoneValid($_POST['continent'],$_POST['city'])) - $tz = $_POST['continent'].'/'.$_POST['city']; + if (!empty($_POST['continent']) && !empty($_POST['city']) + && isTimeZoneValid($_POST['continent'], $_POST['city']) + ) { + $tz = $_POST['continent'] . '/' . $_POST['city']; + } $GLOBALS['timezone'] = $tz; $GLOBALS['title']=$_POST['title']; $GLOBALS['titleLink']=$_POST['titleLink']; @@@ -1519,7 -1522,7 +1523,7 @@@ // -------- User want to post a new link: Display link edit form. if (isset($_GET['post'])) { - $url = cleanup_url(escape($_GET['post'])); + $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) @@@ -1544,8 -1547,8 +1548,8 @@@ // Extract title. $title = html_extract_title($content); // Re-encode title in utf-8 if necessary. - if (! empty($title) && $charset != 'utf-8') { - $title = mb_convert_encoding($title, $charset, 'utf-8'); + if (! empty($title) && strtolower($charset) != 'utf-8') { + $title = mb_convert_encoding($title, 'utf-8', $charset); } } } @@@ -1554,8 -1557,6 +1558,8 @@@ $url = '?' . smallHash($linkdate); $title = 'Note: '; } + $url = escape($url); + $title = escape($title); $link = array( 'linkdate' => $linkdate, @@@ -1587,36 -1588,44 +1591,36 @@@ } // -------- Export as Netscape Bookmarks HTML file. - if ($targetPage == Router::$PAGE_EXPORT) - { - if (empty($_GET['what'])) - { + if ($targetPage == Router::$PAGE_EXPORT) { + if (empty($_GET['selection'])) { $PAGE->assign('linkcount',count($LINKSDB)); $PAGE->renderPage('export'); exit; } - $exportWhat=$_GET['what']; - if (!array_intersect(array('all','public','private'),array($exportWhat))) die('What are you trying to export???'); - header('Content-Type: text/html; charset=utf-8'); - header('Content-disposition: attachment; filename=bookmarks_'.$exportWhat.'_'.strval(date('Ymd_His')).'.html'); - $currentdate=date('Y/m/d H:i:s'); - echo << - - - -Bookmarks -

Bookmarks

-HTML; - foreach($LINKSDB as $link) - { - if ($exportWhat=='all' || - ($exportWhat=='private' && $link['private']!=0) || - ($exportWhat=='public' && $link['private']==0)) - { - $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); - echo '
'.$link['title']."\n"; - if ($link['description']!='') echo '
'.$link['description']."\n"; - } + // export as bookmarks_(all|private|public)_YYYYmmdd_HHMMSS.html + $selection = $_GET['selection']; + try { + $PAGE->assign( + 'links', + NetscapeBookmarkUtils::filterAndFormat($LINKSDB, $selection) + ); + } catch (Exception $exc) { + header('Content-Type: text/plain; charset=utf-8'); + echo $exc->getMessage(); + exit; } - exit; + $now = new DateTime(); + header('Content-Type: text/html; charset=utf-8'); + header( + 'Content-disposition: attachment; filename=bookmarks_' + .$selection.'_'.$now->format(LinkDB::LINK_DATE_FORMAT).'.html' + ); + $PAGE->assign('date', $now->format(DateTime::RFC822)); + $PAGE->assign('eol', PHP_EOL); + $PAGE->assign('selection', $selection); + $PAGE->renderPage('export.bookmarks'); + exit; } // -------- User is uploading a file for import @@@ -2108,10 -2117,10 +2112,10 @@@ function install( if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) { $tz = 'UTC'; - if (!empty($_POST['continent']) && !empty($_POST['city'])) { - if (isTimeZoneValid($_POST['continent'], $_POST['city'])) { - $tz = $_POST['continent'].'/'.$_POST['city']; - } + if (!empty($_POST['continent']) && !empty($_POST['city']) + && isTimeZoneValid($_POST['continent'], $_POST['city']) + ) { + $tz = $_POST['continent'].'/'.$_POST['city']; } $GLOBALS['timezone'] = $tz; // Everything is ok, let's create config file.