122 lines
3.9 KiB
PHP
122 lines
3.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Class website
|
|
* 2xx error codes
|
|
*/
|
|
|
|
|
|
class website
|
|
{
|
|
|
|
public function showScore( ) : string
|
|
{
|
|
try {
|
|
$website = file_get_contents( __DIR__ . '/website_score.html' );
|
|
$website = $this->replaceDefaultThings( $website );
|
|
} catch( Exception $e )
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
public function buildWebsite(): string
|
|
{
|
|
try
|
|
{
|
|
$website = file_get_contents( __DIR__ . '/website.html' );
|
|
$website = $this->replaceDefaultThings( $website );
|
|
|
|
$website = $this->setQuestions( $website );
|
|
return $website;
|
|
|
|
} catch( Exception $e )
|
|
{
|
|
if( ( $code = $e->getCode() ) === 202 || $code === 203 )
|
|
{
|
|
throw new RuntimeException( $e->getMessage(), $code );
|
|
}
|
|
throw new RuntimeException( 'Cannot load the website.html file', 201 );
|
|
}
|
|
}
|
|
|
|
private function replaceDefaultThings( $website )
|
|
{
|
|
if( !isset( language::$lang_file[language::TITLE],
|
|
language::$lang_file[language::MAIN_TITLE],
|
|
language::$lang_file[language::DESCRIPTION],
|
|
language::$lang_file[language::EXPLANATION],
|
|
language::$lang_file[language::SCORE_FINISHED],
|
|
language::$lang_file[language::PROJECT_DESCRIPTION],
|
|
language::$lang_file[language::HELP_US],
|
|
language::$lang_file[language::REQUEST_MORE],
|
|
language::$lang_file[language::LANGUAGE_CHOOSE],
|
|
language::$lang_file[language::JOIN_DISCORD] ) )
|
|
{
|
|
throw new RuntimeException( 'Cannot load default langauge replacements', 202 );
|
|
}
|
|
$website = str_replace(
|
|
array(
|
|
'[LANG]', '[TITLE]', '[MAIN_TITLE]', '[DESCRIPTION]', '[EXPLANATION]', '[SCORE_FINISHED]', '[PROJECT_DESCRIPTION]', '[HELP_US]', '[REQUEST_MORE]','[LANGUAGE_CHOOSE]', '[JOIN_DISCORD]' ),
|
|
array(
|
|
substr( language::$lang, 0, 2 ),
|
|
language::$lang_file[language::TITLE],
|
|
language::$lang_file[language::MAIN_TITLE],
|
|
language::$lang_file[language::DESCRIPTION],
|
|
language::$lang_file[language::EXPLANATION],
|
|
language::$lang_file[language::SCORE_FINISHED],
|
|
language::$lang_file[language::PROJECT_DESCRIPTION],
|
|
language::$lang_file[language::HELP_US],
|
|
language::$lang_file[language::REQUEST_MORE],
|
|
language::$lang_file[language::LANGUAGE_CHOOSE],
|
|
language::$lang_file[language::JOIN_DISCORD]
|
|
), $website );
|
|
$languages = '';
|
|
foreach( language::$languages as $code => $language )
|
|
{
|
|
$languages .= <<<HTML
|
|
<li><a class="blue-text" href="?lang=$code">$language</a></li>
|
|
HTML;
|
|
|
|
}
|
|
$website = str_replace( '[LANGUAGES]', $languages, $website );
|
|
return $website;
|
|
}
|
|
|
|
private function setQuestions( $website ) : string
|
|
{
|
|
if( !isset( language::$lang_file['questions'] ) )
|
|
{
|
|
throw new RuntimeException( 'Error while reading the questions in langauge file', 203 );
|
|
}
|
|
$questions = '';
|
|
foreach( language::$lang_file['questions'] as $number => $question )
|
|
{
|
|
$questions .= <<<CHECKBOX
|
|
<label>
|
|
<input name="question_$number" type="checkbox" class="filled-in" />
|
|
<span>$question</span>
|
|
</label><br>
|
|
CHECKBOX;
|
|
|
|
}
|
|
$form_start = <<<HTML
|
|
<form action="" method="post">
|
|
HTML;
|
|
$submit = language::$lang_file[language::CALCULATE];
|
|
$form_end = <<<HTML
|
|
<br>
|
|
<button class="btn waves-effect btn-large waves-light " type="submit" name="action">{$submit}
|
|
<i class="material-icons right">send</i>
|
|
</button>
|
|
</form>
|
|
HTML;
|
|
|
|
|
|
$questions = $form_start . $questions . $form_end;
|
|
$website = str_replace( '[CONTENT]', $questions, $website );
|
|
|
|
|
|
return $website;
|
|
}
|
|
} |