Skip to content

Commit

Permalink
Initial commit - working
Browse files Browse the repository at this point in the history
  • Loading branch information
René Fritz committed Apr 19, 2018
0 parents commit 8d9ed51
Show file tree
Hide file tree
Showing 26 changed files with 1,256 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
language: php

sudo: false

script:
- >
echo;
echo "Running php lint";
echo;
echo;
errors=$(find . -name \*.php ! -path "./.Build/*" -exec php -d display_errors=stderr -l {} 2>&1 >/dev/null \;) && echo "$errors" && test -z "$errors"
jobs:
fast_finish: true
include:
- stage: test
php: 5.6
- stage: test
php: 7.2

- stage: publish to ter
if: tag IS present
php: 7.1
before_install: skip
install: skip
before_script: skip
script:
- |
if [ -n "$TRAVIS_TAG" ] && [ -n "$TYPO3_ORG_USERNAME" ] && [ -n "$TYPO3_ORG_PASSWORD" ]; then
echo
echo "Preparing upload of release ${TRAVIS_TAG} to TER"
echo
echo
composer global require helhum/ter-client
EXTENSION_KEY="$(composer config extra.typo3/cms.extension-key)"
export PATH=$PATH:$(composer global config bin-dir --absolute 2>/dev/null)
# Cleanup before we upload
git reset --hard HEAD && git clean -fx
TAG_MESSAGE=`git tag -n10 -l $TRAVIS_TAG | sed 's/^[0-9.]*[ ]*//g'`
echo
echo "Uploading release ${TRAVIS_TAG} to TER"
echo
echo
ter-client upload "$EXTENSION_KEY" . -u "$TYPO3_ORG_USERNAME" -p "$TYPO3_ORG_PASSWORD" -m "$TAG_MESSAGE"
fi;
177 changes: 177 additions & 0 deletions Classes/Controller/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php
namespace Colorcube\CookieRedirect\Controller;


/**
* This file is part of the "cookie_redirect" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;


/**
* Plugin for the 'cookie_redirect' extension.
*
* @author René Fritz <r.fritz@colorcube.de>
*/
class Plugin {

/**
* The current cObject
*
* Note: This must be public cause it is set by ContentObjectRenderer::callUserFunction()
*
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
*/
public $cObj;


/**
* @var array TypoScript configuration array
*/
protected $conf = [];

protected $defaultCookiePrefix = 'tx_cookieredirect_pi1';


function main($content, $conf)
{
$this->conf = $conf;

$this->pi_initPIflexForm ();

$cookieName = $this->getConfig('cookiePrefix', 'cookiePrefix', $this->defaultCookiePrefix);
$cookieName = $cookieName.'-'.$GLOBALS['TSFE']->id;

// get cookie end date from Flexform data
$cookieLifetime = (int)($this->getConfig('', 'cookie_lifetime'));
$cookieLifetime = time()<$cookieLifetime ? $cookieLifetime : 0;
// set cookie end date from TS if not already set
$cookieLifetime = $cookieLifetime ? $cookieLifetime : time()+(int)($this->getConfig('cookieLifetime', '', 40000000));


$redirectPID = false;
if($_COOKIE[$cookieName]) {
// cookie is already set - get the default redirect
$redirectPID = (int)($this->getConfig('defaultPID', 'shortcut_default'));
} else {
// first visit - get the redirect PID and set cookie
$redirectPID = (int)($this->getConfig('shortcutPID', 'shortcut'));
if ($redirectPID) {
setcookie($cookieName, true, $cookieLifetime, '/');
}
}

// fetch redirect page from configured PID - and finally: redirect
if ($redirectPID) {
$page = $GLOBALS['TSFE']->getPageShortcut($redirectPID, '', $GLOBALS['TSFE']->id);
$redirectUrl = $this->cObj->getTypoLink_URL($page['uid']);
header('Location: '.GeneralUtility::locationHeaderUrl($redirectUrl));
exit;
}

// no redirect PID - do nothing
}




/*******************************
*
* FlexForms related functions
*
*******************************/


/**
* Get configuration values from TypoScript and Flexform data.
*
* @param string TypoScript key to get a value from ($this->conf[$tsKey]') with stdWrap
* @param string Flexform data key
* @param string Default value which will be used if no value was found
* @return string configuration value
*/
private function getConfig($tsKey, $ffKey, $default='') {
list ($ffKey, $ffSheet) = explode(':', $ffKey);
if($ffKey AND $this->cObj->data['pi_flexform']) {
$config = (string)$this->pi_getFFvalue($this->cObj->data['pi_flexform'], $ffKey, ($ffSheet?$ffSheet:'sDEF'));
}
if($tsKey AND $config=='') {
$config = $this->cObj->stdWrap($this->conf[$tsKey], $this->conf[$tsKey.'.']);
}
$config = $config!='' ? $config : $default;
return $config;
}


/**
* Converts $this->cObj->data['pi_flexform'] from XML string to flexForm array.
*
* @param string $field Field name to convert
*/
public function pi_initPIflexForm($field = 'pi_flexform')
{
// Converting flexform data into array:
if (!is_array($this->cObj->data[$field]) && $this->cObj->data[$field]) {
$this->cObj->data[$field] = GeneralUtility::xml2array($this->cObj->data[$field]);
if (!is_array($this->cObj->data[$field])) {
$this->cObj->data[$field] = [];
}
}
}

/**
* Return value from somewhere inside a FlexForm structure
*
* @param array $T3FlexForm_array FlexForm data
* @param string $fieldName Field name to extract. Can be given like "test/el/2/test/el/field_templateObject" where each part will dig a level deeper in the FlexForm data.
* @param string $sheet Sheet pointer, eg. "sDEF
* @param string $lang Language pointer, eg. "lDEF
* @param string $value Value pointer, eg. "vDEF
* @return string|NULL The content.
*/
public function pi_getFFvalue($T3FlexForm_array, $fieldName, $sheet = 'sDEF', $lang = 'lDEF', $value = 'vDEF')
{
$sheetArray = is_array($T3FlexForm_array) ? $T3FlexForm_array['data'][$sheet][$lang] : '';
if (is_array($sheetArray)) {
return $this->pi_getFFvalueFromSheetArray($sheetArray, explode('/', $fieldName), $value);
}
return null;
}

/**
* Returns part of $sheetArray pointed to by the keys in $fieldNameArray
*
* @param array $sheetArray Multidimensiona array, typically FlexForm contents
* @param array $fieldNameArr Array where each value points to a key in the FlexForms content - the input array will have the value returned pointed to by these keys. All integer keys will not take their integer counterparts, but rather traverse the current position in the array an return element number X (whether this is right behavior is not settled yet...)
* @param string $value Value for outermost key, typ. "vDEF" depending on language.
* @return mixed The value, typ. string.
* @access private
* @see pi_getFFvalue()
*/
public function pi_getFFvalueFromSheetArray($sheetArray, $fieldNameArr, $value)
{
$tempArr = $sheetArray;
foreach ($fieldNameArr as $k => $v) {
if (MathUtility::canBeInterpretedAsInteger($v)) {
if (is_array($tempArr)) {
$c = 0;
foreach ($tempArr as $values) {
if ($c == $v) {
$tempArr = $values;
break;
}
$c++;
}
}
} else {
$tempArr = $tempArr[$v];
}
}
return $tempArr[$value];
}
}
64 changes: 64 additions & 0 deletions Configuration/FlexForms/PluginFlexform.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3DataStructure>
<meta>
<langDisable>1</langDisable>
</meta>

<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>LLL:EXT:cms/locallang_ttc.xml:pi_flexform</sheetTitle>
</TCEforms>
<type>array</type>
<el>

<shortcut>
<TCEforms>
<label>LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.shortcut_page</label>
<label>LLL:EXT:cookie_redirect/Resources/Private/Language/locallang.xlf:tt_content.pi_flexform.shortcut_page</label>
<config>
<type>group</type>
<internal_type>db</internal_type>
<allowed>pages</allowed>
<minitems>0</minitems>
<maxitems>1</maxitems>
<size>1</size>
<show_thumbs>1</show_thumbs>
</config>
</TCEforms>
</shortcut>

<cookie_lifetime>
<TCEforms>
<label>LLL:EXT:cookie_redirect/Resources/Private/Language/locallang.xlf:tt_content.pi_flexform.cookie_lifetime</label>
<config>
<type>input</type>
<eval>datetime</eval>
<checkbox></checkbox>
<size>12</size>
<max>20</max>
</config>
</TCEforms>
</cookie_lifetime>

<shortcut_default>
<TCEforms>
<label>LLL:EXT:cookie_redirect/Resources/Private/Language/locallang.xlf:tt_content.pi_flexform.shortcut_default</label>
<config>
<type>group</type>
<internal_type>db</internal_type>
<allowed>pages</allowed>
<minitems>0</minitems>
<maxitems>1</maxitems>
<size>1</size>
<show_thumbs>1</show_thumbs>
</config>
</TCEforms>
</shortcut_default>

</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
9 changes: 9 additions & 0 deletions Configuration/TCA/Overrides/sys_template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
defined('TYPO3_MODE') or die();


/**
* add TypoScript to template record
*/

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('cookie_redirect','Configuration/TypoScript/','One-Time Forwarder');
21 changes: 21 additions & 0 deletions Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
defined('TYPO3_MODE') || die();

/**
* Register Plugin and flexform
*/


$pluginSignature = 'cookie_redirect_pi1';

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(array(
'LLL:EXT:cookie_redirect/Resources/Private/Language/locallang.xlf:tt_content.list_type_pi1',
$pluginSignature,
'EXT:cookie_redirect/ext_icon.png'
),'list_type', 'cookie_redirect');

$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist'][$pluginSignature] = 'recursive,select_key,pages,recursive';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature,
'FILE:EXT:cookie_redirect/Configuration/FlexForms/PluginFlexform.xml');
14 changes: 14 additions & 0 deletions Configuration/TSconfig/ContentElementWizard.t3s
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mod.wizards.newContentElement.wizardItems.plugins {
elements {
cookie_redirect {
iconIdentifier = ext-cookie-redirect-wizard-icon
title = LLL:EXT:cookie_redirect/Resources/Private/Language/locallang.xlf:pi1_title
description = LLL:EXT:cookie_redirect/Resources/Private/Language/locallang.xlf:pi1_plus_wiz_description
tt_content_defValues {
CType = list
list_type = cookie_redirect_pi1
}
}
}
}

16 changes: 16 additions & 0 deletions Configuration/TypoScript/setup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

plugin.tx_cookieredirect_pi1 {
userFunc = Colorcube\CookieRedirect\Controller\Plugin->main

// default is: tx_cookieredirect_pi1
cookiePrefix =

// cookie lifetime in seconds
cookieLifetime = 10000000

// one-time redirect PID
shortcutPID =

// default PID - default is current page
defaultPID =
}
33 changes: 33 additions & 0 deletions Documentation/AdministratorManual/Index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.. ==================================================
.. FOR YOUR INFORMATION
.. --------------------------------------------------
.. -*- coding: utf-8 -*- with BOM.
.. include:: ../Includes.txt


.. _admin-manual:

Administrator Manual
====================

Installation
------------

There are two ways to properly install the extension.

1. Composer installation
^^^^^^^^^^^^^^^^^^^^^^^^

In case you use Composer to manage dependencies of your TYPO3 project,
you can just issue the following Composer command in your project root directory.

.. code-block:: bash
composer require colorcube/cookie-redirect
2. Installation with Extension Manager
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Download and install the extension with the extension manager module.

Binary file added Documentation/Images/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8d9ed51

Please sign in to comment.