forked from Actindo/actindo-shopconnector-oxid4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.php
317 lines (269 loc) · 7.09 KB
/
util.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
/**
* various utilities
*
* actindo Faktura/WWS connector
*
* @package actindo
* @author Patrick Prasse <[email protected]>
* @version $Revision: 401 $
* @copyright Copyright (c) 2007, Patrick Prasse (Schneebeerenweg 26, D-85551 Kirchheim, GERMANY, [email protected])
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
define( 'SHOP_TYPE_XTCOMMERCE', 'xtcommerce' );
define( 'SHOP_TYPE_XTC4', 'xtcommerce4' );
define( 'SHOP_TYPE_OSCOMMERCE', 'oscommerce' );
define( 'SHOP_TYPE_SHOPWARE', 'shopware' );
define( 'SHOP_TYPE_MAGENTO', 'magentocommerce' );
define( 'SHOP_TYPE_OXID4', 'oxid4' );
define( 'SHOP_TYPE_OXID5', 'oxid5' );
// act_get_shop_type in <shoptype>/util.php
// act_shop_get_capabilities in <shoptype>/util.php
function act_shop_is( $type )
{
return act_get_shop_type() == $type;
}
if( !function_exists('file_put_contents') )
{
function file_put_contents( $filename, $data )
{
$fp = fopen( $filename, 'w' );
if( !$fp )
return false;
$n = fwrite( $fp, $data );
fclose( $fp );
return $n;
}
}
function _actindo_generic_mapper( &$input, &$map )
{
$output = array();
foreach( $input as $_key => $_val )
{
$_newkey = $map[$_key];
if( !isset($_newkey) )
{
$varname = "['xtcshop']['{$_key}']";
}
else
{
parse_str( $_newkey.'=1', $arr );
$varname = _function_do_get_var( $arr );
}
eval( "\$output{$varname} = \$_val;" );
}
return $output;
}
function _function_do_get_var( $arr, $str='' )
{
list( $key, $newarr ) = each( $arr );
if( is_string($key) || is_float($key) )
$str .= sprintf( "['%s']", $key );
else
$str .= sprintf( "[%d]", $key );
if( is_array($newarr) )
$str .= _function_do_get_var( $newarr );
return $str;
}
function var_dump_string( $var )
{
ob_start();var_dump( $var );
return ob_get_clean();
}
function encode_all_base64( $data )
{
if( is_array($data) )
{
if( count($data) )
{
foreach( $data as $idx => $val )
$ret[$idx] = encode_all_base64( $val );
}
else
$ret = array();
}
else
{
if( is_numeric($data) || is_object($data) ) // save overhead with numbers
$ret = $data;
else
$ret = new xmlrpcval( $data, $GLOBALS["xmlrpcBase64"] );
}
return $ret;
}
/**
* @author derernst at gmx dot ch
*/
function decode_entities($text, $quote_style = ENT_COMPAT)
{
if (function_exists('html_entity_decode'))
{
$text = html_entity_decode($text, $quote_style, 'ISO-8859-1'); // NOTE: UTF-8 does not work!
}
else
{
$trans_tbl = get_html_translation_table(HTML_ENTITIES, $quote_style);
$trans_tbl = array_flip($trans_tbl);
$text = strtr($text, $trans_tbl);
}
$text = preg_replace('/&#x([0-9a-f]+);/ei', 'chr(hexdec("\\1"))', $text);
$text = preg_replace('/&#([0-9]+);/e', 'chr("\\1")', $text);
return $text;
}
function get_col( $mapping )
{
return( !is_array($mapping) ? $mapping : '`'.$mapping[0].'`.`'.esc($mapping[1]).'`' );
}
function create_query_from_filter( $request, $mapping, $default_order=null )
{
$q_search = '1';
$order = null;
$limit = '0';
if( is_object($request) )
{
$request = $request->toArray();
$op = array(
1 => '<',
2 => '<=',
3 => '>',
4 => '>=',
5 => '=',
6 => '<>',
);
}
else
{
$op = array(
'lt' => '<',
'gt' => '>',
'eq' => '='
);
}
if( isset($request[0]['field']) ) // just filter, no limit / order
$filter = $request;
else
{
if( isset($request['start']) && isset($request['limit']) )
{
$limit = sprintf( "%d OFFSET %d", $request['limit'], $request['start'] );
}
else
{
$limit = '0';
}
if( is_null($default_order) )
{
$m = array_keys( $mapping );
$default_order = get_col( $mapping[$m[0]] );
}
if( isset($request['sortColName']) && !empty($request['sortColName']))
{
$order_col = $request['sortColName'];
if( !isset($mapping[$order_col]) )
{
$order_col = $default_order;
}
else
{
$order_col = get_col( $mapping[$order_col] );
}
$order_dir = ($request['sortOrder'] < 0 || $request['sortOrder']==='ASC' ? 'ASC' : 'DESC');
}
else
{
$order_col = $default_order;
$order_dir = 'DESC';
}
$order = trim( $order_col.' '.$order_dir );
$filter = $request['filter'];
}
if( isset($filter) && is_array($filter) && count($filter) )
{
$q_filter = array();
foreach( $filter as $_fi => $filter )
{
$fld = $filter['field'];
$filter = $filter['data'];
if( !isset($mapping[$fld]) )
return FALSE;
list( $tablealias, $fld, $forcetype, $listmapping ) = $mapping[$fld];
if( isset($forcetype) && !empty($forcetype) )
$filter['type'] = $forcetype;
if( $filter['type'] === 'date' || $filter['type'] === 1 )
{
$q = '`'.$tablealias.'`.`'.esc($fld).'`';
$q .= $op[$filter['comparison']];
$q .= "'".esc($filter['value'])."'";
}
else if( $filter['type'] === 'list' || $filter['type'] === 2 )
{
$vals = split( ',', $filter['value'] );
$args = array();
foreach( $vals as $_val )
{
if( is_array($listmapping) )
$args[] = "'".esc($listmapping[$_val])."'";
else
$args[] = "'".esc($_val)."'";
}
$q = 'FIELD(`'.$tablealias.'`.`'.esc($fld).'`, '.join(', ', $args).')<>0';
}
else if( $filter['type'] === 'boolean' || $filter['type'] === 3 )
{
if( $filter['value'] === 'false' )
$filter['value'] = 0;
elseif( $filter['value'] === 'true' )
$filter['value'] = 1;
else
$filter['value'] = (int)$filter['value'];
$f1 = '`'.$tablealias.'`.`'.esc($fld).'`';
$q = 'IFNULL('.$f1.',0)'.($filter['value'] ? '<>0' : '=0');
}
else if( $filter['type'] === 'string' || $filter['type'] === 4 )
{
$q = '`'.$tablealias.'`.`'.esc($fld).'` LIKE \'%'.esc($filter['value']).'%\'';
}
else if( $filter['type'] === 'numeric' || $filter['type'] === 5 )
{
$q = '`'.$tablealias.'`.`'.esc($fld).'`';
$q .= $op[$filter['comparison']];
$q .= sprintf( "%f", (float)$filter['value'] );
}
$q_filter[] = $q;
}
if( count($q_filter) )
$q_search = '('.join(' AND ', $q_filter).')';
}
$ret = compact( 'q_search' );
if( !is_null($order) )
$ret['order'] = $order;
if( !is_null($limit) )
$ret['limit'] = $limit;
else
$ret['limit'] = "2147483647 OFFSET 0";
return $ret;
}
if( !function_exists('stripos') )
{
function stripos( $haystack, $needle )
{
return strpos( strtolower($haystack), strtolower($needle) );
}
}
function timestamp_to_datetime( $timestamp )
{
return date( 'Y-m-d H:i:s', $timestamp );
}
/**
* Add last slash to a directory if last char is not a slash
*
* @param string $path Path to add last slash to
* @returns string Path with last slash added
*/
function add_last_slash( $path )
{
if( substr($path,strlen($path)-1,1) != '/' )
$path .= '/';
return $path;
}
?>