1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category modules
|
5
|
* @package output_filter
|
6
|
* @copyright WebsiteBaker Org. e.V.
|
7
|
* @author Manuela v.d.Decken <manuela@isteam.de>
|
8
|
* @link http://websitebaker.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.3
|
11
|
* @requirements PHP 5.3.6 and higher
|
12
|
* @version $Id: cmdInstall.inc 2 2017-07-02 15:14:29Z Manuela $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/modules/output_filter/cmd/cmdInstall.inc $
|
14
|
* @lastmodified $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
|
15
|
*
|
16
|
*/
|
17
|
if(defined('WB_PATH'))
|
18
|
{
|
19
|
|
20
|
$sTable = TABLE_PREFIX.'mod_output_filter';
|
21
|
$i = (!isset($i) ? 1 : $i);
|
22
|
$OK = "<span class=\"ok\">OK</span>";
|
23
|
$FAIL = "<span class=\"error\">FAILED</span>";
|
24
|
$iErr = false;
|
25
|
$msg = array(
|
26
|
'<div style="margin:1em auto;font-size:1.1em;">',
|
27
|
'<h4>Step '.$i++.': Installing Output Filter Settings</h4>'
|
28
|
);
|
29
|
if (is_writable($sAddonPath.'/filters/filterShortUrl.php')){
|
30
|
unlink($sAddonPath.'/filters/filterShortUrl.php');
|
31
|
}
|
32
|
// create tables from sql dump file
|
33
|
$sInstallStruct = $sAddonPath.'/install-struct.sql';
|
34
|
if ( !is_readable($sInstallStruct)) {
|
35
|
$msg[] = '<strong>\'missing or not readable file [install-struct.sql]\'</strong> '.$FAIL.'<br />';
|
36
|
$iErr = true;
|
37
|
} else {
|
38
|
$getDefaultSettings = (function() use ( $sAddonName ){
|
39
|
$aDefaults = array(
|
40
|
'at_replacement' => '@',
|
41
|
'dot_replacement' => '.',
|
42
|
'email_filter' => '1',
|
43
|
'mailto_filter' => '1'
|
44
|
);
|
45
|
$aFiles = glob(WB_PATH.'/modules/'.$sAddonName.'/filters/*');
|
46
|
foreach ( $aFiles as $sFilterFile) {
|
47
|
$key = preg_replace('=^.*?filter([^\.\/\\\\]+)(\.[^\.]+)?$=is', '\1', $sFilterFile);
|
48
|
$aDefaults[$key] = '0';
|
49
|
}
|
50
|
return $aDefaults;
|
51
|
});
|
52
|
$aDefaults = $getDefaultSettings();
|
53
|
|
54
|
// drop old table and create new one
|
55
|
if ($database->SqlImport($sInstallStruct, TABLE_PREFIX, false)) {
|
56
|
if ($aDefaults) {
|
57
|
// restore old settings if there any
|
58
|
$sNameValPairs = '';
|
59
|
foreach ($aDefaults as $index => $val) {
|
60
|
$sNameValPairs .= ', (\''.$index.'\', \''.$database->escapeString($val).'\')';
|
61
|
}
|
62
|
$sValues = ltrim($sNameValPairs, ', ');
|
63
|
$sql = 'INSERT INTO `'.$sTable.'` (`name`, `value`) '
|
64
|
. 'VALUES '.$sValues;
|
65
|
if (!$database->query($sql)) {
|
66
|
$msg[] = '<strong>\'Output Filter install settings\'</strong> '.$FAIL.'<br />';
|
67
|
$iErr = true;
|
68
|
} else {
|
69
|
$msg[] = '<strong>\'Output Filter settings successful installed\'</strong> '.$OK.'<br />';
|
70
|
}
|
71
|
}
|
72
|
} else {
|
73
|
$msg[] = '<strong>\'installing or not readable file [install-struct.sql]\'</strong> '.$FAIL.'<br />';
|
74
|
$iErr = true;
|
75
|
}
|
76
|
unset($getDefaultSettings);
|
77
|
}
|
78
|
$msg[] = '</div>';
|
79
|
// print implode("\n", $msg)."\n";
|
80
|
}
|