diff options
-rw-r--r-- | CONTRIBUTING.md | 1 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | application/LinkDB.php | 8 | ||||
-rw-r--r-- | inc/awesomplete.css | 3 | ||||
-rw-r--r-- | inc/shaarli.css | 11 | ||||
-rw-r--r-- | index.php | 34 | ||||
-rw-r--r-- | tests/LinkDBTest.php | 37 |
7 files changed, 70 insertions, 26 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b819e0b9..054b9a3f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md | |||
@@ -57,6 +57,7 @@ Please report any problem you might find. | |||
57 | * starting from branch ` master`, switch to a new branch (eg. `git checkout -b my-awesome-feature`) | 57 | * starting from branch ` master`, switch to a new branch (eg. `git checkout -b my-awesome-feature`) |
58 | * edit the required files (from the Github web interface or your text editor) | 58 | * edit the required files (from the Github web interface or your text editor) |
59 | * add and commit your changes with a meaningful commit message (eg `Cool new feature, fixes issue #1001`) | 59 | * add and commit your changes with a meaningful commit message (eg `Cool new feature, fixes issue #1001`) |
60 | * run unit tests against your patched version, see [Running unit tests](https://github.com/shaarli/Shaarli/wiki/Running-unit-tests) | ||
60 | * Open your fork in the Github web interface and click the "Compare and Pull Request" button, enter required info and submit your Pull Request. | 61 | * Open your fork in the Github web interface and click the "Compare and Pull Request" button, enter required info and submit your Pull Request. |
61 | 62 | ||
62 | All changes you will do on the `my-awesome-feature` in the future will be added to your Pull Request. Don't work directly on the master branch, don't do unrelated work on your `my-awesome-feature` branch. | 63 | All changes you will do on the `my-awesome-feature` in the future will be added to your Pull Request. Don't work directly on the master branch, don't do unrelated work on your `my-awesome-feature` branch. |
@@ -5,7 +5,7 @@ Shaarli, the personal, minimalist, super-fast, no-database delicious clone. | |||
5 | You want to share the links you discover ? Shaarli is a minimalist delicious clone you can install on your own website. | 5 | You want to share the links you discover ? Shaarli is a minimalist delicious clone you can install on your own website. |
6 | It is designed to be personal (single-user), fast and handy. | 6 | It is designed to be personal (single-user), fast and handy. |
7 | 7 | ||
8 | [![Join the chat at https://gitter.im/shaarli/Shaarli](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/shaarli/Shaarli) [![Bountysource](https://www.bountysource.com/badge/team?team_id=19583&style=bounties_received)](https://www.bountysource.com/teams/shaarli/issues) | 8 | [![Join the chat at https://gitter.im/shaarli/Shaarli](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/shaarli/Shaarli) [![Bountysource](https://www.bountysource.com/badge/team?team_id=19583&style=bounties_received)](https://www.bountysource.com/teams/shaarli/issues) [![](https://api.travis-ci.org/shaarli/Shaarli.svg)](https://travis-ci.org/shaarli/Shaarli) |
9 | 9 | ||
10 | ## Features: | 10 | ## Features: |
11 | 11 | ||
diff --git a/application/LinkDB.php b/application/LinkDB.php index 0f7c5bfe..2b3fb60b 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php | |||
@@ -45,6 +45,9 @@ class LinkDB implements Iterator, Countable, ArrayAccess | |||
45 | // Is the user logged in? (used to filter private links) | 45 | // Is the user logged in? (used to filter private links) |
46 | private $loggedIn; | 46 | private $loggedIn; |
47 | 47 | ||
48 | // Hide public links | ||
49 | private $hidePublicLinks; | ||
50 | |||
48 | /** | 51 | /** |
49 | * Creates a new LinkDB | 52 | * Creates a new LinkDB |
50 | * | 53 | * |
@@ -52,10 +55,11 @@ class LinkDB implements Iterator, Countable, ArrayAccess | |||
52 | * | 55 | * |
53 | * @param $isLoggedIn is the user logged in? | 56 | * @param $isLoggedIn is the user logged in? |
54 | */ | 57 | */ |
55 | function __construct($isLoggedIn) | 58 | function __construct($isLoggedIn, $hidePublicLinks) |
56 | { | 59 | { |
57 | // FIXME: do not access $GLOBALS, pass the datastore instead | 60 | // FIXME: do not access $GLOBALS, pass the datastore instead |
58 | $this->loggedIn = $isLoggedIn; | 61 | $this->loggedIn = $isLoggedIn; |
62 | $this->hidePublicLinks = $hidePublicLinks; | ||
59 | $this->checkDB(); | 63 | $this->checkDB(); |
60 | $this->readdb(); | 64 | $this->readdb(); |
61 | } | 65 | } |
@@ -210,7 +214,7 @@ class LinkDB implements Iterator, Countable, ArrayAccess | |||
210 | { | 214 | { |
211 | 215 | ||
212 | // Public links are hidden and user not logged in => nothing to show | 216 | // Public links are hidden and user not logged in => nothing to show |
213 | if ($GLOBALS['config']['HIDE_PUBLIC_LINKS'] && !isLoggedIn()) { | 217 | if ($this->hidePublicLinks && !$this->loggedIn) { |
214 | $this->links = array(); | 218 | $this->links = array(); |
215 | return; | 219 | return; |
216 | } | 220 | } |
diff --git a/inc/awesomplete.css b/inc/awesomplete.css index 76f903f7..0382e139 100644 --- a/inc/awesomplete.css +++ b/inc/awesomplete.css | |||
@@ -8,7 +8,6 @@ | |||
8 | div.awesomplete { | 8 | div.awesomplete { |
9 | display: inline-block; | 9 | display: inline-block; |
10 | position: relative; | 10 | position: relative; |
11 | width: 100%; | ||
12 | } | 11 | } |
13 | 12 | ||
14 | div.awesomplete > input { | 13 | div.awesomplete > input { |
@@ -94,4 +93,4 @@ div.awesomplete li:hover mark { | |||
94 | div.awesomplete li[aria-selected="true"] mark { | 93 | div.awesomplete li[aria-selected="true"] mark { |
95 | background: hsl(86, 102%, 21%); | 94 | background: hsl(86, 102%, 21%); |
96 | color: inherit; | 95 | color: inherit; |
97 | } \ No newline at end of file | 96 | } |
diff --git a/inc/shaarli.css b/inc/shaarli.css index fcd5c6a2..95732da8 100644 --- a/inc/shaarli.css +++ b/inc/shaarli.css | |||
@@ -221,12 +221,7 @@ h1 { | |||
221 | margin-left:24px; | 221 | margin-left:24px; |
222 | } | 222 | } |
223 | 223 | ||
224 | .tagfilter div.awesomplete { | ||
225 | width: inherit; | ||
226 | } | ||
227 | |||
228 | .tagfilter #tagfilter_value { | 224 | .tagfilter #tagfilter_value { |
229 | width: 100%; | ||
230 | display: inline; | 225 | display: inline; |
231 | } | 226 | } |
232 | 227 | ||
@@ -349,6 +344,7 @@ h1 { | |||
349 | } | 344 | } |
350 | 345 | ||
351 | #headerform label { | 346 | #headerform label { |
347 | cursor: pointer; | ||
352 | margin-right: 10px; | 348 | margin-right: 10px; |
353 | } | 349 | } |
354 | 350 | ||
@@ -976,6 +972,11 @@ div.dailyNoEntry { | |||
976 | 972 | ||
977 | @media handheld, only screen and (max-width: 480px), only screen and (max-device-width: 854px) { | 973 | @media handheld, only screen and (max-width: 480px), only screen and (max-device-width: 854px) { |
978 | /* A few fixes for mobile devices (far from perfect). */ | 974 | /* A few fixes for mobile devices (far from perfect). */ |
975 | |||
976 | .tagfilter div.awesomplete { | ||
977 | width: 70%; | ||
978 | } | ||
979 | |||
979 | .nomobile { | 980 | .nomobile { |
980 | display: none; | 981 | display: none; |
981 | } | 982 | } |
@@ -716,7 +716,11 @@ function showRSS() | |||
716 | $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } | 716 | $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } |
717 | 717 | ||
718 | // If cached was not found (or not usable), then read the database and build the response: | 718 | // If cached was not found (or not usable), then read the database and build the response: |
719 | $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if user it not logged in). | 719 | $LINKSDB = new LinkDB( |
720 | isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'], | ||
721 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'] | ||
722 | ); | ||
723 | // Read links from database (and filter private links if user it not logged in). | ||
720 | 724 | ||
721 | // Optionally filter the results: | 725 | // Optionally filter the results: |
722 | $linksToDisplay=array(); | 726 | $linksToDisplay=array(); |
@@ -791,7 +795,11 @@ function showATOM() | |||
791 | $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } | 795 | $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } |
792 | // If cached was not found (or not usable), then read the database and build the response: | 796 | // If cached was not found (or not usable), then read the database and build the response: |
793 | 797 | ||
794 | $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in). | 798 | // Read links from database (and filter private links if used it not logged in). |
799 | $LINKSDB = new LinkDB( | ||
800 | isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'], | ||
801 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'] | ||
802 | ); | ||
795 | 803 | ||
796 | // Optionally filter the results: | 804 | // Optionally filter the results: |
797 | $linksToDisplay=array(); | 805 | $linksToDisplay=array(); |
@@ -872,7 +880,12 @@ function showDailyRSS() | |||
872 | $cache = new pageCache(pageUrl(),startsWith($query,'do=dailyrss') && !isLoggedIn()); | 880 | $cache = new pageCache(pageUrl(),startsWith($query,'do=dailyrss') && !isLoggedIn()); |
873 | $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } | 881 | $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } |
874 | // If cached was not found (or not usable), then read the database and build the response: | 882 | // If cached was not found (or not usable), then read the database and build the response: |
875 | $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in). | 883 | |
884 | // Read links from database (and filter private links if used it not logged in). | ||
885 | $LINKSDB = new LinkDB( | ||
886 | isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'], | ||
887 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'] | ||
888 | ); | ||
876 | 889 | ||
877 | /* Some Shaarlies may have very few links, so we need to look | 890 | /* Some Shaarlies may have very few links, so we need to look |
878 | back in time (rsort()) until we have enough days ($nb_of_days). | 891 | back in time (rsort()) until we have enough days ($nb_of_days). |
@@ -940,7 +953,10 @@ function showDailyRSS() | |||
940 | // "Daily" page. | 953 | // "Daily" page. |
941 | function showDaily() | 954 | function showDaily() |
942 | { | 955 | { |
943 | $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in). | 956 | $LINKSDB = new LinkDB( |
957 | isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'], | ||
958 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'] | ||
959 | ); | ||
944 | 960 | ||
945 | $day=Date('Ymd',strtotime('-1 day')); // Yesterday, in format YYYYMMDD. | 961 | $day=Date('Ymd',strtotime('-1 day')); // Yesterday, in format YYYYMMDD. |
946 | if (isset($_GET['day'])) $day=$_GET['day']; | 962 | if (isset($_GET['day'])) $day=$_GET['day']; |
@@ -1006,7 +1022,10 @@ function showDaily() | |||
1006 | // Render HTML page (according to URL parameters and user rights) | 1022 | // Render HTML page (according to URL parameters and user rights) |
1007 | function renderPage() | 1023 | function renderPage() |
1008 | { | 1024 | { |
1009 | $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in). | 1025 | $LINKSDB = new LinkDB( |
1026 | isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'], | ||
1027 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'] | ||
1028 | ); | ||
1010 | 1029 | ||
1011 | // -------- Display login form. | 1030 | // -------- Display login form. |
1012 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=login')) | 1031 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=login')) |
@@ -1584,7 +1603,10 @@ HTML; | |||
1584 | function importFile() | 1603 | function importFile() |
1585 | { | 1604 | { |
1586 | if (!(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'])) { die('Not allowed.'); } | 1605 | if (!(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'])) { die('Not allowed.'); } |
1587 | $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in). | 1606 | $LINKSDB = new LinkDB( |
1607 | isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'], | ||
1608 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'] | ||
1609 | ); | ||
1588 | $filename=$_FILES['filetoupload']['name']; | 1610 | $filename=$_FILES['filetoupload']['name']; |
1589 | $filesize=$_FILES['filetoupload']['size']; | 1611 | $filesize=$_FILES['filetoupload']['size']; |
1590 | $data=file_get_contents($_FILES['filetoupload']['tmp_name']); | 1612 | $data=file_get_contents($_FILES['filetoupload']['tmp_name']); |
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index bbe4e026..f67d4d9b 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -41,8 +41,8 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
41 | self::$refDB->write(self::$testDatastore, PHPPREFIX, PHPSUFFIX); | 41 | self::$refDB->write(self::$testDatastore, PHPPREFIX, PHPSUFFIX); |
42 | 42 | ||
43 | $GLOBALS['config']['DATASTORE'] = self::$testDatastore; | 43 | $GLOBALS['config']['DATASTORE'] = self::$testDatastore; |
44 | self::$publicLinkDB = new LinkDB(false); | 44 | self::$publicLinkDB = new LinkDB(false, false); |
45 | self::$privateLinkDB = new LinkDB(true); | 45 | self::$privateLinkDB = new LinkDB(true, false); |
46 | } | 46 | } |
47 | 47 | ||
48 | /** | 48 | /** |
@@ -76,7 +76,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
76 | */ | 76 | */ |
77 | public function testConstructLoggedIn() | 77 | public function testConstructLoggedIn() |
78 | { | 78 | { |
79 | new LinkDB(true); | 79 | new LinkDB(true, false); |
80 | $this->assertFileExists(self::$testDatastore); | 80 | $this->assertFileExists(self::$testDatastore); |
81 | } | 81 | } |
82 | 82 | ||
@@ -85,7 +85,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
85 | */ | 85 | */ |
86 | public function testConstructLoggedOut() | 86 | public function testConstructLoggedOut() |
87 | { | 87 | { |
88 | new LinkDB(false); | 88 | new LinkDB(false, false); |
89 | $this->assertFileExists(self::$testDatastore); | 89 | $this->assertFileExists(self::$testDatastore); |
90 | } | 90 | } |
91 | 91 | ||
@@ -98,7 +98,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
98 | public function testConstructDatastoreNotWriteable() | 98 | public function testConstructDatastoreNotWriteable() |
99 | { | 99 | { |
100 | $GLOBALS['config']['DATASTORE'] = 'null/store.db'; | 100 | $GLOBALS['config']['DATASTORE'] = 'null/store.db'; |
101 | new LinkDB(false); | 101 | new LinkDB(false, false); |
102 | } | 102 | } |
103 | 103 | ||
104 | /** | 104 | /** |
@@ -106,7 +106,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
106 | */ | 106 | */ |
107 | public function testCheckDBNew() | 107 | public function testCheckDBNew() |
108 | { | 108 | { |
109 | $linkDB = new LinkDB(false); | 109 | $linkDB = new LinkDB(false, false); |
110 | unlink(self::$testDatastore); | 110 | unlink(self::$testDatastore); |
111 | $this->assertFileNotExists(self::$testDatastore); | 111 | $this->assertFileNotExists(self::$testDatastore); |
112 | 112 | ||
@@ -126,7 +126,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
126 | */ | 126 | */ |
127 | public function testCheckDBLoad() | 127 | public function testCheckDBLoad() |
128 | { | 128 | { |
129 | $linkDB = new LinkDB(false); | 129 | $linkDB = new LinkDB(false, false); |
130 | $this->assertEquals( | 130 | $this->assertEquals( |
131 | self::$dummyDatastoreSHA1, | 131 | self::$dummyDatastoreSHA1, |
132 | sha1_file(self::$testDatastore) | 132 | sha1_file(self::$testDatastore) |
@@ -148,7 +148,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
148 | public function testReadEmptyDB() | 148 | public function testReadEmptyDB() |
149 | { | 149 | { |
150 | file_put_contents(self::$testDatastore, PHPPREFIX.'S7QysKquBQA='.PHPSUFFIX); | 150 | file_put_contents(self::$testDatastore, PHPPREFIX.'S7QysKquBQA='.PHPSUFFIX); |
151 | $emptyDB = new LinkDB(false); | 151 | $emptyDB = new LinkDB(false, false); |
152 | $this->assertEquals(0, sizeof($emptyDB)); | 152 | $this->assertEquals(0, sizeof($emptyDB)); |
153 | $this->assertEquals(0, count($emptyDB)); | 153 | $this->assertEquals(0, count($emptyDB)); |
154 | } | 154 | } |
@@ -180,7 +180,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
180 | */ | 180 | */ |
181 | public function testSaveDB() | 181 | public function testSaveDB() |
182 | { | 182 | { |
183 | $testDB = new LinkDB(true); | 183 | $testDB = new LinkDB(true, false); |
184 | $dbSize = sizeof($testDB); | 184 | $dbSize = sizeof($testDB); |
185 | 185 | ||
186 | $link = array( | 186 | $link = array( |
@@ -198,7 +198,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
198 | 198 | ||
199 | $testDB->savedb(); | 199 | $testDB->savedb(); |
200 | 200 | ||
201 | $testDB = new LinkDB(true); | 201 | $testDB = new LinkDB(true, false); |
202 | $this->assertEquals($dbSize + 1, sizeof($testDB)); | 202 | $this->assertEquals($dbSize + 1, sizeof($testDB)); |
203 | } | 203 | } |
204 | 204 | ||
@@ -218,6 +218,23 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
218 | } | 218 | } |
219 | 219 | ||
220 | /** | 220 | /** |
221 | * Count existing links - public links hidden | ||
222 | */ | ||
223 | public function testCountHiddenPublic() | ||
224 | { | ||
225 | $linkDB = new LinkDB(false, true); | ||
226 | |||
227 | $this->assertEquals( | ||
228 | 0, | ||
229 | $linkDB->count() | ||
230 | ); | ||
231 | $this->assertEquals( | ||
232 | 0, | ||
233 | $linkDB->count() | ||
234 | ); | ||
235 | } | ||
236 | |||
237 | /** | ||
221 | * List the days for which links have been posted | 238 | * List the days for which links have been posted |
222 | */ | 239 | */ |
223 | public function testDays() | 240 | public function testDays() |