user()->subscribe; $subUrl = route('sub', $subscribe->code); self::$valuables = [ '{{siteName}}' => $siteName, '{{urlEndcodeSiteName}}' => urlencode($siteName), '{{urlEndcodeSiteUrl}}' => urlencode($siteUrl), '{{siteUrl}}' => $siteUrl, '{{subUrl}}' => $subUrl, '{{urlEncodeSubUrl}}' => urlencode($subUrl), '{{base64SubUrl}}' => base64url_encode($subUrl), ]; } /** * @return mixed */ public function getContent() { $content = self::$article->content; $this->formatAccessable($content); $this->formatValuables($content); return $content; } private function formatAccessable(&$body) { $noAccess = ! UserService::getInstance()->isActivePaying(); if ($noAccess) { while ($this->getInBetween($body, '', '', true) !== '') { $accessArea = $this->getInBetween($body, '', ''); if ($accessArea) { $body = strtr($body, [$accessArea => '
'.__('You must have a valid subscription to view content in this area!').'
']); } } } while ($this->getInBetween($body, '', '', true) !== '') { $accessArea = $this->getInBetween($body, '', ''); $hasAccessArea = $this->getInBetween($accessArea, '', '', true); $noAccessArea = $this->getInBetween($accessArea, '', '', true); $body = strtr($body, [$accessArea => $accessArea && $noAccess ? $noAccessArea : $hasAccessArea]); } } private function getInBetween($input, $start, $end, $bodyOnly = false): string { $substr = substr($input, strpos($input, $start) + strlen($start), strpos($input, $end) - strlen($input)); return $bodyOnly ? $substr : $start.$substr.$end; } private function formatValuables(&$body) { $body = strtr($body, self::$valuables); } }