-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.tweak.php
464 lines (429 loc) · 16.4 KB
/
class.tweak.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<?php
/**
* imageTweak
*
* @author Ralf Hertsch <ralf.hertsch@phpmanufaktur.de>
* @link http://phpmanufaktur.de
* @copyright 2008-2013
* @license MIT License (MIT) http://www.opensource.org/licenses/MIT
*/
// include class.secure.php to protect this file and the whole CMS!
if (defined('WB_PATH')) {
if (defined('LEPTON_VERSION'))
include(WB_PATH.'/framework/class.secure.php');
}
else {
$oneback = "../";
$root = $oneback;
$level = 1;
while (($level < 10) && (!file_exists($root.'/framework/class.secure.php'))) {
$root .= $oneback;
$level += 1;
}
if (file_exists($root.'/framework/class.secure.php')) {
include($root.'/framework/class.secure.php');
}
else {
trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
}
// end include class.secure.php
// Sprachdateien einbinden
if(!file_exists(WB_PATH .'/modules/'.basename(dirname(__FILE__)).'/languages/' .LANGUAGE .'.php')) {
require_once(WB_PATH .'/modules/'.basename(dirname(__FILE__)).'/languages/DE.php');
}
else {
require_once(WB_PATH .'/modules/'.basename(dirname(__FILE__)).'/languages/' .LANGUAGE .'.php');
}
// dbConnect_LE einbinden
if (!class_exists('dbConnectLE')) require_once(WB_PATH.'/modules/dbconnect_le/include.php');
class dbImageTweakCfg extends dbConnectLE {
const field_id = 'cfg_id';
const field_name = 'cfg_name';
const field_type = 'cfg_type';
const field_value = 'cfg_value';
const field_label = 'cfg_label';
const field_description = 'cfg_desc';
const field_status = 'cfg_status';
const field_update_by = 'cfg_update_by';
const field_update_when = 'cfg_update_when';
const status_active = 1;
const status_deleted = 0;
const type_undefined = 0;
const type_array = 7;
const type_boolean = 1;
const type_email = 2;
const type_float = 3;
const type_integer = 4;
const type_path = 5;
const type_string = 6;
const type_url = 8;
public $type_array = array(
self::type_undefined => '-UNDEFINED-',
self::type_array => 'ARRAY',
self::type_boolean => 'BOOLEAN',
self::type_email => 'E-MAIL',
self::type_float => 'FLOAT',
self::type_integer => 'INTEGER',
self::type_path => 'PATH',
self::type_string => 'STRING',
self::type_url => 'URL'
);
private $createTables = false;
private $message = '';
const cfgTweakExec = 'cfgTweakExec';
const cfgTweakImageDir = 'cfgTweakImageDir';
const cfgClassNoTweak = 'cfgClassNoTweak';
const cfgExtensions = 'cfgExtensions';
const cfgCheckAltTags = 'cfgCheckAltTags';
const cfgDefaultAltTag = 'cfgDefaultAltTag';
const cfgSetTitleTag = 'cfgSetTitleTag';
const cfgIgnorePageIDs = 'cfgIgnorePageIDs';
const cfgIgnoreTopicIDs = 'cfgIgnoreTopicIDs';
const cfgLimitLogEntries = 'cfgLimitLogEntries';
const cfgClassFancybox = 'cfgClassFancybox';
const cfgFancyboxRel = 'cfgFancyboxRel';
const cfgFancyboxGrp = 'cfgFancyboxGrp';
const cfgMemoryLimit = 'cfgMemoryLimit';
const cfgMemoryBuffer = 'cfgMemoryBuffer';
const cfgJPEGquality = 'cfgJPEGquality';
const cfgClassTweakGallery = 'cfgClassTweakGallery';
const cfgChangeURL2WB_URL = 'cfgChangeURL2WB_URL';
public $config_array = array(
array('tweak_label_cfg_exec', self::cfgTweakExec, self::type_boolean, '1', 'tweak_desc_cfg_exec'),
array('tweak_label_cfg_image_dir', self::cfgTweakImageDir, self::type_string, 'tweaked', 'tweak_desc_cfg_image_dir'),
array('tweak_label_cfg_class_no_tweak', self::cfgClassNoTweak, self::type_string, 'no-tweak', 'tweak_desc_cfg_class_no_tweak'),
array('tweak_label_cfg_extensions', self::cfgExtensions, self::type_array, 'jpg,jpeg,gif,png', 'tweak_desc_cfg_extensions'),
array('tweak_label_cfg_check_alt_tags', self::cfgCheckAltTags, self::type_boolean, '1', 'tweak_desc_cfg_check_alt_tags'),
array('tweak_label_cfg_default_alt_tag', self::cfgDefaultAltTag, self::type_string, tweak_text_alt_default, 'tweak_desc_cfg_default_alt_tag'),
array('tweak_label_cfg_set_title_tag', self::cfgSetTitleTag, self::type_boolean, '0', 'tweak_desc_cfg_set_title_tag'),
array('tweak_label_cfg_ignore_page_ids', self::cfgIgnorePageIDs, self::type_array, '', 'tweak_desc_cfg_ignore_page_ids'),
array('tweak_label_cfg_ignore_topic_ids', self::cfgIgnoreTopicIDs, self::type_array, '', 'tweak_desc_cfg_ignore_topic_ids'),
array('tweak_label_cfg_limit_log_entries', self::cfgLimitLogEntries, self::type_integer, '200', 'tweak_desc_cfg_limit_log_entries'),
array('tweak_label_cfg_class_fancybox', self::cfgClassFancybox, self::type_string, 'tweak-fancybox', 'tweak_desc_cfg_class_fancybox'),
array('tweak_label_cfg_memory_limit', self::cfgMemoryLimit, self::type_integer, '0', 'tweak_desc_cfg_memory_limit'),
array('tweak_label_cfg_fancybox_grp', self::cfgFancyboxGrp, self::type_string, 'grouped_elements', 'tweak_desc_cfg_fancybox_grp'),
array('tweak_label_cfg_fancybox_rel', self::cfgFancyboxRel, self::type_string, 'fancybox', 'tweak_desc_cfg_fancybox_rel'),
array('tweak_label_cfg_memory_buffer', self::cfgMemoryBuffer, self::type_integer, '4', 'tweak_desc_cfg_memory_buffer'),
array('tweak_label_cfg_jpeg_quality', self::cfgJPEGquality, self::type_integer, '90', 'tweak_desc_cfg_jpeg_quality'),
array('tweak_label_cfg_class_tweak_gallery', self::cfgClassTweakGallery, self::type_string, 'tweak-gallery', 'tweak_desc_cfg_class_tweak_gallery'),
array('tweak_label_cfg_change_url2wb_url', self::cfgChangeURL2WB_URL, self::type_array, '', 'tweak_desc_cfg_change_url2wb_url')
);
protected static $config_file = 'config.json';
protected static $table_prefix = TABLE_PREFIX;
public function __construct($createTables = false) {
// create table?
$this->createTables = $createTables;
// use another table prefix?
if (file_exists(WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/config.json')) {
$config = json_decode(file_get_contents(WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/config.json'), true);
if (isset($config['table_prefix']))
self::$table_prefix = $config['table_prefix'];
}
parent::__construct();
$this->setTablePrefix(self::$table_prefix);
$this->setTableName('mod_img_tweak_config');
$this->addFieldDefinition(self::field_id, "INT(11) NOT NULL AUTO_INCREMENT", true);
$this->addFieldDefinition(self::field_name, "VARCHAR(32) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_type, "TINYINT UNSIGNED NOT NULL DEFAULT '".self::type_undefined."'");
$this->addFieldDefinition(self::field_value, "VARCHAR(255) NOT NULL DEFAULT ''", false, false, true);
$this->addFieldDefinition(self::field_label, "VARCHAR(64) NOT NULL DEFAULT 'ed_str_undefined'");
$this->addFieldDefinition(self::field_description, "VARCHAR(255) NOT NULL DEFAULT 'ed_str_undefined'");
$this->addFieldDefinition(self::field_status, "TINYINT UNSIGNED NOT NULL DEFAULT '".self::status_active."'");
$this->addFieldDefinition(self::field_update_by, "VARCHAR(32) NOT NULL DEFAULT 'SYSTEM'");
$this->addFieldDefinition(self::field_update_when, "DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
$this->setIndexFields(array(self::field_name));
$this->setAllowedHTMLtags('<a><abbr><acronym><span>');
$this->checkFieldDefinitions();
// Tabelle erstellen
if ($this->createTables) {
if (!$this->sqlTableExists()) {
if (!$this->sqlCreateTable()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
}
}
}
// Default Werte garantieren
if ($this->sqlTableExists()) {
$this->checkConfig();
}
} // __construct()
public function setMessage($message) {
$this->message = $message;
} // setMessage()
/**
* Get Message from $this->message;
*
* @return STR $this->message
*/
public function getMessage() {
return $this->message;
} // getMessage()
/**
* Check if $this->message is empty
*
* @return BOOL
*/
public function isMessage() {
return (bool) !empty($this->message);
} // isMessage
/**
* Aktualisiert den Wert $new_value des Datensatz $name
*
* @param $new_value STR - Wert, der uebernommen werden soll
* @param $id INT - ID des Datensatz, dessen Wert aktualisiert werden soll
*
* @return BOOL Ergebnis
*
*/
public function setValueByName($new_value, $name) {
$where = array();
$where[self::field_name] = $name;
$config = array();
if (!$this->sqlSelectRecord($where, $config)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($config) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(tweak_error_cfg_name, $name)));
return false;
}
return $this->setValue($new_value, $config[0][self::field_id]);
} // setValueByName()
/**
* Haengt einen Slash an das Ende des uebergebenen Strings
* wenn das letzte Zeichen noch kein Slash ist
*
* @param STR $path
* @return STR
*/
public function addSlash($path) {
$path = substr($path, strlen($path)-1, 1) == "/" ? $path : $path."/";
return $path;
}
/**
* Wandelt einen String in einen Float Wert um.
* Geht davon aus, dass Dezimalzahlen mit ',' und nicht mit '.'
* eingegeben wurden.
*
* @param STR $string
* @return FLOAT
*/
public function str2float($string) {
$string = str_replace('.', '', $string);
$string = str_replace(',', '.', $string);
$float = floatval($string);
return $float;
}
public function str2int($string) {
$string = str_replace('.', '', $string);
$string = str_replace(',', '.', $string);
$int = intval($string);
return $int;
}
/**
* Ueberprueft die uebergebene E-Mail Adresse auf logische Gueltigkeit
*
* @param STR $email
* @return BOOL
*/
public function validateEMail($email) {
//if(eregi("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $email)) {
// PHP 5.3 compatibility - eregi is deprecated
if(preg_match("/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/i", $email)) {
return true; }
else {
return false; }
}
/**
* Aktualisiert den Wert $new_value des Datensatz $id
*
* @param $new_value STR - Wert, der uebernommen werden soll
* @param $id INT - ID des Datensatz, dessen Wert aktualisiert werden soll
*
* @return BOOL Ergebnis
*/
public function setValue($new_value, $id) {
$value = '';
$where = array();
$where[self::field_id] = $id;
$config = array();
if (!$this->sqlSelectRecord($where, $config)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($config) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(tweak_error_cfg_id, $id)));
return false;
}
$config = $config[0];
switch ($config[self::field_type]):
case self::type_array:
// Funktion geht davon aus, dass $value als STR uebergeben wird!!!
$worker = explode(",", $new_value);
$data = array();
foreach ($worker as $item) {
$data[] = trim($item);
};
$value = implode(",", $data);
break;
case self::type_boolean:
$value = (bool) $new_value;
$value = (int) $value;
break;
case self::type_email:
if ($this->validateEMail($new_value)) {
$value = trim($new_value);
}
else {
$this->setMessage(sprintf(tweak_msg_invalid_email, $new_value));
return false;
}
break;
case self::type_float:
$value = $this->str2float($new_value);
break;
case self::type_integer:
$value = $this->str2int($new_value);
break;
case self::type_url:
case self::type_path:
$value = $this->addSlash(trim($new_value));
break;
case self::type_string:
$value = (string) trim($new_value);
// Hochkommas demaskieren
$value = str_replace('"', '"', $value);
break;
endswitch;
unset($config[self::field_id]);
$config[self::field_value] = (string) $value;
$config[self::field_update_by] = 'SYSTEM';
$config[self::field_update_when] = date('Y-m-d H:i:s');
if (!$this->sqlUpdateRecord($config, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
return true;
} // setValue()
/**
* Gibt den angeforderten Wert zurueck
*
* @param $name - Bezeichner
*
* @return WERT entsprechend des TYP
*/
public function getValue($name) {
$result = '';
$where = array();
$where[self::field_name] = $name;
$config = array();
if (!$this->sqlSelectRecord($where, $config)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($config) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(tweak_error_cfg_name, $name)));
return false;
}
$config = $config[0];
switch ($config[self::field_type]):
case self::type_array:
$result = explode(",", $config[self::field_value]);
break;
case self::type_boolean:
$result = (bool) $config[self::field_value];
break;
case self::type_email:
case self::type_path:
case self::type_string:
case self::type_url:
$result = (string) utf8_decode($config[self::field_value]);
break;
case self::type_float:
$result = (float) $config[self::field_value];
break;
case self::type_integer:
$result = (integer) $config[self::field_value];
break;
default:
$result = utf8_decode($config[self::field_value]);
break;
endswitch;
return $result;
} // getValue()
public function checkConfig() {
foreach ($this->config_array as $item) {
$where = array();
$where[self::field_name] = $item[1];
$check = array();
if (!$this->sqlSelectRecord($where, $check)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($check) < 1) {
// Eintrag existiert nicht
$data = array();
$data[self::field_label] = $item[0];
$data[self::field_name] = $item[1];
$data[self::field_type] = $item[2];
$data[self::field_value] = $item[3];
$data[self::field_description] = $item[4];
$data[self::field_update_when] = date('Y-m-d H:i:s');
$data[self::field_update_by] = 'SYSTEM';
if (!$this->sqlInsertRecord($data)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
}
}
return true;
}
} // class dbImageTweakCfg
class dbImageTweakLog extends dbConnectLE {
const field_id = 'log_id';
const field_category = 'log_category';
const field_page_id = 'log_page_id';
const field_text = 'log_text';
const field_timestamp = 'log_timestamp';
const category_info = 'info';
const category_warning = 'warning';
const category_error = 'error';
const category_hint = 'hint';
public $category_array = array(
self::category_error => tweak_category_error,
self::category_hint => tweak_category_hint,
self::category_info => tweak_category_info,
self::category_warning => tweak_category_warning
);
private $createTables = false;
protected static $config_file = 'config.json';
protected static $table_prefix = TABLE_PREFIX;
public function __construct($createTables = false) {
// create table?
$this->createTables = $createTables;
// use another table prefix?
if (file_exists(WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/config.json')) {
$config = json_decode(file_get_contents(WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/config.json'), true);
if (isset($config['table_prefix']))
self::$table_prefix = $config['table_prefix'];
}
parent::__construct();
$this->setTablePrefix(self::$table_prefix);
$this->setTableName('mod_img_tweak_log');
$this->addFieldDefinition(self::field_id, "INT(11) NOT NULL AUTO_INCREMENT", true);
$this->addFieldDefinition(self::field_category, "VARCHAR(20) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_page_id, "INT(11) NOT NULL DEFAULT '-1'");
$this->addFieldDefinition(self::field_text, "TEXT NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_timestamp, "TIMESTAMP");
$this->checkFieldDefinitions();
// Tabelle erstellen
if ($this->createTables) {
if (!$this->sqlTableExists()) {
if (!$this->sqlCreateTable()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
}
}
}
} // __construct()
} // class dbImageTweakLog