-
Notifications
You must be signed in to change notification settings - Fork 5
/
functions.php
69 lines (59 loc) · 1.61 KB
/
functions.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
<?php
// echo 300 new lines
function ClearScreen(){
echo str_repeat(PHP_EOL, 300);
}
// Display a menu object and it's options
function DisplayMenu($menu_object){
ClearScreen();
echo '[' . $menu_object->Name . ']' . PHP_EOL;
foreach($menu_object->MenuOptions as $key => $value) {
echo "$key: $value" . PHP_EOL;
}
}
// Get user input/feedback
function GetCommmand($text = ''){
$cmd = readline($text);
readline_add_history($cmd); // add command to history
return $cmd;
};
// Quit the application
function Quit(){
ClearScreen();
$GLOBALS['Application']->RunState = 0;
echo "Buh Bye!!!" . PHP_EOL;
}
// Cross-platform open a text editor example
function OpenTextEditor(){
$OS = strtoupper(substr(PHP_OS, 0, 3));
if($OS == 'WIN'){ // Windows
pclose(popen("start /B notepad", "r")); // open notepad
}
elseif($OS == 'DAR'){ // Mac
pclose(popen("TextEdit", "r")); // open TextEdit
}
elseif($OS == 'LIN'){ // Linux
pclose(popen("nano", "r")); // open nano
}
elseif($OS == 'BSD'){
echo "Not Implemented." . PHP_EOL;
}
elseif($OS == 'SOL'){ // Solaris
echo "Not Implemented." . PHP_EOL;
}
elseif($OS == 'UNK'){ // Unknown
echo "Not Implemented." . PHP_EOL;
}
else{
echo "Not Implemented." . PHP_EOL;
}
}
// Ping an address example
function Ping($address){
system("ping $address");
}
// Change the application current menu to a new menu object
function ChangeMenu($new_menu){
ClearScreen();
$GLOBALS['Application']->CurrentMenu = $GLOBALS[$new_menu];
}