Example #1
0
 /**
  * @return bool status of the paywall
  */
 public static function isPaywallEnabled()
 {
     return \plenigo\services\UserService::isPaywallEnabled();
 }
 /**
  * Returns a flag indicating if the user still has free views left.
  * 
  * @return True if the user still has free views left, false otherwise
  */
 public static function hasFreeViews()
 {
     $clazz = get_class();
     $meteredUserData = static::getMeteredUserData();
     if (is_null($meteredUserData)) {
         $limitParam = filter_input(INPUT_GET, "meteredLimitReached");
         if ($limitParam !== FALSE && !is_null($limitParam) && $limitParam === 'true') {
             PlenigoManager::notice($clazz, "Limit reached by URL parameter. You shall NOT pass!");
             return false;
         }
         PlenigoManager::warn($clazz, "Returning TRUE but I have no metered Data!!!!!");
         return true;
     }
     $active = $meteredUserData->isMeteredViewActivated();
     if (is_null($active) || $active === false) {
         PlenigoManager::notice($clazz, "Metered view deactivated!!");
         return false;
     }
     $loggedIn = UserService::isLoggedIn();
     if (is_null($loggedIn)) {
         $loggedIn = false;
     }
     $limitReached = $meteredUserData->isLimitReached();
     if (is_null($limitReached)) {
         $limitReached = false;
     }
     $viewsAvailable = $meteredUserData->getFreeViewsAllowed();
     $viewsUsed = $meteredUserData->getFreeViewsTaken();
     $loginLimitReached = $meteredUserData->isLoginLimitReached();
     if (is_null($loginLimitReached)) {
         $loginLimitReached = false;
     }
     $loginViewsAvailable = $meteredUserData->getLoginFreeViewsAllowed();
     $loginViewsUsed = $meteredUserData->getLoginFreeViewsTaken();
     $validCookie = self::checkCookieValidity($meteredUserData);
     //invalid Metered cookie, the Javascript should take care of it
     if ($validCookie === false) {
         PlenigoManager::notice($clazz, "Invalid. You shall pass this time!");
         return true;
     }
     $limitToCheck = $limitReached;
     $viewsToCheck = $viewsAvailable;
     $viewsUsedToCheck = $viewsUsed;
     //if login views enabled
     if ($loggedIn === true && $loginViewsAvailable > 0) {
         $limitToCheck = $loginLimitReached;
         $viewsToCheck = $loginViewsAvailable;
         $viewsUsedToCheck = $loginViewsUsed;
     }
     if ($limitToCheck === true) {
         PlenigoManager::notice($clazz, "Limit reached. You shall NOT pass!");
         return false;
     }
     PlenigoManager::notice($clazz, "Limit not reached. You shall pass! (" . $viewsUsedToCheck . "/" . $viewsToCheck . ")");
     return true;
 }
 /**
  * @param \GeorgRinger\News\Domain\Model\News $news
  * @param  integer $currentPage
  */
 public function detailActionSlot($news, $currentPage)
 {
     $plenigoFields = $this->getPlenigoFields($news->getUid());
     //        \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($plenigoFields);
     if (empty($plenigoFields)) {
         $GLOBALS['TSFE']->pageUnavailableAndExit("Plenigo Extension not configured yet or Error reading Data", 'HTTP/1.1 500 Internal Server Error');
         throw new \Exception("Plenigo Extension not configured yet or Error reading Data from News-Table");
         return true;
     }
     $this->plenigoSettings = $this->getPlenigoSettings();
     if (is_null($this->plenigoSettings)) {
         $GLOBALS['TSFE']->pageUnavailableAndExit("Plenigo Extension not configured yet or Error reading Data", 'HTTP/1.1 500 Internal Server Error');
     }
     $hasUserBought = null;
     //            $secret     = $plenigoSetting->getCompanyPrivateKey();
     //            $companyId  = $plenigoSetting->getCompanyID();
     //            $isTestMode = $plenigoSetting->isTestMode();
     $this->connect();
     // is there a category
     if ($plenigoFields['plenigo_category']) {
         $category = $this->getPlenigoCategory($plenigoFields['plenigo_category']);
         $productID = 'item-' . $news->getUid();
         // is it bought already?
         $hasUserBought = \plenigo\services\UserService::hasUserBought($productID);
         if (!$hasUserBought) {
             //creating the product ($productId, $productTitle, $price, $currency)
             try {
                 // new custom ProductID (https://github.com/plenigo/plenigo_php_sdk/wiki/Checkout#other-products)
                 $product = new \plenigo\models\ProductBase($productID, $news->getTitle());
                 $product->setCategoryId($category['plenigo_i_d']);
             } catch (\Exception $e) {
                 $GLOBALS['TSFE']->pageUnavailableAndExit("Could not create Plenigo-Product", 'HTTP/1.1 500 Internal Server Error');
             }
         }
     }
     // its not bought yet, but we have an associated product
     if (!$hasUserBought && $plenigoFields['plenigo_product']) {
         $productData = $this->getPlenigoProduct($plenigoFields['plenigo_product']);
         // ist it bought?
         $hasUserBought = \plenigo\services\UserService::hasUserBought($productData['product_i_d']);
         if (!$hasUserBought) {
             // https://github.com/plenigo/plenigo_php_sdk/wiki/Checkout#plenigo-managed-product
             try {
                 $product = new \plenigo\models\ProductBase($productData['product_i_d']);
                 //                    \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($productData);
             } catch (\Exception $e) {
                 $GLOBALS['TSFE']->pageUnavailableAndExit("Could not create Plenigo-Product", 'HTTP/1.1 500 Internal Server Error');
             }
         }
     }
     if (FALSE === $hasUserBought) {
         // inject our js-sdk into html-header
         $this->buildHeader();
         if (!is_object($product)) {
             $GLOBALS['TSFE']->pageUnavailableAndExit("Product is not bought, but no productidentity given", 'HTTP/1.1 500 Internal Server Error');
             throw new \Exception("no Product given!");
         }
         $curtain = new Curtain($this->plenigoSettings);
         $checkout = new \plenigo\builders\CheckoutSnippetBuilder($product);
         $builder = new \plenigo\builders\LoginSnippetBuilder();
         //This will generate the login snippet of the following format:
         //plenigo.login();
         $curtain->setLoginButton($builder->build());
         $curtain->setCheckoutCode($checkout->build());
         $news->setBodytext($this->getPaymentInfo($news->getBodytext()) . $curtain->getCode());
     }
     // else displaying normal news
 }