X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=cc7f3ca3497feaf96288b61f718997eb0c3a09cf;hb=15162272f46a3ae6e93a9f405173e0c770219fff;hp=62d719e1141cd757d18242b93da8c305cec371ef;hpb=adc4aee80f7cd3242f65f0b316af2b560a64712c;p=github%2Fshaarli%2FShaarli.git diff --git a/index.php b/index.php index 62d719e1..cc7f3ca3 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ /shaarli/ define('WEB_PATH', substr($_SERVER['REQUEST_URI'], 0, 1+strrpos($_SERVER['REQUEST_URI'], '/', 0))); @@ -62,7 +62,6 @@ require_once __DIR__ . '/vendor/autoload.php'; require_once 'application/ApplicationUtils.php'; require_once 'application/Cache.php'; require_once 'application/CachedPage.php'; -require_once 'application/config/ConfigManager.php'; require_once 'application/config/ConfigPlugin.php'; require_once 'application/FeedBuilder.php'; require_once 'application/FileUtils.php'; @@ -79,10 +78,12 @@ require_once 'application/Utils.php'; require_once 'application/PluginManager.php'; require_once 'application/Router.php'; require_once 'application/Updater.php'; +use \Shaarli\ThemeUtils; +use \Shaarli\Config\ConfigManager; // Ensure the PHP version is supported try { - ApplicationUtils::checkPHPVersion('5.3', PHP_VERSION); + ApplicationUtils::checkPHPVersion('5.5', PHP_VERSION); } catch(Exception $exc) { header('Content-Type: text/plain; charset=utf-8'); echo $exc->getMessage(); @@ -122,7 +123,6 @@ if (isset($_COOKIE['shaarli']) && !is_session_id_valid($_COOKIE['shaarli'])) { $conf = new ConfigManager(); $conf->setEmpty('general.timezone', date_default_timezone_get()); $conf->setEmpty('general.title', 'Shared links on '. escape(index_url($_SERVER))); -$conf->setEmpty('resource.theme', 'default'); RainTPL::$tpl_dir = $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme').'/'; // template directory RainTPL::$cache_dir = $conf->get('resource.raintpl_tmp'); // cache directory @@ -204,7 +204,7 @@ function setup_login_state($conf) } // If session does not exist on server side, or IP address has changed, or session has expired, logout. if (empty($_SESSION['uid']) - || ($conf->get('security.session_protection_disabled') == false && $_SESSION['ip'] != allIPs()) + || ($conf->get('security.session_protection_disabled') === false && $_SESSION['ip'] != allIPs()) || time() >= $_SESSION['expires_on']) { logout(); @@ -618,7 +618,7 @@ function showDailyRSS($conf) { $tpl->assign('links', $links); $tpl->assign('rssdate', escape($dayDate->format(DateTime::RSS))); $tpl->assign('hide_timestamps', $conf->get('privacy.hide_timestamps', false)); - $html = $tpl->draw('dailyrss', $return_string=true); + $html = $tpl->draw('dailyrss', true); echo $html . PHP_EOL; } @@ -1012,7 +1012,12 @@ function renderPage($conf, $pluginManager, $LINKSDB) $_SESSION['LINKS_PER_PAGE']=abs(intval($_GET['linksperpage'])); } - header('Location: '. generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('linksperpage'))); + if (! empty($_SERVER['HTTP_REFERER'])) { + $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('linksperpage')); + } else { + $location = '?'; + } + header('Location: '. $location); exit; } @@ -1024,7 +1029,12 @@ function renderPage($conf, $pluginManager, $LINKSDB) unset($_SESSION['privateonly']); // See all links } - header('Location: '. generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('privateonly'))); + if (! empty($_SERVER['HTTP_REFERER'])) { + $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('privateonly')); + } else { + $location = '?'; + } + header('Location: '. $location); exit; } @@ -1155,7 +1165,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) { $PAGE->assign('title', $conf->get('general.title')); $PAGE->assign('theme', $conf->get('resource.theme')); - $PAGE->assign('theme_available', getAllTheme($conf->get('resource.raintpl_tpl'))); + $PAGE->assign('theme_available', ThemeUtils::getThemes($conf->get('resource.raintpl_tpl'))); $PAGE->assign('redirector', $conf->get('redirector.url')); list($timezone_form, $timezone_js) = generateTimeZoneForm($conf->get('general.timezone')); $PAGE->assign('timezone_form', $timezone_form); @@ -1198,7 +1208,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) $LINKSDB[$key]=$value; } $LINKSDB->save($conf->get('resource.page_cache')); - echo ''; + echo ''; exit; } @@ -1207,15 +1217,15 @@ function renderPage($conf, $pluginManager, $LINKSDB) $needle = trim($_POST['fromtag']); // True for case-sensitive tag search. $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true); - foreach($linksToAlter as $key=>$value) - { - $tags = explode(' ',trim($value['tags'])); - $tags[array_search($needle,$tags)] = trim($_POST['totag']); // Replace tags value. - $value['tags']=trim(implode(' ',$tags)); - $LINKSDB[$key]=$value; + foreach($linksToAlter as $key=>$value) { + $tags = preg_split('/\s+/', trim($value['tags'])); + // Replace tags value. + $tags[array_search($needle, $tags)] = trim($_POST['totag']); + $value['tags'] = implode(' ', array_unique($tags)); + $LINKSDB[$key] = $value; } $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk. - echo ''; + echo ''; exit; } } @@ -1339,31 +1349,15 @@ function renderPage($conf, $pluginManager, $LINKSDB) // If we are called from the bookmarklet, we must close the popup: if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo ''; exit; } - // Pick where we're going to redirect - // ============================================================= - // Basically, we can't redirect to where we were previously if it was a permalink - // or an edit_link, because it would 404. - // Cases: - // - / : nothing in $_GET, redirect to self - // - /?page : redirect to self - // - /?searchterm : redirect to self (there might be other links) - // - /?searchtags : redirect to self - // - /permalink : redirect to / (the link does not exist anymore) - // - /?edit_link : redirect to / (the link does not exist anymore) - // PHP treats the permalink as a $_GET variable, so we need to check if every condition for self - // redirect is not satisfied, and only then redirect to / - $location = "?"; - // Self redirection - if (count($_GET) == 0 - || isset($_GET['page']) - || isset($_GET['searchterm']) - || isset($_GET['searchtags']) - ) { - if (isset($_POST['returnurl'])) { - $location = $_POST['returnurl']; // Handle redirects given by the form - } else { - $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('delete_link')); - } + + $location = '?'; + if (isset($_SERVER['HTTP_REFERER'])) { + // Don't redirect to where we were previously if it was a permalink or an edit_link, because it would 404. + $location = generateLocation( + $_SERVER['HTTP_REFERER'], + $_SERVER['HTTP_HOST'], + ['delete_link', 'edit_link', $link['shorturl']] + ); } header('Location: ' . $location); // After deleting the link, redirect to appropriate location @@ -1534,7 +1528,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) $_POST, $_FILES, $LINKSDB, - $conf->get('resource.page_cache') + $conf ); echo ''; @@ -1620,8 +1614,8 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) } } else { // Filter links according search parameters. - $privateonly = !empty($_SESSION['privateonly']); - $linksToDisplay = $LINKSDB->filterSearch($_GET, false, $privateonly); + $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all'; + $linksToDisplay = $LINKSDB->filterSearch($_GET, false, $visibility); } // ---- Handle paging. @@ -1688,6 +1682,7 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) 'result_count' => count($linksToDisplay), 'search_term' => $searchterm, 'search_tags' => $searchtags, + 'visibility' => ! empty($_SESSION['privateonly']) ? 'private' : '', 'redirector' => $conf->get('redirector.url'), // Optional redirector URL. 'links' => $linkDisp, 'tags' => $LINKSDB->allTags(), @@ -2237,12 +2232,14 @@ $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'); })->add('\Shaarli\Api\ApiMiddleware'); $response = $app->run(true); // Hack to make Slim and Shaarli router work together: -// If a Slim route isn't found, we call renderPage(). -if ($response->getStatusCode() == 404) { +// If a Slim route isn't found and NOT API call, we call renderPage(). +if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], '/api/v1') === false) { // We use UTF-8 for proper international characters handling. header('Content-Type: text/html; charset=utf-8'); renderPage($conf, $pluginManager, $linkDb);