-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem.php
61 lines (44 loc) · 2.05 KB
/
problem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
require_once 'autoload.php';
use ProjectEuler\Main\Site;
use ProjectEuler\Content\ProblemContent;
use ProjectEuler\Renderers\ProblemRenderer;
use ProjectEuler\Main\Logger;
use ProjectEuler\Main\PEException;
$site = new Site();
if (! isset($_GET['id'])) {
$message = 'No problem ID specified when accessing problem.php';
Logger::log($message);
throw new PEException($message, PEException::INVALID_REQUEST);
} elseif (! $site->isValidID($_GET['id'])) {
$message = 'Invalid problem ID specified when acccessing problem.php';
Logger::log($message);
throw new PEException($message, PEException::INVALID_REQUEST);
}
$problemId = $_GET['id'];
$problemContent = new ProblemContent();
$problem = $problemContent->getProblem($problemId);
if (count($problem) == 0 || ! $problem['is_translated']) {
if (count($problem) == 0) {
$message = 'Non-existent problem ID specified when acccessing problem.php';
} elseif (! $problem['is_translated']) {
$message = 'Not-translated problem requested when acccessing problem.php';
}
Logger::log($message);
throw new PEException($message, PEException::INVALID_REQUEST);
}
$tags = $problemContent->getTags($problemId);
$neighBorsStatus = $problemContent->areNeighboursTranslated($problemId);
$problemContent->increaseHits($problemId);
$problemTpl = file_get_contents('templates/problem/problem.tpl');
$tagTpl = file_get_contents('templates/problem/tag.tpl');
$tagBoxTpl = file_get_contents('templates/problem/tag_box.tpl');
$prevLinkTpl = file_get_contents('templates/problem/previous_link.tpl');
$nextLinkTpl = file_get_contents('templates/problem/next_link.tpl');
$renderer = new ProblemRenderer();
$renderedProblem = $renderer->renderProblem($problemTpl, $prevLinkTpl, $nextLinkTpl, $problem, $neighBorsStatus);
$renderedTags = $renderer->renderTags($tagBoxTpl, $tagTpl, $tags);
$finalContent = str_replace('{tag_box}', $renderedTags, $renderedProblem);
$htmlout = $site->getFullPageTemplate('problems.php');
$htmlout = str_replace('{page_content}', $finalContent, $htmlout);
echo $htmlout;