Bearsampp
2026.9.23
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-2026 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
{
17
private
$wbLabelName
;
19
private
$wbInputName
;
21
private
$wbLabelDest
;
23
private
$wbInputDest
;
25
private
$wbBtnDest
;
27
private
$wbLabelExp
;
28
34
protected
function
getWindowTitle
()
35
{
36
global
$bearsamppLang
;
37
38
return
sprintf(
$bearsamppLang
->getValue(
Lang::EDIT_ALIAS_TITLE
), $this->initValue);
39
}
40
46
protected
function
getDialogTitle
()
47
{
48
global
$bearsamppLang
;
49
50
return
$bearsamppLang
->getValue(
Lang::ADD_ALIAS_TITLE
);
51
}
52
58
protected
function
getDeleteDialogTitle
()
59
{
60
global
$bearsamppLang
;
61
62
return
$bearsamppLang
->getValue(
Lang::DELETE_ALIAS_TITLE
);
63
}
64
72
protected
function
initializeDialog
($args)
73
{
74
global
$bearsamppRoot
;
75
76
if
(!isset($args[0]) || empty($args[0])) {
77
return
false
;
78
}
79
80
$filePath =
Path::getAliasPath
() .
'/'
. $args[0] .
'.conf'
;
81
if
(!file_exists($filePath)) {
82
return
false
;
83
}
84
85
$fileContent = file_get_contents($filePath);
86
if
(!preg_match(
'/^Alias \/'
. $args[0] .
' "(.+)"/'
, $fileContent, $match)) {
87
return
false
;
88
}
89
90
$this->initValue = $args[0];
91
92
return
true
;
93
}
94
102
protected
function
createFormFields
($bearsamppWinbinder)
103
{
104
global
$bearsamppRoot
,
$bearsamppLang
,
$bearsamppBins
;
105
106
// Load existing alias data
107
$filePath =
Path::getAliasPath
() .
'/'
. $this->initValue .
'.conf'
;
108
$fileContent = file_get_contents($filePath);
109
preg_match(
'/^Alias \/'
. $this->initValue .
' "(.+)"/'
, $fileContent, $match);
110
$initDest =
Path::formatWindowsPath
($match[1]);
111
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
112
113
$this->wbLabelName = $bearsamppWinbinder->createLabel(
114
$this->wbWindow,
115
$bearsamppLang
->getValue(
Lang::ALIAS_NAME_LABEL
) .
' :'
,
116
15,
117
15,
118
85,
119
null
,
120
WBC_RIGHT
121
);
122
$this->wbInputName = $bearsamppWinbinder->createInputText(
123
$this->wbWindow,
124
$this->initValue,
125
105,
126
13,
127
150,
128
null
129
);
130
131
$this->wbLabelDest = $bearsamppWinbinder->createLabel(
132
$this->wbWindow,
133
$bearsamppLang
->getValue(
Lang::ALIAS_DEST_LABEL
) .
' :'
,
134
15,
135
45,
136
85,
137
null
,
138
WBC_RIGHT
139
);
140
$this->wbInputDest = $bearsamppWinbinder->createInputText(
141
$this->wbWindow,
142
$initDest,
143
105,
144
43,
145
190,
146
null
,
147
null
,
148
WBC_READONLY
149
);
150
$this->wbBtnDest = $bearsamppWinbinder->createButton(
151
$this->wbWindow,
152
$bearsamppLang
->getValue(
Lang::BUTTON_BROWSE
),
153
300,
154
43,
155
110
156
);
157
158
$this->wbLabelExp = $bearsamppWinbinder->createLabel(
159
$this->wbWindow,
160
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $this->initValue, $initDest),
161
15,
162
80,
163
470,
164
50
165
);
166
}
167
175
protected
function
getFormValues
($bearsamppWinbinder)
176
{
177
return
[
178
'name'
=> $bearsamppWinbinder->getText($this->wbInputName[
WinBinder::CTRL_OBJ
]),
179
'dest'
=> $bearsamppWinbinder->getText($this->wbInputDest[
WinBinder::CTRL_OBJ
])
180
];
181
}
182
190
protected
function
validateInput
($values)
191
{
192
global
$bearsamppLang
;
193
194
if
(!ctype_alnum($values[
'name'
])) {
195
return
[
196
'valid'
=>
false
,
197
'error'
=> sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_NOT_VALID_ALPHA
), $values[
'name'
])
198
];
199
}
200
201
return
[
'valid'
=>
true
];
202
}
203
211
protected
function
itemExists
($values)
212
{
213
global
$bearsamppRoot
,
$bearsamppLang
, $bearsamppWinbinder;
214
215
// Only check if name changed
216
if
($values[
'name'
] != $this->initValue && is_file(
Path::getAliasPath
() .
'/'
. $values[
'name'
] .
'.conf'
)) {
217
$bearsamppWinbinder->messageBoxError(
218
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_ALREADY_EXISTS
), $values[
'name'
]),
219
$this->getDialogTitle()
220
);
221
222
return
true
;
223
}
224
225
return
false
;
226
}
227
235
protected
function
saveItem
($values)
236
{
237
global
$bearsamppRoot
,
$bearsamppBins
;
238
239
return
file_put_contents(
240
Path::getAliasPath
() .
'/'
. $values[
'name'
] .
'.conf'
,
241
$bearsamppBins
->getApache()->getAliasContent($values[
'name'
], $values[
'dest'
])
242
) !==
false
;
243
}
244
250
protected
function
deleteItem
()
251
{
252
global
$bearsamppRoot
;
253
254
return
@unlink(
Path::getAliasPath
() .
'/'
. $this->initValue .
'.conf'
);
255
}
256
264
protected
function
getSaveSuccessMessage
($values)
265
{
266
global
$bearsamppLang
,
$bearsamppBins
;
267
268
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
269
270
return
sprintf(
271
$bearsamppLang
->getValue(
Lang::ALIAS_CREATED
),
272
$values[
'name'
],
273
$apachePortUri,
274
$values[
'name'
],
275
$values[
'dest'
]
276
);
277
}
278
284
protected
function
getSaveErrorMessage
()
285
{
286
global
$bearsamppLang
;
287
288
return
$bearsamppLang
->getValue(
Lang::ALIAS_CREATED_ERROR
);
289
}
290
296
protected
function
getDeleteConfirmMessage
()
297
{
298
global
$bearsamppLang
;
299
300
return
sprintf(
$bearsamppLang
->getValue(
Lang::DELETE_ALIAS
), $this->initValue);
301
}
302
308
protected
function
getDeleteSuccessMessage
()
309
{
310
global
$bearsamppLang
;
311
312
return
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_REMOVED
), $this->initValue);
313
}
314
320
protected
function
getDeleteErrorMessage
()
321
{
322
global
$bearsamppRoot
,
$bearsamppLang
;
323
324
return
sprintf(
325
$bearsamppLang
->getValue(
Lang::ALIAS_REMOVE_ERROR
),
326
Path::getAliasPath
() .
'/'
. $this->initValue .
'.conf'
327
);
328
}
329
335
protected
function
restartService
()
336
{
337
global
$bearsamppBins
;
338
$bearsamppBins
->getApache()->getService()->restart();
339
}
340
352
protected
function
handleCustomEvent
($window, $id, $ctrl, $param1, $param2)
353
{
354
global
$bearsamppLang
,
$bearsamppBins
, $bearsamppWinbinder;
355
356
$apachePortUri =
$bearsamppBins
->getApache()->getPort() != 80 ?
':'
.
$bearsamppBins
->getApache()->getPort() :
''
;
357
$aliasName = $bearsamppWinbinder->getText($this->wbInputName[
WinBinder::CTRL_OBJ
]);
358
$aliasDest = $bearsamppWinbinder->getText($this->wbInputDest[
WinBinder::CTRL_OBJ
]);
359
360
// Handle name input change
361
if
($id == $this->wbInputName[
WinBinder::CTRL_ID
]) {
362
$bearsamppWinbinder->setText(
363
$this->wbLabelExp[
WinBinder::CTRL_OBJ
],
364
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $aliasName, $aliasDest)
365
);
366
$bearsamppWinbinder->setEnabled(
367
$this->wbBtnSave[
WinBinder::CTRL_OBJ
],
368
!empty($aliasName)
369
);
370
}
371
372
// Handle browse button
373
if
($id == $this->wbBtnDest[
WinBinder::CTRL_ID
]) {
374
$aliasDest = $bearsamppWinbinder->sysDlgPath(
375
$window,
376
$bearsamppLang
->getValue(
Lang::ALIAS_DEST_PATH
),
377
$aliasDest
378
);
379
if
($aliasDest && is_dir($aliasDest)) {
380
$bearsamppWinbinder->setText($this->wbInputDest[
WinBinder::CTRL_OBJ
], $aliasDest .
'\\'
);
381
$bearsamppWinbinder->setText(
382
$this->wbLabelExp[
WinBinder::CTRL_OBJ
],
383
sprintf(
$bearsamppLang
->getValue(
Lang::ALIAS_EXP_LABEL
), $apachePortUri, $aliasName, $aliasDest .
'\\'
)
384
);
385
}
386
}
387
}
388
}
389
$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:102
ActionEditAlias\$wbInputDest
$wbInputDest
Definition
class.action.editAlias.php:23
ActionEditAlias\$wbLabelExp
$wbLabelExp
Definition
class.action.editAlias.php:27
ActionEditAlias\$wbLabelName
$wbLabelName
Definition
class.action.editAlias.php:17
ActionEditAlias\getDeleteSuccessMessage
getDeleteSuccessMessage()
Definition
class.action.editAlias.php:308
ActionEditAlias\handleCustomEvent
handleCustomEvent($window, $id, $ctrl, $param1, $param2)
Definition
class.action.editAlias.php:352
ActionEditAlias\$wbBtnDest
$wbBtnDest
Definition
class.action.editAlias.php:25
ActionEditAlias\$wbLabelDest
$wbLabelDest
Definition
class.action.editAlias.php:21
ActionEditAlias\validateInput
validateInput($values)
Definition
class.action.editAlias.php:190
ActionEditAlias\getSaveSuccessMessage
getSaveSuccessMessage($values)
Definition
class.action.editAlias.php:264
ActionEditAlias\getDeleteDialogTitle
getDeleteDialogTitle()
Definition
class.action.editAlias.php:58
ActionEditAlias\getSaveErrorMessage
getSaveErrorMessage()
Definition
class.action.editAlias.php:284
ActionEditAlias\restartService
restartService()
Definition
class.action.editAlias.php:335
ActionEditAlias\getDeleteErrorMessage
getDeleteErrorMessage()
Definition
class.action.editAlias.php:320
ActionEditAlias\$wbInputName
$wbInputName
Definition
class.action.editAlias.php:19
ActionEditAlias\getDialogTitle
getDialogTitle()
Definition
class.action.editAlias.php:46
ActionEditAlias\saveItem
saveItem($values)
Definition
class.action.editAlias.php:235
ActionEditAlias\deleteItem
deleteItem()
Definition
class.action.editAlias.php:250
ActionEditAlias\getDeleteConfirmMessage
getDeleteConfirmMessage()
Definition
class.action.editAlias.php:296
ActionEditAlias\getWindowTitle
getWindowTitle()
Definition
class.action.editAlias.php:34
ActionEditAlias\getFormValues
getFormValues($bearsamppWinbinder)
Definition
class.action.editAlias.php:175
ActionEditAlias\initializeDialog
initializeDialog($args)
Definition
class.action.editAlias.php:72
ActionEditAlias\itemExists
itemExists($values)
Definition
class.action.editAlias.php:211
Lang\EDIT_ALIAS_TITLE
const EDIT_ALIAS_TITLE
Definition
class.lang.php:227
Lang\ALIAS_REMOVE_ERROR
const ALIAS_REMOVE_ERROR
Definition
class.lang.php:215
Lang\BUTTON_BROWSE
const BUTTON_BROWSE
Definition
class.lang.php:380
Lang\ADD_ALIAS_TITLE
const ADD_ALIAS_TITLE
Definition
class.lang.php:218
Lang\ALIAS_DEST_LABEL
const ALIAS_DEST_LABEL
Definition
class.lang.php:220
Lang\ALIAS_NAME_LABEL
const ALIAS_NAME_LABEL
Definition
class.lang.php:219
Lang\ALIAS_DEST_PATH
const ALIAS_DEST_PATH
Definition
class.lang.php:222
Lang\ALIAS_CREATED
const ALIAS_CREATED
Definition
class.lang.php:225
Lang\ALIAS_ALREADY_EXISTS
const ALIAS_ALREADY_EXISTS
Definition
class.lang.php:224
Lang\ALIAS_EXP_LABEL
const ALIAS_EXP_LABEL
Definition
class.lang.php:221
Lang\ALIAS_REMOVED
const ALIAS_REMOVED
Definition
class.lang.php:214
Lang\ALIAS_NOT_VALID_ALPHA
const ALIAS_NOT_VALID_ALPHA
Definition
class.lang.php:223
Lang\ALIAS_CREATED_ERROR
const ALIAS_CREATED_ERROR
Definition
class.lang.php:226
Lang\DELETE_ALIAS_TITLE
const DELETE_ALIAS_TITLE
Definition
class.lang.php:212
Lang\DELETE_ALIAS
const DELETE_ALIAS
Definition
class.lang.php:213
Path\getAliasPath
static getAliasPath($aetrayPath=false)
Definition
class.path.php:348
Path\formatWindowsPath
static formatWindowsPath($path)
Definition
class.path.php:127
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