Skip to content
Snippets Groups Projects
Commit e2c813e1 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

Merge branch 'feature_UpgradeTo9LTS' into 'master'

Feature upgrade to9 lts

See merge request !8
parents 292066f8 28280660
No related branches found
No related tags found
1 merge request!8Feature upgrade to9 lts
Showing
with 711 additions and 565 deletions
......@@ -27,17 +27,20 @@ namespace SGalinski\SgNews\Command;
***************************************************************/
use SGalinski\SgNews\Domain\Model\News;
use SGalinski\SgNews\Domain\Model\Tag;
use SGalinski\SgNews\Domain\Repository\FileReferenceRepository;
use SGalinski\SgNews\Domain\Repository\NewsRepository;
use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
use TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
......@@ -50,29 +53,41 @@ class MigrateNewsCommandController extends CommandController {
protected $requestAdminPermissions = TRUE;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
* @inject
* @var PersistenceManager
*/
protected $persistenceManager;
/**
* @var \SGalinski\SgNews\Domain\Repository\NewsRepository
* @inject
* @param PersistenceManager $persistenceManager
*/
public function injectPersistenceManager(PersistenceManager $persistenceManager) {
$this->persistenceManager = $persistenceManager;
}
/**
* @var NewsRepository
*/
protected $newsRepository;
/**
* @var \SGalinski\SgNews\Domain\Repository\TagRepository
* @inject
* @param NewsRepository $newsRepository
*/
private $tagRepository;
public function injectNewsRepository(NewsRepository $newsRepository) {
$this->newsRepository = $newsRepository;
}
/**
* @var \SGalinski\SgNews\Domain\Repository\FileReferenceRepository
* @inject
* @var FileReferenceRepository
*/
private $fileReferenceRepository;
/**
* @param FileReferenceRepository $fileReferenceRepository
*/
public function injectFileReferenceRepository(FileReferenceRepository $fileReferenceRepository) {
$this->fileReferenceRepository = $fileReferenceRepository;
}
/**
* this array maps new pages to their original entry in the tx_news table
*
......@@ -117,8 +132,7 @@ class MigrateNewsCommandController extends CommandController {
) {
// fix repair translation bug where tsfe is missing from command controller, can be removed when v1.5 is released
if (!$GLOBALS['TSFE']) {
/** @var TypoScriptFrontendController $typoScriptController */
$GLOBALS['TSFE'] = $typoScriptController = $this->objectManager->get(
$GLOBALS['TSFE'] = $this->objectManager->get(
TypoScriptFrontendController::class, $GLOBALS['TYPO3_CONF_VARS'], 0, 0
);
}
......@@ -126,13 +140,14 @@ class MigrateNewsCommandController extends CommandController {
$this->languageMap = json_decode($languageMapAsJson, TRUE);
$this->categoryMap = json_decode($categoryMapAsJson, TRUE);
/** @var DatabaseConnection $db */
$db = $GLOBALS['TYPO3_DB'];
$where = 'hidden = 0 and deleted = 0 and endtime = 0 and pid = ' . (int) $pId;
/** @var \mysqli_result $result */
$result = $db->exec_SELECTquery('*', 'tx_news_domain_model_news', $where);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_news_domain_model_news');
$queryBuilder->getRestrictions()->removeByType(StartTimeRestriction::class);
$rows = $queryBuilder->select('*')
->from('tx_news_domain_model_news')
->where(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pId, \PDO::PARAM_INT))
)
->execute()->fetchAll();
$localDataHandler = GeneralUtility::makeInstance(DataHandler::class);
$beUser = $this->simulateBackendUser();
$localCommandMap = [
......@@ -143,13 +158,11 @@ class MigrateNewsCommandController extends CommandController {
]
];
$resultArray = [];
while ($row = $result->fetch_assoc()) {
foreach ($rows as $row) {
// ignore the entry if its not within the given year
if ((int) date('Y', $row['datetime']) !== $year) {
continue;
}
$resultArray[] = $row;
// if no l10n_parent exists, create a copy of the page
if ((int) $row['l10n_parent'] === 0) {
......@@ -199,8 +212,17 @@ class MigrateNewsCommandController extends CommandController {
$this->persistenceManager->persistAll();
// update content element from the new page
$where = 'pid = ' . $newPageId . ' AND sys_language_uid = ' . $this->languageMap[(int) $row['sys_language_uid']];
$db->exec_UPDATEquery('tt_content', $where, ['bodytext' => $row['bodytext']]);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder->update('tt_content')
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($newPageId, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($this->languageMap[(int) $row['sys_language_uid']], \PDO::PARAM_INT))
)
)
->set('bodytext', $row['bodytext'], TRUE)
->execute();
}
} else { // this row is a translation and should simply update the content accordingly
$this->updateTranslation($row);
......@@ -217,20 +239,30 @@ class MigrateNewsCommandController extends CommandController {
*/
private function getMatchingFile(array $row) {
// match old page id with old file reference id
/** @var DatabaseConnection $db */
$db = $GLOBALS['TYPO3_DB'];
$where = 'tablenames = "tx_news_domain_model_news" AND fieldname = "fal_media" AND uid_foreign = ' . $row['uid'];
/** @var \mysqli_result $result */
$fileReferenceResult = $db->exec_SELECTgetSingleRow(
'uid, uid_local', 'sys_file_reference_news_migration', $where
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference_news_migration');
$queryBuilder->getRestrictions()->removeAll();
$fileReferenceResult = $queryBuilder->select('uid', 'uid_local')
->from('sys_file_reference_news_migration')
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news')),
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('fal_media')),
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($row['uid'], \PDO::PARAM_INT))
)
)
->execute()->fetch();
if (!$fileReferenceResult) {
return NULL;
}
$where = 'uid = ' . $fileReferenceResult['uid_local'];
/** @var \mysqli_result $result */
$fileResult = $db->exec_SELECTgetSingleRow('identifier', 'sys_file_news_migration', $where);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_news_migration');
$queryBuilder->getRestrictions()->removeAll();
$fileResult = $queryBuilder->select('identifier')
->from('sys_file_news_migration')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($fileReferenceResult['uid_local'], \PDO::PARAM_INT))
)
->execute()->fetch();
if (!$fileResult) {
return NULL;
}
......@@ -249,17 +281,17 @@ class MigrateNewsCommandController extends CommandController {
* Get the tag / category, matching the news
*
* @param array $row
* @return News
*/
private function setMatchingTag(array $row) {
/** @var DatabaseConnection $db */
$db = $GLOBALS['TYPO3_DB'];
$where = 'uid_foreign = ' . (int) $row['uid'];
/** @var \mysqli_result $result */
$result = $db->exec_SELECTquery('uid_local, sorting_foreign', 'sys_category_record_mm_news_migration', $where);
while ($mmRow = $result->fetch_assoc()) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_category_record_mm_news_migration');
$queryBuilder->getRestrictions()->removeAll();
$mmRows = $queryBuilder->select('uid_local', 'sorting_foreign')
->from('sys_category_record_mm_news_migration')
->where(
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($row['uid'], \PDO::PARAM_INT))
)
->execute()->fetchAll();
foreach ($mmRows as $mmRow) {
$values = [
'uid_local' => $this->categoryMap[(int) $mmRow['uid_local']],
'uid_foreign' => $this->newsPagesMap[(int) $row['uid']],
......@@ -267,7 +299,8 @@ class MigrateNewsCommandController extends CommandController {
'fieldname' => 'tx_sgnews_tags',
'sorting_foreign' => (int) $mmRow['sorting_foreign']
];
$db->exec_INSERTquery('sys_category_record_mm', $values);
$queryBuilder->insert('sys_category_record_mm')
->values($values);
}
}
......@@ -277,68 +310,111 @@ class MigrateNewsCommandController extends CommandController {
* @param array $row
*/
private function updateTranslation(array $row) {
/** @var DatabaseConnection $db */
$db = $GLOBALS['TYPO3_DB'];
// get entry in news map
$parentId = $this->newsPagesMap[$row['l10n_parent']];
// get content element from the original page
$where = 'pid = ' . (int) $parentId;
/** @var \mysqli_result $result */
$result = $db->exec_SELECTquery('l18n_parent', 'tt_content', $where);
$originalContentElement = $result->fetch_row();
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
$queryBuilder->getRestrictions()->removeAll();
$originalContentElement = $queryBuilder->select('l18n_parent')
->from('tt_content')
->where(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($parentId, \PDO::PARAM_INT))
)
->execute()->fetch();
$queryBuilder->update('tt_content');
// if its the new default, there is no l18n_parent
if ((int) $this->languageMap[(int) $row['sys_language_uid'] === 0]) {
$where = 'uid = ' . (int) $originalContentElement[0];
$queryBuilder->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($originalContentElement[0], \PDO::PARAM_INT))
);
} else {
$where = 'l18n_parent = ' . (int) $originalContentElement[0];
$queryBuilder->where(
$queryBuilder->expr()->eq('l18n_parent', $queryBuilder->createNamedParameter($originalContentElement[0], \PDO::PARAM_INT))
);
}
// look up the correct language id, if they have changed
if (isset($this->languageMap[(int) $row['sys_language_uid']])) {
$where .= ' AND sys_language_uid = ' . $this->languageMap[(int) $row['sys_language_uid']];
$queryBuilder->andWhere(
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($this->languageMap[(int) $row['sys_language_uid']], \PDO::PARAM_INT))
);
} else {
$where .= ' AND sys_language_uid = ' . (int) $row['sys_language_uid'];
$queryBuilder->andWhere(
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($row['sys_language_uid'], \PDO::PARAM_INT))
);
}
$db->exec_UPDATEquery('tt_content', $where, ['bodytext' => $row['bodytext']]);
$queryBuilder->set('bodytext', $row['bodytext'], TRUE)
->execute();
// possibly the default language needs to be overwritten and the old default translation needs to be preserved
if (isset($this->languageMap[(int) $row['sys_language_uid']]) && $this->languageMap[(int) $row['sys_language_uid']] === 0) {
$where = 'uid = ' . (int) $parentId;
/** @var \mysqli_result $result */
$result = $db->exec_SELECTgetSingleRow('title, subtitle', 'pages', $where);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll();
$result = $queryBuilder->select('title', 'subtitle')
->from('pages')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($parentId, \PDO::PARAM_INT))
)
->execute()->fetch();
if ($result) {
$where = 'pid = ' . (int) $parentId . ' AND sys_language_uid = ' . $this->languageMap[0];
$db->exec_UPDATEquery(
'pages_language_overlay', $where,
['title' => $result['title'], 'subtitle' => $result['subtitle'], 'navtitle' => '']
$queryBuilder->where(
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($this->languageMap[0], \PDO::PARAM_INT))
);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$queryBuilder->update('pages_language_overlay')
->andWhere(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($parentId, \PDO::PARAM_INT))
);
} else {
$queryBuilder->update('pages')
->andWhere(
$queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($this->languageMap[0], \PDO::PARAM_INT))
);
}
$queryBuilder->set('title', $result['title'], TRUE)
->set('subtitle', $result['subtitle'], TRUE)
->set('navtitle', '', TRUE)
->execute();
}
$where = 'uid = ' . (int) $parentId;
$db->exec_UPDATEquery(
'pages', $where, ['title' => date(
'Y-m-d', $row['datetime']
) . ' - ' . $row['title'], 'subtitle' => $row['title'], 'lastUpdated' => $row['datetime'], 'navtitle' => '']
);
$newTitle = date('Y-m-d', $row['datetime']) . ' - ' . $row['title'];
$queryBuilder->update('pages')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($parentId, \PDO::PARAM_INT))
)
->set('title', $newTitle, TRUE)
->set('subtitle', $row['title'], TRUE)
->set('lastUpdated', $row['datetime'], TRUE)
->set('navtitle', '', TRUE)
->execute();
} else {
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$queryBuilder->update('pages_language_overlay')
->where(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($parentId, \PDO::PARAM_INT))
);
} else {
$queryBuilder->update('pages')
->where(
$queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($parentId, \PDO::PARAM_INT))
);
}
// finally translate the page title if necessary
/** @noinspection NotOptimalIfConditionsInspection */
if (isset($this->languageMap[(int) $row['sys_language_uid']]) && $this->languageMap[(int) $row['sys_language_uid']] > 0) {
$where = 'pid = ' . (int) $parentId . ' AND sys_language_uid = ' . $this->languageMap[(int) $row['sys_language_uid']];
$queryBuilder->andWhere(
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($this->languageMap[(int) $row['sys_language_uid']], \PDO::PARAM_INT))
);
} else {
$where = 'pid = ' . (int) $parentId . ' AND sys_language_uid = ' . (int) $row['sys_language_uid'];
$queryBuilder->andWhere(
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($row['sys_language_uid'], \PDO::PARAM_INT))
);
}
$queryBuilder->set('title', date('Y-m-d', $row['datetime']) . ' - ' . $row['title'], TRUE)
->execute();
}
$db->exec_UPDATEquery(
'pages_language_overlay', $where, ['title' => date('Y-m-d', $row['datetime']) . ' - ' . $row['title']]
);
}
/**
......
......@@ -29,6 +29,7 @@ namespace SGalinski\SgNews\Controller;
use RuntimeException;
use SGalinski\SgNews\Domain\Model\Category;
use SGalinski\SgNews\Domain\Model\News;
use SGalinski\SgNews\Utility\ExtensionUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
......@@ -59,8 +60,7 @@ abstract class AbstractController extends ActionController {
*/
public function initializeAction() {
$extensionKey = $this->request->getControllerExtensionKey();
$serializedConfiguration = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey];
$this->extensionConfiguration = unserialize($serializedConfiguration, [FALSE]);
$this->extensionConfiguration = ExtensionUtility::getExtensionConfiguration($extensionKey);
parent::initializeAction();
}
......
......@@ -27,9 +27,8 @@ namespace SGalinski\SgNews\Controller\Ajax;
***************************************************************/
use SGalinski\SgAjax\Controller\Ajax\AbstractAjaxController;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Page\PageRepository;
/**
* The LikeController handles the Ajax-Actions related to the like feature
......@@ -46,13 +45,17 @@ class LikeController extends AbstractAjaxController {
*/
public function addLikeAction($newsPid) {
try {
/** @var DatabaseConnection $database */
$database = $GLOBALS['TYPO3_DB'];
/** @var PageRepository $pageRepository */
$pageRepository = GeneralUtility::makeInstance(PageRepository::class);
$database->sql_query('UPDATE pages SET tx_sgnews_likes = tx_sgnews_likes ' . '+ 1 WHERE uid=' . (int) $newsPid .
$pageRepository->enableFields('pages'));
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->update('pages')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($newsPid, \PDO::PARAM_INT))
)
->set(
'tx_sgnews_likes',
'`tx_sgnews_likes` + 1',
FALSE
)
->execute();
} catch (\Exception $exception) {
$this->returnData(['success' => false]);
}
......
......@@ -35,6 +35,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
......@@ -121,11 +122,7 @@ class BackendController extends ActionController {
* @api
*/
protected function initializeView(ViewInterface $view) {
if (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 8000000) {
$GLOBALS['LANG']->includeLLFile('EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf');
} else {
$GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_mod_web_list.xlf');
}
$GLOBALS['LANG']->includeLLFile('EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf');
// create doc header component
$this->pageUid = (int) GeneralUtility::_GP('id');
/** @var BackendUserAuthentication $backendUser */
......@@ -157,6 +154,14 @@ class BackendController extends ActionController {
$currentLanguageInfo = $languageOptions[$this->language] ?? NULL;
}
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addJsInlineCode('typo3_version', 'TYPO3.version='
. VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getCurrentTypo3Version())
. ';');
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$pageRenderer->loadExtJS();
}
$this->docHeaderComponent->setMetaInformation($this->pageInfo);
$this->makeButtons();
$this->makeLanguageMenu();
......@@ -223,11 +228,21 @@ class BackendController extends ActionController {
/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$locallangPath = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:';
} else {
$locallangPath = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:';
}
// Refresh
$refreshButton = $buttonBar->makeLinkButton()
->setHref(GeneralUtility::getIndpEnv('REQUEST_URI'))
->setTitle(LocalizationUtility::translate('LLL:EXT:lang/locallang_core.xlf:labels.reload', ''))
->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
->setTitle(
LocalizationUtility::translate(
$locallangPath . 'labels.reload'
)
)
->setIcon($iconFactory->getIcon('actions-edit-undo', Icon::SIZE_SMALL));
$buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT);
// shortcut button
......
......@@ -26,8 +26,9 @@ namespace SGalinski\SgNews\Domain\Repository;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use SGalinski\SgNews\Domain\Model\FileReference;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Resource\File;
/**
......@@ -78,23 +79,23 @@ class FileReferenceRepository extends AbstractRepository {
* @throws \Exception
*/
public function addFileReferenceFromFileId($fileId, array $reference, $tablename, $fieldname) {
/** @var DatabaseConnection $db */
$db = $GLOBALS['TYPO3_DB'];
$arguments = [
'crdate' => $GLOBALS['EXEC_TIME'],
'tstamp' => $GLOBALS['EXEC_TIME'],
'pid' => (int) $reference['pid'],
'table_local' => 'sys_file',
'uid_local' => $fileId,
'uid_foreign' => (int) $reference['uid'],
'tablenames' => $tablename,
'fieldname' => $fieldname,
];
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
$success = $queryBuilder->insert('sys_file_reference')
->values([
'crdate' => $GLOBALS['EXEC_TIME'],
'tstamp' => $GLOBALS['EXEC_TIME'],
'pid' => (int) $reference['pid'],
'table_local' => 'sys_file',
'uid_local' => $fileId,
'uid_foreign' => (int) $reference['uid'],
'tablenames' => $tablename,
'fieldname' => $fieldname
]);
if (!$db->exec_INSERTquery('sys_file_reference', $arguments)) {
if (!$success) {
throw new \Exception('An error occurred while adding a file reference record.', 1452590219);
}
return (int) $db->sql_insert_id();
return (int) $queryBuilder->getConnection()->lastInsertId();
}
}
......@@ -30,7 +30,9 @@ use SGalinski\SgNews\Utility\BackendNewsUtility;
use TYPO3\CMS\Backend\Controller\PageLayoutController as CorePageLayoutController;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
......@@ -68,29 +70,10 @@ class PageLayoutController {
) {
return $out;
}
$moduleTemplate = $controller->getModuleTemplate();
$moduleTemplate->addJavaScriptCode(
'newsModuleLink', '
function newsModuleLinkGotToPageCallbackNoFollow(path){
var callback = top.Ext.createDelegate(top.nav.mainTree.selectPath, top.nav.mainTree);
callback.apply(this, arguments);
}
function sgNewsGoToNewsModule(uid, path) {
if (top.nav) {
top.nav.invokePageId(uid, newsModuleLinkGotToPageCallbackNoFollow);
} else {
var tree = top.Ext.getCmp(\'typo3-pagetree\');
if (tree) {
tree.activeTree.selectPath(path);
}
}
parent.fsMod.recentIds[\'web\'] = uid;
parent.TYPO3.ModuleMenu.App.showModule(\'web_SgNewsNews\');
return false;
}
'
);
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->loadRequireJsModule('TYPO3/CMS/SgNews/Backend');
/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$icon = $iconFactory->getIcon('sg_news-module-transparent');
......@@ -98,14 +81,22 @@ class PageLayoutController {
$buttonLabel = LocalizationUtility::translate('backend.button.goToNewsModule', 'SgNews');
$buttonLabel = '<span style="vertical-align: middle;">' . $buttonLabel . '</span>';
$rootline = BackendUtility::BEgetRootLine($categoryRow['uid'], '', TRUE);
ksort($rootline);
$path = '/root';
foreach ($rootline as $page) {
$path .= '/p' . dechex($page['uid']);
$path = '';
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$pageRenderer->addJsInlineCode('typo3_version', 'TYPO3.version='
. VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getCurrentTypo3Version())
. ';');
$rootline = BackendUtility::BEgetRootLine($categoryRow['uid'], '', TRUE);
ksort($rootline);
$path = '/root';
foreach ($rootline as $page) {
$path .= '/p' . dechex($page['uid']);
}
$path = ', \'' . $path . '\'';
}
$onclick = 'return sgNewsGoToNewsModule(' . $categoryRow['uid'] . ', \'' . $path . '\');';
$onclick = 'TYPO3.SgNewsModule.sgNewsGoToNewsModule(' . $categoryRow['uid'] . $path . '); return false;';
$wrap = ' <div class="btn-group" role="group">%s</div>';
$link = '<a href="#" onclick="' . $onclick . '" class="btn btn-primary">%s</a>';
$link = sprintf($link, $icon . ' ' . $buttonLabel);
......
......@@ -49,9 +49,9 @@ class ConfigurationService implements SingletonInterface {
* @param string $key
* @param array $settings
* @throws InvalidConfigurationTypeException
* @return string
* @return array|string|NULL
*/
public function getConfiguration($key, array $settings): string {
public function getConfiguration($key, array $settings) {
if (!$this->tsConfig) {
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
$this->tsConfig = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
......
......@@ -28,7 +28,9 @@ namespace SGalinski\SgNews\Service;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use SGalinski\SgNews\Utility\ExtensionUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Http\NullResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
......@@ -54,7 +56,7 @@ class LicensingService {
public static function checkKey(): bool {
if (static::$isLicenseKeyValid === NULL) {
static::$isLicenseKeyValid = FALSE;
$configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::EXTENSION_KEY], [FALSE]);
$configuration = ExtensionUtility::getExtensionConfiguration(self::EXTENSION_KEY);
if (isset($configuration['key']) && $key = trim($configuration['key'])) {
static::$isLicenseKeyValid = (bool) preg_match('/^([A-Z\d]{6}-?){4}$/', $key);
}
......@@ -71,7 +73,7 @@ class LicensingService {
*/
public static function ping($returnUrl = FALSE): string {
try {
$configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::EXTENSION_KEY], [FALSE]);
$configuration = ExtensionUtility::getExtensionConfiguration(self::EXTENSION_KEY);
$key = '';
if (isset($configuration['key'])) {
$key = trim($configuration['key']);
......@@ -103,13 +105,14 @@ class LicensingService {
* @return ResponseInterface
* @throws \InvalidArgumentException
*/
public function ajaxPing(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface {
public function ajaxPing(ServerRequestInterface $request, ResponseInterface $response = NULL): ResponseInterface {
/** @var BackendUserAuthentication $backendUser */
$backendUser = $GLOBALS['BE_USER'];
if ($backendUser && !$backendUser->getModuleData('tools_beuser/index.php/web_SgNewsNews_pinged', 'ses')) {
$backendUser->pushModuleData('tools_beuser/index.php/web_SgNewsNews_pinged', TRUE);
self::ping();
}
return $response;
return $response ?? new NullResponse();
}
}
......@@ -25,7 +25,7 @@ namespace SGalinski\SgNews\TCA;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -57,9 +57,6 @@ class TcaProvider implements SingletonInterface {
* @return void
*/
public function processDatamap_afterAllOperations(DataHandler $tceMain) {
/** @var DatabaseConnection $database */
$database = $GLOBALS['TYPO3_DB'];
/** @var array $tablesData */
foreach ($tceMain->datamap as $table => $tablesData) {
if (!in_array($table, ['pages', 'pages_language_overlay'], TRUE)) {
......@@ -75,31 +72,42 @@ class TcaProvider implements SingletonInterface {
$translationRow = [];
$pagesIdentity = (int) $identity;
if ($table === 'pages_language_overlay') {
$translationRow = $database->exec_SELECTgetSingleRow(
'pid, subtitle, t3ver_oid', 'pages_language_overlay', 'uid = ' . (int) $identity
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages_language_overlay');
$queryBuilder->getRestrictions()->removeAll();
$translationRow = $queryBuilder->select('pid', 'subtitle', 't3ver_oid')
->from('pages_language_overlay')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($identity, \PDO::PARAM_INT))
)
->execute()->fetch();
$workspaceOriginalId = (int) $translationRow['t3ver_oid'];
if ($workspaceOriginalId > 0) {
$translationRow = $database->exec_SELECTgetSingleRow(
'pid, subtitle, t3ver_oid', 'pages_language_overlay', 'uid = ' . $workspaceOriginalId
);
$translationRow = $queryBuilder->select('pid', 'subtitle', 't3ver_oid')
->from('pages_language_overlay')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($workspaceOriginalId, \PDO::PARAM_INT))
)
->execute()->fetch();
}
$pagesIdentity = (int) $translationRow['pid'];
}
$row = $database->exec_SELECTgetSingleRow(
'doktype, subtitle, lastUpdated, tx_sgnews_highlighted, t3ver_oid', 'pages', 'uid = ' .
$pagesIdentity
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll();
$row = $queryBuilder->select('doktype', 'subtitle', 'lastUpdated', 'tx_sgnews_highlighted', 't3ver_oid')
->from('pages')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($pagesIdentity, \PDO::PARAM_INT))
)
->execute()->fetch();
$workspaceOriginalId = (int) $row['t3ver_oid'];
if ($workspaceOriginalId > 0) {
$row = $database->exec_SELECTgetSingleRow(
'doktype, subtitle, lastUpdated, tx_sgnews_highlighted, t3ver_oid', 'pages', 'uid = ' .
$workspaceOriginalId
);
$row = $queryBuilder->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($workspaceOriginalId, \PDO::PARAM_INT))
)->execute()->fetch();
}
// only articles
......@@ -119,8 +127,14 @@ class TcaProvider implements SingletonInterface {
}
$calculatedTitle = $prefix . strftime('%Y-%m-%d', $row['lastUpdated']) . ' - ' . $subtitle;
$updateFields = ['nav_title' => $subtitle, 'title' => trim($calculatedTitle)];
$database->exec_UPDATEquery($table, 'uid = ' . $identity, $updateFields);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->update($table)
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($identity, \PDO::PARAM_INT))
)
->set('nav_title', $subtitle, TRUE)
->set('title', trim($calculatedTitle), TRUE)
->execute();
}
}
}
......
......@@ -32,8 +32,15 @@ use SGalinski\SgNews\Domain\Repository\NewsRepository;
use SGalinski\SgNews\Domain\Repository\TagRepository;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\QueryGenerator;
use TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider;
use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
use TYPO3\CMS\Core\Imaging\IconRegistry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
......@@ -83,14 +90,21 @@ class BackendNewsUtility {
*/
public static function getAlternativePageOptions(): array {
$options = [];
$andWhere = ' AND sys_language_uid IN (0,-1)';
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$andWhere = '';
}
/** @var array $rootOptionRows */
$rootOptionRows = self::getRecordsByField('pages', 'is_siteroot', 1, '', '', 'sorting');
$rootOptionRows = self::getRecordsByField(
'pages', 'is_siteroot', 1, $andWhere, '', 'sorting'
);
if ($rootOptionRows) {
foreach ($rootOptionRows as $row) {
$pageInfo = BackendUtility::readPageAccess($row['uid'], $GLOBALS['BE_USER']->getPagePermsClause(1));
if ($pageInfo) {
$options[] = self::getOptionPageInfo($pageInfo);
}
$categories = self::getCategoriesForSiteRoot((int) $row['uid']);
/** @var int $categoryUid */
foreach ($categories as $categoryUid => $categoryTitle) {
......@@ -105,6 +119,7 @@ class BackendNewsUtility {
}
}
}
return $options;
}
......@@ -122,10 +137,12 @@ class BackendNewsUtility {
foreach ($rootline as $page) {
$path .= '/p' . dechex($page['uid']);
}
$pageInfo['path'] = $path;
$pageInfo['_thePathFull'] = substr($pageInfo['_thePathFull'], 1);
$pageInfo['_thePathFull'] = substr($pageInfo['_thePathFull'], 0, -1);
}
return $pageInfo;
}
......@@ -144,14 +161,18 @@ class BackendNewsUtility {
$siteRootUid, PHP_INT_MAX, 0, $GLOBALS['BE_USER']->getPagePermsClause(1)
);
// if doktype = 117 (category) then get the category name (page title)
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$where = 'deleted = 0 AND doktype = ' . self::CATEGORY_DOKTYPE . ' AND uid in (' . $childPids . ')';
$result = $databaseConnection->exec_SELECTgetRows('uid, title', 'pages', $where);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$result = $queryBuilder->select('uid', 'title')
->from('pages')
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('doktype', $queryBuilder->createNamedParameter(self::CATEGORY_DOKTYPE, \PDO::PARAM_INT)),
$queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter(explode(',', $childPids), Connection::PARAM_INT_ARRAY))
)
)
->execute()->fetchAll();
$categories = [];
/** @var array $result */
foreach ($result as $page) {
$categoryPageInfo = BackendUtility::readPageAccess(
(int) $page['uid'], $GLOBALS['BE_USER']->getPagePermsClause(1)
......@@ -180,6 +201,7 @@ class BackendNewsUtility {
$GLOBALS['TSFE'] = new \stdClass();
$GLOBALS['TSFE']->gr_list = '';
}
$pageUid = (int) $pageUid;
$languageUid = (int) $languageUid;
$tags = [];
......@@ -199,18 +221,22 @@ class BackendNewsUtility {
if (isset($pageTS['TCEFORM.']['pages.']['tx_sgnews_tags.']['PAGE_TSCONFIG_ID'])) {
$tagsPid = (int) $pageTS['TCEFORM.']['pages.']['tx_sgnews_tags.']['PAGE_TSCONFIG_ID'];
}
if ($tagsPid) {
$query->matching($query->equals('pid', $tagsPid));
}
}
$query->setOrderings(['title' => QueryInterface::ORDER_ASCENDING]);
$resultTags = $query->execute(TRUE);
if ($temporaryTSFEInstance) {
unset($GLOBALS['TSFE']);
}
foreach ($resultTags as $tag) {
$tags[(int) $tag['uid']] = trim($tag['title']);
}
return $tags;
}
......@@ -230,6 +256,7 @@ class BackendNewsUtility {
$GLOBALS['TSFE'] = new \stdClass();
$GLOBALS['TSFE']->gr_list = '';
}
$newsItemUid = (int) $newsItemUid;
$languageUid = (int) $languageUid;
$tags = [];
......@@ -244,17 +271,20 @@ class BackendNewsUtility {
if ($newsItemUid) {
$query->matching($query->equals('uid', $newsItemUid));
}
/** @var News $newsItem */
$newsItem = $query->execute()->getFirst();
if ($temporaryTSFEInstance) {
unset($GLOBALS['TSFE']);
}
if ($newsItem) {
/** @var Tag $tag */
foreach ($newsItem->getTags() as $tag) {
$tags[(int) $tag->getUid()] = trim($tag->getTitle());
}
}
return $tags;
}
......@@ -274,6 +304,7 @@ class BackendNewsUtility {
if (!$rootPageUid) {
return $out;
}
$categories = [];
if (!isset($filters['categories']) || !is_array($filters['categories']) || !count($filters['categories'])) {
$rootCategories = self::getCategoriesForSiteRoot($rootPageUid);
......@@ -292,9 +323,11 @@ class BackendNewsUtility {
}
}
}
if (!count($categories)) {
return $out;
}
$queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class);
$allowedUids = [];
foreach ($categories as $categoryUid) {
......@@ -305,119 +338,79 @@ class BackendNewsUtility {
);
$allowedUids = array_unique(array_merge($allowedUids, $allowedUidsTemp));
}
if (!count($allowedUids)) {
return $out;
}
list($select, $tables, $where) = self::getNewsQueryParts($allowedUids, $filters, $languageUid);
if ($tables === '') {
if (!count($allowedUids)) {
return $out;
}
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$result = $databaseConnection->exec_SELECTquery($select, $tables, $where, '`pages`.`uid`', '`pages`.`sorting`');
while ($row = $result->fetch_assoc()) {
$out[] = $row;
}
$databaseConnection->sql_free_result($result);
return $out;
}
/**
* Creates news query parts
*
* @param array $allowedUids
* @param array $filters
* @param int $languageUid
* @return array
*/
private static function getNewsQueryParts(array $allowedUids, array $filters = [], $languageUid = 0): array {
$out = [0 => '
`pages`.`uid` AS uid,
`pages`.`pid` AS pid,
`pages`.`hidden` AS hidden,
`pages`.`sorting` AS sorting,
`pages`.`doktype` AS doktype,
`pages`.`title` AS title
', 1 => '', 2 => ''];
$out[1] = '`pages`';
$out[2] = '`pages`.`uid` IN(' . implode(',', $allowedUids) . ') ' . BackendUtility::deleteClause('pages') .
' AND `pages`.`doktype` = ' . self::NEWS_DOKTYPE;
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$queryBuilder->select('p.uid',
'p.pid',
'p.hidden',
'p.sorting',
'p.doktype',
'p.title'
)->from('pages', 'p')
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->in('p.uid', $queryBuilder->createNamedParameter($allowedUids, Connection::PARAM_INT_ARRAY)),
$queryBuilder->expr()->eq('p.doktype', $queryBuilder->createNamedParameter(self::NEWS_DOKTYPE, \PDO::PARAM_INT))
)
)
->groupBy('p.uid')
->orderBy('p.sorting');
if ($languageUid) {
$out[0] .= ', `translation`.`title` AS translation_title';
$out[0] .= ', `translation`.`uid` AS translation_uid';
$out[1] .= ' LEFT JOIN `pages_language_overlay` AS `translation` ON `translation`.`pid` = `pages`.`uid` ' .
BackendUtility::deleteClause('pages_language_overlay', 'translation') .
' AND `translation`.`sys_language_uid` = ' . $languageUid;
}
if (isset($filters['tags']) && is_array($filters['tags']) && count($filters['tags'])) {
$tagUids = [];
/** @var array $filterTags */
$filterTags = $filters['tags'];
foreach ($filterTags as $tagUid) {
if ((int) $tagUid && !in_array((int) $tagUid, $tagUids, TRUE)) {
$tagUids[] = (int) $tagUid;
}
}
if (count($tagUids)) {
$out[1] .= ' INNER JOIN `sys_category_record_mm` AS `tag` ON `tag`.`tablenames` = \'pages\'' .
' AND `tag`.`fieldname` = \'tx_sgnews_tags\' AND `tag`.`uid_foreign` = `pages`.`uid`' .
' AND `tag`.`uid_local` IN (' . implode(',', $filters['tags']) . ')';
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$queryBuilder->leftJoin('p', 'pages_language_overlay', 'translation',
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('translation.pid', 'p.uid'),
$queryBuilder->expr()->eq('translation.sys_language_uid', $queryBuilder->createNamedParameter($languageUid, \PDO::PARAM_INT))
)
);
} else {
$queryBuilder->leftJoin('p', 'pages', 'translation',
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('translation.l10n_parent', 'p.uid'),
$queryBuilder->expr()->eq('translation.sys_language_uid', $queryBuilder->createNamedParameter($languageUid, \PDO::PARAM_INT))
)
);
}
}
if (isset($filters['search']) && trim($filters['search'])) {
$out[2] .= self::getNewsSearchClause(trim($filters['search']), $languageUid);
}
return $out;
}
/**
* Creates constraints of query for searching news by search-word
*
* @param string $searchString
* @param int $languageUid
* @return string
*/
private static function getNewsSearchClause($searchString = '', $languageUid = 0): string {
$out = '';
$searchString = strtolower(trim($searchString));
$languageUid = (int) $languageUid;
if (!$searchString) {
return $out;
}
$out = ' AND (';
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$likeString = 'LIKE \'%' . $databaseConnection->escapeStrForLike($searchString, 'pages') . '%\'';
$constraints = [];
$pageFields = [
'title' => TRUE,
'description' => TRUE,
'author' => TRUE,
'abstract' => TRUE,
];
foreach ($pageFields as $fieldName => $isCommonField) {
if ($isCommonField) {
$constraints[] = 'LOWER(`pages`.`' . $fieldName . '`) ' . $likeString;
}
if (isset($filters['tags']) && is_array($filters['tags']) && count($filters['tags'])) {
$queryBuilder->innerJoin('p', 'sys_category_record_mm', 'tag',
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('tag.tablenames', $queryBuilder->createNamedParameter('pages')),
$queryBuilder->expr()->eq('tag.fieldname', $queryBuilder->createNamedParameter('tx_sgnews_tags')),
$queryBuilder->expr()->eq('tag.uid_foreign', 'p.uid'),
$queryBuilder->expr()->in('tag.uid_local', $queryBuilder->createNamedParameter(\array_unique($filters['tags']), Connection::PARAM_INT_ARRAY))
)
);
}
if (!$languageUid) {
foreach ($pageFields as $fieldName => $isCommonField) {
if (!$isCommonField) {
$constraints[] = 'LOWER(`pages`.`' . $fieldName . '`) ' . $likeString;
}
}
} else {
foreach ($pageFields as $fieldName => $isCommonField) {
if ($isCommonField) {
$constraints[] = 'LOWER(`translation`.`' . $fieldName . '`) ' . $likeString;
}
if (isset($filters['search']) && trim($filters['search'])) {
$expressions = [
$queryBuilder->expr()->like('p.title', $queryBuilder->createNamedParameter('%' . trim($filters['search']) . '%')),
$queryBuilder->expr()->like('p.description', $queryBuilder->createNamedParameter('%' . trim($filters['search']) . '%')),
$queryBuilder->expr()->like('p.author', $queryBuilder->createNamedParameter('%' . trim($filters['search']) . '%')),
$queryBuilder->expr()->like('p.abstract', $queryBuilder->createNamedParameter('%' . trim($filters['search']) . '%')),
];
if ($languageUid) {
$expressions[] = $queryBuilder->expr()->like('translation.title', $queryBuilder->createNamedParameter('%' . trim($filters['search']) . '%'));
$expressions[] = $queryBuilder->expr()->like('translation.description', $queryBuilder->createNamedParameter('%' . trim($filters['search']) . '%'));
$expressions[] = $queryBuilder->expr()->like('translation.author', $queryBuilder->createNamedParameter('%' . trim($filters['search']) . '%'));
$expressions[] = $queryBuilder->expr()->like('translation.abstract', $queryBuilder->createNamedParameter('%' . trim($filters['search']) . '%'));
}
$queryBuilder->andWhere(
$queryBuilder->expr()->orX(
...$expressions
)
);
}
$out .= implode(' OR ', $constraints) . ')';
return $out;
return $queryBuilder->execute()->fetchAll();
}
/**
......@@ -435,22 +428,20 @@ class BackendNewsUtility {
if (isset($pageTS['mod.']['SHARED.']['defaultLanguageLabel'])) {
$defaultLanguage = $pageTS['mod.']['SHARED.']['defaultLanguageLabel'] . ' (' . $defaultLanguage . ')';
}
$defaultLanguageFlag = 'empty-empty';
if (isset($pageTS['mod.']['SHARED.']['defaultLanguageFlag'])) {
$defaultLanguageFlag = 'flags-' . $pageTS['mod.']['SHARED.']['defaultLanguageFlag'];
}
$languages = [
0 => ['title' => $defaultLanguage, 'flag' => $defaultLanguageFlag]
];
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$orderBy = '';
if (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 8000000) {
$orderBy = 'sorting';
}
$languageRows = $databaseConnection->exec_SELECTgetRows(
'uid, title, flag', 'sys_language', 'hidden = 0', '', $orderBy
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
$languageRows = $queryBuilder->select('uid', 'title', 'flag')
->from('sys_language')
->orderBy('sorting')
->execute()->fetchAll();
if ($languageRows) {
/** @var BackendUserAuthentication $backendUser */
$backendUser = $GLOBALS['BE_USER'];
......@@ -463,6 +454,7 @@ class BackendNewsUtility {
}
}
}
return $languages;
}
......@@ -486,28 +478,83 @@ class BackendNewsUtility {
$useDeleteClause = TRUE
) {
if (is_array($GLOBALS['TCA'][$theTable])) {
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$result = $databaseConnection->exec_SELECTquery(
'*',
$theTable,
$theField . '=' . $databaseConnection->fullQuoteStr($theValue, $theTable) .
($useDeleteClause ? BackendUtility::deleteClause($theTable) . ' ' : '') .
BackendUtility::versioningPlaceholderClause($theTable) . ' ' .
$whereClause,
$groupBy,
$orderBy,
$limit
);
$rows = [];
while ($row = $databaseConnection->sql_fetch_assoc($result)) {
$rows[] = $row;
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($theTable);
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));;
if ($useDeleteClause) {
$queryBuilder->getRestrictions()
->add(GeneralUtility::makeInstance(DeletedRestriction::class));
}
$queryBuilder->select('*')
->from($theTable)
->where(
$queryBuilder->expr()->eq($theField, $queryBuilder->createNamedParameter($theValue))
);
// additional where
if ($whereClause) {
$queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($whereClause));
}
// group by
if ($groupBy !== '') {
$queryBuilder->groupBy(QueryHelper::parseGroupBy($groupBy));
}
$databaseConnection->sql_free_result($result);
if (!empty($rows)) {
return $rows;
// order by
if ($orderBy !== '') {
foreach (QueryHelper::parseOrderBy($orderBy) as $orderPair) {
list($fieldName, $order) = $orderPair;
$queryBuilder->addOrderBy($fieldName, $order);
}
}
// limit
if ($limit !== '') {
if (strpos($limit, ',')) {
$limitOffsetAndMax = GeneralUtility::intExplode(',', $limit);
$queryBuilder->setFirstResult((int)$limitOffsetAndMax[0]);
$queryBuilder->setMaxResults((int)$limitOffsetAndMax[1]);
} else {
$queryBuilder->setMaxResults((int)$limit);
}
}
return $queryBuilder->execute()->fetchAll();
}
return NULL;
}
/**
* Register the extension icons
* For use in ext_localconf.php
*/
public static function registerIcons() {
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
$iconRegistry->registerIcon(
'actions-document-open-white',
SvgIconProvider::class,
['source' => 'EXT:sg_news/Resources/Public/Icons/actions-document-open-white.svg']
);
$iconRegistry->registerIcon(
'sg_news-module',
SvgIconProvider::class,
['source' => 'EXT:sg_news/Resources/Public/Icons/module-sgnews.svg']
);
$iconRegistry->registerIcon(
'sg_news-module-transparent',
SvgIconProvider::class,
['source' => 'EXT:sg_news/Resources/Public/Icons/module-sgnews-transparent.svg']
);
$iconRegistry->registerIcon(
'tcarecords-pages-' . self::CATEGORY_DOKTYPE,
BitmapIconProvider::class,
['source' => 'EXT:sg_news/Resources/Public/Images/Category.png']
);
$iconRegistry->registerIcon(
'tcarecords-pages-' . self::NEWS_DOKTYPE,
BitmapIconProvider::class,
['source' => 'EXT:sg_news/Resources/Public/Images/News.png']
);
}
}
<?php
namespace SGalinski\SgNews\Utility;
/**
*
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.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 3 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\VersionNumberUtility;
/**
* Class ExtensionUtility
*
* @package SGalinski\SgMail\Utility
* @author Kevin Ditscheid <kevin.ditscheid@sgalinski.de>
*/
class ExtensionUtility {
/**
* Get the extension configuration
*
* @param string $extKey
* @return array
*/
public static function getExtensionConfiguration(string $extKey = 'sg_news'): array {
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$extConf = \unserialize(
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extKey], ['allowed_classes' => FALSE]
);
return is_array($extConf) ? $extConf : [];
}
return $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$extKey] ?? [];
}
}
<?php
namespace SGalinski\SgNews\Utility;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.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 3 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\VersionNumberUtility;
/**
* Helper class to detect the used TYPO3 version.
*/
class VersionUtility {
/**
* Returns true if the current version ts TYPO3 6.2.
*
* @return bool
*/
public static function isVersion62(): bool {
$versionNumber = self::getVersion();
return ($versionNumber >= 6002000 && $versionNumber < 7000000);
}
/**
* Returns true if the current version ts TYPO3 7.6 and less version 8
*
* @return bool
*/
public static function isVersion76(): bool {
$versionNumber = self::getVersion();
return ($versionNumber >= 7006000 && $versionNumber < 8000000);
}
/**
* Returns true if the current version ts TYPO3 7.6 or later
*
* @return bool
*/
public static function isVersion76OOrHigher(): bool {
return (self::getVersion() >= 7006000);
}
/**
* Returns true if the current version ts TYPO3 8.7 or later
*
* @return bool
*/
public static function isVersion870OrHigher(): bool {
return (self::getVersion() >= 8007000);
}
/**
* Returns the current version as an integer.
*
* @return int
*/
protected static function getVersion(): int {
return VersionNumberUtility::convertVersionNumberToInteger(
VersionNumberUtility::getNumericTypo3Version()
);
}
}
......@@ -30,10 +30,11 @@ use SGalinski\SgNews\Service\LicensingService;
use SGalinski\SgNews\ViewHelpers\AbstractViewHelper;
use TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
......@@ -41,31 +42,54 @@ use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
* Class ControlViewHelper
**/
class ControlViewHelper extends AbstractViewHelper {
/**
* Initialize the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('table', 'string', 'The table to control', TRUE);
$this->registerArgument('row', 'mixed', 'The row of the record', TRUE);
$this->registerArgument('sortingData', 'array', 'The sorting data', FALSE, []);
$this->registerArgument('clipboard', 'bool', 'Use the clipboard', FALSE, FALSE);
}
/**
* Renders the control buttons for the specified record
*
* @param string $table
* @param mixed $row
* @param array $sortingData
* @param boolean $clipboard
* @return string
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
*/
public function render($table, $row, array $sortingData = [], $clipboard = FALSE): string {
public function render(): string {
$table = $this->arguments['table'];
$row = $this->arguments['row'];
$sortingData = $this->arguments['sortingData'];
$clipboard = $this->arguments['clipboard'];
if (!is_array($row)) {
$row = BackendUtility::getRecord($table, $row->getUid());
}
/** @var DatabaseRecordList $databaseRecordList */
$databaseRecordList = GeneralUtility::makeInstance(DatabaseRecordList::class);
/** @var BackendUserAuthentication $backendUser */
$backendUser = $GLOBALS['BE_USER'];
$pageInfo = BackendUtility::readPageAccess($row['pid'], $backendUser->getPagePermsClause(1));
$databaseRecordList->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageInfo);
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/AjaxDataHandler');
$pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf');
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$languageService = GeneralUtility::makeInstance(\TYPO3\CMS\Lang\LanguageService::class);
} else {
$languageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\LanguageService::class);
}
$languageService->includeLLFile('EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf');
$databaseRecordList->currentTable = $sortingData;
if ($table === 'pages') {
$databaseRecordList->searchLevels = 1;
}
$out = $databaseRecordList->makeControl($table, $row);
if ($clipboard) {
$databaseRecordList->MOD_SETTINGS['clipBoard'] = TRUE;
......@@ -74,24 +98,30 @@ class ControlViewHelper extends AbstractViewHelper {
$GLOBALS['SOBE'] = $databaseRecordList;
$out .= $databaseRecordList->makeClip($table, $row);
}
if ($table === 'pages' && LicensingService::checkKey()) {
$rootline = BackendUtility::BEgetRootLine($row['uid'], '', TRUE);
ksort($rootline);
$path = '/root';
foreach ($rootline as $page) {
$path .= '/p' . dechex($page['uid']);
}
/** @var IconFactory $iconFactory */
if ($table === 'pages' && LicensingService::checkKey()) {
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$buttonLabel = LocalizationUtility::translate('backend.button.editPageContent', 'SgNews');
$onclick = 'return sgNewsGoToPageModule(' . $row['uid'] . ', \'' . $path . '\');';
$path = '';
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$rootline = BackendUtility::BEgetRootLine($row['uid'], '', TRUE);
ksort($rootline);
$path = '/root';
foreach ($rootline as $page) {
$path .= '/p' . dechex($page['uid']);
}
$path = ', \'' . $path . '\'';
}
$onclick = 'return TYPO3.SgNewsModule.sgNewsGoToPageModule(' . $row['uid'] . $path . ');';
$icon = $iconFactory->getIcon('actions-document-open-white', Icon::SIZE_SMALL)->render();
$wrap = ' <div class="btn-group" role="group">%s</div>';
$link = '<a href="#" onclick="' . $onclick . '" class="btn btn-primary" title="' . $buttonLabel . '">%s</a>';
$link = sprintf($link, $icon . ' ' . $buttonLabel);
$out .= sprintf($wrap, $link);
}
return $out;
}
}
......@@ -34,21 +34,34 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
* Class EditOnClickViewHelper
**/
class EditOnClickViewHelper extends AbstractViewHelper {
/**
* Register the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('table', 'string', 'The table for the clickenlarge link', TRUE);
$this->registerArgument('uid', 'int', 'The uid of the record to clickenlarge', TRUE);
$this->registerArgument('new', 'bool', 'Open a new record in the popup', FALSE, FALSE);
$this->registerArgument('type', 'string', 'The type of the news', FALSE, '');
}
/**
* Renders the onclick script for editing a record
*
* @param string $table
* @param int $uid
* @param boolean $new
* @param string $type
* @return string
*/
public function render($table, $uid, $new = FALSE, $type = ''): string {
public function render(): string {
$table = $this->arguments['table'];
$uid = $this->arguments['uid'];
$new = $this->arguments['new'];
$type = $this->arguments['type'];
$additionalParameters = '';
if ($new && $table === 'pages' && in_array($type, ['news', 'category'], TRUE)) {
$additionalParameters = '&overrideVals[pages][doktype]=' .
($type === 'news' ? BackendNewsUtility::NEWS_DOKTYPE : BackendNewsUtility::CATEGORY_DOKTYPE);
}
return BackendUtility::editOnClick(
'&edit[' . $table . '][' . $uid . ']=' . ($new ? 'new' : 'edit') . $additionalParameters, '', -1
);
......
......@@ -35,19 +35,28 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
* Class IconViewHelper
**/
class IconViewHelper extends AbstractViewHelper {
/**
* Initialize the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('id', 'string', 'The id of the record', TRUE);
$this->registerArgument('size', 'string', 'The size of the icon', FALSE, '');
$this->registerArgument('overlayId', 'string', 'The overlay of the icon', FALSE);
}
/**
* Renders the icon for the specified identifier
* with the requested size option and overlay.
*
* @param string $id
* @param string $size
* @param string $overlayId
* @return string
* @throws \InvalidArgumentException
*/
public function render($id, $size = '', $overlayId = NULL): string {
$id = trim($id);
$size = trim($size);
public function render(): string {
$id = trim($this->arguments['id']);
$size = trim($this->arguments['size']);
$overlayId = $this->arguments['overlayId'];
switch ($size) {
case 'small' :
$size = Icon::SIZE_SMALL;
......@@ -59,7 +68,7 @@ class IconViewHelper extends AbstractViewHelper {
$size = Icon::SIZE_DEFAULT;
break;
}
/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
return $iconFactory->getIcon($id, $size, $overlayId)->render();
}
......
......@@ -33,23 +33,32 @@ use SGalinski\SgNews\ViewHelpers\AbstractViewHelper;
* Class EditOnClickViewHelper
**/
class NewsItemTagsViewHelper extends AbstractViewHelper {
/**
* Initialize the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('uid', 'int', 'The uid of the news', FALSE, 0);
$this->registerArgument('languageUid', 'int', 'The language uid', FALSE, 0);
}
/**
* Renders the tags for the specified news uid
*
* @param int $uid
* @param int $languageUid
* @return string
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \InvalidArgumentException
*/
public function render($uid = 0, $languageUid = 0): string {
public function render(): string {
$out = '';
$uid = (int) $uid;
$languageUid = (int) $languageUid;
$uid = $this->arguments['uid'];
$languageUid = $this->arguments['languageUid'];
if ($uid) {
$tags = BackendNewsUtility::getTagsForNewsItem($uid, $languageUid);
$out = implode(', ', $tags);
}
return $out;
}
}
......@@ -36,17 +36,27 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
* Class IconViewHelper
**/
class RecordIconViewHelper extends AbstractViewHelper {
/**
* Initialize the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('table', 'string', 'The table of the record', TRUE);
$this->registerArgument('row', 'array', 'The row of the record icon', TRUE);
$this->registerArgument('clickMenu', 'bool', 'Render the click menu', FALSE, TRUE);
}
/**
* Renders the icon for the specified record
*
* @param string $table
* @param mixed $row
* @param boolean $clickMenu
* @return string
* @throws \InvalidArgumentException
*/
public function render($table, $row, $clickMenu = TRUE): string {
/** @var IconFactory $iconFactory */
public function render(): string {
$table = $this->arguments['table'];
$row = $this->arguments['row'];
$clickMenu = $this->arguments['clickMenu'];
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$toolTip = BackendUtility::getRecordToolTip($row, $table);
$iconImg = '<span ' . $toolTip . '>'
......@@ -55,6 +65,7 @@ class RecordIconViewHelper extends AbstractViewHelper {
if ($clickMenu) {
return BackendUtility::wrapClickMenuOnIcon($iconImg, $table, $row['uid']);
}
return $iconImg;
}
}
......@@ -29,40 +29,54 @@ namespace SGalinski\SgNews\ViewHelpers\Backend;
use SGalinski\SgNews\Service\LicensingService;
use SGalinski\SgNews\Utility\BackendNewsUtility;
use SGalinski\SgNews\ViewHelpers\AbstractViewHelper;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Type\Icon\IconState;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* Class EditOnClickViewHelper
**/
class TranslationLinksViewHelper extends AbstractViewHelper {
/**
* Register the ViewHelp0er arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('uid', 'int', 'The uid of the record', TRUE);
$this->registerArgument('table', 'string', 'The table of the record', TRUE);
$this->registerArgument('pageUid', 'int', 'The uid of the page', FALSE, 0);
}
/**
* Renders the translation links for the specified record
*
* @param int $pageUid
* @param string $table
* @param int $uid
* @return string
* @throws \InvalidArgumentException
*/
public function render($pageUid = 0, $table, $uid): string {
public function render(): string {
$uid = $this->arguments['uid'];
$table = $this->arguments['table'];
$pageUid = $this->arguments['pageUid'];
$out = '';
if (!LicensingService::checkKey()) {
return $out;
}
$table = trim($table);
if ($table !== 'pages' && !isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])) {
return $out;
}
$uid = (int) $uid;
$pageUid = (int) $pageUid;
$row = BackendUtility::getRecord($table, $uid);
if ($row) {
/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$lanuageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
$currentLanguageUid = $table === 'pages' ? 0 : $row[$lanuageField];
......@@ -76,52 +90,72 @@ class TranslationLinksViewHelper extends AbstractViewHelper {
} else {
$languages = BackendNewsUtility::getAvailableLanguages($pageUid);
}
$editLabel = LocalizationUtility::translate('backend.action.edit', 'SgNews');
$newLabel = LocalizationUtility::translate('backend.action.new', 'SgNews');
$translationParameters = '&cmd[' . $table . '][' . $row['uid'] . '][localize]=%s';
if ($table === 'pages') {
$translationParameters = '&edit[pages_language_overlay][' . $row['uid'] . ']=new';
$translationParameters .= '&overrideVals[pages_language_overlay][doktype]=' . $row['doktype'];
$translationParameters .= '&overrideVals[pages_language_overlay][sys_language_uid]=%s';
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$returnUrl = BackendUtility::getModuleUrl('web_SgNewsNews', ['id' => GeneralUtility::_GP('id')]);
} else {
$returnUrl = GeneralUtility::makeInstance(UriBuilder::class)
->buildUriFromRoute('web_SgNewsNews', ['id' => GeneralUtility::_GP('id')]);
}
foreach ($languages as $languageUid => $language) {
$translatedUid = 0;
if ((int) $languageUid <= 0) {
$translationTable = $table;
$translatedUid = $uid;
} else {
$translationTable = $table === 'pages' ? 'pages_language_overlay' : $table;
$translationTable = $table;
$translatedRows = BackendUtility::getRecordLocalization($table, $uid, $languageUid);
if (count($translatedRows)) {
$translatedUid = (int) $translatedRows[0]['uid'];
}
}
if ($translatedUid) {
$onClick = BackendUtility::editOnClick(
'&edit[' . $translationTable . '][' . $translatedUid . ']=edit', '', -1
);
$out .= ' <a href="#" onclick="' . $onClick . '" title="' . $language['title'] . ' [' . $editLabel . ']" >' .
$iconFactory->getIcon($language['flag'], Icon::SIZE_SMALL)->render() .
'</a>';
} else {
if ($table === 'pages') {
$onClick = BackendUtility::editOnClick(
sprintf($translationParameters, $languageUid), '', -1
);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$link = BackendUtility::getModuleUrl('record_edit', [
'edit' => [
$translationTable => [
$translatedUid => 'edit'
]
],
'returnUrl' => $returnUrl
]);
} else {
$onClick = 'window.location.href=' . BackendUtility::getLinkToDataHandlerAction(
sprintf($translationParameters, $languageUid), -1
) . ' return false;';
$link = GeneralUtility::makeInstance(UriBuilder::class)
->buildUriFromRoute('record_edit', [
'edit' => [
$translationTable => [
$translatedUid => 'edit'
]
],
'returnUrl' => (string) $returnUrl
]);
}
$out .= ' <a href="#" onclick="' . $onClick . '" title="' . $language['title'] . ' [' . $newLabel . ']" >' .
$iconFactory->getIcon(
$language['flag'], Icon::SIZE_SMALL, 'overlay-new',
$out .= ' <a href="' . $link . '" title="'. $language['title'] . ' [' . $editLabel . ']" >'
. $iconFactory->getIcon($language['flag'], Icon::SIZE_SMALL)->render()
. '</a>';
} else {
$out .= ' <a href="'
. BackendUtility::getLinkToDataHandlerAction(
sprintf($translationParameters, $languageUid), $returnUrl
)
. '" title="' . $language['title'] . ' [' . $newLabel . ']" >'
. $iconFactory->getIcon(
$language['flag'],
Icon::SIZE_SMALL,
'overlay-new',
IconState::cast(IconState::STATE_DISABLED)
)->render() .
'</a>';
)->render()
. '</a>';
}
}
}
return $out;
}
}
......@@ -33,7 +33,7 @@ use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper;
*/
class PaginateViewHelper extends AbstractWidgetViewHelper {
/**
* @var \SGalinski\SgNews\ViewHelpers\Backend\Widget\Controller\PaginateController
* @var PaginateController
*/
protected $controller;
......@@ -42,25 +42,38 @@ class PaginateViewHelper extends AbstractWidgetViewHelper {
*
* @param PaginateController $controller
*/
public function injectPaginateController(
PaginateController $controller
) {
public function injectPaginateController(PaginateController $controller) {
$this->controller = $controller;
}
/**
* Initialize the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('objects', 'mixed', 'The objects to paginate', TRUE);
$this->registerArgument('as', 'string', 'The name of the variable inside the pagination', TRUE);
$this->registerArgument(
'configuration',
'array',
'The configuration of the pagination',
FALSE,
[
'itemsPerPage' => 10,
'insertAbove' => FALSE,
'insertBelow' => TRUE,
'recordsLabel' => ''
]
);
}
/**
* Renders the paginator
*
* @param mixed $objects
* @param string $as
* @param array $configuration
* @return string
* @throws \TYPO3\CMS\Fluid\Core\Widget\Exception\MissingControllerException
*/
public function render(
$objects, $as,
array $configuration = ['itemsPerPage' => 10, 'insertAbove' => FALSE, 'insertBelow' => TRUE, 'recordsLabel' => '']
): string {
public function render(): string {
return $this->initiateSubRequest();
}
}
<?php
namespace SGalinski\SgNews\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.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 3 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\VersionNumberUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
/**
* ExtendedIfViewHelper
*/
class ExtendedIfViewHelper extends AbstractConditionViewHelper {
/**
* Initializes the "then" and "else" arguments
*/
public function initializeArguments() {
parent::initializeArguments();
if(VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) < 8000000) {
$this->registerArgument(
'condition', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
}
$this->registerArgument(
'or', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
$this->registerArgument(
'or2', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
$this->registerArgument(
'or3', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
$this->registerArgument(
'or4', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
$this->registerArgument(
'and', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE
);
$this->registerArgument(
'and2', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE
);
$this->registerArgument(
'and3', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE
);
$this->registerArgument(
'and4', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE
);
$this->registerArgument(
'negate', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
}
/**
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
*
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
* @return bool
*/
static protected function evaluateCondition($arguments = NULL) {
$conditionResult = (
isset($arguments['condition']) && $arguments['condition'] ||
isset($arguments['or']) && $arguments['or'] ||
isset($arguments['or2']) && $arguments['or2'] ||
isset($arguments['or3']) && $arguments['or3'] ||
isset($arguments['or4']) && $arguments['or4']
) && isset($arguments['and']) && $arguments['and'] &&
isset($arguments['and2']) && $arguments['and2'] &&
isset($arguments['and3']) && $arguments['and3'] &&
isset($arguments['and4']) && $arguments['and4'];
return isset($arguments['negate']) && $arguments['negate'] ? !$conditionResult : $conditionResult;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment