|
1 | 1 | <?php
|
2 | 2 | abstract class lCommand{
|
| 3 | + static function getAutoCompleteFor($input){ |
| 4 | + $input = explode(" ", $input); |
| 5 | + $input = $input[count($input)-1]; |
| 6 | + $all = []; |
| 7 | + // add programs |
| 8 | + $dirs = array_filter(glob('programms/*'), 'is_dir'); |
| 9 | + foreach($dirs as $d){ |
| 10 | + array_push($all, str_replace("programms/", "", $d)); |
| 11 | + } |
| 12 | + // add files |
| 13 | + $pwd = lSystem::getPWD(); |
| 14 | + $files = glob($pwd."/*"); |
| 15 | + foreach($files as $f){ |
| 16 | + array_push($all, basename($f)); |
| 17 | + } |
| 18 | + asort($all); |
| 19 | + foreach($all as $a){ |
| 20 | + if(substr( $a, 0, strlen($input) ) == $input) return str_replace($input, "", $a); |
| 21 | + } |
| 22 | + return null; |
| 23 | + } |
3 | 24 | static function addToStack($command){
|
4 |
| - array_push($_SESSION["commandstack"], $command); |
| 25 | + array_push($_SESSION["phpcommandline"]["commandstack"], $command); |
| 26 | + } |
| 27 | + static function setNextCommand($command){ |
| 28 | + array_unshift($_SESSION["phpcommandline"]["commandstack"], $command); |
5 | 29 | }
|
6 | 30 |
|
7 | 31 | static function addToStackIfNotExists($command){
|
8 | 32 | if(!lCommand::existsCommandInStack($command)) lCommand::addToStack($command);
|
9 | 33 | }
|
10 | 34 |
|
11 | 35 | static function existsCommandInStack($command){
|
12 |
| - foreach($_SESSION["commandstack"] as $c){ |
| 36 | + foreach($_SESSION["phpcommandline"]["commandstack"] as $c){ |
13 | 37 | $programm = explode(" ", $c)[0];
|
14 | 38 | if($programm==$command || $c==$command) return true;
|
15 | 39 | }
|
16 | 40 | return false;
|
17 | 41 | }
|
18 | 42 |
|
19 | 43 | static function getResult(){
|
20 |
| - return $_SESSION["commandresult"]; |
| 44 | + return $_SESSION["phpcommandline"]["commandresult"]; |
21 | 45 | }
|
22 | 46 |
|
23 | 47 | static function write($result){
|
24 |
| - $_SESSION["commandresult"] .= (strlen($_SESSION["commandresult"])==0 ? "" : "<br>").$result; |
| 48 | + $_SESSION["phpcommandline"]["commandresult"] .= (strlen($_SESSION["phpcommandline"]["commandresult"])==0 ? "" : "<br>").$result; |
25 | 49 | }
|
26 | 50 |
|
27 | 51 | private static function popCommand(){
|
28 |
| - $_SESSION["commandstack"] = array_slice($_SESSION["commandstack"], 1); |
| 52 | + $_SESSION["phpcommandline"]["commandstack"] = array_slice($_SESSION["phpcommandline"]["commandstack"], 1); |
29 | 53 | }
|
30 | 54 |
|
31 | 55 | private static function getCurrentCommand(){
|
32 |
| - return count($_SESSION["commandstack"])>0 ? $_SESSION["commandstack"][0] : ""; |
| 56 | + return count($_SESSION["phpcommandline"]["commandstack"])>0 ? $_SESSION["phpcommandline"]["commandstack"][0] : ""; |
33 | 57 | }
|
34 | 58 |
|
35 | 59 | static function getNextItemAndPop(){
|
@@ -58,6 +82,7 @@ static function performNextCommand(){
|
58 | 82 | lCommand::write("command \"$command\" not found");
|
59 | 83 | }
|
60 | 84 | }else{
|
| 85 | + lCommand::write("> $command"); |
61 | 86 | lCommand::write("not authorized to run this command");
|
62 | 87 | }
|
63 | 88 | }
|
|
0 commit comments