Commit 866bd1d6 authored by Nico Schallehn's avatar Nico Schallehn

test

parent 115085df
<?php <?php
class Colors { class Console {
private $foreground_colors = array(); private $foreground_colors = array();
private $background_colors = array(); private $background_colors = array();
public function __construct() { public function __construct() {
// Set up shell colors // Set up shell colors
$this->foreground_colors['black'] = '0;30'; $this->foreground_colors['black'] = '0;30';
$this->foreground_colors['dark_gray'] = '1;30'; $this->foreground_colors['dark_gray'] = '1;30';
$this->foreground_colors['blue'] = '0;34'; $this->foreground_colors['blue'] = '0;34';
$this->foreground_colors['light_blue'] = '1;34'; $this->foreground_colors['light_blue'] = '1;34';
$this->foreground_colors['green'] = '0;32'; $this->foreground_colors['green'] = '0;32';
$this->foreground_colors['light_green'] = '1;32'; $this->foreground_colors['light_green'] = '1;32';
$this->foreground_colors['cyan'] = '0;36'; $this->foreground_colors['cyan'] = '0;36';
$this->foreground_colors['light_cyan'] = '1;36'; $this->foreground_colors['light_cyan'] = '1;36';
$this->foreground_colors['red'] = '0;31'; $this->foreground_colors['red'] = '0;31';
$this->foreground_colors['light_red'] = '1;31'; $this->foreground_colors['light_red'] = '1;31';
$this->foreground_colors['purple'] = '0;35'; $this->foreground_colors['purple'] = '0;35';
$this->foreground_colors['light_purple'] = '1;35'; $this->foreground_colors['light_purple'] = '1;35';
$this->foreground_colors['brown'] = '0;33'; $this->foreground_colors['brown'] = '0;33';
$this->foreground_colors['yellow'] = '1;33'; $this->foreground_colors['yellow'] = '1;33';
$this->foreground_colors['light_gray'] = '0;37'; $this->foreground_colors['light_gray'] = '0;37';
$this->foreground_colors['white'] = '1;37'; $this->foreground_colors['white'] = '1;37';
$this->background_colors['black'] = '40'; $this->background_colors['black'] = '40';
$this->background_colors['red'] = '41'; $this->background_colors['red'] = '41';
$this->background_colors['green'] = '42'; $this->background_colors['green'] = '42';
$this->background_colors['yellow'] = '43'; $this->background_colors['yellow'] = '43';
$this->background_colors['blue'] = '44'; $this->background_colors['blue'] = '44';
$this->background_colors['magenta'] = '45'; $this->background_colors['magenta'] = '45';
$this->background_colors['cyan'] = '46'; $this->background_colors['cyan'] = '46';
$this->background_colors['light_gray'] = '47'; $this->background_colors['light_gray'] = '47';
} }
// Returns colored string // Returns colored string
public function getColoredString($string, $foreground_color = null, $background_color = null) { public function getColoredString($string, $foreground_color = null, $background_color = null) {
$colored_string = ""; $colored_string = "";
// Check if given foreground color found // Check if given foreground color found
if (isset($this->foreground_colors[$foreground_color])) { if (isset($this->foreground_colors[$foreground_color])) {
$colored_string .= "\033[" . $this->foreground_colors[$foreground_color] . "m"; $colored_string .= "\033[" . $this->foreground_colors[$foreground_color] . "m";
} }
// Check if given background color found // Check if given background color found
if (isset($this->background_colors[$background_color])) { if (isset($this->background_colors[$background_color])) {
$colored_string .= "\033[" . $this->background_colors[$background_color] . "m"; $colored_string .= "\033[" . $this->background_colors[$background_color] . "m";
} }
// Add string and end coloring // Add string and end coloring
$colored_string .= $string . "\033[0m"; $colored_string .= $string . "\033[0m";
return $colored_string; return $colored_string;
} }
// Returns all foreground color names // Returns all foreground color names
public function getForegroundColors() { public function getForegroundColors() {
return array_keys($this->foreground_colors); return array_keys($this->foreground_colors);
} }
// Returns all background color names // Returns all background color names
public function getBackgroundColors() { public function getBackgroundColors() {
return array_keys($this->background_colors); return array_keys($this->background_colors);
} }
public function clearscreen($out = TRUE) {
$clearscreen = chr(27)."[H".chr(27)."[2J";
if ($out) print $clearscreen;
else return $clearscreen;
}
} }
?> ?>
\ No newline at end of file
<?php
class Media {
private $Console;
private $configfile;
private $config;
public function __construct($configfile) {
$this->Console = new Console();
$this->configfile = $configfile;
if(file_exists($configfile)){
echo $this->Console->getColoredString("Hinweis:","black", "light_gray")." Configfile: ".$configfile." geladen!".PHP_EOL.PHP_EOL;
$dateihandle = fopen($this->configfile,"r");
$this->config = json_decode(fread($dateihandle, filesize($this->configfile)),true);
}
else{
echo $this->Console->getColoredString("Hinweis:","black", "light_gray")." Configfile: ".$configfile." exisitiert nicht! Es werden defaults geladen!".PHP_EOL;
echo " Zum Anlegen der config bitte config save eingeben!".PHP_EOL.PHP_EOL;
$this->config = array("configChangeTime" => time(),
"HDD" => array(1 => array("HDDdir"=>"/media/QNAP/",
"FolderFilme" => "Filme/",
"Folder3D" => "Filme3D/"),
2 => NULL,
3 => NULL,
4 => NULL,
5 => NULL)
);
}
}
public function config_show(){
//var_dump($this->config);
echo $this->Console->getColoredString("Folgende Config ist geladen:","black", "light_gray").PHP_EOL.PHP_EOL;
echo "Config erstellt: ".date("H:i:s d.m.Y ",$this->config["configChangeTime"]) .PHP_EOL;
echo PHP_EOL;
return 0;
}
public function config_save(){
$dateihandle = fopen($this->configfile,"w");
fwrite($dateihandle, json_encode($this->config, JSON_PRETTY_PRINT));
fclose($dateihandle);
}
}
\ No newline at end of file
<?php include './color.class.php'; <?php
include './color.class.php';
include './media.class.php';
$Console = new Console();
$Console->clearscreen();
$Media = new Media("config.json");
$colors = new Colors();
//echo "md5: ".$colors->getColoredString("Fehler!", "white", "red") .PHP_EOL;
//echo "md5: ".$colors->getColoredString("Erfolgreich!", "white", "green") .PHP_EOL;
if(isset($argv[1])){ $exit = false;
switch ($argv[1]){
do{
echo $Console->getColoredString("Benutzung:", "black", "light_gray") .PHP_EOL.PHP_EOL;
echo " filme Filme aus einen Verzeichnis zur DB hinzufügen".PHP_EOL;
echo " config show Zeigt die Konfiguration an!".PHP_EOL;
echo " config save Speichert die Konfiguration!".PHP_EOL;
echo " exit beendet das Programm".PHP_EOL.PHP_EOL;
echo "Bitte Befehl eingeben: ";
$name = trim(fgets(STDIN));
$Console->clearscreen();
//echo "Hallo $name \n";
switch ($name){
case "filme": case "filme":
echo $colors->getColoredString("Filme", "black", "light_gray") .PHP_EOL; echo $Console->getColoredString("Filme", "black", "light_gray") .PHP_EOL;
break;
case "config save":
$Media->config_save();
break; break;
case "showconfig": case "config show":
echo $colors->getColoredString("Konfiguration", "black", "light_gray") .PHP_EOL; $Media->config_show();
echo "Verzeichnis zum einlesen: ".$argv[2]." "; break;
case "exit":
$exit = true;
break; break;
default: default:
echo $colors->getColoredString("Fehler", "red", "light_gray") .PHP_EOL; echo $Console->getColoredString("Ungülter Befehl!", "red", "light_gray") .PHP_EOL;
echo "Bitte ohne Parameter aufrufen für Hilfe!".PHP_EOL;
break; break;
} }
}else{ //echo "Weiter mit (ENTER)".PHP_EOL;
echo $colors->getColoredString("Benutzung:", "black", "light_gray") .PHP_EOL; //trim(fgets(STDIN));
echo " filme [Pfad zum einlesen] [Zielfestplatte]".PHP_EOL; }while(!$exit);
}
//echo "md5: ".$colors->getColoredString("Fehler!", "white", "red") .PHP_EOL;
//echo "md5: ".$colors->getColoredString("Erfolgreich!", "white", "green") .PHP_EOL;
/*
if(isset($argv[1])){
switch ($argv[1]){
case "filme":
echo $colors->getColoredString("Filme", "black", "light_gray") .PHP_EOL;
break;
default:
echo $colors->getColoredString("Fehler", "red", "light_gray") .PHP_EOL;
echo "Bitte ohne Parameter aufrufen für Hilfe!".PHP_EOL;
break;
}
}else{
echo $colors->getColoredString("Benutzung:", "black", "light_gray") .PHP_EOL;
echo " filme [Pfad zum einlesen] [Zielfestplatte]".PHP_EOL;
}
*/
?> ?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment