diff --git a/BookmarkManager.php b/BookmarkManager.php
index 725e9e5..aa476b1 100644
--- a/BookmarkManager.php
+++ b/BookmarkManager.php
@@ -6,6 +6,7 @@
class BookmarkManager
{
+ protected $config;
protected $db;
protected $user;
protected $baseDir;
@@ -14,13 +15,13 @@ class BookmarkManager
public function __construct($requestUri = '/')
{
- $config = require __DIR__.'/config.php';
+ $this->config = require __DIR__.'/config.php';
- if (empty($config['baseDir'])) {
+ if (empty($this->config['baseDir'])) {
throw new \Exception('baseDir not defined in config.php');
}
- $this->baseDir = $config['baseDir'];
+ $this->baseDir = $this->config['baseDir'];
if (!is_dir($this->baseDir)) {
throw new \Exception('invalid baseDir in config.php');
@@ -32,11 +33,11 @@ public function __construct($requestUri = '/')
$this->baseDir = rtrim($this->baseDir, '/').'/';
- if (empty($config['baseUri'])) {
+ if (empty($this->config['baseUri'])) {
throw new \Exception('baseUri not defined in config.php');
}
- $baseUri = rtrim($config['baseUri'], '/').'/';
+ $baseUri = rtrim($this->config['baseUri'], '/').'/';
if (strpos($requestUri, $baseUri) !== 0) {
throw new \Exception('invalid baseuri');
@@ -75,6 +76,15 @@ public function __construct($requestUri = '/')
$this->db = new DB($this->baseDir.$user.'/b.db');
}
+ public function getConfig($key)
+ {
+ if (isset($this->config[$key])) {
+ return $this->config[$key];
+ }
+
+ return false;
+ }
+
public function getDB()
{
return $this->db;
@@ -145,8 +155,8 @@ public function handleAjaxRequest($postData)
$result['result'] = true;
}
- header('Content-Type: application/json');
- echo json_encode($result, JSON_FORCE_OBJECT);
+ header('Content-Type: application/json; charset=utf-8');
+ echo json_encode($result, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE);
exit();
}
diff --git a/DB.php b/DB.php
index 9cd903f..c8944a5 100644
--- a/DB.php
+++ b/DB.php
@@ -55,19 +55,33 @@ public function exists($link)
return (bool) $st->fetch();
}
- public function getEntries($filter = false)
+ public function getEntries($filter = false, $skip = false, $count = false)
{
if (!$filter) {
$filter = '%';
}
- $st = $this->pdo->prepare('
+ if ($skip !== false && $count !== false) {
+ $limit = 'LIMIT :skip, :count';
+ } else {
+ $limit = '';
+ }
+
+ $st = $this->pdo->prepare("
SELECT id, desc, link FROM b
WHERE desc LIKE :filter
ORDER BY date DESC
- ');
+ $limit
+ ");
+
+ $args = [ ':filter' => "%$filter%" ];
+
+ if ($skip !== false && $count !== false) {
+ $args['skip'] = $skip;
+ $args['count'] = $count;
+ }
- $st->execute([ ':filter' => "%$filter%" ]);
+ $st->execute($args);
$ret = $st->fetchAll();
diff --git a/LICENSE b/LICENSE
index 484b4ca..5e1f299 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2011-2016 Sebastian Volland
+Copyright (c) 2011-2017 Sebastian Volland
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 24206da..3e6bc8c 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,14 @@
# b - Bookmark manager
-b is a minimalistic bookmark manager for your own server written in PHP where bookmarks are stored in a sqlite database.
+b is a minimalistic bookmark manager for your own server. Written in PHP.
+Bookmarks are stored in a sqlite database. Features:
+
+ * filtering
+ * tagging
+ * automatic fetching of page title
+ * infinite scrolling (optional)
+ * bookmarklet
+ * multiple users
### Requirements
@@ -10,15 +18,23 @@ b is a minimalistic bookmark manager for your own server written in PHP where bo
### Configuration instructions
- * Copy all repository files to a directory accessible by the webserver-user, like `/var/www/b`
+ * Copy all repository files to a directory accessible by the webserver-user,
+ like `/var/www/b`
* Move `config.template.php` to `config.php` and edit it
- * `baseDir` is the directory where the sqlite dbs are stored, e.g. `/var/bookmarks/`. The directory must be readable and writeable by the webserver-user
- * `baseUri` is the base uri's relative path param, e.g. `/b/` if the website is accessible via `http://example.com/b/`. Or use `/` for `http://bookmarks.example.com/` for example, if you want to have a dedicated subdomain for the service.
- * Create a new user-account simply by creating a new directory in `baseDir`: `mkdir /var/bookmarks/peter/`
+ * `baseDir` is the directory where the sqlite dbs are stored, e.g.
+ `/var/bookmarks/`. The directory must be readable and writeable by the
+ webserver-user
+ * `baseUri` is the base uri's relative path param, e.g. `/b/` if the website
+ is accessible via `http://example.com/b/`. Or use `/` for
+ `http://bookmarks.example.com/` for example, if you want to have a
+ dedicated subdomain for the service.
+ * Create a new user-account simply by creating a new directory in `baseDir`:
+ `mkdir /var/bookmarks/peter/`
#### Webserver configuration example for apache
- * If you want your bookmarks to be accessible under their own subdomain like `http://bookmarks.example.com/`, add a virtual host to your `httpd.conf`:
+ * If you want your bookmarks to be accessible under their own subdomain like
+ `http://bookmarks.example.com/`, add a virtual host to your `httpd.conf`: