Merge pull request 'small-fixes' (#1) from small-fixes into master

Reviewed-on: Rasmus/PasswordPhraseGenerator#1
This commit is contained in:
Rasmus Malver 2021-03-04 20:41:49 +00:00
commit 42a770e21c
5 changed files with 350 additions and 118 deletions

View file

@ -0,0 +1,150 @@
<?php
/**
* PasswordPhraseGenerator
*/
class PasswordPhraseGenerator
{
/**
* Initializing object
*/
function __construct()
{
$this->sub = json_decode(file_get_contents('data/navneord.json'));
$this->ver = json_decode(file_get_contents('data/verber.json'));
$this->adj = json_decode(file_get_contents('data/adj.json'));
$this->ord = [
"sub" => json_decode(file_get_contents('data/navneord.json')),
"ver" => json_decode(file_get_contents('data/verber.json')),
"adj" => json_decode(file_get_contents('data/adj.json')),
"pro" => ["jeg", "han", "hun", "den", "det", "de", "I", "vi", "du", "De"],
"tid" => ["før", "efter", "imens", "inden"],
"for" => ["over", "under", "ved siden af", "bag", "foran", "overfor"],
];
$this->tal = rand(2, 79);
$this->model = rand(0, 1);
$this->end = array(".", "!", "?", "!?", "...", " :-)", " ;-)");
$this->tegn = $this->end[array_rand($this->end)];
}
/**
* Random sub element
*
* @param array $arr
* @return array
*/
private function _rando($arr)
{
return $arr[array_rand($arr)];
}
/**
* Select random word from class
*
* @param string $cla
* @param int $conj
* @return string $word
*/
private function _word($cla, $conj = null)
{
$word = $this->ord[$cla][array_rand($this->ord[$cla])]; //rand(0,count($ord[$cla]));
if ($conj == null) {
return $word;
} else {
return $word[$conj];
}
}
/**
* Main model generator
*
* @param integer $conj
* @return string $phrase
*/
function lego($conj = 0)
{
// 0 = ubestemt ental, eks. "en grim tyr" el. "et dumt æg".
// 1 = bestemt ental, eks. "den grimme tyr" el. "det dumme æg"
// 2 = ubestemt flertal, eks. "ægte tedåser"
// 3 = bestemt flertal, eks. "de rådne æbler"
$main = $this->_word("sub");
$desc = $this->_word("adj");
if ($main[4] == "t") {
$neutrum = true;
} else {
$neutrum = false;
}
switch ($conj) {
case 0:
if ($neutrum) {
$phrase = "et " . $this->_word("adj")[1] . " " . $main[0];
} else {
$phrase = "en " . $this->_word("adj")[0] . " " . $main[0];
}
break;
case 1:
if ($neutrum) {
$phrase = "det " . $this->_word("adj")[2] . " " . $main[0];
} else {
$phrase = "den " . $this->_word("adj")[2] . " " . $main[0];
}
break;
case 2:
$phrase = $this->_word("adj")[2] . " " . $main[2];
break;
case 3:
$phrase = "de " . $this->_word("adj")[2] . " " . $main[2];
break;
}
return $phrase;
}
/**
* Generate phrase
*
* @return string $phrase
*/
public function generate()
{
switch ($this->model) {
case 0:
if ($this->tal > 1) {
$b = $this->lego(2);
} else {
$b = $this->lego(rand(0, 1));
}
$c = $this->_word("ver", rand(1, 4));
$d = $this->_word("sub", $this->_rando([1, 3]));
if (rand(0, 1) > 0) {
$which = rand(1, 3);
switch ($which) {
case 1:
$b = mb_strtoupper($b);
break;
case 2:
$c = mb_strtoupper($c);
break;
case 1:
$d = mb_strtoupper($d);
break;
}
}
$result = "{$this->tal} $b $c $d{$this->tegn}";
break;
case 1:
$a = $this->lego($this->_rando([0, 1, 3]));
$b = $this->_word("ver", rand(1, 4));
if ($this->tal > 1) {
$c = $this->_word("sub", 2);
} else {
$c = $this->_word("sub", $this->_rando([1, 3]));
}
$result = "$a $b {$this->tal} $c{$this->tegn}";
break;
}
return ucwords($result);
}
}

0
core/functions.php Normal file
View file

131
index.php
View file

@ -1,111 +1,48 @@
<?php
require_once 'core/PasswordPhraseGenerator.php';
$sentence = new PasswordPhraseGenerator;
$result = $sentence->generate();
?>
<!DOCTYPE html>
<html lang="da">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Sætningsgenerator</title>
<style>
*{margin:0;padding:0;}html{height:100%;}
h1{text-align:center;margin-top:10%;}
* {
margin: 0;
padding: 0;
}
html {
height: 100%;
}
h1 {
text-align: center;
margin-top: 10%;
}
.the-result {
background: #333;
color: #FFF;
padding: 0.3em;
}
</style>
</head>
<body><!--
<?php
$tal = rand(2,79);
$model = rand(0,1);
$end=array(".","!","?","!?","..."," :-)"," ;-)");
$tegn=$end[array_rand($end)];
$result = "";
<body>
$ord = array(
"sub"=>JSON_Decode(file_get_contents('data/navneord.json')),
"ver"=>JSON_Decode(file_get_contents('data/verber.json')),
"adj"=>JSON_Decode(file_get_contents('data/adj.json')),
"pro"=>array("jeg","han","hun","den","det","de","I","vi","du","De"),
"tid"=>array("før","efter","imens","inden"),
"for"=>array("over","under","ved siden af","bag","foran","overfor"));
function rando($arr){
return $arr[array_rand($arr)];
}
function word($cla,$conj=null){
global $ord;
$word = $ord[$cla][array_rand($ord[$cla])]; //rand(0,count($ord[$cla]));
if($conj==null){
return $word;
}else{
return $word[$conj];
}
}
function lego($conj=0){
// 0 = ubestemt ental, eks. "en grim tyr" el. "et dumt æg".
// 1 = bestemt ental, eks. "den grimme tyr" el. "det dumme æg"
// 2 = ubestemt flertal, eks. "ægte tedåser"
// 3 = bestemt flertal, eks. "de rådne æbler"
$main = word("sub");
$desc = word("adj");
if($main[4]=="t"){$neutrum=true;}else{$neutrum = false;}
print_r($main);
switch($conj){
case 0:
if($neutrum){
$phrase="et ".word("adj")[1]." ".$main[0];
}else{
$phrase="en ".word("adj")[0]." ".$main[0];
}
break;
case 1:
if($neutrum){
$phrase="det ".word("adj")[2]." ".$main[0];
}else{
$phrase="den ".word("adj")[2]." ".$main[0];
}
break;
case 2:
$phrase=word("adj")[2]." ".$main[2];
break;
case 3:
$phrase="de ".word("adj")[2]." ".$main[2];
break;
}
return $phrase;
}
switch($model){
case 0:
if($tal>1){
$b = lego(2);
}else{
$b = lego(rand(0,1));
}
$c = word("ver",rand(1,4));
$d = word("sub",rando([1,3]));
$result="$tal $b $c $d$tegn";
break;
case 1:
$a = lego(rando([0,1,3]));
$b = word("ver",rand(1,4));
if($tal>1){$c = word("sub",2);}else{$c = word("sub",rando([1,3]));}
$result = "$a $b $tal $c$tegn";
break;
}
#$result=str_replace("\n","",$result);
/*
tal tillæg navneord verb navneord
tillæg navneord verb tal navneord
stedord verb tal tillægsord navneord
stedord verb tid stedord verb tillægsord navneord
stedord tillægsord navneord! stedord verbum.
*/
?>--><h1><?=ucwords($result,"|")?></h1>
<h1>
<span class="the-result"><?=$result?></span>
</h1>
</body>
</html>

View file

@ -8,10 +8,9 @@
<style>
*{margin:0;padding:0;}html{height:100%;}
h1{text-align:center;margin-top:10%;}
span{background: #333;color:#FFF;padding:0.3em;}
</style>
</head>
<body>
<body><!--
<?php
$tal = rand(2,79);
$model = rand(0,1);
@ -51,6 +50,8 @@ function lego($conj=0){
$desc = word("adj");
if($main[4]=="t"){$neutrum=true;}else{$neutrum = false;}
print_r($main);
switch($conj){
case 0:
if($neutrum){
@ -85,17 +86,6 @@ switch($model){
}
$c = word("ver",rand(1,4));
$d = word("sub",rando([1,3]));
if(rand(0,1)>0){
$which=rand(1,3);
switch($which){
case 1:
$b = mb_strtoupper($b);break;
case 2:
$c = mb_strtoupper($c);break;
case 1:
$d = mb_strtoupper($d);break;
}
}
$result="$tal $b $c $d$tegn";
break;
@ -106,6 +96,16 @@ switch($model){
$result = "$a $b $tal $c$tegn";
break;
}
?><h1><span><?=ucwords($result,"|")?></span></h1>
#$result=str_replace("\n","",$result);
/*
tal tillæg navneord verb navneord
tillæg navneord verb tal navneord
stedord verb tal tillægsord navneord
stedord verb tid stedord verb tillægsord navneord
stedord tillægsord navneord! stedord verbum.
*/
?>--><h1><?=ucwords($result,"|")?></h1>
</body>
</html>

145
index__.php Normal file
View file

@ -0,0 +1,145 @@
<!DOCTYPE html>
<html lang="da">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Sætningsgenerator</title>
<style>
* {
margin: 0;
padding: 0;
}
html {
height: 100%;
}
h1 {
text-align: center;
margin-top: 10%;
}
span {
background: #333;
color: #FFF;
padding: 0.3em;
}
</style>
</head>
<body>
<?php
$tal = rand(2, 79);
$model = rand(0, 1);
$end = array(".", "!", "?", "!?", "...", " :-)", " ;-)");
$tegn = $end[array_rand($end)];
$result = "";
$ord = array(
"sub" => JSON_Decode(file_get_contents('data/navneord.json')),
"ver" => JSON_Decode(file_get_contents('data/verber.json')),
"adj" => JSON_Decode(file_get_contents('data/adj.json')),
"pro" => array("jeg", "han", "hun", "den", "det", "de", "I", "vi", "du", "De"),
"tid" => array("før", "efter", "imens", "inden"),
"for" => array("over", "under", "ved siden af", "bag", "foran", "overfor"),
);
function rando($arr)
{
return $arr[array_rand($arr)];
}
function word($cla, $conj = null)
{
global $ord;
$word = $ord[$cla][array_rand($ord[$cla])]; //rand(0,count($ord[$cla]));
if ($conj == null) {
return $word;
} else {
return $word[$conj];
}
}
function lego($conj = 0)
{
// 0 = ubestemt ental, eks. "en grim tyr" el. "et dumt æg".
// 1 = bestemt ental, eks. "den grimme tyr" el. "det dumme æg"
// 2 = ubestemt flertal, eks. "ægte tedåser"
// 3 = bestemt flertal, eks. "de rådne æbler"
$main = word("sub");
$desc = word("adj");
if ($main[4] == "t") {
$neutrum = true;
} else {
$neutrum = false;
}
switch ($conj) {
case 0:
if ($neutrum) {
$phrase = "et " . word("adj")[1] . " " . $main[0];
} else {
$phrase = "en " . word("adj")[0] . " " . $main[0];
}
break;
case 1:
if ($neutrum) {
$phrase = "det " . word("adj")[2] . " " . $main[0];
} else {
$phrase = "den " . word("adj")[2] . " " . $main[0];
}
break;
case 2:
$phrase = word("adj")[2] . " " . $main[2];
break;
case 3:
$phrase = "de " . word("adj")[2] . " " . $main[2];
break;
}
return $phrase;
}
switch ($model) {
case 0:
if ($tal > 1) {
$b = lego(2);
} else {
$b = lego(rand(0, 1));
}
$c = word("ver", rand(1, 4));
$d = word("sub", rando([1, 3]));
if (rand(0, 1) > 0) {
$which = rand(1, 3);
switch ($which) {
case 1:
$b = mb_strtoupper($b);
break;
case 2:
$c = mb_strtoupper($c);
break;
case 1:
$d = mb_strtoupper($d);
break;
}
}
$result = "$tal $b $c $d$tegn";
break;
case 1:
$a = lego(rando([0, 1, 3]));
$b = word("ver", rand(1, 4));
if ($tal > 1) {
$c = word("sub", 2);
} else {
$c = word("sub", rando([1, 3]));
}
$result = "$a $b $tal $c$tegn";
break;
}
?><h1><span><?=ucwords($result, "|")?></span></h1>
</body>
</html>