forked from franzholz/div2007
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.tx_div2007_ff.php
200 lines (184 loc) · 6.34 KB
/
class.tx_div2007_ff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/***************************************************************
* Copyright notice
*
* (c) 2018 Fabien Udriot (fudriot@omic.ch)
* 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 2 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
/**
* Collection of static functions for flexforms
*
*
* @package TYPO3
* @subpackage div2007
* @author Fabien Udriot <fudriot@omic.ch>
* @copyright 2006-2007 Fabien Udriot
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 0.1
*/
// deprecated: will be removed in 2024
/**
* Collection of static functions for flexforms
*
* This class contains diverse static functions to support flexform handling.
*
* @package TYPO3
* @subpackage div2007
* @author Fabien Udriot <fudriot@omic.ch>
*/
class tx_div2007_ff {
/**
* The current loaded flexform
*
* @var array
*/
static protected $flexForm = array(); //the current loaded flexform
/**
* A set of flexforms that are stored in case they are going to be used.
*
* @var array
*/
static protected $flexForms = array();
/**
* Load a flexform into memory
*
* @param mixed $flexForm can be an xml string or an array or a key array.
* @param string $flexFormName (optinal) give a name to the flexform in order to be stored for further use.
* @return void
*/
static public function load ($flexForm, $flexFormName = ''){
//handle the case $flexForm is a string. It can be a xml string or key array
if(is_string($flexForm)){
//test if $flexForm already exists in the memory. In this case load the flexform according to its key
if(array_key_exists($flexForm, self::$flexForms)){
self::$flexForm = self::$flexForms[$flexForm];
}
else{
//if false, it means it is *still* a string to convert in an array
self::$flexForm = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($flexForm);
}
}
else{
//else it is right away an array, load it in memory
self::$flexForm = $flexForm;
}
//true when the flexform is going to be stored for further use
if($flexFormName != ''){
self::setFlexForm($flexFormName, self::$flexForm);
}
}
/**
* Add a flexform in memory
*
* @param string the flexForm name
* @param array the flexForm
* @return void
*/
static public function setFlexForm ($flexFormName, $flexForm){
self::$flexForms[$flexFormName] = $flexForm;
}
/**
* Get a flexform from memory
*
* @param string the flexForm name
* @return array the flexform
*/
static public function getFlexForm ($flexFormName) {
$result = false;
if(array_key_exists($flexFormName, self::$flexForms)) {
$result = self::$flexForms[$flexFormName];
}
return $result;
}
/**
* Return value from somewhere inside the loaded flexForm structure
*
* @param mixed $flexForm, (optional) a flexForm array or a key array that contains a flexform
* @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 array The content.
*/
static public function get () {
$num_args = func_num_args();
//true when the first argument is a flexForm or a reference to flexForm
if(
$num_args &&
(
is_array(func_get_arg(0)) ||
array_key_exists(
func_get_arg(0),
self::$flexForms
)
)
) {
//case 1, $args 1 is an array... case 2, $args 1 is a key array that contains a flexform
is_array(func_get_arg(0)) ? $_flexForm = func_get_arg(0) : $_flexForm =& self::getFlexForm(func_get_arg(0));
$index = 1;
} else {
$_flexForm = &self::$flexForm;
$index = 0;
}
$fieldName = func_get_arg($index);
$num_args > $index + 1 ? $sheet = func_get_arg($index + 1) : $sheet = 'sDEF';
$num_args > $index + 2 ? $lang = func_get_arg($index + 2) : $lang = 'lDEF';
$num_args > $index + 3 ? $value = func_get_arg($index + 3) : $value = 'vDEF';
is_array($_flexForm) ? $sheetArray = $_flexForm['data'][$sheet][$lang] : $sheetArray = '';
$result = null;
if (is_array($sheetArray)){
$result = self::_getFFValueFromSheetArray($sheetArray, explode('/', $fieldName), $value);
}
return $result;
}
/**
* Returns part of $sheetArray pointed to by the keys in $fieldNameArray
*
* @param array Multidimensiona array, typically FlexForm contents
* @param array 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 for outermost key, typ. "vDEF" depending on language.
* @return mixed The value, typ. string. private
*/
static public function _getFFValueFromSheetArray ($sheetArray, $fieldNameArr, $value){
$tempArr = $sheetArray;
foreach($fieldNameArr as $k => $v){
if (
tx_div2007_core::testInt($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];
}
}
?>