1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AOE\Languagevisibility\Hooks; |
4
|
|
|
|
5
|
|
|
/*************************************************************** |
6
|
|
|
* Copyright notice |
7
|
|
|
* |
8
|
|
|
* (c) 2016 AOE GmbH <[email protected]> |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class/Function which manipulates the item-array for the listing (see piFlexform). |
30
|
|
|
* |
31
|
|
|
* @author Fabrizio Brance |
32
|
|
|
* @author Timo Schmidt |
33
|
|
|
*/ |
34
|
|
|
class AoeWsPreview { |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Alternative diff implementation |
38
|
|
|
* |
39
|
|
|
* @param array params |
40
|
|
|
* @return array element |
41
|
|
|
*/ |
42
|
|
|
public function aoewspreview_createDiff(array $params) { |
43
|
|
|
$element = $params['element']; |
44
|
|
|
|
45
|
|
|
if (($params['fieldName'] == 'tx_languagevisibility_visibility')) { |
46
|
|
|
$diff = array(); |
47
|
|
|
|
48
|
|
|
$recordNew = unserialize($params['newRecord'][$params['fieldName']]); |
49
|
|
|
$recordOld = unserialize($params['oldRecord'][$params['fieldName']]); |
50
|
|
|
|
51
|
|
|
$recordNew = is_array($recordNew) ? $recordNew : array(); |
52
|
|
|
$recordOld = is_array($recordOld) ? $recordOld : array(); |
53
|
|
|
|
54
|
|
|
$equalInBoth = array_intersect_assoc($recordNew, $recordOld); |
55
|
|
|
$changedKeyOld = array_keys(array_diff_assoc($recordOld, $equalInBoth)); |
56
|
|
|
$changedKeyNew = array_keys(array_diff_assoc($recordNew, $equalInBoth)); |
57
|
|
|
$keyOfChangedLanguageSettings = array_unique(array_merge($changedKeyNew, $changedKeyOld)); |
58
|
|
|
|
59
|
|
|
if (is_array($keyOfChangedLanguageSettings) && (count($keyOfChangedLanguageSettings) > 0)) { |
60
|
|
|
foreach ( $keyOfChangedLanguageSettings as $key ) { |
61
|
|
|
if (empty($recordOld[$key]) && ($recordNew[$key] == '-')) { |
62
|
|
|
// this is equal, too! |
63
|
|
|
// we need to inform the user what happens because he doesn't understand |
64
|
|
|
// what happend if the field tx_languagevisibility_visibility was configured as critical field |
65
|
|
|
// and if was just initialized with default values. |
66
|
|
|
$diff[] = sprintf('%s Visibility was initialized with the default value (%s)', tx_mvc_common_typo3::getLanguageFlag($key, $params['newRecord']['pid']), $recordNew[$key]); |
67
|
|
|
} elseif (empty($recordNew[$key])) { |
68
|
|
|
// in this case an old visibility setting has been changed to an empty value, |
69
|
|
|
// this can happen when a new workspace version is created |
70
|
|
|
$diff[0] = 'Languagevisibility was changed from ' . serialize($recordOld) . ' to ' . serialize($recordNew); |
71
|
|
|
} else { |
72
|
|
|
$diff[] = sprintf('%s Visibility changed from <span class="diff-r">%s</span> to <span class="diff-g">%s</span>', tx_mvc_common_typo3::getLanguageFlag($key, $params['newRecord']['pid']), $GLOBALS['LANG']->sL('LLL:EXT:languagevisibility/locallang_db.xml:tx_languagevisibility_visibility.I.' . $recordOld[$key]), $GLOBALS['LANG']->sL('LLL:EXT:languagevisibility/locallang_db.xml:tx_languagevisibility_visibility.I.' . $recordNew[$key])); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} else { |
76
|
|
|
// in this case the structure of the languagevisibility was changed but no visibility setting |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if (count($diff) > 0) { |
80
|
|
|
$element['diffResult'] = implode('<br />', $diff); |
81
|
|
|
} else { |
82
|
|
|
// element will be removed when returning "false" |
83
|
|
|
$element = FALSE; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $element; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|