205 lines
8.6 KiB
PHP
205 lines
8.6 KiB
PHP
<?php
|
|
namespace TYPO3\TgmSocialshareprivacy\Controller;
|
|
|
|
/***************************************************************
|
|
* Copyright notice
|
|
*
|
|
* (c) 2014 Paul Beck <pb@teamgeist-medien.de>, Teamgeist Medien GbR
|
|
*
|
|
* 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!
|
|
* Just always need this: \TYPO3\CMS\Core\Utility\DebugUtility::debug();
|
|
***************************************************************/
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @package tgm_socialshareprivacy
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
|
|
*
|
|
*/
|
|
class SocialButtonController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
|
|
|
|
/**
|
|
* Include helper class
|
|
*
|
|
* @var \TYPO3\TgmSocialshareprivacy\Helper\HelperFunctions
|
|
* @inject
|
|
*/
|
|
protected $helperClass;
|
|
|
|
/**
|
|
* Content Object UID
|
|
* @var Number
|
|
*/
|
|
protected $cObjUid;
|
|
|
|
|
|
/**
|
|
* socialButtonRepository
|
|
*
|
|
* @var \TYPO3\TgmSocialshareprivacy\Domain\Repository\SocialButtonRepository
|
|
* @inject
|
|
*/
|
|
protected $socialButtonRepository;
|
|
|
|
/**
|
|
* Main buttons to show
|
|
*/
|
|
protected $main_buttons;
|
|
|
|
/**
|
|
* Additional buttons to show
|
|
*/
|
|
protected $additional_buttons;
|
|
|
|
/**
|
|
* Initialize action
|
|
* Adding required header data and Javascript
|
|
*
|
|
* @return void
|
|
*/
|
|
public function initializeAction() {
|
|
/** Combine Typoscript and Flexform settings first */
|
|
$this->settings = $this->helperClass->getSettings();
|
|
|
|
/** Get the cObj UID */
|
|
$this->cObjUid = $this->helperClass->getContentObjectUid();
|
|
if ($this->cObjUid == '') {
|
|
$this->cObjUid = 1;
|
|
}
|
|
|
|
/** Get the selected social buttons (main and additional buttons) */
|
|
|
|
/** @var \TYPO3\TgmSocialshareprivacy\Domain\Model\SocialButton */
|
|
$this->main_buttons = $this->socialButtonRepository->findByUids($this->settings['main_buttons']);
|
|
|
|
/** @var \TYPO3\TgmSocialshareprivacy\Domain\Model\SocialButton */
|
|
$this->additional_buttons = $this->socialButtonRepository->findByUids($this->settings['additional_buttons']);
|
|
|
|
/** Include Javascript libaries jQuery / jQuery UI depending on settings */
|
|
if($this->settings['include_jquery']) {
|
|
if($this->settings['include_to_footer']) {
|
|
$jqueryFile = '/typo3conf/ext/tgm_socialshareprivacy/Resources/Public/Javascript/jquery-1.10.2.js';
|
|
$GLOBALS['TSFE']->getPageRenderer()->addJsFooterFile ($jqueryFile, $type= 'text/javascript', $compress=FALSE, $forceOnTop=FALSE, $allWrap= '', $excludeFromConcatenation=TRUE);
|
|
}
|
|
else {
|
|
$this->response->addAdditionalHeaderData('<script src="typo3conf/ext/tgm_socialshareprivacy/Resources/Public/Javascript/jquery-1.10.2.js" type="text/javascript"></script>');
|
|
}
|
|
}
|
|
if($this->settings['include_jqueryui']) {
|
|
if($this->settings['include_to_footer']) {
|
|
$jqueryUiFile = '/typo3conf/ext/tgm_socialshareprivacy/Resources/Public/Javascript/jquery-ui-1.10.4.custom.min.js';
|
|
$GLOBALS['TSFE']->getPageRenderer()->addJsFooterFile ($jqueryUiFile, $type='text/javascript', $compress=FALSE, $forceOnTop=FALSE, $allWrap= '', $excludeFromConcatenation=TRUE);
|
|
}
|
|
else {
|
|
$this->response->addAdditionalHeaderData('<script src="typo3conf/ext/tgm_socialshareprivacy/Resources/Public/Javascript/jquery-ui-1.10.4.custom.min.js" type="text/javascript"></script>');
|
|
}
|
|
}
|
|
|
|
/** Add required extension Javascript, Javascript configuration, CSS and IE7 workaround */
|
|
if($this->settings['include_to_footer']) {
|
|
/** required extension Javascript */
|
|
$socialSharePrivacyJsFile = '/typo3conf/ext/tgm_socialshareprivacy/Resources/Public/Javascript/tgm_socialshareprivacy.js';
|
|
$GLOBALS['TSFE']->getPageRenderer()->addJsFooterFile ($socialSharePrivacyJsFile, $type= 'text/javascript', $compress=FALSE, $forceOnTop=FALSE, $allWrap= '', $excludeFromConcatenation=TRUE);
|
|
|
|
/** required CSS and IE7 workaround */
|
|
$this->response->addAdditionalHeaderData('
|
|
<link rel="stylesheet" type="text/css" href="'.$this->settings['css_path'].'" media="all">
|
|
<!--[if IE 7]>
|
|
<link rel="stylesheet" href="/typo3conf/ext/tgm_socialshareprivacy/Resources/Public/Css/fontello-ie7.css">
|
|
<![endif]-->
|
|
');
|
|
|
|
/** javascript configuration */
|
|
$socialSharePrivacyJsConfiguration = $this->renderJavascriptConfiguration();
|
|
$GLOBALS['TSFE']->getPageRenderer()->addJsFooterInlineCode ('socialSharePrivacyButtons', $socialSharePrivacyJsConfiguration, $compress=FALSE, $forceOnTop=FALSE);
|
|
|
|
}
|
|
else {
|
|
/** required extension Javascript, CSS and IE7 workaround */
|
|
$this->response->addAdditionalHeaderData('
|
|
<script src="typo3conf/ext/tgm_socialshareprivacy/Resources/Public/Javascript/tgm_socialshareprivacy.js" type="text/javascript"></script>
|
|
<link rel="stylesheet" type="text/css" href="'.$this->settings['css_path'].'" media="all">
|
|
<!--[if IE 7]>
|
|
<link rel="stylesheet" href="/typo3conf/ext/tgm_socialshareprivacy/Resources/Public/Css/fontello-ie7.css">
|
|
<![endif]-->
|
|
');
|
|
|
|
/** javascript configuration */
|
|
$this->response->addAdditionalHeaderData('<script type="text/javascript">' . $this->renderJavascriptConfiguration() . '</script>');
|
|
}
|
|
|
|
// So könnte man auch CSS Dateien mit der TypoScript Methode einbinden
|
|
/*
|
|
$cssFile = $this->settings['css_path'];
|
|
$GLOBALS['TSFE']->getPageRenderer()->addCssFile ($cssFile, $rel='stylesheet', $media= 'all', $title= '', $compress=TRUE, $forceOnTop=FALSE, $allWrap= '');
|
|
*/
|
|
|
|
}
|
|
|
|
/**
|
|
* Index Action / Default View
|
|
*
|
|
* @return void
|
|
*/
|
|
public function indexAction() {
|
|
/** Pass the buttons and cObjUid to fluid */
|
|
$this->view->assignMultiple(array(
|
|
'socialbuttons' => $this->main_buttons,
|
|
'additional_socialbuttons' => $this->additional_buttons,
|
|
'cObjUid' => $this->cObjUid
|
|
));
|
|
}
|
|
|
|
|
|
/**
|
|
* Render the Javascript standalone template for configuration in FE
|
|
*
|
|
* @return string The rendered Javascript part
|
|
*/
|
|
public function renderJavascriptConfiguration() {
|
|
|
|
/** @var \TYPO3\CMS\Fluid\View\StandaloneView $javascriptConfigView */
|
|
$javascriptConfigView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
|
|
|
|
/** Define format */
|
|
$javascriptConfigView->setFormat('html');
|
|
$extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
|
|
|
|
/** Get configuration of the template from Typoscript */
|
|
$templateRootPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($extbaseFrameworkConfiguration['view']['templateRootPath']);
|
|
|
|
/** Set template path */
|
|
$templatePathAndFilename = $templateRootPath . 'Standalone/JavascriptConfiguration.html';
|
|
$javascriptConfigView->setTemplatePathAndFilename($templatePathAndFilename);
|
|
|
|
/** Pass the buttons, settings and cObjUid to the Fluid standalone template */
|
|
$javascriptConfigView->assignMultiple(array(
|
|
'socialbuttons' => $this->main_buttons,
|
|
'additional_socialbuttons' => $this->additional_buttons,
|
|
'settings' => $this->settings,
|
|
'cObjUid' => $this->cObjUid
|
|
));
|
|
|
|
/** Render the view and return it to the initializeAction for including */
|
|
$javascriptConfigView = $javascriptConfigView->render();
|
|
return $javascriptConfigView;
|
|
}
|
|
}
|
|
?>
|