|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AOE\Languagevisibility\Hooks; |
|
4
|
|
|
|
|
5
|
|
|
/*************************************************************** |
|
6
|
|
|
* Copyright notice |
|
7
|
|
|
* |
|
8
|
|
|
* (c) 2014 AOE GmbH <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* All rights reserved |
|
11
|
|
|
* |
|
12
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
13
|
|
|
* free software; you can redistribute it and/or modify |
|
14
|
|
|
* it under the terms of the GNU General Public License as published by |
|
15
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
16
|
|
|
* (at your option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* The GNU General Public License can be found at |
|
19
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
20
|
|
|
* |
|
21
|
|
|
* This script is distributed in the hope that it will be useful, |
|
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
24
|
|
|
* GNU General Public License for more details. |
|
25
|
|
|
* |
|
26
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
27
|
|
|
***************************************************************/ |
|
28
|
|
|
|
|
29
|
|
|
use AOE\Languagevisibility\CacheManager; |
|
30
|
|
|
use AOE\Languagevisibility\Services\BeServices; |
|
31
|
|
|
use AOE\Languagevisibility\Services\VisibilityService; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Class T3libTceMain |
|
35
|
|
|
*/ |
|
36
|
|
|
class T3libTceMain { |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param string $table |
|
40
|
|
|
* @param integer $id |
|
41
|
|
|
* @param array $data |
|
42
|
|
|
* @param integer $res (but only 0 and 1 is relevant so it's boolean technically) |
|
43
|
|
|
* @param $tcemain |
|
44
|
|
|
* @internal param object $this |
|
45
|
|
|
* @return integer |
|
46
|
|
|
*/ |
|
47
|
|
|
public function checkRecordUpdateAccess($table, $id, $data, $res, $tcemain) { |
|
|
|
|
|
|
48
|
|
|
if ($table == 'pages' && !BeServices::hasUserAccessToPageRecord($id, 'edit')) { |
|
49
|
|
|
$result = 0; |
|
50
|
|
|
} elseif (!BeServices::hasUserAccessToEditRecord($table, $id)) { |
|
51
|
|
|
$result = 0; |
|
52
|
|
|
} else { |
|
53
|
|
|
$result = $res; |
|
54
|
|
|
} |
|
55
|
|
|
return $result; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* This function is called my TYPO each time an element is saved in the backend |
|
60
|
|
|
* |
|
61
|
|
|
* @param array $incomingFieldArray |
|
62
|
|
|
* @param string $table |
|
63
|
|
|
* @param unknown_type $id |
|
64
|
|
|
* @param unknown_type $reference |
|
65
|
|
|
*/ |
|
66
|
|
|
public function processDatamap_preProcessFieldArray(&$incomingFieldArray, $table, $id, &$reference) { |
|
|
|
|
|
|
67
|
|
|
$data = $incomingFieldArray; |
|
68
|
|
|
|
|
69
|
|
|
if (! is_array($data)) { |
|
70
|
|
|
return; /** some strange DB situation */ |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if (in_array($table, VisibilityService::getSupportedTables())) { |
|
74
|
|
|
/** |
|
75
|
|
|
* NOTE: This code does not affect new records because the field 'tx_languagevisibility_visibility' is not set |
|
76
|
|
|
*/ |
|
77
|
|
|
if (isset($incomingFieldArray['tx_languagevisibility_visibility']) && is_array($incomingFieldArray['tx_languagevisibility_visibility'])) { |
|
78
|
|
|
|
|
79
|
|
|
if ($table == 'pages') { |
|
80
|
|
|
|
|
81
|
|
|
$incomingFieldArray['tx_languagevisibility_inheritanceflag_original'] = (in_array('no+', $incomingFieldArray['tx_languagevisibility_visibility'])) ? '1' : '0'; |
|
82
|
|
|
} elseif ($table == 'pages_language_overlay') { |
|
83
|
|
|
$incomingFieldArray['tx_languagevisibility_inheritanceflag_overlayed'] = (in_array('no+', $incomingFieldArray['tx_languagevisibility_visibility'])) ? '1' : '0'; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$incomingFieldArray['tx_languagevisibility_visibility'] = serialize($incomingFieldArray['tx_languagevisibility_visibility']); |
|
87
|
|
|
|
|
88
|
|
|
// flush all caches |
|
89
|
|
|
CacheManager::getInstance()->flushAllCaches(); |
|
90
|
|
|
|
|
91
|
|
|
// Flush TYPO3 Caching Framework caches |
|
92
|
|
|
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager') |
|
93
|
|
|
->getCache('tx_languagevisibility') |
|
94
|
|
|
->flush(); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* This method is used to initialize new Elements with the default |
|
101
|
|
|
* |
|
102
|
|
|
* @param unknown_type $status |
|
103
|
|
|
* @param unknown_type $table |
|
104
|
|
|
* @param unknown_type $id |
|
105
|
|
|
* @param unknown_type $fieldArray |
|
106
|
|
|
* @param unknown_type $reference |
|
107
|
|
|
*/ |
|
108
|
|
|
public function processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, &$reference) { |
|
109
|
|
|
|
|
110
|
|
|
if (in_array($table, VisibilityService::getSupportedTables())) { |
|
111
|
|
|
/** |
|
112
|
|
|
* Now we set the default visibility for elements which did not get a defaultvisibility array. |
|
113
|
|
|
* This can happen, if a user creates a new element AND the user has no access for the languagevisibility_field |
|
114
|
|
|
*/ |
|
115
|
|
|
if ($status == 'new') { |
|
116
|
|
|
$row = array(); |
|
117
|
|
|
$row['uid'] = $reference->substNEWwithIDs[$id]; |
|
118
|
|
|
|
|
119
|
|
|
if ($fieldArray['pid'] == '-1') { |
|
120
|
|
|
$row = \TYPO3\CMS\Backend\Utility\BackendUtility::getWorkspaceVersionOfRecord($fieldArray['t3ver_wsid'], $table, $row['uid'], $fields = '*'); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$newdata = array('tx_languagevisibility_visibility' => serialize(BeServices::getDefaultVisibilityArray())); |
|
124
|
|
|
$where = "tx_languagevisibility_visibility = '' AND uid=" . $row['uid']; |
|
125
|
|
|
|
|
126
|
|
|
$GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, $where, $newdata); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
CacheManager::getInstance()->flushAllCaches(); |
|
130
|
|
|
|
|
131
|
|
|
// Flush TYPO3 Caching Framework caches |
|
132
|
|
|
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager') |
|
133
|
|
|
->getCache('tx_languagevisibility') |
|
134
|
|
|
->flush(); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.