Initial commit - Typo3 11.5.41

This commit is contained in:
Matteo Gallo
2026-07-03 17:53:31 +02:00
commit 5ca4743197
6811 changed files with 568848 additions and 0 deletions

View File

@@ -0,0 +1,429 @@
<?php
namespace PwTeaserTeam\PwTeaser\Controller;
/***************************************************************
* Copyright notice
*
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
* Tim Klein-Hitpass <tim.klein-hitpass@diemedialen.de>
* Kai Ratzeburg <kai.ratzeburg@diemedialen.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
/**
* Controller for the teaser object
*
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class TeaserController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
/**
* @var array
*/
protected $settings = [];
/**
* @var integer
*/
protected $currentPageUid = null;
/**
* @var \PwTeaserTeam\PwTeaser\Domain\Repository\PageRepository
* @TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $pageRepository;
/**
* @var \PwTeaserTeam\PwTeaser\Domain\Repository\ContentRepository
* @TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $contentRepository;
/**
* @var \TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository
* @TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $categoryRepository;
/**
* @var \PwTeaserTeam\PwTeaser\Utility\Settings
* @TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $settingsUtility;
/**
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
*/
protected $contentObject = null;
/**
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
* @TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $signalSlotDispatcher;
/**
* @var \TYPO3\CMS\Fluid\View\TemplateView
*/
protected $view;
/**
* @var array
*/
protected $viewSettings = [];
/**
* Initialize Action will performed before each action will be executed
*
* @return void
*/
public function initializeAction()
{
$this->settings = $this->settingsUtility->renderConfigurationArray($this->settings);
$frameworkSettings = $this->configurationManager->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK
);
$viewSettings = $frameworkSettings['view'];
$presets = $viewSettings['presets'];
unset($viewSettings['presets']);
$this->viewSettings = $this->settingsUtility->renderConfigurationArray($viewSettings, 'view.');
$this->viewSettings['presets'] = $presets;
}
/**
* Displays teasers
*
* @return void
*/
public function indexAction()
{
$this->currentPageUid = $GLOBALS['TSFE']->id;
$this->performTemplatePathAndFilename();
$this->setOrderingAndLimitation();
$this->performPluginConfigurations();
switch ($this->settings['source']) {
default:
case 'thisChildren':
$rootPageUids = $this->currentPageUid;
$pages = $this->pageRepository->findByPid($this->currentPageUid);
break;
case 'thisChildrenRecursively':
$rootPageUids = $this->currentPageUid;
$pages = $this->pageRepository->findByPidRecursively(
$this->currentPageUid,
(int)$this->settings['recursionDepthFrom'],
(int)$this->settings['recursionDepth']
);
break;
case 'custom':
$rootPageUids = $this->settings['customPages'];
$pages = $this->pageRepository->findByPidList(
$this->settings['customPages'],
$this->settings['orderByPlugin']
);
break;
case 'customChildren':
$rootPageUids = $this->settings['customPages'];
$pages = $this->pageRepository->findChildrenByPidList($this->settings['customPages']);
break;
case 'customChildrenRecursively':
$rootPageUids = $this->settings['customPages'];
$pages = $this->pageRepository->findChildrenRecursivelyByPidList(
$this->settings['customPages'],
(int)$this->settings['recursionDepthFrom'],
(int)$this->settings['recursionDepth']
);
break;
}
if ($this->settings['pageMode'] !== 'nested') {
$pages = $this->performSpecialOrderings($pages);
}
/** @var $page \PwTeaserTeam\PwTeaser\Domain\Model\Page */
foreach ($pages as $page) {
if ($page->getUid() === $this->currentPageUid) {
$page->setIsCurrentPage(true);
}
// Load contents if enabled in configuration
if ($this->settings['loadContents'] == '1') {
$page->setContents($this->contentRepository->findByPid($page->getUid()));
}
}
if ($this->settings['pageMode'] === 'nested') {
$pages = $this->convertFlatToNestedPagesArray($pages, $rootPageUids);
}
$this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'ModifyPages', [&$pages, $this]);
$this->view->assign('pages', $pages);
}
/**
* Function to sort given pages by recursiveRootLineOrdering string
*
* @param \PwTeaserTeam\PwTeaser\Domain\Model\Page $a
* @param \PwTeaserTeam\PwTeaser\Domain\Model\Page $b
* @return integer
*/
protected function sortByRecursivelySorting(
\PwTeaserTeam\PwTeaser\Domain\Model\Page $a,
\PwTeaserTeam\PwTeaser\Domain\Model\Page $b
) {
if ($a->getRecursiveRootLineOrdering() == $b->getRecursiveRootLineOrdering()) {
return 0;
}
return ($a->getRecursiveRootLineOrdering() < $b->getRecursiveRootLineOrdering()) ? -1 : 1;
}
/**
* Sets ordering and limitation settings from $this->settings
*
* @return void
*/
protected function setOrderingAndLimitation()
{
if (!empty($this->settings['orderBy'])) {
if ($this->settings['orderBy'] === 'customField') {
$this->pageRepository->setOrderBy($this->settings['orderByCustomField']);
} else {
$this->pageRepository->setOrderBy($this->settings['orderBy']);
}
}
if (!empty($this->settings['orderDirection'])) {
$this->pageRepository->setOrderDirection($this->settings['orderDirection']);
}
if (!empty($this->settings['limit']) && $this->settings['orderBy'] !== 'random') {
$this->pageRepository->setLimit(intval($this->settings['limit']));
}
}
/**
* Sets the fluid template to file if file is selected in flexform
* configuration and file exists
*
* @return boolean Returns TRUE if templateType is file and exists,
* otherwise returns FALSE
*/
protected function performTemplatePathAndFilename()
{
$templateType = $this->viewSettings['templateType'];
$templateFile = $this->viewSettings['templateRootFile'];
$layoutRootPaths = $this->viewSettings['layoutRootPaths'] ?: [$this->viewSettings['layoutRootPath'] ?: null];
$partialRootPaths = $this->viewSettings['partialRootPaths'] ?: [$this->viewSettings['partialRootPath'] ?: null];
$templateRootPaths = $this->viewSettings['templateRootPaths'] ?: [$this->viewSettings['templateRootPath'] ?: null];
$preset = $this->viewSettings['templatePreset'] ?? null;
if ($templateType === 'preset' && !empty($preset)) {
$currentPreset = $this->viewSettings['presets'][$preset];
if (array_key_exists('partialRootPaths', $currentPreset) && !empty($currentPreset['partialRootPaths'])) {
$partialRootPaths = $currentPreset['partialRootPaths'];
}
if (array_key_exists('layoutRootPaths', $currentPreset) && !empty($currentPreset['layoutRootPaths'])) {
$layoutRootPaths = $currentPreset['layoutRootPaths'];
}
$templateType = 'file';
$templateFile = $currentPreset['templateRootFile'];
}
if ($templateType !== 'preset' && $templateRootPaths !== [null] && !empty($templateRootPaths)) {
if (!file_exists(GeneralUtility::getFileAbsFileName(reset($templateRootPaths)))) {
throw new \Exception('Template folder "' . reset($templateRootPaths) . '" not found!');
}
$this->view->setTemplateRootPaths($templateRootPaths);
}
if ($layoutRootPaths !== [null] && !empty($layoutRootPaths)) {
if (!file_exists(GeneralUtility::getFileAbsFileName(reset($layoutRootPaths)))) {
throw new \Exception('Layout folder "' . reset($layoutRootPaths) . '" not found!');
}
$this->view->setLayoutRootPaths($layoutRootPaths);
}
if ($partialRootPaths !== [null] && !empty($partialRootPaths)) {
if (!file_exists(GeneralUtility::getFileAbsFileName(reset($partialRootPaths)))) {
throw new \Exception('Partial folder "' . reset($partialRootPaths) . '" not found!');
}
$this->view->setPartialRootPaths($partialRootPaths);
}
if ($templateType === 'file' &&
!empty($templateFile) &&
file_exists(GeneralUtility::getFileAbsFileName($templateFile))
) {
$this->view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateFile));
return true;
}
$templatePathAndFilename = $this->viewSettings['templatePathAndFilename'] ?? '';
if ($templateType === null && !empty($templatePathAndFilename)
&& file_exists(GeneralUtility::getFileAbsFileName($templatePathAndFilename))) {
$this->view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFilename));
return true;
}
return false;
}
/**
* Performs configurations from plugin settings (flexform)
*
* @return void
*/
protected function performPluginConfigurations()
{
// Set ShowNavHiddenItems to TRUE
$this->pageRepository->setShowNavHiddenItems(($this->settings['showNavHiddenItems'] == '1'));
$this->pageRepository->setFilteredDokType(
GeneralUtility::trimExplode(
',',
$this->settings['showDoktypes'],
true
)
);
if ($this->settings['hideCurrentPage'] == '1') {
$this->pageRepository->setIgnoreOfUid($this->currentPageUid);
}
if ($this->settings['ignoreUids']) {
$ignoringUids = GeneralUtility::trimExplode(',', $this->settings['ignoreUids'], true);
array_map([$this->pageRepository, 'setIgnoreOfUid'], $ignoringUids);
}
if ($this->settings['categoriesList'] && $this->settings['categoryMode']) {
$categories = [];
foreach (GeneralUtility::intExplode(',', $this->settings['categoriesList'], true) as $categoryUid) {
$categories[] = $this->categoryRepository->findByUid($categoryUid);
}
switch ((int)$this->settings['categoryMode']) {
case \PwTeaserTeam\PwTeaser\Domain\Repository\PageRepository::CATEGORY_MODE_OR:
case \PwTeaserTeam\PwTeaser\Domain\Repository\PageRepository::CATEGORY_MODE_OR_NOT:
$isAnd = false;
break;
default:
$isAnd = true;
}
switch ((int)$this->settings['categoryMode']) {
case \PwTeaserTeam\PwTeaser\Domain\Repository\PageRepository::CATEGORY_MODE_AND_NOT:
case \PwTeaserTeam\PwTeaser\Domain\Repository\PageRepository::CATEGORY_MODE_OR_NOT:
$isNot = true;
break;
default:
$isNot = false;
}
$this->pageRepository->addCategoryConstraint($categories, $isAnd, $isNot);
}
if ($this->settings['source'] === 'custom') {
$this->settings['pageMode'] = 'flat';
}
if ($this->settings['pageMode'] === 'nested') {
$this->settings['recursionDepthFrom'] = 0;
$this->settings['orderBy'] = 'uid';
$this->settings['limit'] = 0;
}
}
/**
* Performs special orderings like "random" or "sorting"
*
* @param array <Pages> $pages
* @return array
*/
protected function performSpecialOrderings(array $pages)
{
// Make random if selected on queryResult, cause Extbase doesn't support it
if ($this->settings['orderBy'] === 'random') {
shuffle($pages);
if (!empty($this->settings['limit'])) {
$pages = array_slice($pages, 0, $this->settings['limit']);
}
}
if ($this->settings['orderBy'] === 'sorting' && strpos($this->settings['source'], 'Recursively') !== false) {
usort($pages, [$this, 'sortByRecursivelySorting']);
if (strtolower($this->settings['orderDirection']) === strtolower(QueryInterface::ORDER_DESCENDING)) {
$pages = array_reverse($pages);
}
if (!empty($this->settings['limit'])) {
$pages = array_slice($pages, 0, $this->settings['limit']);
return $pages;
}
return $pages;
}
return $pages;
}
/**
* Converts given pages array (flat) to nested one
*
* @param array <Pages> $pages
* @param string $rootPageUids Comma separated list of page uids
* @return array<Pages>
*/
protected function convertFlatToNestedPagesArray($pages, $rootPageUids)
{
$rootPageUidArray = GeneralUtility::intExplode(',', $rootPageUids);
$rootPages = [];
foreach ($rootPageUidArray as $rootPageUid) {
$page = $this->pageRepository->findByUid($rootPageUid);
$this->fillChildPagesRecursivley($page, $pages);
$rootPages[] = $page;
}
return $rootPages;
}
/**
* Fills given parentPage's childPages attribute recursively with pages
*
* @param \PwTeaserTeam\PwTeaser\Domain\Model\Page $parentPage
* @param array $pages
* @return \PwTeaserTeam\PwTeaser\Domain\Model\Page
*/
protected function fillChildPagesRecursivley($parentPage, array $pages)
{
$childPages = [];
/** @var $page \PwTeaserTeam\PwTeaser\Domain\Model\Page */
foreach ($pages as $page) {
if ($page->getPid() === $parentPage->getUid()) {
$this->fillChildPagesRecursivley($page, $pages);
$childPages[$page->getSorting()] = $page;
}
}
ksort($childPages);
$parentPage->setChildPages(array_values($childPages));
return $parentPage;
}
}

View File

@@ -0,0 +1,323 @@
<?php
namespace PwTeaserTeam\PwTeaser\Domain\Model;
/***************************************************************
* Copyright notice
*
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
* Tim Klein-Hitpass <tim.klein-hitpass@diemedialen.de>
* Kai Ratzeburg <kai.ratzeburg@diemedialen.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\Category;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\CMS\Frontend\Page\PageRepository;
/**
* Content model
*
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Content extends AbstractEntity
{
/**
* ctype
*
* @var string
*/
protected $ctype;
/**
* colPos
*
* @var integer
*/
protected $colPos;
/**
* header
*
* @var string
*/
protected $header;
/**
* bodytext
*
* @var string
*/
protected $bodytext;
/**
* It may contain multiple images, but TYPO3 called this field just "image"
*
* @var ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
*/
protected $image;
/**
* Categories
*
* @var ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category>
*/
protected $categories;
/**
* Complete row (from database) of this content element
*
* @var array
*/
protected $contentRow;
/**
* Constructor
*/
public function __construct()
{
$this->image = new ObjectStorage();
}
/**
* Setter for images
*
* @param ObjectStorage $image
* @return void
*/
public function setImage(ObjectStorage $image)
{
$this->image = $image;
}
/**
* Getter for images
*
* @return ObjectStorage images
*/
public function getImage()
{
return $this->image;
}
/**
* Add image
*
* @param FileReference $image
* @return void
*/
public function addImage(FileReference $image)
{
$this->image->attach($image);
}
/**
* Remove image
*
* @param FileReference $image
* @return void
*/
public function removeImage(FileReference $image)
{
$this->image->detach($image);
}
/**
* Returns image files as array (with all attributes)
*
* @return array
*/
public function getImageFiles()
{
$imageFiles = [];
/** @var FileReference $image */
foreach ($this->getImage() as $image) {
$imageFiles[] = $image->getOriginalResource()->toArray();
}
return $imageFiles;
}
/**
* Setter for bodytext
*
* @param string $bodytext bodytext
* @return void
*/
public function setBodytext($bodytext)
{
$this->bodytext = $bodytext;
}
/**
* Getter for bodytext
*
* @return string bodytext
*/
public function getBodytext()
{
return $this->bodytext;
}
/**
* Setter for ctype
*
* @param string $ctype ctype
* @return void
*/
public function setCtype($ctype)
{
$this->ctype = $ctype;
}
/**
* Getter for ctype
*
* @return string ctype
*/
public function getCtype()
{
return $this->ctype;
}
/**
* Setter for colPos
*
* @param integer $colPos colPos
* @return void
*/
public function setColPos($colPos)
{
$this->colPos = $colPos;
}
/**
* Getter for colPos
*
* @return integer colPos
*/
public function getColPos()
{
return $this->colPos;
}
/**
* Setter for header
*
* @param string $header header
* @return void
*/
public function setHeader($header)
{
$this->header = $header;
}
/**
* Getter for header
*
* @return string header
*/
public function getHeader()
{
return $this->header;
}
/**
* Getter for categories
*
* @return ObjectStorage
*/
public function getCategories()
{
return $this->categories;
}
/**
* Setter for categories
*
* @param ObjectStorage $categories
* @return void
*/
public function setCategories($categories)
{
$this->categories = $categories;
}
/**
* Add category
*
* @param Category $category
* @return void
*/
public function addCategory(Category $category)
{
$this->categories->attach($category);
}
/**
* Remove category
*
* @param Category $category
* @return void
*/
public function removeCategory(Category $category)
{
$this->categories->detach($category);
}
/**
* Checks for attribute in _contentRow
*
* @param string $name Name of unknown method
* @param array arguments Arguments of call
* @return mixed
*/
public function __call($name, $arguments)
{
if (substr(strtolower($name), 0, 3) == 'get' && strlen($name) > 3) {
$attributeName = lcfirst(substr($name, 3));
if (empty($this->contentRow)) {
/** @var PageRepository $pageSelect */
$pageSelect = $GLOBALS['TSFE']->sys_page;
$contentRow = $pageSelect->getRawRecord('tt_content', $this->getUid());
foreach ($contentRow as $key => $value) {
$this->contentRow[GeneralUtility::underscoredToLowerCamelCase($key)] = $value;
}
}
if (isset($this->contentRow[$attributeName])) {
return $this->contentRow[$attributeName];
}
}
}
/**
* Get raw content row
*
* @return array
*/
public function getContentRow()
{
return $this->contentRow;
}
}

View File

@@ -0,0 +1,922 @@
<?php
namespace PwTeaserTeam\PwTeaser\Domain\Model;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;
/***************************************************************
* Copyright notice
*
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
* 2016 Tim Klein-Hitpass <tim.klein-hitpass@diemedialen.de>
* Kai Ratzeburg <kai.ratzeburg@diemedialen.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Page model
*
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Page extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/** Translation constant: Show page always */
const L18N_SHOW_ALWAYS = 0;
/** Translation constant: Hide page on default language */
const L18N_HIDE_DEFAULT_LANGUAGE = 1;
/** Translation constant: Hide page on foreign language if no translation exists */
const L18N_HIDE_IF_NO_TRANSLATION_EXISTS = 2;
/** Translation constant: Hide page always, but show on foreign langauge if translation exists */
const L18N_HIDE_ALWAYS_BUT_TRANSLATION_EXISTS = 3;
/**
* doktype
*
* @var integer
*/
protected $doktype;
/**
* isCurrentPage
*
* @var boolean
*/
protected $isCurrentPage = false;
/**
* title
*
* @var string
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
*/
protected $title;
/**
* subtitle
*
* @var string
*/
protected $subtitle;
/**
* navTitle
*
* @var string
*/
protected $navTitle;
/**
* meta keywords
*
* @var string
*/
protected $keywords;
/**
* meta description
*
* @var string
*/
protected $description;
/**
* abstract
*
* @var string
*/
protected $abstract;
/**
* alias
*
* @var string
*/
protected $alias;
/**
* media
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
*/
protected $media;
/**
* sorting
*
* @var integer
*/
protected $sorting;
/**
* creation date (crdate)
*
* @var integer
*/
protected $creationDate;
/**
* timestamp (tstamp)
*
* @var integer
*/
protected $tstamp;
/**
* lastUpdated
*
* @var integer
*/
protected $lastUpdated;
/**
* start time
*
* @var integer
*/
protected $starttime;
/**
* end time
*
* @var integer
*/
protected $endtime;
/**
* new until
*
* @var integer
*/
protected $newUntil;
/**
* author
*
* @var string
*/
protected $author;
/**
* author email
*
* @var string
*/
protected $authorEmail;
/**
* contents
*
* @var array<\PwTeaserTeam\PwTeaser\Domain\Model\Content>
*/
protected $contents;
/**
* Categories
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category>
*/
protected $categories;
/**
* @var integer
*/
protected $l18nConfiguration;
/**
* Child pages
*
* @var array<Page>
*/
protected $childPages = [];
/**
* Custom Attributes
* which can be set by hooks
*
* @var array<mixed>
*/
protected $customAttributes = [];
/**
* Complete row (from database) of this page
*
* @var array
*/
protected $pageRow = null;
/**
* @var \TYPO3\CMS\Core\Resource\FileRepository
* @TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $fileRepository;
/**
* Sets a custom attribute
*
* @param string $key The name of the attribute
* @param mixed $value Attribute's value
*
* @return void
*/
public function setCustomAttribute($key, $value)
{
$this->customAttributes[$key] = $value;
}
/**
* Returns the value of a custom attribute
*
* @param string $key Name of attribute
* @return mixed The value of a custom attribute
*/
public function getCustomAttribute($key)
{
if (!empty($key) && $this->hasCustomAttribute($key)) {
return $this->customAttributes[$key];
}
return null;
}
/**
* Checks if given custom attribute has been set
*
* @param string $key
* @return bool
*/
public function hasCustomAttribute($key)
{
return isset($this->customAttributes[$key]);
}
/**
* @return array
*/
public function getGet(): array
{
if (empty($this->pageRow)) {
/** @var \TYPO3\CMS\Frontend\Page\PageRepository $pageSelect */
$pageSelect = $GLOBALS['TSFE']->sys_page;
$pageRow = $pageSelect->getPage($this->getUid());
foreach ($pageRow as $key => $value) {
$this->pageRow[GeneralUtility::underscoredToLowerCamelCase($key)] = $value;
}
}
return array_merge($this->customAttributes, $this->pageRow);
}
/**
* Checks for attribute in _customAttributes and _pageRow
*
* @param string $name Name of unknown method
* @param array arguments Arguments of call
* @return mixed
* @deprecated Use getGet() instead (in fluid template: {page.get.attributeName})
*/
public function __call($name, $arguments)
{
if (substr(strtolower($name), 0, 3) === 'get' && strlen($name) > 3) {
$attributeName = lcfirst(substr($name, 3));
return $this->getGet()[$attributeName];
}
}
/**
* Constructor
*/
public function __construct()
{
$this->categories = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->media = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Setter for contents
*
* @param array <\PwTeaserTeam\PwTeaser\Domain\Model\Content> $contents array of contents
* @return void
*/
public function setContents($contents)
{
$this->contents = $contents;
}
/**
* Getter for contents
*
* @return array<\PwTeaserTeam\PwTeaser\Domain\Model\Content> contents
*/
public function getContents()
{
return $this->contents;
}
/**
* Getter for isCurrentPage
*
* @return boolean
*/
public function getIsCurrentPage()
{
return $this->isCurrentPage;
}
/**
* Setter for isCurrentPage
*
* @param boolean $isCurrentPage
* @return void
*/
public function setIsCurrentPage($isCurrentPage)
{
$this->isCurrentPage = $isCurrentPage;
}
/**
* Setter for authorEmail
*
* @param string $authorEmail authorEmail
* @return void
*/
public function setAuthorEmail($authorEmail)
{
$this->authorEmail = $authorEmail;
}
/**
* Getter for authorEmail
*
* @return string authorEmail
*/
public function getAuthorEmail()
{
return $this->authorEmail;
}
/**
* Setter for keywords
*
* @param string $keywords keywords
* @return void
*/
public function setKeywords($keywords)
{
$this->keywords = $keywords;
}
/**
* Getter for keywords
*
* @return array array of keywords
*/
public function getKeywords()
{
return (GeneralUtility::trimExplode(',', $this->keywords, true));
}
/**
* Getter for keywords. Returns a string
*
* @return string keywords as string
*/
public function getKeywordsAsString()
{
return $this->keywords;
}
/**
* Setter for description
*
* @param string $description description
* @return void
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Getter for description
*
* @return string description
*/
public function getDescription()
{
return $this->description;
}
/**
* Setter for alias
*
* @param string $alias alias
* @return void
*/
public function setAlias($alias)
{
$this->alias = $alias;
}
/**
* Getter for alias
*
* @return string alias
*/
public function getAlias()
{
return $this->alias;
}
/**
* Setter for navTitle
*
* @param string $navTitle navTitle
* @return void
*/
public function setNavTitle($navTitle)
{
$this->navTitle = $navTitle;
}
/**
* Getter for navTitle
*
* @return string navTitle
*/
public function getNavTitle()
{
return $this->navTitle;
}
/**
* Setter for abstract
*
* @param string $abstract abstract
* @return void
*/
public function setAbstract($abstract)
{
$this->abstract = $abstract;
}
/**
* Getter for abstract
*
* @return string abstract
*/
public function getAbstract()
{
return $this->abstract;
}
/**
* Setter for subtitle
*
* @param string $subtitle subtitle
* @return void
*/
public function setSubtitle($subtitle)
{
$this->subtitle = $subtitle;
}
/**
* Getter for subtitle
*
* @return string subtitle
*/
public function getSubtitle()
{
return $this->subtitle;
}
/**
* Setter for title
*
* @param string $title title
* @return void
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Getter for title
*
* @return string title
*/
public function getTitle()
{
return $this->title;
}
/**
* Setter for media
*
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $media
* @return void
*/
public function setMedia(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $media)
{
$this->media = $media;
}
/**
* Getter for media (returns FileReference objects)
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
*/
public function getMedia()
{
return $this->media;
}
/**
* Add single medium
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $medium
* @return void
*/
public function addMedium(\TYPO3\CMS\Extbase\Domain\Model\FileReference $medium)
{
$this->media->attach($medium);
}
/**
* Removes single medium
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $medium
* @return void
*/
public function removeMedium(\TYPO3\CMS\Extbase\Domain\Model\FileReference $medium)
{
$this->media->detach($medium);
}
/**
* Returns media files as array (with all attributes)
*
* @return array
* @deprecated Use media attribute instead
*/
public function getMediaFiles()
{
GeneralUtility::deprecationLog(
'Please don\'t use {page.mediaFiles} anymore in your pw_teaser templates. Use {page.media} instead.'
);
return $this->getMedia()->toArray();
}
/**
* Setter for newUntil
*
* @param integer $newUntil newUntil
* @return void
*/
public function setNewUntil($newUntil)
{
$this->newUntil = $newUntil;
}
/**
* Getter for newUntil
*
* @return integer newUntil
*/
public function getNewUntil()
{
return $this->newUntil;
}
/**
* Return TRUE if the page is marked as new
*
* @return boolean TRUE if the page is marked as new, otherwise FALSE
*/
public function getIsNew()
{
if (!empty($this->newUntil) && $this->newUntil !== 0) {
return $this->newUntil < time();
}
return false;
}
/**
* Setter for creationDate (crdate)
*
* @param integer $creationDate creationDate
* @return void
*/
public function setCreationDate($creationDate)
{
$this->creationDate = $creationDate;
}
/**
* Getter for creationDate (crdate)
*
* @return integer creationDate
*/
public function getCreationDate()
{
return $this->creationDate;
}
/**
* Setter for tstamp
*
* @param integer $tstamp tstamp
* @return void
*/
public function setTstamp($tstamp)
{
$this->tstamp = $tstamp;
}
/**
* Getter for tstamp
*
* @return integer tstamp
*/
public function getTstamp()
{
return $this->tstamp;
}
/**
* Setter for lastUpdated
*
* @param integer $lastUpdated lastUpdated
* @return void
*/
public function setLastUpdated($lastUpdated)
{
$this->lastUpdated = $lastUpdated;
}
/**
* Getter for lastUpdated
*
* @return integer lastUpdated
*/
public function getLastUpdated()
{
return $this->lastUpdated;
}
/**
* Setter for starttime
*
* @param integer $starttime
* @return void
*/
public function setStarttime($starttime)
{
$this->starttime = $starttime;
}
/**
* Getter for starttime
*
* @return integer starttime
*/
public function getStarttime()
{
return $this->starttime;
}
/**
* Getter for endtime
*
* @return integer endtime
*/
public function getEndtime()
{
return $this->endtime;
}
/**
* Setter for endtime
*
* @param integer $endtime endtime
* @return void
*/
public function setEndtime($endtime)
{
$this->endtime = $endtime;
}
/**
* Getter for author
*
* @return string author
*/
public function getAuthor()
{
return $this->author;
}
/**
* Setter for author
*
* @param string $author author
* @return void
*/
public function setAuthor($author)
{
$this->author = $author;
}
/**
* Getter for doktype
*
* @return integer the doktype
*/
public function getDoktype()
{
return $this->doktype;
}
/**
* Setter for doktype
*
* @param integer $doktype the doktype
* @return void
*/
public function setDoktype($doktype)
{
$this->doktype = $doktype;
}
/**
* Getter for l18nConfiguration
*
* @return integer
*/
public function getL18nConfiguration()
{
return $this->l18nConfiguration;
}
/**
* Setter for l18nConfiguration
*
* @param integer $l18nCfg
* @return void
*/
public function setL18nConfiguration($l18nCfg)
{
$this->l18nConfiguration = $l18nCfg;
}
/**
* Getter for categories
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
*/
public function getCategories()
{
return $this->categories;
}
/**
* Setter for categories
*
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $categories
* @return void
*/
public function setCategories($categories)
{
$this->categories = $categories;
}
/**
* Add category
*
* @param \TYPO3\CMS\Extbase\Domain\Model\Category $category
* @return void
*/
public function addCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category)
{
$this->categories->attach($category);
}
/**
* Remove category
*
* @param \TYPO3\CMS\Extbase\Domain\Model\Category $category
* @return void
*/
public function removeCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category)
{
$this->categories->detach($category);
}
/**
* Returns rootLine of this page
*
* @return array
*/
public function getRootLine()
{
$context = GeneralUtility::makeInstance(Context::class);
/** @var RootlineUtility $rootline */
$rootline = GeneralUtility::makeInstance(RootlineUtility::class, $this->getUid(), '', $context);
return $rootline->get();
}
/**
* Returns amount of parent pages, including this page itself.
* The root page (not id=0) got depth 1.
*
* @return integer
*/
public function getRootLineDepth()
{
return count($this->getRootLine());
}
/**
* Returns string of sortings of all root pages including this page.
*
* @return string String with orderings of this page and all root pages
*/
public function getRecursiveRootLineOrdering()
{
$recursiveOrdering = [];
foreach ($this->getRootLine() as $pageRootPart) {
array_unshift($recursiveOrdering, str_pad($pageRootPart['sorting'], 11, '0', STR_PAD_LEFT));
}
return implode('-', $recursiveOrdering);
}
/**
* Returns the complete page row (from database) as array
*
* @return array
*/
public function getPageRow()
{
return $this->pageRow;
}
/**
* Getter for sorting
*
* @return integer
*/
public function getSorting()
{
return $this->sorting;
}
/**
* Setter for sorting
*
* @param integer $sorting
* @return void
*/
public function setSorting($sorting)
{
$this->sorting = $sorting;
}
/**
* Getter for child pages
*
* @return array
*/
public function getChildPages()
{
return $this->childPages;
}
/**
* Setter for child pages
*
* @param array <Page> $childPages
* @return void
*/
public function setChildPages(array $childPages)
{
$this->childPages = $childPages;
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace PwTeaserTeam\PwTeaser\Domain\Repository;
/***************************************************************
* Copyright notice
*
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
* 2016 Tim Klein-Hitpass <tim.klein-hitpass@diemedialen.de>
* Kai Ratzeburg <kai.ratzeburg@diemedialen.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Repository for Content model
*
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class ContentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
/**
* Initializes the repository.
*
* @return void
* @see \TYPO3\CMS\Extbase\Persistence\Repository::initializeObject()
*/
public function initializeObject()
{
/** @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings */
$querySettings = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface');
$querySettings->setRespectStoragePage(false);
$this->setDefaultQuerySettings($querySettings);
}
/**
* Returns all objects of this repository which matches the given pid. This
* overwritten method exists, to perform sorting
*
* @param integer $pid Pid to search for
* @return \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult All found objects, will be
* empty if there are no objects
*/
public function findByPid($pid)
{
$query = $this->createQuery();
$query->matching($query->equals('pid', $pid));
$query->setOrderings(
[
'sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
]
);
return $query->execute();
}
/**
* Returns all objects of this repository which are located inside the
* given pages
*
* @param array <\PwTeaserTeam\PwTeaser\Domain\Model\Page> $pages Pages to get content elements
* @return \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult All found objects, will be
* empty if there are no objects
*/
public function findByPages($pages)
{
$query = $this->createQuery();
$constraint = [];
foreach ($pages as $page) {
$constraint[] = $query->equals('pid', $page->getUid());
}
$query->matching($query->logicalOr($constraint));
return $query->execute();
}
}

View File

@@ -0,0 +1,456 @@
<?php
namespace PwTeaserTeam\PwTeaser\Domain\Repository;
/***************************************************************
* Copyright notice
*
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
* 2016 Tim Klein-Hitpass <tim.klein-hitpass@diemedialen.de>
* Kai Ratzeburg <kai.ratzeburg@diemedialen.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use PwTeaserTeam\PwTeaser\Domain\Model\Page;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Repository for Page model
*
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class PageRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
/** Category Mode: Or */
const CATEGORY_MODE_OR = 1;
/** Category Mode: And */
const CATEGORY_MODE_AND = 2;
/** Category Mode: Or Not */
const CATEGORY_MODE_OR_NOT = 3;
/** Category Mode: And Not */
const CATEGORY_MODE_AND_NOT = 4;
/**
* page attribute to order by
*
* @var string
*/
protected $orderBy = 'uid';
/**
* Direction to order. Default is ascending.
*
* @var string
*/
protected $orderDirection = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING;
/**
* @var \TYPO3\CMS\Extbase\Persistence\QueryInterface
*/
protected $query = null;
/**
* @var array
*/
protected $queryConstraints = [];
/**
* Initializes the repository.
*
* @return void
* @see \TYPO3\CMS\Extbase\Persistence\Repository::initializeObject()
*/
public function initializeObject()
{
/** @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings */
$querySettings = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface');
$querySettings->setRespectStoragePage(false);
$this->setDefaultQuerySettings($querySettings);
$this->query = $this->createQuery();
}
/**
* Returns all objects of this repository which match the pid
*
* @param integer $pid the pid to search for
* @return array All found pages, will be empty if the result is empty
*/
public function findByPid($pid)
{
$this->addQueryConstraint($this->query->equals('pid', $pid));
return $this->executeQuery();
}
/**
* Returns all objects of this repository which are children of the matched
* pid (recursively)
*
* @param integer $pid the pid to search for recursively
* @param integer $recursionDepthFrom Start of recursion depth
* @param integer $recursionDepth Depth of recursion
* @return array All found pages, will be empty if the result is empty
*/
public function findByPidRecursively($pid, $recursionDepthFrom, $recursionDepth)
{
return $this->findChildrenRecursivelyByPidList($pid, $recursionDepthFrom, $recursionDepth);
}
/**
* Returns all objects of this repository which are in the pidlist
*
* @param string $pidlist comma seperated list of pids to search for
* @param boolean $orderByPlugin setting of ordering by plugin
* @return array All found pages, will be empty if the result is empty
*/
public function findByPidList($pidlist, $orderByPlugin = false)
{
$pagePids = GeneralUtility::intExplode(',', $pidlist, true);
// early return when list is empty to prevent sql exception
if (empty($pagePids)) {
return [];
}
$query = $this->query;
$this->addQueryConstraint($query->in('uid', $pagePids));
$query->matching($query->logicalAnd($this->queryConstraints));
if ($orderByPlugin == false) {
$this->handleOrdering($query);
$results = $query->execute();
$this->resetQuery();
return $this->handlePageLocalization($results);
} else {
$results = $query->execute();
$this->resetQuery();
return $this->orderByPlugin($pagePids, $this->handlePageLocalization($results));
}
}
/**
* Creates array of result items, with the order of given pagePids
*
* @param array $pagePids pagePids to order for
* @param array $results results to reorder
* @return array results ordered by plugin
*/
protected function orderByPlugin(array $pagePids, array $results)
{
$sortedResults = [];
foreach ($pagePids as $pagePid) {
foreach ($results as $result) {
if ($pagePid === $result->getUid()) {
$sortedResults[] = $result;
continue;
}
}
}
return $sortedResults;
}
/**
* Returns all objects of this repository which are in the pidlist
*
* @param string $pidlist comma seperated list of pids to search for
* @return array All found pages, will be empty if the result is empty
*/
public function findChildrenByPidList($pidlist)
{
$pagePids = GeneralUtility::intExplode(',', $pidlist, true);
// early return when list is empty to prevent sql exception
if (empty($pagePids)) {
return [];
}
$this->addQueryConstraint($this->query->in('pid', $pagePids));
return $this->executeQuery();
}
/**
* Returns all objects of this repository which are children of pages in the
* pidlist (recursively)
*
* @param string $pidlist comma seperated list of pids to search for
* @param integer $recursionDepthFrom Start level for recursion
* @param integer $recursionDepth Depth of recursion
* @return array All found pages, will be empty if the result is empty
*/
public function findChildrenRecursivelyByPidList($pidlist, $recursionDepthFrom, $recursionDepth)
{
$pagePids = $this->getRecursivePageList($pidlist, $recursionDepthFrom, $recursionDepth);
$this->addQueryConstraint($this->query->in(($recursionDepthFrom === 0) ? 'pid' : 'uid', $pagePids));
return $this->executeQuery();
}
/**
* Adds query constraint to array
*
* @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint Constraint to add
* @return void
*/
protected function addQueryConstraint(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint)
{
$this->queryConstraints[] = $constraint;
}
/**
* Add category constraint
*
* @param array $categories
* @param boolean $isAnd If TRUE categories get a logicalAnd. Otherwise a logicalOr.
* @param boolean $isNot If TRUE categories get a logicalNot operator. Otherwise not.
* @return void
*/
public function addCategoryConstraint(array $categories, $isAnd = true, $isNot = false)
{
if ($isAnd === true && $isNot === false) {
$this->queryConstraints[] = $this->query->logicalAnd($this->buildCategoryConstraint($categories));
}
if ($isAnd === true && $isNot === true) {
$this->queryConstraints[] = $this->query->logicalNot(
$this->query->logicalAnd(
$this->buildCategoryConstraint($categories)
)
);
}
if ($isAnd === false && $isNot === false) {
$this->queryConstraints[] = $this->query->logicalOr($this->buildCategoryConstraint($categories));
}
if ($isAnd === false && $isNot === true) {
$this->queryConstraints[] = $this->query->logicalNot(
$this->query->logicalOr(
$this->buildCategoryConstraint($categories)
)
);
}
}
/**
* Build category constraint for each category (contains)
*
* @param array $categories
* @return array
*/
protected function buildCategoryConstraint(array $categories)
{
$contraints = [];
foreach ($categories as $category) {
$contraints[] = $this->query->contains('categories', $category);
}
return $contraints;
}
/**
* Finalize given query constraints and executes the query
*
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface Result of query
*/
protected function executeQuery()
{
$query = $this->query;
$query->matching($query->logicalAnd($this->queryConstraints));
$this->handleOrdering($query);
$queryResult = $query->execute();
$this->resetQuery();
$queryResult = $this->handlePageLocalization($queryResult);
return $queryResult;
}
/**
* Handles page localization
*
* @param \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult $pages
* @return array<\PwTeaserTeam\PwTeaser\Domain\Model\Page>
*/
protected function handlePageLocalization(\TYPO3\CMS\Extbase\Persistence\Generic\QueryResult $pages)
{
/** @var Context $context */
$context = GeneralUtility::makeInstance(Context::class);
$currentLangUid = $context->getPropertyFromAspect('language', 'id');
$displayedPages = [];
/** @var Page $page */
foreach ($pages as $page) {
if ($currentLangUid === 0) {
if ($page->getL18nConfiguration() !== Page::L18N_HIDE_DEFAULT_LANGUAGE &&
$page->getL18nConfiguration() !== Page::L18N_HIDE_ALWAYS_BUT_TRANSLATION_EXISTS) {
$displayedPages[] = $page;
}
} else {
/** @var \TYPO3\CMS\Frontend\Page\PageRepository $pageSelect */
$pageSelect = $GLOBALS['TSFE']->sys_page;
$pageRowWithOverlays = $pageSelect->getPage($page->getUid());
if ((boolean)$GLOBALS['TYPO3_CONF_VARS']['FE']['hidePagesIfNotTranslatedByDefault'] === false) {
if (!($page->getL18nConfiguration() === Page::L18N_HIDE_IF_NO_TRANSLATION_EXISTS ||
$page->getL18nConfiguration() === Page::L18N_HIDE_ALWAYS_BUT_TRANSLATION_EXISTS) ||
isset($pageRowWithOverlays['_PAGES_OVERLAY'])) {
$displayedPages[] = $page;
}
} else {
if (($page->getL18nConfiguration() === Page::L18N_HIDE_IF_NO_TRANSLATION_EXISTS ||
$page->getL18nConfiguration() === Page::L18N_HIDE_ALWAYS_BUT_TRANSLATION_EXISTS) &&
!isset($pageRowWithOverlays['_PAGES_OVERLAY']) ||
isset($pageRowWithOverlays['_PAGES_OVERLAY'])) {
$displayedPages[] = $page;
}
}
}
}
return $displayedPages;
}
/**
* Get subpages recursivley of given pid(s).
*
* @param string $pidlist List of pageUids to get subpages of. May contain a single uid.
* @param integer $recursionDepthFrom Start of recursion depth
* @param integer $recursionDepth Depth of recursion
* @return array Found subpages, recursivley
*/
protected function getRecursivePageList($pidlist, $recursionDepthFrom, $recursionDepth)
{
/** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer */
$contentObjectRenderer = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
$pagePids = [];
$pids = GeneralUtility::intExplode(',', $pidlist, true);
foreach ($pids as $pid) {
$pageList = GeneralUtility::intExplode(
',',
$contentObjectRenderer->getTreeList($pid, $recursionDepth, $recursionDepthFrom),
true
);
$pagePids = array_merge($pagePids, $pageList);
if ($recursionDepthFrom === 0) {
array_unshift($pagePids, $pid);
}
}
return array_unique($pagePids);
}
/**
* Sets the order by which is used by all find methods
*
* @param string $orderBy property to order by
* @return void
*/
public function setOrderBy($orderBy)
{
if ($orderBy !== 'random') {
$this->orderBy = $orderBy;
}
}
/**
* Sets the order direction which is used by all find methods
*
* @param string $orderDirection the direction to order, may be desc or asc
* @return void
*/
public function setOrderDirection($orderDirection)
{
if ($orderDirection == 'desc' || $orderDirection == 1) {
$this->orderDirection = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING;
} else {
$this->orderDirection = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING;
}
}
/**
* Sets the query limit
*
* @param integer $limit The limit of elements to show
* @return void
*/
public function setLimit($limit)
{
$this->query->setLimit($limit);
}
/**
* Sets the nav_hide_state flag
*
* @param boolean $showNavHiddenItems If TRUE lets show items which should not be visible in navigation.
* Default is FALSE.
* @return void
*/
public function setShowNavHiddenItems($showNavHiddenItems)
{
if ($showNavHiddenItems === true) {
$this->addQueryConstraint($this->query->in('nav_hide', [0, 1]));
} else {
$this->addQueryConstraint($this->query->in('nav_hide', [0]));
}
}
/**
* Sets doktypes to filter for
*
* @param array $dokTypesToFilterFor doktypes as array, may be empty
* @return void
*/
public function setFilteredDokType(array $dokTypesToFilterFor)
{
if (count($dokTypesToFilterFor) > 0) {
$this->addQueryConstraint($this->query->in('doktype', $dokTypesToFilterFor));
}
}
/**
* Ignores given uid
*
* @param integer $currentPageUid Uid to ignore
* @return void
*/
public function setIgnoreOfUid($currentPageUid)
{
$this->addQueryConstraint($this->query->logicalNot($this->query->equals('uid', $currentPageUid)));
}
/**
* Adds handle of ordering to query object
*
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @return void
*/
protected function handleOrdering(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query)
{
$query->setOrderings([$this->orderBy => $this->orderDirection]);
}
/**
* Resets query and queryConstraints after execution
*
* @return void
*/
protected function resetQuery()
{
unset($this->query);
$this->query = $this->createQuery();
unset($this->queryConstraints);
$this->queryConstraints = [];
}
}

View File

@@ -0,0 +1,20 @@
<?php declare(strict_types=1);
namespace PwTeaserTeam\PwTeaser\UserFunction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Object\ObjectManager;
class ItemsProcFunc
{
public function getAvailableTemplatePresets(array &$parameters): void
{
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$configurationManager = $objectManager->get(ConfigurationManager::class);
$config = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
$presets = $config['plugin.']['tx_pwteaser.']['view.']['presets.'] ?? [];
foreach ($presets as $key => $preset) {
$parameters['items'][] = [$preset['label'], rtrim($key, '.')];
}
}
}

View File

@@ -0,0 +1,140 @@
<?php
namespace PwTeaserTeam\PwTeaser\Utility;
/***************************************************************
* Copyright notice
*
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
* Benjamin Schulte <benjamin.schulte@diemedialen.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* This class provides some methods to prepare and render given extension settings
*
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Settings
{
/**
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
*/
protected $contentObject;
/**
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
* @TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $configurationManager = null;
/**
* Initialize this settings utility
*
* @return void
*/
public function initializeObject()
{
$this->contentObject = $this->configurationManager->getContentObject();
}
/**
* Renders a given typoscript configuration and returns the whole array with
* calculated values.
*
* @param array $settings the typoscript configuration array
* @param string $section
* @return array the configuration array with the rendered typoscript
*/
public function renderConfigurationArray(array $settings, string $section = 'settings.')
{
$settings = $this->enhanceSettingsWithTypoScript($this->makeConfigurationArrayRenderable($settings), $section);
$result = [];
foreach ($settings as $key => $value) {
if (substr($key, -1) === '.') {
$keyWithoutDot = substr($key, 0, -1);
if (array_key_exists($keyWithoutDot, $settings)) {
$result[$keyWithoutDot] = $this->contentObject->cObjGetSingle($settings[$keyWithoutDot], $value);
} else {
$result[$keyWithoutDot] = $this->renderConfigurationArray($value);
}
} else {
if (!array_key_exists($key . '.', $settings)) {
$result[$key] = $value;
}
}
}
return $result;
}
/**
* Overwrite flexform values with typoscript if flexform value is empty and typoscript value exists.
*
* @param array $settings Settings from flexform
* @param string $section
* @param string $extKey
* @return array enhanced settings
*/
protected function enhanceSettingsWithTypoScript(
array $settings,
string $section = 'settings.',
string $extKey = 'tx_pwteaser'
) {
$typoscript = $this->configurationManager->getConfiguration(
\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);
$typoscript = $typoscript['plugin.'][$extKey . '.'][$section];
foreach ($settings as $key => $setting) {
if ($setting === '' && is_array($typoscript) && array_key_exists($key, $typoscript)) {
$settings[$key] = $typoscript[$key];
}
}
return $settings;
}
/**
* Formats a given array with typoscript syntax, recursively. After the
* transformation it can be rendered with cObjGetSingle.
*
* Example:
* Before: $array['level1']['level2']['finalLevel'] = 'hello kitty'
* After: $array['level1.']['level2.']['finalLevel'] = 'hello kitty'
* $array['level1'] = 'TEXT'
*
* @param array $configuration settings array to make renderable
* @return array the renderable settings
*/
protected function makeConfigurationArrayRenderable(array $configuration)
{
$dottedConfiguration = [];
foreach ($configuration as $key => $value) {
if (is_array($value)) {
if (array_key_exists('_typoScriptNodeValue', $value)) {
$dottedConfiguration[$key] = $value['_typoScriptNodeValue'];
}
$dottedConfiguration[$key . '.'] = $this->makeConfigurationArrayRenderable($value);
} else {
$dottedConfiguration[$key] = $value;
}
}
return $dottedConfiguration;
}
}

View File

@@ -0,0 +1,102 @@
<?php
namespace PwTeaserTeam\PwTeaser\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
* 2016 Tim Klein-Hitpass <tim.klein-hitpass@diemedialen.de>
* Kai Ratzeburg <kai.ratzeburg@diemedialen.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* This class creates links to social bookmark services, recommending the
* current front-end page.
*
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class GetContentViewHelper extends \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper
{
protected $escapeOutput = false;
/**
* @return void
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('contents', 'array', 'Content elements');
$this->registerArgument('as', 'string', 'the name of the iteration variable', true);
$this->registerArgument('colPos', 'integer', 'column position to get content elements from', false, 0);
$this->registerArgument('cType', 'string', 'the cType to filter content elements for');
$this->registerArgument('index', 'integer', 'limits the output to n-th element');
}
public function render()
{
$contents = $this->arguments['contents'];
if ($contents === null) {
return '';
}
$output = '';
$indexCount = 0;
$breakNow = false;
$asHasBeenSet = false;
/** @var $content \PwTeaserTeam\PwTeaser\Domain\Model\Content */
foreach ($contents as $content) {
$contentCtype = $content->getCtype();
$contentColPos = $content->getColPos();
if ($contentColPos == $this->arguments['colPos']) {
if ($this->arguments['cType'] === null || $contentCtype == $this->arguments['cType']) {
if ($this->arguments['index'] === null) {
$this->templateVariableContainer->add($this->arguments['as'], $content);
$asHasBeenSet = true;
} else {
if ($indexCount == $this->arguments['index']) {
$this->templateVariableContainer->add($this->arguments['as'], $content);
$asHasBeenSet = true;
$breakNow = true;
}
}
}
}
if ($asHasBeenSet) {
$output .= $this->renderChildren();
$this->templateVariableContainer->remove($this->arguments['as']);
$asHasBeenSet = false;
}
if ($breakNow) {
break;
}
if ($this->arguments['cType'] === null || $contentCtype == $this->arguments['cType']) {
$indexCount++;
}
}
return $output;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace PwTeaserTeam\PwTeaser\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* This view helper removes whitespaces which are annoying the HTML output,
* cause some browsers are interpreting tabs and new lines.
*
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class RemoveWhitespacesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
/**
* Returns the content without dispensable whitespaces
*
* @return string Rendered string, may be empty.
*/
public function render()
{
return str_replace(["\t", "\r", "\n"], '', $this->renderChildren());
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace PwTeaserTeam\PwTeaser\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* This class strips html and php code out of a string
*
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class StripTagsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
/**
* Strips html and php code out of a string
*
* @param string $string The string which will be stripped
* @return string the stripped string
*/
public function render($string = null)
{
if ($string === null) {
$string = html_entity_decode($this->renderChildren());
if ($string === null) {
return '';
}
}
return strip_tags($string);
}
}

View File

@@ -0,0 +1,252 @@
<?php
namespace PwTeaserTeam\PwTeaser\ViewHelpers\Widget\Controller;
/***************************************************************
* Copyright notice
*
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* This view helper uses the technology of paginate widget but works with arrays
* and the assigned objects don't need the QueryResultInterface.
*
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class PaginateController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController
{
/**
* @var array
*/
protected $configuration = [
'itemsPerPage' => 5,
'insertAbove' => false,
'insertBelow' => true,
'maximumVisiblePages' => 7
];
/**
* @var array
*/
protected $objects;
/**
* @var integer
*/
protected $currentPage = 1;
/**
* @var integer
*/
protected $numberOfPages = 1;
/**
* @var integer
*/
protected $itemsPerPage = 0;
/**
* Initialize Action of the widget controller
*
* @return void
*/
public function initializeAction()
{
$this->objects = $this->widgetConfiguration['objects'];
\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule(
$this->configuration,
$this->widgetConfiguration['configuration']
);
}
/**
* Returns the items per page
*
* @return integer the items per page
*/
public function getItemsPerPage()
{
return $this->itemsPerPage;
}
/**
* Sets the items per page
*
* @param integer $itemsPerPage the items per page
* @return void
*/
public function setItemsPerPage($itemsPerPage)
{
if (empty($itemsPerPage)) {
$this->itemsPerPage = (integer)$this->configuration['itemsPerPage'];
} else {
$this->itemsPerPage = $itemsPerPage;
}
}
/**
* Returns the number of pages
*
* @return integer
*/
public function getNumberOfPages()
{
return $this->numberOfPages;
}
/**
* Sets the number of pages
*
* @param integer $numberOfPages the number of pages
* @return void
*/
public function setNumberOfPages($numberOfPages)
{
$this->numberOfPages = $numberOfPages;
}
/**
* Returns the current page
*
* @return integer the current page
*/
public function getCurrentPage()
{
return $this->currentPage;
}
/**
* Sets the current page and limits it between 1 and $this->numberOfPages.
*
* @param integer $currentPage the current page
* @return void
*/
public function setCurrentPage($currentPage)
{
$this->currentPage = $currentPage;
if ($this->currentPage < 1) {
$this->currentPage = 1;
} elseif ($this->currentPage > $this->numberOfPages) {
$this->currentPage = $this->numberOfPages;
}
}
/**
* Returns all visible objects within a range, depending on itemsPerPage and the currentPage.
*
* @param \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult|array $objects the list of objects
* @return array<mixed> the list of visible objects
*/
public function getVisibleObjects($objects)
{
$i = 0;
$modifiedObjects = [];
$indexMin = $this->itemsPerPage * ($this->currentPage - 1);
$indexMax = $this->itemsPerPage * $this->currentPage - 1;
foreach ($objects as $object) {
if ($i >= $indexMin && $i <= $indexMax) {
$modifiedObjects[] = $object;
}
$i++;
}
return $modifiedObjects;
}
/**
* Index action of the widget controller
*
* @param integer $currentPage
* @param integer $itemsPerPage
* @return void
*/
public function indexAction($currentPage = 1, $itemsPerPage = 0)
{
$this->setItemsPerPage($itemsPerPage);
$this->setNumberOfPages(intval(ceil(count($this->objects) / (integer)$this->itemsPerPage)));
$this->setCurrentPage((integer)$currentPage);
$this->view->assign(
'contentArguments',
[
$this->widgetConfiguration['as'] => $this->getVisibleObjects($this->objects)
]
);
$this->view->assign('configuration', $this->configuration);
$this->view->assign('pagination', $this->buildPagination());
$this->view->assign('itemsPerPage', $this->itemsPerPage);
}
/**
* Returns an array with the keys "pages", "current", "numberOfPages", "nextPage" & "previousPage"
*
* @return array
*/
protected function buildPagination()
{
$sidePageCount = intval($this->configuration['maximumVisiblePages']) >> 1;
$firstPage = max($this->currentPage - $sidePageCount, 1);
$lastPage = min($firstPage + $sidePageCount * 2, $this->numberOfPages);
$firstPage = max($lastPage - $sidePageCount * 2, 1);
$pages = [];
foreach (range($firstPage, $lastPage) as $index) {
$pages[] = [
'number' => $index,
'isCurrent' => ($index === $this->currentPage)
];
}
$pagination = [
'pages' => $pages,
'current' => $this->currentPage,
'numberOfPages' => $this->numberOfPages,
'itemsPerPage' => $this->itemsPerPage,
'firstPage' => 1,
'lastPage' => $this->numberOfPages,
'isFirstPage' => ($this->currentPage == 1),
'isLastPage' => ($this->currentPage == $this->numberOfPages)
];
return $this->addPreviousAndNextPage($pagination);
}
/**
* Adds the nextPage and the previousPage to the pagination array
*
* @param array $pagination the pagination array which get previous and
* next page
* @return array the pagination array which contains some meta data and
* another array which are the pages
*/
protected function addPreviousAndNextPage($pagination)
{
if ($this->currentPage < $this->numberOfPages) {
$pagination['nextPage'] = $this->currentPage + 1;
}
if ($this->currentPage > 1) {
$pagination['previousPage'] = $this->currentPage - 1;
}
return $pagination;
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace PwTeaserTeam\PwTeaser\ViewHelpers\Widget;
/***************************************************************
* Copyright notice
*
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* This widget is a copy of the fluid paginate widget. Now it's possible to
* use arrays with paginate, not only query results.
*
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class PaginateViewHelper extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper
{
/**
* @var \PwTeaserTeam\PwTeaser\ViewHelpers\Widget\Controller\PaginateController
* @TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $controller;
/**
* The render method of widget
*
* @param mixed $objects
* @param string $as
* @param array $configuration
* @return string
*/
public function render(
$objects,
$as,
array $configuration = ['itemsPerPage' => 10, 'insertAbove' => false, 'insertBelow' => true]
) {
return $this->initiateSubRequest();
}
}