Commit 4f78a38e authored by Ben Hayward's avatar Ben Hayward

Updated to support old-style mature flagged blogs

1 merge request!384[Sprint/QuietQuail](fix): Blog & media edit updated to new nsfw system #1936
Pipeline #97721529 passed with stages
in 6 minutes and 45 seconds
......@@ -271,7 +271,7 @@ class blog implements Interfaces\Api
}
if ($blog->isMonetized()) {
if ($blog->getNsfw()) {
if ($blog->getNsfw() || $blog->isMature()) {
return Factory::response([
'status' => 'error',
'message' => 'Cannot monetize an explicit blog'
......@@ -288,7 +288,8 @@ class blog implements Interfaces\Api
}
}
if (isset($_POST['nsfw']) && $_POST['nsfw']) {
if ((isset($_POST['nsfw']) && $_POST['nsfw'])
|| (isset($_POST['mature']) && $_POST['mature'])) {
$user = Core\Session::getLoggedInUser();
if (!$user->getMatureContent()) {
......
......@@ -266,6 +266,7 @@ class media implements Interfaces\Api, Interfaces\ApiIgnorePam
$entity->patch([
'title' => isset($data['name']) ? $data['name'] : '',
'mature' => isset($data['mature']) && !!$data['mature'],
'nsfw' => !is_array($_POST['nsfw']) ? json_decode($_POST['nsfw']) : $_POST['nsfw'],
'batch_guid' => 0,
'access_id' => 0,
......
......@@ -58,6 +58,7 @@ class CreateActivity
->setURL($blog->getURL())
->setThumbnail($blog->getIconUrl())
->setFromEntity($blog)
->setMature($blog->isMature())
->setNsfw($blog->getNsfw())
->setOwner($owner->export())
->setWireThreshold($blog->getWireThreshold())
......
......@@ -189,6 +189,7 @@ class Image extends File
'thumbnail',
'cinemr_guid',
'license',
'mature',
'nsfw',
'boost_rejection_reason',
'rating',
......@@ -221,6 +222,7 @@ class Image extends File
$export['thumbs:up:count'] = Helpers\Counters::get($this->guid, 'thumbs:up');
$export['thumbs:down:count'] = Helpers\Counters::get($this->guid, 'thumbs:down');
$export['description'] = $this->description; //videos need to be able to export html.. sanitize soon!
$export['mature'] = $this->mature ?: $this->getFlag('mature');
$export['nsfw'] = $this->nsfw ?: [];
$export['rating'] = $this->getRating();
$export['width'] = $this->width ?: 0;
......@@ -264,6 +266,7 @@ class Image extends File
'title' => null,
'description' => null,
'license' => null,
'mature' => null,
'nsfw' => null,
'boost_rejection_reason' => null,
'hidden' => null,
......@@ -282,6 +285,7 @@ class Image extends File
'batch_guid',
'access_id',
'container_guid',
'mature',
'nsfw',
'boost_rejection_reason',
'rating',
......@@ -298,6 +302,8 @@ class Image extends File
} elseif ($field == 'nsfw') {
$this->nsfw = !is_array($data['nsfw']) ? json_decode($data['nsfw']) : $data['nsfw'];
continue;
} elseif ($field == 'mature') {
$this->setFlag('mature', !!$data['mature']);
}
$this->$field = $data[$field];
......@@ -343,6 +349,7 @@ class Image extends File
[[
'src' => \elgg_get_site_url() . 'fs/v1/thumbnail/' . $this->guid,
'href' => \elgg_get_site_url() . 'media/' . ($this->container_guid ? $this->container_guid . '/' : '') . $this->guid,
'mature' => $this->getFlag('mature'),
'nsfw' => $this->getFlag('nsfw'),
'width' => $this->width ?? 0,
'height' => $this->height ?? 0,
......
......@@ -187,6 +187,7 @@ class Video extends MindsObject
'title' => null,
'description' => null,
'license' => null,
'mature' => null,
'nsfw' => null,
'boost_rejection_reason' => null,
'hidden' => null,
......@@ -204,6 +205,7 @@ class Video extends MindsObject
'hidden',
'access_id',
'container_guid',
'mature',
'nsfw',
'boost_rejection_reason',
'rating',
......@@ -218,7 +220,7 @@ class Video extends MindsObject
if ($field == 'access_id') {
$data[$field] = (int) $data[$field];
} elseif (in_array($field, ['full_hd'], true)) {
} elseif ((in_array($field, ['full_hd'], true)) || (in_array($field, ['mature', 'full_hd'], true))) {
$this->setFlag($field, !!$data[$field]);
continue;
}
......
......@@ -55,6 +55,10 @@ class CreateActivitySpec extends ObjectBehavior
$blog->getIconUrl()
->shouldBeCalled()
->willReturn('http://phpspec/icon.spec.ext');
$blog->isMature()
->shouldBeCalled()
->willReturn(false);
$blog->getNsfw()
->shouldBeCalled()
......
Please register or to comment