Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
steve
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Milan Bartky
steve
Commits
b5111c9f
Commit
b5111c9f
authored
Apr 23, 2020
by
Milan Bartky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated code
parent
ea3088ea
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
22 deletions
+29
-22
php/functions.php
php/functions.php
+0
-14
php/generator.php
php/generator.php
+29
-8
No files found.
php/functions.php
View file @
b5111c9f
...
...
@@ -56,20 +56,6 @@ class Helper
}
return
$list
;
}
/**
* Shuffles all lines in a given text.
* @param string $text
* @return string
*/
public
static
function
shuffleLines
(
string
$text
)
:
string
{
$texts
=
explode
(
"
\n
"
,
$text
);
shuffle
(
$texts
);
$text
=
implode
(
"
\n
"
,
$texts
);
return
$text
;
}
}
/**
...
...
php/generator.php
View file @
b5111c9f
<?php
define
(
'SOURCE_FILE'
,
'data.txt'
);
include_once
"functions.php"
;
include
"markov.php"
;
...
...
@@ -45,15 +47,31 @@ function prepareTextForFrontend(string $text) : string
$text
=
$nText
;
return
$text
;
}
/**
* Removes lines that were already used
* @param string $text
*/
function
removeUsedLines
(
string
&
$text
)
{
$lines
=
explode
(
"
\n
"
,
$text
);
$newLines
=
[];
foreach
(
$lines
as
$line
)
{
if
(
!
exec
(
'grep '
.
escapeshellarg
(
trim
(
$line
))
.
' ./steve/steve.txt'
))
{
$newLines
[]
=
$line
;
}
}
$text
=
implode
(
"
\n
"
,
$newLines
);
}
// Refresh cache when GET parameter "g" is set or the cache file does'nt exist
if
(
isset
(
$_GET
[
"g"
])
||
!
file_exists
(
"data.txt"
))
if
(
isset
(
$_GET
[
"g"
])
||
!
file_exists
(
SOURCE_FILE
))
{
// Including vichans config (for database credentials)
require_once
(
"../../www/inc/instance-config.php"
);
// Making sure the cache file is deleted
unlink
(
"data.txt"
);
unlink
(
SOURCE_FILE
);
$text
=
""
;
...
...
@@ -139,7 +157,7 @@ if (isset($_GET["g"]) || !file_exists("data.txt"))
$text
=
NormalizeHelper
::
quickCleanup
(
$text
);
// Finally saving that text to a file (so we dont have to regenerate it every time)
file_put_contents
(
"data.txt"
,
$text
);
file_put_contents
(
SOURCE_FILE
,
$text
);
// Redirecting to the same site without the "g" get parameter so we dont cache on every reload
header
(
"Location: generator.php"
);
...
...
@@ -147,13 +165,10 @@ if (isset($_GET["g"]) || !file_exists("data.txt"))
}
// Getting cached data from data.txt
$origtext
=
file_get_contents
(
"data.txt"
);
// Shuffling lines
$text
=
Helper
::
shuffleLines
(
$origtext
);
$origtext
=
file_get_contents
(
SOURCE_FILE
);
// Removing unicode to avoid utf-8 errors
$text
=
preg_replace
(
'/[\x10-\x1F\x80-\xFF]/'
,
''
,
$text
);
$text
=
preg_replace
(
'/[\x10-\x1F\x80-\xFF]/'
,
''
,
$
orig
text
);
// Building markov table and then generating text with a length of 200 characters
...
...
@@ -174,6 +189,8 @@ NormalizeHelper::advancedCleanUp($generated);
$generated
=
NormalizeHelper
::
removeDirt
(
$generated
);
removeUsedLines
(
$generated
);
/*
* Lets get at least 5 lines of generated text
*/
...
...
@@ -200,6 +217,8 @@ while(sizeof(explode("\n", $generated)) < 5)
$generated
.
=
"
\n
"
;
}
$generated
=
trim
(
$generated
.
$generated2
);
removeUsedLines
(
$generated
);
}
/*
...
...
@@ -261,6 +280,8 @@ if (isset($_GET["w"]) && Helper::includes($text, $_GET["w"]))
<title>
Steve
</title>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=iso-8859-1"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<?php
include
'meta.html'
;
?>
<script
src=
"./rita-full.min.js"
></script>
<script
src=
"./compromise.min.js"
></script>
<style>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment