// Is the user logged in? (used to filter private links)
private $loggedIn;
+ // Hide public links
+ private $hidePublicLinks;
+
/**
* Creates a new LinkDB
*
*
* @param $isLoggedIn is the user logged in?
*/
- function __construct($isLoggedIn)
+ function __construct($isLoggedIn, $hidePublicLinks)
{
// FIXME: do not access $GLOBALS, pass the datastore instead
$this->loggedIn = $isLoggedIn;
+ $this->hidePublicLinks = $hidePublicLinks;
$this->checkDB();
$this->readdb();
}
{
// Public links are hidden and user not logged in => nothing to show
- if ($GLOBALS['config']['HIDE_PUBLIC_LINKS'] && !isLoggedIn()) {
+ if ($this->hidePublicLinks && !$this->loggedIn) {
$this->links = array();
return;
}
$cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; }
// If cached was not found (or not usable), then read the database and build the response:
- $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if user it not logged in).
+ $LINKSDB = new LinkDB(
+ isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'],
+ $GLOBALS['config']['HIDE_PUBLIC_LINKS']
+ );
+ // Read links from database (and filter private links if user it not logged in).
// Optionally filter the results:
$linksToDisplay=array();
$cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; }
// If cached was not found (or not usable), then read the database and build the response:
- $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in).
-
+ $LINKSDB = new LinkDB(
+ isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'],
+ $GLOBALS['config']['HIDE_PUBLIC_LINKS']
+ );
// Optionally filter the results:
$linksToDisplay=array();
$cache = new pageCache(pageUrl(),startsWith($query,'do=dailyrss') && !isLoggedIn());
$cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; }
// If cached was not found (or not usable), then read the database and build the response:
- $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in).
+
+ $LINKSDB = new LinkDB(
+ isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'],
+ $GLOBALS['config']['HIDE_PUBLIC_LINKS']
+ );
/* Some Shaarlies may have very few links, so we need to look
back in time (rsort()) until we have enough days ($nb_of_days).
// "Daily" page.
function showDaily()
{
- $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in).
-
+ $LINKSDB = new LinkDB(
+ isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'],
+ $GLOBALS['config']['HIDE_PUBLIC_LINKS']
+ );
$day=Date('Ymd',strtotime('-1 day')); // Yesterday, in format YYYYMMDD.
if (isset($_GET['day'])) $day=$_GET['day'];
// Render HTML page (according to URL parameters and user rights)
function renderPage()
{
- $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in).
+ $LINKSDB = new LinkDB(
+ isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'],
+ $GLOBALS['config']['HIDE_PUBLIC_LINKS']
+ );
// -------- Display login form.
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=login'))
function importFile()
{
if (!(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'])) { die('Not allowed.'); }
- $LINKSDB = new LinkDB(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in).
+ $LINKSDB = new LinkDB(
+ isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'],
+ $GLOBALS['config']['HIDE_PUBLIC_LINKS']
+ );
$filename=$_FILES['filetoupload']['name'];
$filesize=$_FILES['filetoupload']['size'];
$data=file_get_contents($_FILES['filetoupload']['tmp_name']);
self::$refDB->write(self::$testDatastore, PHPPREFIX, PHPSUFFIX);
$GLOBALS['config']['DATASTORE'] = self::$testDatastore;
- self::$publicLinkDB = new LinkDB(false);
- self::$privateLinkDB = new LinkDB(true);
+ self::$publicLinkDB = new LinkDB(false, false);
+ self::$privateLinkDB = new LinkDB(true, false);
}
/**
*/
public function testConstructLoggedIn()
{
- new LinkDB(true);
+ new LinkDB(true, false);
$this->assertFileExists(self::$testDatastore);
}
*/
public function testConstructLoggedOut()
{
- new LinkDB(false);
+ new LinkDB(false, false);
$this->assertFileExists(self::$testDatastore);
}
public function testConstructDatastoreNotWriteable()
{
$GLOBALS['config']['DATASTORE'] = 'null/store.db';
- new LinkDB(false);
+ new LinkDB(false, false);
}
/**
*/
public function testCheckDBNew()
{
- $linkDB = new LinkDB(false);
+ $linkDB = new LinkDB(false, false);
unlink(self::$testDatastore);
$this->assertFileNotExists(self::$testDatastore);
*/
public function testCheckDBLoad()
{
- $linkDB = new LinkDB(false);
+ $linkDB = new LinkDB(false, false);
$this->assertEquals(
self::$dummyDatastoreSHA1,
sha1_file(self::$testDatastore)
public function testReadEmptyDB()
{
file_put_contents(self::$testDatastore, PHPPREFIX.'S7QysKquBQA='.PHPSUFFIX);
- $emptyDB = new LinkDB(false);
+ $emptyDB = new LinkDB(false, false);
$this->assertEquals(0, sizeof($emptyDB));
$this->assertEquals(0, count($emptyDB));
}
*/
public function testSaveDB()
{
- $testDB = new LinkDB(true);
+ $testDB = new LinkDB(true, false);
$dbSize = sizeof($testDB);
$link = array(
$testDB->savedb();
- $testDB = new LinkDB(true);
+ $testDB = new LinkDB(true, false);
$this->assertEquals($dbSize + 1, sizeof($testDB));
}
);
}
+ /**
+ * Count existing links - public links hidden
+ */
+ public function testCountHiddenPublic()
+ {
+ $linkDB = new LinkDB(false, true);
+
+ $this->assertEquals(
+ 0,
+ $linkDB->count()
+ );
+ $this->assertEquals(
+ 0,
+ $linkDB->count()
+ );
+ }
+
/**
* List the days for which links have been posted
*/