/**
  * Render everything
  *
  * @param \GeorgRinger\News\Domain\Model\News $object current news object
  * @param string $as name of property which holds the text
  * @param integer $currentPage Selected page
  * @param string $token Token used to split the text
  * @return string
  */
 public function render(\GeorgRinger\News\Domain\Model\News $object, $as, $currentPage, $token = '###more###')
 {
     $parts = GeneralUtility::trimExplode($token, $object->getBodytext(), true);
     $numberOfPages = count($parts);
     if ($numberOfPages === 1) {
         $result = $parts[0];
     } else {
         $currentPage = (int) $currentPage;
         if ($currentPage < 1) {
             $currentPage = 1;
         } elseif ($currentPage > $numberOfPages) {
             $currentPage = $numberOfPages;
         }
         $tagsToOpen = array();
         $tagsToClose = array();
         for ($j = 0; $j < $currentPage; $j++) {
             $chunk = $parts[$j];
             while ($chunk = mb_strstr($chunk, '<')) {
                 $tag = $this->extractTag($chunk);
                 $tagStrLen = mb_strlen($tag);
                 if ($this->isOpeningTag($tag)) {
                     if ($j < $currentPage - 1) {
                         $tagsToOpen[] = $tag;
                     }
                     $tagsToClose[] = $tag;
                 } elseif ($this->isClosingTag($tag)) {
                     if ($j < $currentPage - 1) {
                         array_pop($tagsToOpen);
                     } elseif (mb_strpos($parts[$j], $chunk) === 0) {
                         $parts[$j] = mb_substr($parts[$j], $tagStrLen);
                         array_pop($tagsToOpen);
                     }
                     array_pop($tagsToClose);
                 }
                 $chunk = mb_substr($chunk, $tagStrLen);
             }
         }
         $result = join('', $tagsToOpen) . $parts[$currentPage - 1];
         while ($tag = array_pop($tagsToClose)) {
             $result .= $this->getClosingTagByOpeningTag($tag);
         }
     }
     $pages = array();
     for ($i = 1; $i <= $numberOfPages; $i++) {
         $pages[] = array('number' => $i, 'isCurrent' => $i === $currentPage);
     }
     $pagination = array('pages' => $pages, 'numberOfPages' => $numberOfPages, 'current' => $currentPage);
     if ($currentPage < $numberOfPages) {
         $pagination['nextPage'] = $currentPage + 1;
     }
     if ($currentPage > 1) {
         $pagination['previousPage'] = $currentPage - 1;
     }
     $this->templateVariableContainer->add($as, $result);
     $this->templateVariableContainer->add('pagination', $pagination);
     return $this->renderChildren();
 }
示例#2
0
 /**
  * Test if bodytext can be set
  *
  * @test
  * @return void
  */
 public function bodytextCanBeSet()
 {
     $bodytext = 'News bodytext';
     $this->newsDomainModelInstance->setBodytext($bodytext);
     $this->assertEquals($bodytext, $this->newsDomainModelInstance->getBodytext());
 }
 /**
  * @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
 }