1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OcLegacy\Controller; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
6
|
|
|
use Oc\AbstractController; |
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
8
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
9
|
|
|
|
10
|
|
|
class ArticlesController extends AbstractController |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Connection |
14
|
|
|
*/ |
15
|
|
|
private $connection; |
16
|
|
|
|
17
|
|
|
public function __construct(Connection $connection) |
18
|
|
|
{ |
19
|
|
|
$this->connection = $connection; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @Route("/articles.php", name="legacy_articles") |
24
|
|
|
*/ |
25
|
|
|
public function index() |
26
|
|
|
{ |
27
|
|
|
global $opt, $tpl; |
28
|
|
|
|
29
|
|
|
ob_start(); |
30
|
|
|
|
31
|
|
|
//get the article name to display |
32
|
|
|
$article = ''; |
33
|
|
|
$language = $opt['template']['locale']; |
34
|
|
|
if (isset($_REQUEST['page']) && |
35
|
|
|
(mb_strpos($_REQUEST['page'], '.') === false) && |
36
|
|
|
(mb_strpos($_REQUEST['page'], '/') === false) && |
37
|
|
|
(mb_strpos($_REQUEST['page'], '\\') === false) |
38
|
|
|
) { |
39
|
|
|
$article = $_REQUEST['page']; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if ($article === '') { |
43
|
|
|
//no article specified |
44
|
|
|
$tpl->redirect('index.php'); |
45
|
|
|
} elseif (isset($_REQUEST['wiki'])) { |
46
|
|
|
$tpl->redirect(helppageurl($article)); |
47
|
|
|
} elseif (!file_exists($opt['stylepath'] . '/articles/' . $language . '/' . $article . '.tpl')) { |
48
|
|
|
// does article exist in default-language? |
49
|
|
|
$file = $opt['stylepath'] . '/articles/' . $opt['template']['default']['article_locale'] . '/' . $article . '.tpl'; |
50
|
|
|
if (file_exists($file)) { |
51
|
|
|
$language = $opt['template']['default']['article_locale']; |
52
|
|
|
} elseif (file_exists($opt['stylepath'] . '/articles/EN/' . $article . '.tpl')) { |
53
|
|
|
$language = 'EN'; |
54
|
|
|
} else { |
55
|
|
|
// use any |
56
|
|
|
$language = false; |
57
|
|
|
if ($hDir = opendir($opt['stylepath'] . '/articles/')) { |
58
|
|
|
while ((($sFile = readdir($hDir)) !== false) && ($language === false)) { |
59
|
|
|
if ($sFile != '.' |
60
|
|
|
&& $sFile != '..' |
61
|
|
|
&& is_dir($opt['stylepath'] . '/articles/' . $sFile) |
62
|
|
|
&& file_exists($opt['stylepath'] . '/articles/' . $sFile . '/' . $article . '.tpl') |
63
|
|
|
) { |
64
|
|
|
$language = $sFile; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
closedir($hDir); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
//article doesn't exists |
71
|
|
|
if ($language === false) { |
72
|
|
|
$tpl->redirect('index.php'); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$tpl->name = 'articles'; |
78
|
|
|
|
79
|
|
|
$tpl->caching = true; |
80
|
|
|
$tpl->cache_id = 'articles|' . $language . '|' . $article; |
81
|
|
|
$tpl->cache_lifetime = 43200; |
82
|
|
|
|
83
|
|
|
$tpl->menuitem = $this->connection->fetchColumn( |
84
|
|
|
'SELECT `id` FROM `sys_menu` WHERE `href`= :href LIMIT 1', |
85
|
|
|
[':href' => 'articles.php?page=' . urlencode($article)] |
86
|
|
|
); |
87
|
|
|
if ($tpl->menuitem == 0) { |
88
|
|
|
$tpl->redirect('index.php'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (!$tpl->is_cached()) { |
92
|
|
|
$tpl->assign('article', $article); |
93
|
|
|
$tpl->assign('language', $language); |
94
|
|
|
|
95
|
|
|
/* prepare smarty vars for special pages ... |
96
|
|
|
*/ |
97
|
|
|
if ($article === 'cacheinfo') { |
98
|
|
|
require_once __DIR__ . '/../../../lib2/logic/attribute.class.php'; |
99
|
|
|
$attributes = \attribute::getSelectableAttributesListArray(true); |
100
|
|
|
$tpl->assign('attributes', $attributes); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$tpl->display(); |
105
|
|
|
|
106
|
|
|
$content = ob_get_contents(); |
107
|
|
|
ob_clean(); |
108
|
|
|
|
109
|
|
|
return Response::create($content); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|