Basic outline for how the blacklist tag done

Images have a tag array associated, take said tag array and make it a var. Then take a user's blacklist (I wonder if the user class has an array space) and make it a var. run array_intersect on both those vars. if anything is in returned array, return true. else return false. access denied and censor images in other areas if tags appear in array
This commit is contained in:
Your Name 2022-08-04 09:47:59 -05:00
parent f038cd72fb
commit 54e200eeba
4 changed files with 101 additions and 0 deletions

16
ext/blacklist/info.php Normal file
View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
class Blacklist extends ExtensionInfo
{
public const KEY = "blacklist";
public string $key = self::KEY;
public string $name = "Blacklist";
public string $url = self::SHIMMIE_URL;
public array $authors = self::SHISH_AUTHOR;
public string $license = self::LICENSE_GPLV2;
public string $description = "Allow users to blacklist certain tags from being viewed";
public ?string $documentation = "Hides the sinful, shameful, or otherwise undesirable tags from innocent eyes";
}

45
ext/blacklist/main.php Normal file
View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
private function check_blacklist(Image $image): bool
{
//Images have a tag array associated, take said tag array and make it a var
//Then take a user's blacklist (I wonder if the user class has an array space) and make it a var
//run array_intersect on it
//if anything is in said array, return true
//else return false
//access denied and censor images in other areas
global $user, $config;
if ($config->get_bool(ApprovalConfig::IMAGES) && $image->approved===false && !$user->can(Permissions::APPROVE_IMAGE) {
return false;
}
return true;
}
public function onImageDownloading(ImageDownloadingEvent $event)
{
/**
* Deny images upon insufficient permissions.
**/
if (!$this->check_permissions($event->image)) {
throw new SCoreException("Access denied");
}
}
public function onDisplayingImage(DisplayingImageEvent $event)
{
global $page;
if (!$this->check_permissions(($event->image))) {
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link("post/list"));
}
}

38
ext/blacklist/test.php Normal file
View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
class RatingsTest extends ShimmiePHPUnitTestCase
{
public function testRatingSafe()
{
$this->log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$image = Image::by_id($image_id);
send_event(new RatingSetEvent($image, "s"));
# search for it in various ways
$this->assert_search_results(["rating=Safe"], [$image_id]);
$this->assert_search_results(["rating=s"], [$image_id]);
$this->assert_search_results(["rating=sqe"], [$image_id]);
# test that search by tag still works
$this->assert_search_results(["pbx"], [$image_id]);
# searching for a different rating should return nothing
$this->assert_search_results(["rating=q"], []);
}
public function testRatingExplicit()
{
global $config;
$config->set_array("ext_rating_anonymous_privs", ["s", "q"]);
$this->log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$image = Image::by_id($image_id);
send_event(new RatingSetEvent($image, "e"));
# the explicit image shouldn't show up in anon's searches
$this->log_out();
$this->assert_search_results(["pbx"], []);
}
}

2
ext/blacklist/theme.php Normal file
View File

@ -0,0 +1,2 @@
<?php
declare(strict_types=1);