X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=e392e501aee16891e6b7c24895b6e51d0130c60f;hb=4c7045229c94973c1cb83193e69463f426ddc35b;hp=5497a23e2adfb3b25ca238c69f0161f6dd03774a;hpb=49bc541d7973bd86776441eb072e66d01b368e68;p=github%2Fshaarli%2FShaarli.git diff --git a/index.php b/index.php index 5497a23e..e392e501 100644 --- a/index.php +++ b/index.php @@ -432,7 +432,7 @@ if (isset($_POST['login'])) // Optional redirect after login: if (isset($_GET['post'])) { $uri = '?post='. urlencode($_GET['post']); - foreach (array('description', 'source', 'title') as $param) { + foreach (array('description', 'source', 'title', 'tags') as $param) { if (!empty($_GET[$param])) { $uri .= '&'.$param.'='.urlencode($_GET[$param]); } @@ -461,7 +461,7 @@ if (isset($_POST['login'])) $redir = '&username='. $_POST['login']; if (isset($_GET['post'])) { $redir .= '&post=' . urlencode($_GET['post']); - foreach (array('description', 'source', 'title') as $param) { + foreach (array('description', 'source', 'title', 'tags') as $param) { if (!empty($_GET[$param])) { $redir .= '&' . $param . '=' . urlencode($_GET[$param]); } @@ -472,34 +472,6 @@ if (isset($_POST['login'])) } } -// ------------------------------------------------------------------------------------------ -// Misc utility functions: - -// Convert post_max_size/upload_max_filesize (e.g. '16M') parameters to bytes. -function return_bytes($val) -{ - $val = trim($val); $last=strtolower($val[strlen($val)-1]); - switch($last) - { - case 'g': $val *= 1024; - case 'm': $val *= 1024; - case 'k': $val *= 1024; - } - return $val; -} - -// Try to determine max file size for uploads (POST). -// Returns an integer (in bytes) -function getMaxFileSize() -{ - $size1 = return_bytes(ini_get('post_max_size')); - $size2 = return_bytes(ini_get('upload_max_filesize')); - // Return the smaller of two: - $maxsize = min($size1,$size2); - // FIXME: Then convert back to readable notations ? (e.g. 2M instead of 2000000) - return $maxsize; -} - // ------------------------------------------------------------------------------------------ // Token management for XSRF protection // Token should be used in any form which acts on data (create,update,delete,import...). @@ -695,9 +667,11 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager) $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, ); @@ -1044,7 +1018,13 @@ function renderPage($conf, $pluginManager, $LINKSDB) // Show login screen, then redirect to ?post=... if (isset($_GET['post'])) { - header('Location: ?do=login&post='.urlencode($_GET['post']).(!empty($_GET['title'])?'&title='.urlencode($_GET['title']):'').(!empty($_GET['description'])?'&description='.urlencode($_GET['description']):'').(!empty($_GET['source'])?'&source='.urlencode($_GET['source']):'')); // Redirect to login page, then back to post link. + header( // Redirect to login page, then back to post link. + 'Location: ?do=login&post='.urlencode($_GET['post']). + (!empty($_GET['title'])?'&title='.urlencode($_GET['title']):''). + (!empty($_GET['description'])?'&description='.urlencode($_GET['description']):''). + (!empty($_GET['tags'])?'&tags='.urlencode($_GET['tags']):''). + (!empty($_GET['source'])?'&source='.urlencode($_GET['source']):'') + ); exit; } @@ -1141,7 +1121,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) $conf->set('feed.rss_permalinks', !empty($_POST['enableRssPermalinks'])); $conf->set('updates.check_updates', !empty($_POST['updateCheck'])); $conf->set('privacy.hide_public_links', !empty($_POST['hidePublicLinks'])); - $conf->set('api.enabled', !empty($_POST['apiEnabled'])); + $conf->set('api.enabled', !empty($_POST['enableApi'])); $conf->set('api.secret', escape($_POST['apiSecret'])); try { $conf->write(isLoggedIn()); @@ -1248,7 +1228,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) } // lf_id should only be present if the link exists. - $id = !empty($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : $LINKSDB->getNextId(); + $id = isset($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : $LINKSDB->getNextId(); // 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 @@ -1321,9 +1301,13 @@ function renderPage($conf, $pluginManager, $LINKSDB) // -------- User clicked the "Cancel" button when editing a link. if (isset($_POST['cancel_edit'])) { + $id = isset($_POST['lf_id']) ? (int) escape($_POST['lf_id']) : false; + if (! isset($LINKSDB[$id])) { + header('Location: ?'); + } // If we are called from the bookmarklet, we must close the popup: if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo ''; exit; } - $link = $LINKSDB[(int) escape($_POST['lf_id'])]; + $link = $LINKSDB[$id]; $returnurl = ( isset($_POST['returnurl']) ? $_POST['returnurl'] : '?' ); // Scroll to the link which has been edited. $returnurl .= '#'. $link['shorturl']; @@ -1508,7 +1492,22 @@ function renderPage($conf, $pluginManager, $LINKSDB) if (! isset($_POST['token']) || ! isset($_FILES['filetoupload'])) { // Show import dialog - $PAGE->assign('maxfilesize', getMaxFileSize()); + $PAGE->assign( + 'maxfilesize', + get_max_upload_size( + ini_get('post_max_size'), + ini_get('upload_max_filesize'), + false + ) + ); + $PAGE->assign( + 'maxfilesizeHuman', + get_max_upload_size( + ini_get('post_max_size'), + ini_get('upload_max_filesize'), + true + ) + ); $PAGE->renderPage('import'); exit; } @@ -1518,7 +1517,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) // The file is too big or some form field may be missing. echo ''; exit; @@ -2227,9 +2226,10 @@ $app = new \Slim\App($container); // REST API routes $app->group('/api/v1', function() { - $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo'); - $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks'); - $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink'); + $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo')->setName('getInfo'); + $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks')->setName('getLinks'); + $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink')->setName('getLink'); + $this->post('/links', '\Shaarli\Api\Controllers\Links:postLink')->setName('postLink'); })->add('\Shaarli\Api\ApiMiddleware'); $response = $app->run(true);