Skip to content

Commit

Permalink
Merge pull request #714 from wazari972/upstream_tags
Browse files Browse the repository at this point in the history
Add support for private (@) and hidden (#) tags
  • Loading branch information
SSilence committed Dec 28, 2015
2 parents b784b35 + 64e8745 commit 4de3692
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 4 deletions.
11 changes: 10 additions & 1 deletion controllers/Index.php
Expand Up @@ -49,7 +49,16 @@ public function home() {
$this->view->statsAll = $stats['total'];
$this->view->statsUnread = $stats['unread'];
$this->view->statsStarred = $stats['starred'];


if ($tagsDao->hasTag("#")) {
foreach ($tags as $tag) {
if (strcmp($tag["tag"], "#") !== 0) {
continue;
}
$this->view->statsUnread -= $tag["unread"];
}
}

// prepare tags display list
$tagsController = new \controllers\Tags();
$this->view->tags = $tagsController->renderTags($tags);
Expand Down
12 changes: 12 additions & 0 deletions controllers/Items.php
Expand Up @@ -146,6 +146,18 @@ public function stats() {

$itemsDao = new \daos\Items();
$stats = $itemsDao->stats();
$stats['unread'] -= $itemsDao->numberOfUnreadForTag("#");

$tagsDao = new \daos\Tags();
$tags = $tagsDao->getWithUnread();
if ($tagsDao->hasTag("#")) {
foreach ($tags as $tag) {
if (strcmp($tag["tag"], "#") !== 0) {
continue;
}
$stats['unread'] -= $tag["unread"];
}
}

if( array_key_exists('tags', $_GET) && $_GET['tags'] == 'true' ) {
$tagsDao = new \daos\Tags();
Expand Down
24 changes: 23 additions & 1 deletion daos/Items.php
Expand Up @@ -80,6 +80,28 @@ public function get($options = array()) {
$options
);

return $this->backend->get($options);
$items = $this->backend->get($options);

// remove private posts with private tags
if(!\F3::get('auth')->showPrivateTags()) {
foreach($items as $idx => $item) {
if (strpos($item['tags'], "@") !== false) {
unset($items[$idx]);
}
}
$items = array_values($items);
}

// remove posts with hidden tags
if(!isset($options['tag']) || strlen($options['tag']) === 0) {
foreach($items as $idx => $item) {
if (strpos($item['tags'], "#") !== false) {
unset($items[$idx]);
}
}
$items = array_values($items);
}

return $items;
}
}
14 changes: 14 additions & 0 deletions daos/Sources.php
Expand Up @@ -47,6 +47,20 @@ public function __call($name, $args) {
\F3::get('logger')->log('Unimplemented method for ' . \F3::get('db_type') . ': ' . $name, \ERROR);
}

public function get() {
$sources = $this->backend->get();
// remove items with private tags
if(!\F3::get('auth')->showPrivateTags()) {
foreach($sources as $idx => $source) {
if (strpos($source['tags'], "@") !== false) {
unset($sources[$idx]);
}
}
$sources = array_values($sources);
}

return $sources;
}

/**
* validate new data for a given source
Expand Down
16 changes: 15 additions & 1 deletion daos/Tags.php
Expand Up @@ -30,7 +30,21 @@ public function __construct() {
$this->backend = new $class();
parent::__construct();
}


public function get() {
$tags = $this->backend->get();
// remove items with private tags
if(!\F3::get('auth')->showPrivateTags()) {
foreach($tags as $idx => $tag) {
if (strpos($tag['tag'], "@") !== false) {
unset($tags[$idx]);
}
}
$tags = array_values($tags);
}

return $tags;
}

/**
* pass any method call to the backend.
Expand Down
1 change: 0 additions & 1 deletion defaults.ini
Expand Up @@ -36,4 +36,3 @@ unread_order=
load_images_on_mobile=0
auto_hide_read_on_mobile=0
env_prefix=selfoss_

10 changes: 10 additions & 0 deletions helpers/Authentication.php
Expand Up @@ -124,6 +124,16 @@ public function isLoggedin() {
return $this->loggedin;
}


/**
* showPrivateTags
*
* @return bool
*/
public function showPrivateTags() {
return $this->isLoggedin();
}


/**
* logout
Expand Down

0 comments on commit 4de3692

Please sign in to comment.