Skip to content

Commit b346553

Browse files
eiennohimarkharding
authored andcommitted
[Sprint/GiddyGiraffe] (fix): paywall doesnt work for blogs
1 parent a7729df commit b346553

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

Controllers/api/v1/blog.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function post($pages)
204204
}
205205

206206
if (isset($_POST['tags']) && $_POST['tags'] !== '') {
207-
$tags = !is_array($_POST['tags']) ? explode(',', $_POST['tags']) : $_POST['tags'];
207+
$tags = !is_array($_POST['tags']) ? json_decode($_POST['tags']) : $_POST['tags'];
208208
$blog->setTags($tags);
209209
}
210210

@@ -213,7 +213,8 @@ public function post($pages)
213213
}
214214

215215
if (isset($_POST['wire_threshold'])) {
216-
$blog->setWireThreshold($_POST['wire_threshold']);
216+
$threshold = is_string($_POST['wire_threshold']) ? json_decode($_POST['wire_threshold']) : $_POST['wire_threshold'];
217+
$blog->setWireThreshold($threshold);
217218
}
218219

219220
if (isset($_POST['published'])) {
@@ -228,8 +229,12 @@ public function post($pages)
228229
$blog->setSlug($_POST['slug']);
229230
}
230231

231-
if (isset($_POST['custom_meta']) && is_array($_POST['custom_meta'])) {
232-
$blog->setCustomMeta($_POST['custom_meta']);
232+
if (isset($_POST['custom_meta'])) {
233+
$meta = is_string($_POST['custom_meta']) ? json_decode($_POST['custom_meta'], true) : $_POST['custom_meta'];
234+
235+
if (is_array($meta)) {
236+
$blog->setCustomMeta($meta);
237+
}
233238
}
234239

235240
//draft

Core/Blogs/Blog.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ public function setCustomMeta(array $customMeta = [])
381381
'author' => FILTER_SANITIZE_SPECIAL_CHARS
382382
]);
383383

384+
$this->markAsDirty('customMeta');
385+
384386
return $this;
385387
}
386388

Core/Blogs/Delegates/CreateActivity.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function save(Blog $blog)
4242
->setThumbnail($blog->getIconUrl())
4343
->setFromEntity($blog)
4444
->setMature($blog->isMature())
45-
->setOwner($owner->export());
45+
->setOwner($owner->export())
46+
->setWireThreshold($blog->getWireThreshold())
47+
->setPaywall($blog->isPaywall());
4648

4749
$activity->container_guid = $owner->guid;
4850
$activity->owner_guid = $owner->guid;

Core/Wire/Thresholds.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public function isAllowed($user, $entity)
2828
}
2929

3030
$isPaywall = false;
31-
if (method_exists($entity, 'isPaywall') && $entity->isPaywall()) {
31+
32+
if ((MagicAttributes::getterExists($entity, 'isPaywall') || method_exists($entity, 'isPaywall')) && $entity->isPaywall()) {
3233
$isPaywall = true;
3334
} elseif (method_exists($entity, 'getFlag') && $entity->getFlag('paywall')) {
3435
$isPaywall = true;
@@ -48,9 +49,15 @@ public function isAllowed($user, $entity)
4849

4950
$amount = 0;
5051

52+
if (MagicAttributes::getterExists($entity, 'getOwnerGuid')) {
53+
$ownerGuid = $entity->getOwnerGuid();
54+
} else {
55+
$ownerGuid = $entity->getOwnerGUID();
56+
}
57+
5158
/** @var Sums $sums */
5259
$sums = Di::_()->get('Wire\Sums');
53-
$sums->setReceiver($entity->getOwnerGUID())
60+
$sums->setReceiver($ownerGuid)
5461
->setSender($user->guid)
5562
->setFrom((new \DateTime('midnight'))->modify("-30 days")->getTimestamp());
5663

@@ -76,10 +83,8 @@ public function isAllowed($user, $entity)
7683
return true;
7784
}
7885
}
79-
8086
return false;
8187
}
82-
8388
return true;
8489
}
8590
}

Helpers/MagicAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function setterExists($class, $setter)
4040
*/
4141
public static function getterExists($class, $getter)
4242
{
43-
$prop = lcfirst(preg_replace('/^get/', '', $getter));
43+
$prop = lcfirst(preg_replace('/^(get|is)/', '', $getter));
4444
return method_exists($class, $getter) || (static::used($class) && property_exists($class, $prop));
4545
}
4646
}

Spec/Core/Blogs/Delegates/CreateActivitySpec.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ function it_should_save(
5656
->shouldBeCalled()
5757
->willReturn(false);
5858

59+
$blog->getWireThreshold()
60+
->shouldBeCalled()
61+
->willReturn(null);
62+
63+
$blog->isPaywall()
64+
->shouldBeCalled()
65+
->willReturn(false);
66+
5967
$user->export()
6068
->shouldBeCalled()
6169
->willReturn([]);

0 commit comments

Comments
 (0)