/** * Check if has access to content * * @param TinypassContentSettings $contentSettings * @param string $content * @param callback $trimFunction Function for truncation * @param TinypassResource[] $resources * * @return TinypassContentResult|null * @throws Exception */ public function checkAccessSettings(TinypassContentSettings $contentSettings, $content = null, $trimFunction = null, $resources = array()) { // Validate if content access setings are valid $contentSettings->validate($this->businessModel(), $this->enablePayPerPost(), $this->algorithmicKeyAvailable(), $resources); $result = new TinypassContentResult(); // If content is supposed to be free - return null if ($contentSettings->isFree()) { return $result; } if ($this->businessModel() == self::BUSINESS_MODEL_METERED) { // Process content for metered paywall business model if ($contentSettings->chargeOption() == TinypassContentSettings::CHARGE_OPTION_METERED) { $result = $this->initMeteredPaywall($contentSettings, $content, $trimFunction); // For metered charge option the content needs to be always wrapped in proper html, since actual access checking is done via javascript $result->content($this->trimMeter($contentSettings, $content)); } elseif ($contentSettings->chargeOption() == TinypassContentSettings::CHARGE_OPTION_ALWAYS) { $result = $this->initConstantPaywall($contentSettings); if ($result->isKeyed()) { // For constant paywall, however, content should be wrapped and trimmed only if it's keyed (if user don't have access) $result->content($this->trimOffer($contentSettings, $content, $trimFunction)); } } } elseif ($this->businessModel() == self::BUSINESS_MODEL_SUBSCRIPTION) { // Process content for hard / keyed business model if ($contentSettings->chargeOption() == TinypassContentSettings::CHARGE_OPTION_SUBSCRIPTION) { $result = $this->initHardKeyedPaywall($contentSettings, $resources); } elseif ($contentSettings->chargeOption() == TinypassContentSettings::CHARGE_OPTION_ALGORITHMIC) { $result = $this->initAlgorithmicKeyedPaywall($contentSettings, $resources); } if ($result->isKeyed()) { // Trim content if it's keyed $result->content($this->trimOffer($contentSettings, $content, $trimFunction)); } } return $result; }
public function sanitizeDefaultAccessSettings() { if (is_array(self::$default_access_settings)) { $contentSettings = new TinypassContentSettings(); $chargeOption = isset(self::$default_access_settings[$contentSettings->chargeOptionPropertyName()]) ? self::$default_access_settings[$contentSettings->chargeOptionPropertyName()] : null; $contentSettings->chargeOption($chargeOption)->resourceIds(isset(self::$default_access_settings[$chargeOption][$contentSettings->resourceIdsPropertyName()]) ? self::$default_access_settings[$chargeOption][$contentSettings->resourceIdsPropertyName()] : null)->pppPrice(isset(self::$default_access_settings[$chargeOption][$contentSettings->pppPricePropertyName()]) ? self::$default_access_settings[$chargeOption][$contentSettings->pppPricePropertyName()] : null)->pppCurrency(isset(self::$default_access_settings[$chargeOption][$contentSettings->pppCurrencyPropertyName()]) ? self::$default_access_settings[$chargeOption][$contentSettings->pppCurrencyPropertyName()] : null); $contentSettings->validate(self::$business_model, self::$enable_ppp, self::$tinypass->algorithmicKeyAvailable(), $this->getResources()); $this->setOption(self::OPTION_NAME_DEFAULT_ACCESS_SETTINGS, $contentSettings->toArray()); } }