Bearsampp
2026.7.11
Toggle main menu visibility
Loading...
Searching...
No Matches
class.action.editAlias.php
Go to the documentation of this file.
1
<?php
2
/*
3
* Copyright (c) 2021-2024 Bearsampp
4
* License: GNU General Public License version 3 or later; see LICENSE.txt
5
* Author: Bear
6
* Website: https://bearsampp.com
7
* Github: https://github.com/Bearsampp
8
*/
9
14
class
ActionEditAlias
extends
ActionDialogBase
15
{
16
private
$wbLabelName
;
17
private
$wbInputName
;
18
private
$wbLabelDest
;
19
private
$wbInputDest
;
20
private
$wbBtnDest
;
21
private
$wbLabelExp
;
22
23
protected
function
getWindowTitle
()
24
{
25
global
$bearsamppLang
;
26
return
sprintf(
$bearsamppLang
->getValue(
Lang::EDIT_ALIAS_TITLE
), $this->initValue);
27
}
28
29
protected
function
getDialogTitle
()
30
{
31
global
$bearsamppLang
;
32
return
$bearsamppLang
->getValue(
Lang::ADD_ALIAS_TITLE
);
33
}
34
35
protected
function
getDeleteDialogTitle
()
36
{
37
global
$bearsamppLang
;
38
return
$bearsamppLang
->getValue(
Lang::DELETE_ALIAS_TITLE
);
39
}
40
41
protected
function
initializeDialog
($args)
42
{
43
global
$bearsamppRoot
;
44
45
if
(!isset($args[0]) || empty($args[0])) {
46
return
false
;
47
}
48
49
$filePath =
Path::getAliasPath
() .
'/'
. $args[0] .
'.conf'
;
50
if
(!file_exists($filePath)) {
51
return
false
;
52
}
53
54
$fileContent = file_get_contents($filePath);
55
if
(!preg_match(
'/^Alias \/'
. $args[0] .
' "(.+)"/'
, $fileContent, $match)) {
56
return
false
;
57
}
58
59
$this->initValue = $args[0];
60
return
true
;
61
}
62
63
protected
function
createFormFields
($bearsamppWinbinder)
64
{
65
global
$bearsamppRoot
,
$bearsamppLang
,
$bearsamppBins
;
66
67
// Load existing alias data
68
$filePath =
Path::getAliasPath
() .
'/'
. $this->initValue .
'.conf'
;
69
$fileContent = file_get_contents($filePath);
70
preg_match(
'/^Alias \/'
. $this->initValue .
' "(.+)"/'
, $fileContent, $match);
71
$initDest =
Path::formatWindowsPath
($match[1]);
72
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
73
74
$this->wbLabelName = $bearsamppWinbinder->createLabel(
75
$this->wbWindow,
76
$bearsamppLang
->getValue(
Lang::ALIAS_NAME_LABEL
) .
' :'
,
77
15, 15, 85,
null
, WBC_RIGHT
78
);
79
$this->wbInputName = $bearsamppWinbinder->createInputText(
80
$this->wbWindow,
81
$this->initValue,
82
105, 13, 150,
null
83
);
84
85
$this->wbLabelDest = $bearsamppWinbinder->createLabel(
86
$this->wbWindow,
87
$bearsamppLang
->getValue(
Lang::ALIAS_DEST_LABEL
) .
' :'
,
88
15, 45, 85,
null
, WBC_RIGHT
89
);
90
$this->wbInputDest = $bearsamppWinbinder->createInputText(
91
$this->wbWindow,
92
$initDest,
93
105, 43, 190,
null
,
null
, WBC_READONLY
94
);
95
$this->wbBtnDest = $bearsamppWinbinder->createButton(
96
$this->wbWindow,
97
$bearsamppLang
->getValue(
Lang::BUTTON_BROWSE
),
98
300, 43, 110
99
);
100
101
$this->wbLabelExp = $bearsamppWinbinder->createLabel(
102
$this->wbWindow,
103
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $this->initValue, $initDest),
104
15, 80, 470, 50
105
);
106
}
107
108
protected
function
getFormValues
($bearsamppWinbinder)
109
{
110
return
[
111
'name'
=> $bearsamppWinbinder->getText($this->wbInputName[
WinBinder::CTRL_OBJ
]),
112
'dest'
=> $bearsamppWinbinder->getText($this->wbInputDest[
WinBinder::CTRL_OBJ
])
113
];
114
}
115
116
protected
function
validateInput
($values)
117
{
118
global
$bearsamppLang
;
119
120
if
(!ctype_alnum($values[
'name'
])) {
121
return
[
122
'valid'
=>
false
,
123
'error'
=> sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_NOT_VALID_ALPHA
), $values[
'name'
])
124
];
125
}
126
127
return
[
'valid'
=>
true
];
128
}
129
130
protected
function
itemExists
($values)
131
{
132
global
$bearsamppRoot
,
$bearsamppLang
, $bearsamppWinbinder;
133
134
// Only check if name changed
135
if
($values[
'name'
] != $this->initValue && is_file(
Path::getAliasPath
() .
'/'
. $values[
'name'
] .
'.conf'
)) {
136
$bearsamppWinbinder->messageBoxError(
137
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_ALREADY_EXISTS
), $values[
'name'
]),
138
$this->getDialogTitle()
139
);
140
return
true
;
141
}
142
143
return
false
;
144
}
145
146
protected
function
saveItem
($values)
147
{
148
global
$bearsamppRoot
,
$bearsamppBins
;
149
150
return
file_put_contents(
151
Path::getAliasPath
() .
'/'
. $values[
'name'
] .
'.conf'
,
152
$bearsamppBins
->getApache()->getAliasContent($values[
'name'
], $values[
'dest'
])
153
) !==
false
;
154
}
155
156
protected
function
deleteItem
()
157
{
158
global
$bearsamppRoot
;
159
160
return
@unlink(
Path::getAliasPath
() .
'/'
. $this->initValue .
'.conf'
);
161
}
162
163
protected
function
getSaveSuccessMessage
($values)
164
{
165
global
$bearsamppLang
,
$bearsamppBins
;
166
167
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
168
return
sprintf(
169
$bearsamppLang
->getValue(
Lang::ALIAS_CREATED
),
170
$values[
'name'
],
171
$apachePortUri,
172
$values[
'name'
],
173
$values[
'dest'
]
174
);
175
}
176
177
protected
function
getSaveErrorMessage
()
178
{
179
global
$bearsamppLang
;
180
return
$bearsamppLang
->getValue(
Lang::ALIAS_CREATED_ERROR
);
181
}
182
183
protected
function
getDeleteConfirmMessage
()
184
{
185
global
$bearsamppLang
;
186
return
sprintf(
$bearsamppLang
->getValue(
Lang::DELETE_ALIAS
), $this->initValue);
187
}
188
189
protected
function
getDeleteSuccessMessage
()
190
{
191
global
$bearsamppLang
;
192
return
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_REMOVED
), $this->initValue);
193
}
194
195
protected
function
getDeleteErrorMessage
()
196
{
197
global
$bearsamppRoot
,
$bearsamppLang
;
198
return
sprintf(
199
$bearsamppLang
->getValue(
Lang::ALIAS_REMOVE_ERROR
),
200
Path::getAliasPath
() .
'/'
. $this->initValue .
'.conf'
201
);
202
}
203
204
protected
function
restartService
()
205
{
206
global
$bearsamppBins
;
207
$bearsamppBins
->getApache()->getService()->restart();
208
}
209
210
protected
function
handleCustomEvent
($window, $id, $ctrl, $param1, $param2)
211
{
212
global
$bearsamppLang
,
$bearsamppBins
, $bearsamppWinbinder;
213
214
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
215
$aliasName = $bearsamppWinbinder->getText($this->wbInputName[
WinBinder::CTRL_OBJ
]);
216
$aliasDest = $bearsamppWinbinder->getText($this->wbInputDest[
WinBinder::CTRL_OBJ
]);
217
218
// Handle name input change
219
if
($id == $this->wbInputName[
WinBinder::CTRL_ID
]) {
220
$bearsamppWinbinder->setText(
221
$this->wbLabelExp[
WinBinder::CTRL_OBJ
],
222
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $aliasName, $aliasDest)
223
);
224
$bearsamppWinbinder->setEnabled(
225
$this->wbBtnSave[
WinBinder::CTRL_OBJ
],
226
!empty($aliasName)
227
);
228
}
229
230
// Handle browse button
231
if
($id == $this->wbBtnDest[
WinBinder::CTRL_ID
]) {
232
$aliasDest = $bearsamppWinbinder->sysDlgPath(
233
$window,
234
$bearsamppLang
->getValue(
Lang::ALIAS_DEST_PATH
),
235
$aliasDest
236
);
237
if
($aliasDest && is_dir($aliasDest)) {
238
$bearsamppWinbinder->setText($this->wbInputDest[
WinBinder::CTRL_OBJ
], $aliasDest .
'\\'
);
239
$bearsamppWinbinder->setText(
240
$this->wbLabelExp[
WinBinder::CTRL_OBJ
],
241
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $aliasName, $aliasDest .
'\\'
)
242
);
243
}
244
}
245
}
246
}
247
$bearsamppBins
global $bearsamppBins
Definition
ajax.apache.php:16
$bearsamppLang
global $bearsamppLang
Definition
ajax.apache.php:16
$bearsamppRoot
global $bearsamppRoot
Definition
ajax.apache.php:16
ActionDialogBase
Definition
class.action.dialogBase.php:18
ActionEditAlias
Definition
class.action.editAlias.php:15
ActionEditAlias\createFormFields
createFormFields($bearsamppWinbinder)
Definition
class.action.editAlias.php:63
ActionEditAlias\$wbInputDest
$wbInputDest
Definition
class.action.editAlias.php:19
ActionEditAlias\$wbLabelExp
$wbLabelExp
Definition
class.action.editAlias.php:21
ActionEditAlias\$wbLabelName
$wbLabelName
Definition
class.action.editAlias.php:16
ActionEditAlias\getDeleteSuccessMessage
getDeleteSuccessMessage()
Definition
class.action.editAlias.php:189
ActionEditAlias\handleCustomEvent
handleCustomEvent($window, $id, $ctrl, $param1, $param2)
Definition
class.action.editAlias.php:210
ActionEditAlias\$wbBtnDest
$wbBtnDest
Definition
class.action.editAlias.php:20
ActionEditAlias\$wbLabelDest
$wbLabelDest
Definition
class.action.editAlias.php:18
ActionEditAlias\validateInput
validateInput($values)
Definition
class.action.editAlias.php:116
ActionEditAlias\getSaveSuccessMessage
getSaveSuccessMessage($values)
Definition
class.action.editAlias.php:163
ActionEditAlias\getDeleteDialogTitle
getDeleteDialogTitle()
Definition
class.action.editAlias.php:35
ActionEditAlias\getSaveErrorMessage
getSaveErrorMessage()
Definition
class.action.editAlias.php:177
ActionEditAlias\restartService
restartService()
Definition
class.action.editAlias.php:204
ActionEditAlias\getDeleteErrorMessage
getDeleteErrorMessage()
Definition
class.action.editAlias.php:195
ActionEditAlias\$wbInputName
$wbInputName
Definition
class.action.editAlias.php:17
ActionEditAlias\getDialogTitle
getDialogTitle()
Definition
class.action.editAlias.php:29
ActionEditAlias\saveItem
saveItem($values)
Definition
class.action.editAlias.php:146
ActionEditAlias\deleteItem
deleteItem()
Definition
class.action.editAlias.php:156
ActionEditAlias\getDeleteConfirmMessage
getDeleteConfirmMessage()
Definition
class.action.editAlias.php:183
ActionEditAlias\getWindowTitle
getWindowTitle()
Definition
class.action.editAlias.php:23
ActionEditAlias\getFormValues
getFormValues($bearsamppWinbinder)
Definition
class.action.editAlias.php:108
ActionEditAlias\initializeDialog
initializeDialog($args)
Definition
class.action.editAlias.php:41
ActionEditAlias\itemExists
itemExists($values)
Definition
class.action.editAlias.php:130
Lang\EDIT_ALIAS_TITLE
const EDIT_ALIAS_TITLE
Definition
class.lang.php:226
Lang\ALIAS_REMOVE_ERROR
const ALIAS_REMOVE_ERROR
Definition
class.lang.php:214
Lang\BUTTON_BROWSE
const BUTTON_BROWSE
Definition
class.lang.php:373
Lang\ADD_ALIAS_TITLE
const ADD_ALIAS_TITLE
Definition
class.lang.php:217
Lang\ALIAS_DEST_LABEL
const ALIAS_DEST_LABEL
Definition
class.lang.php:219
Lang\ALIAS_NAME_LABEL
const ALIAS_NAME_LABEL
Definition
class.lang.php:218
Lang\ALIAS_DEST_PATH
const ALIAS_DEST_PATH
Definition
class.lang.php:221
Lang\ALIAS_CREATED
const ALIAS_CREATED
Definition
class.lang.php:224
Lang\ALIAS_ALREADY_EXISTS
const ALIAS_ALREADY_EXISTS
Definition
class.lang.php:223
Lang\ALIAS_EXP_LABEL
const ALIAS_EXP_LABEL
Definition
class.lang.php:220
Lang\ALIAS_REMOVED
const ALIAS_REMOVED
Definition
class.lang.php:213
Lang\ALIAS_NOT_VALID_ALPHA
const ALIAS_NOT_VALID_ALPHA
Definition
class.lang.php:222
Lang\ALIAS_CREATED_ERROR
const ALIAS_CREATED_ERROR
Definition
class.lang.php:225
Lang\DELETE_ALIAS_TITLE
const DELETE_ALIAS_TITLE
Definition
class.lang.php:211
Lang\DELETE_ALIAS
const DELETE_ALIAS
Definition
class.lang.php:212
Path\getAliasPath
static getAliasPath($aetrayPath=false)
Definition
class.path.php:331
Path\formatWindowsPath
static formatWindowsPath($path)
Definition
class.path.php:118
WinBinder\CTRL_ID
const CTRL_ID
Definition
class.winbinder.php:21
WinBinder\CTRL_OBJ
const CTRL_OBJ
Definition
class.winbinder.php:22
sandbox
core
classes
actions
class.action.editAlias.php
Generated by
1.17.0