-
- // Compute paging navigation
- $searchtagsUrl = $searchtags === '' ? '' : '&searchtags=' . urlencode($searchtags);
- $searchtermUrl = empty($searchterm) ? '' : '&searchterm=' . urlencode($searchterm);
- $previous_page_url = '';
- if ($i != count($keys)) {
- $previous_page_url = '?page=' . ($page+1) . $searchtermUrl . $searchtagsUrl;
- }
- $next_page_url='';
- if ($page>1) {
- $next_page_url = '?page=' . ($page-1) . $searchtermUrl . $searchtagsUrl;
- }
-
- // Fill all template fields.
- $data = array(
- 'previous_page_url' => $previous_page_url,
- 'next_page_url' => $next_page_url,
- 'page_current' => $page,
- 'page_max' => $pagecount,
- 'result_count' => count($linksToDisplay),
- 'search_term' => $searchterm,
- 'search_tags' => $searchtags,
- 'visibility' => ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : '',
- 'links' => $linkDisp,
- );
-
- // If there is only a single link, we change on-the-fly the title of the page.
- if (count($linksToDisplay) == 1) {
- $data['pagetitle'] = $linksToDisplay[$keys[0]]->getTitle() .' - '. $conf->get('general.title');
- } elseif (! empty($searchterm) || ! empty($searchtags)) {
- $data['pagetitle'] = t('Search: ');
- $data['pagetitle'] .= ! empty($searchterm) ? $searchterm .' ' : '';
- $bracketWrap = function ($tag) {
- return '['. $tag .']';
- };
- $data['pagetitle'] .= ! empty($searchtags)
- ? implode(' ', array_map($bracketWrap, preg_split('/\s+/', $searchtags))).' '
- : '';
- $data['pagetitle'] .= '- '. $conf->get('general.title');
- }
-
- $pluginManager->executeHooks('render_linklist', $data, array('loggedin' => $loginManager->isLoggedIn()));
-
- foreach ($data as $key => $value) {
- $PAGE->assign($key, $value);
- }
-
- return;
-}
-
-/**
- * Installation
- * This function should NEVER be called if the file data/config.php exists.
- *
- * @param ConfigManager $conf Configuration Manager instance.
- * @param SessionManager $sessionManager SessionManager instance
- * @param LoginManager $loginManager LoginManager instance
- */
-function install($conf, $sessionManager, $loginManager)
-{
- // On free.fr host, make sure the /sessions directory exists, otherwise login will not work.
- if (endsWith($_SERVER['HTTP_HOST'], '.free.fr') && !is_dir($_SERVER['DOCUMENT_ROOT'].'/sessions')) {
- mkdir($_SERVER['DOCUMENT_ROOT'].'/sessions', 0705);
- }
-
-
- // This part makes sure sessions works correctly.
- // (Because on some hosts, session.save_path may not be set correctly,
- // or we may not have write access to it.)
- if (isset($_GET['test_session'])
- && ( !isset($_SESSION) || !isset($_SESSION['session_tested']) || $_SESSION['session_tested']!='Working')) {
- // Step 2: Check if data in session is correct.
- $msg = t(
- '<pre>Sessions do not seem to work correctly on your server.<br>'.
- 'Make sure the variable "session.save_path" is set correctly in your PHP config, '.
- 'and that you have write access to it.<br>'.
- 'It currently points to %s.<br>'.
- 'On some browsers, accessing your server via a hostname like \'localhost\' '.
- 'or any custom hostname without a dot causes cookie storage to fail. '.
- 'We recommend accessing your server via it\'s IP address or Fully Qualified Domain Name.<br>'
- );
- $msg = sprintf($msg, session_save_path());
- echo $msg;
- echo '<br><a href="?">'. t('Click to try again.') .'</a></pre>';
- die;
- }
- if (!isset($_SESSION['session_tested'])) {
- // Step 1 : Try to store data in session and reload page.
- $_SESSION['session_tested'] = 'Working'; // Try to set a variable in session.
- header('Location: '.index_url($_SERVER).'?test_session'); // Redirect to check stored data.
- }
- if (isset($_GET['test_session'])) {
- // Step 3: Sessions are OK. Remove test parameter from URL.
- header('Location: '.index_url($_SERVER));
- }
-
-
- if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) {
- $tz = 'UTC';
- if (!empty($_POST['continent']) && !empty($_POST['city'])
- && isTimeZoneValid($_POST['continent'], $_POST['city'])
- ) {
- $tz = $_POST['continent'].'/'.$_POST['city'];
- }
- $conf->set('general.timezone', $tz);
- $login = $_POST['setlogin'];
- $conf->set('credentials.login', $login);
- $salt = sha1(uniqid('', true) .'_'. mt_rand());
- $conf->set('credentials.salt', $salt);
- $conf->set('credentials.hash', sha1($_POST['setpassword'] . $login . $salt));
- if (!empty($_POST['title'])) {
- $conf->set('general.title', escape($_POST['title']));
- } else {
- $conf->set('general.title', 'Shared bookmarks on '.escape(index_url($_SERVER)));
- }
- $conf->set('translation.language', escape($_POST['language']));
- $conf->set('updates.check_updates', !empty($_POST['updateCheck']));
- $conf->set('api.enabled', !empty($_POST['enableApi']));
- $conf->set(
- 'api.secret',
- generate_api_secret(
- $conf->get('credentials.login'),
- $conf->get('credentials.salt')
- )
- );
- try {
- // Everything is ok, let's create config file.
- $conf->write($loginManager->isLoggedIn());
- } catch (Exception $e) {
- error_log(
- 'ERROR while writing config file after installation.' . PHP_EOL .
- $e->getMessage()
- );
-
- // TODO: do not handle exceptions/errors in JS.
- echo '<script>alert("'. $e->getMessage() .'");document.location=\'?\';</script>';
- exit;
- }
-
- $history = new History($conf->get('resource.history'));
- $bookmarkService = new BookmarkFileService($conf, $history, true);
- if ($bookmarkService->count() === 0) {
- $bookmarkService->initialize();
- }
-
- echo '<script>alert('
- .'"Shaarli is now configured. '
- .'Please enter your login/password and start shaaring your bookmarks!"'
- .');document.location=\'./login\';</script>';
- exit;
- }
-
- $PAGE = new PageBuilder($conf, $_SESSION, null, $sessionManager->generateToken());
- list($continents, $cities) = generateTimeZoneData(timezone_identifiers_list(), date_default_timezone_get());
- $PAGE->assign('continents', $continents);
- $PAGE->assign('cities', $cities);
- $PAGE->assign('languages', Languages::getAvailableLanguages());
- $PAGE->renderPage('install');
- exit;
-}
-
-if (!isset($_SESSION['LINKS_PER_PAGE'])) {
- $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20);
-}
-
-try {
- $history = new History($conf->get('resource.history'));
-} catch (Exception $e) {
- die($e->getMessage());
-}
-
-$linkDb = new BookmarkFileService($conf, $history, $loginManager->isLoggedIn());
-
-if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=dailyrss')) {
- header('Location: ./daily-rss');
- exit;
-}
-
-$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager);
-$container = $containerBuilder->build();
-$app = new App($container);