)
+ * Template for the list of bookmarks (
)
* This function fills all the necessary fields in the $PAGE for the template 'linklist.html'
*
- * @param pageBuilder $PAGE pageBuilder instance.
- * @param LinkDB $LINKSDB LinkDB instance.
- * @param ConfigManager $conf Configuration Manager instance.
- * @param PluginManager $pluginManager Plugin Manager instance.
- * @param LoginManager $loginManager LoginManager instance
+ * @param pageBuilder $PAGE pageBuilder instance.
+ * @param BookmarkServiceInterface $linkDb LinkDB instance.
+ * @param ConfigManager $conf Configuration Manager instance.
+ * @param PluginManager $pluginManager Plugin Manager instance.
+ * @param LoginManager $loginManager LoginManager instance
*/
-function buildLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager)
+function buildLinkList($PAGE, $linkDb, $conf, $pluginManager, $loginManager)
{
+ $factory = new FormatterFactory($conf, $loginManager->isLoggedIn());
+ $formatter = $factory->getFormatter();
+
// Used in templates
if (isset($_GET['searchtags'])) {
if (! empty($_GET['searchtags'])) {
@@ -1623,19 +1676,19 @@ function buildLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager)
if (! empty($_SERVER['QUERY_STRING'])
&& preg_match('/^[a-zA-Z0-9-_@]{6}($|&|#)/', $_SERVER['QUERY_STRING'])) {
try {
- $linksToDisplay = $LINKSDB->filterHash($_SERVER['QUERY_STRING']);
- } catch (LinkNotFoundException $e) {
+ $linksToDisplay = $linkDb->findByHash($_SERVER['QUERY_STRING']);
+ } catch (BookmarkNotFoundException $e) {
$PAGE->render404($e->getMessage());
exit;
}
} else {
- // Filter links according search parameters.
- $visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : '';
+ // Filter bookmarks according search parameters.
+ $visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : null;
$request = [
'searchtags' => $searchtags,
'searchterm' => $searchterm,
];
- $linksToDisplay = $LINKSDB->filterSearch($request, false, $visibility, !empty($_SESSION['untaggedonly']));
+ $linksToDisplay = $linkDb->search($request, $visibility, false, !empty($_SESSION['untaggedonly']));
}
// ---- Handle paging.
@@ -1661,40 +1714,26 @@ function buildLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager)
$linkDisp = array();
while ($i<$end && $iget('redirector.url'),
- $conf->get('redirector.encode_url')
- );
- $classLi = ($i % 2) != 0 ? '' : 'publicLinkHightLight';
- $link['class'] = $link['private'] == 0 ? $classLi : 'private';
- $link['timestamp'] = $link['created']->getTimestamp();
- if (! empty($link['updated'])) {
- $link['updated_timestamp'] = $link['updated']->getTimestamp();
- } else {
- $link['updated_timestamp'] = '';
- }
- $taglist = preg_split('/\s+/', $link['tags'], -1, PREG_SPLIT_NO_EMPTY);
- uasort($taglist, 'strcasecmp');
- $link['taglist'] = $taglist;
+ $link = $formatter->format($linksToDisplay[$keys[$i]]);
// Logged in, thumbnails enabled, not a note,
// and (never retrieved yet or no valid cache file)
- if ($loginManager->isLoggedIn() && $thumbnailsEnabled && $link['url'][0] != '?'
- && (! isset($link['thumbnail']) || ($link['thumbnail'] !== false && ! is_file($link['thumbnail'])))
+ if ($loginManager->isLoggedIn()
+ && $thumbnailsEnabled
+ && !$linksToDisplay[$keys[$i]]->isNote()
+ && $linksToDisplay[$keys[$i]]->getThumbnail() !== false
+ && ! is_file($linksToDisplay[$keys[$i]]->getThumbnail())
) {
- $elem = $LINKSDB[$keys[$i]];
- $elem['thumbnail'] = $thumbnailer->get($link['url']);
- $LINKSDB[$keys[$i]] = $elem;
+ $linksToDisplay[$keys[$i]]->setThumbnail($thumbnailer->get($link['url']));
+ $linkDb->set($linksToDisplay[$keys[$i]], false);
$updateDB = true;
- $link['thumbnail'] = $elem['thumbnail'];
+ $link['thumbnail'] = $linksToDisplay[$keys[$i]]->getThumbnail();
}
// Check for both signs of a note: starting with ? and 7 chars long.
- if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
- $link['url'] = index_url($_SERVER) . $link['url'];
- }
+// if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
+// $link['url'] = index_url($_SERVER) . $link['url'];
+// }
$linkDisp[$keys[$i]] = $link;
$i++;
@@ -1702,7 +1741,7 @@ function buildLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager)
// If we retrieved new thumbnails, we update the database.
if (!empty($updateDB)) {
- $LINKSDB->save($conf->get('resource.page_cache'));
+ $linkDb->save();
}
// Compute paging navigation
@@ -1727,13 +1766,12 @@ function buildLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager)
'search_term' => $searchterm,
'search_tags' => $searchtags,
'visibility' => ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : '',
- 'redirector' => $conf->get('redirector.url'), // Optional redirector URL.
'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]]['title'] .' - '. $conf->get('general.title');
+ $data['pagetitle'] = $linksToDisplay[$keys[0]]->getTitle() .' - '. $conf->get('general.title');
} elseif (! empty($searchterm) || ! empty($searchtags)) {
$data['pagetitle'] = t('Search: ');
$data['pagetitle'] .= ! empty($searchterm) ? $searchterm .' ' : '';
@@ -1818,7 +1856,7 @@ function install($conf, $sessionManager, $loginManager)
if (!empty($_POST['title'])) {
$conf->set('general.title', escape($_POST['title']));
} else {
- $conf->set('general.title', 'Shared links on '.escape(index_url($_SERVER)));
+ $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']));
@@ -1843,10 +1881,17 @@ function install($conf, $sessionManager, $loginManager)
echo '';
exit;
}
+
+ $history = new History($conf->get('resource.history'));
+ $bookmarkService = new BookmarkFileService($conf, $history, true);
+ if ($bookmarkService->count() === 0) {
+ $bookmarkService->initialize();
+ }
+
echo '';
+ .'Please enter your login/password and start shaaring your bookmarks!"'
+ .');document.location=\'./login\';';
exit;
}
@@ -1859,11 +1904,6 @@ function install($conf, $sessionManager, $loginManager)
exit;
}
-if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=dailyrss')) {
- showDailyRSS($conf, $loginManager);
- exit;
-}
-
if (!isset($_SESSION['LINKS_PER_PAGE'])) {
$_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20);
}
@@ -1874,19 +1914,16 @@ try {
die($e->getMessage());
}
-$linkDb = new LinkDB(
- $conf->get('resource.datastore'),
- $loginManager->isLoggedIn(),
- $conf->get('privacy.hide_public_links'),
- $conf->get('redirector.url'),
- $conf->get('redirector.encode_url')
-);
+$linkDb = new BookmarkFileService($conf, $history, $loginManager->isLoggedIn());
-$container = new \Slim\Container();
-$container['conf'] = $conf;
-$container['plugins'] = $pluginManager;
-$container['history'] = $history;
-$app = new \Slim\App($container);
+if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=dailyrss')) {
+ showDailyRSS($linkDb, $conf, $loginManager);
+ exit;
+}
+
+$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager);
+$container = $containerBuilder->build();
+$app = new App($container);
// REST API routes
$app->group('/api/v1', function () {
@@ -1902,9 +1939,13 @@ $app->group('/api/v1', function () {
$this->put('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:putTag')->setName('putTag');
$this->delete('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:deleteTag')->setName('deleteTag');
- $this->get('/history', '\Shaarli\Api\Controllers\History:getHistory')->setName('getHistory');
+ $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
})->add('\Shaarli\Api\ApiMiddleware');
+$app->group('', function () {
+ $this->get('/login', '\Shaarli\Front\Controller\LoginController:index')->setName('login');
+})->add('\Shaarli\Front\ShaarliMiddleware');
+
$response = $app->run(true);
// Hack to make Slim and Shaarli router work together: