This repository was archived by the owner on Dec 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathReader.php
More file actions
279 lines (233 loc) · 9.24 KB
/
Reader.php
File metadata and controls
279 lines (233 loc) · 9.24 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
namespace Foolz\Foolslide\Controller;
use Foolz\Foolframe\Controller\Common;
use Foolz\Foolframe\Model\Config;
use Foolz\Foolframe\Model\Preferences;
use Foolz\Foolframe\Model\Uri;
use Foolz\Foolframe\Model\Util;
use Foolz\Foolframe\Model\Validation\ActiveConstraint\Trim;
use Foolz\Foolframe\Model\Validation\Validator;
use Foolz\Foolframe\Model\Cookie;
use Foolz\Foolslide\Model\Ban;
use Foolz\Foolslide\Model\BanFactory;
use Foolz\Foolslide\Model\Board;
use Foolz\Foolslide\Model\Comment;
use Foolz\Foolslide\Model\CommentBulk;
use Foolz\Foolslide\Model\CommentFactory;
use Foolz\Foolslide\Model\CommentInsert;
use Foolz\Foolslide\Model\Media;
use Foolz\Foolslide\Model\MediaFactory;
use Foolz\Foolslide\Model\Radix;
use Foolz\Foolslide\Model\RadixCollection;
use Foolz\Foolslide\Model\Report;
use Foolz\Foolslide\Model\Search;
use Foolz\Inet\Inet;
use Foolz\Profiler\Profiler;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Validator\Constraints as Assert;
class Reader extends Common
{
/**
* The Theme object
*
* @var \Foolz\Theme\Theme
*/
protected $theme = null;
/**
* A builder object with some defaults appended
*
* @var \Foolz\Theme\Builder
*/
protected $builder = null;
/**
* The ParamManager object of the builder
*
* @var \Foolz\Theme\ParamManager
*/
protected $param_manager = null;
/**
* The Request object
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request = null;
/**
* The Response object
*
* @var Response|StreamedResponse
*/
protected $response = null;
/**
* @var Config
*/
protected $config;
/**
* @var Preferences
*/
protected $preferences;
/**
* @var Uri
*/
protected $uri;
/**
* @var Profiler
*/
protected $profiler;
public function before()
{
$this->config = $this->getContext()->getService('config');
$this->preferences = $this->getContext()->getService('preferences');
$this->uri = $this->getContext()->getService('uri');
$this->profiler = $this->getContext()->getService('profiler');
// this has already been forged in the foolslide bootstrap
$theme_instance = \Foolz\Theme\Loader::forge('foolslide');
try {
$theme_name = $this->getQuery('theme', $this->getCookie('theme')) ? : $this->preferences->get('foolslide.theme.default');
$theme_name_exploded = explode('/', $theme_name);
if (count($theme_name_exploded) >=2) {
$theme_name = $theme_name_exploded[0].'/'.$theme_name_exploded[1];
}
$theme = $theme_instance->get($theme_name);
if (!isset($theme->enabled) || !$theme->enabled) {
throw new \OutOfBoundsException;
}
$this->theme = $theme;
} catch (\OutOfBoundsException $e) {
$theme_name = 'foolz/foolslide-theme-foolslide';
$this->theme = $theme_instance->get('foolz/foolslide-theme-foolslide');
}
// TODO this is currently bootstrapped in the foolslide bootstrap because we need it running before the router.
//$this->theme->bootstrap();
$this->builder = $this->theme->createBuilder();
$this->param_manager = $this->builder->getParamManager();
$this->builder->createLayout('chan');
if (count($theme_name_exploded) == 3) {
try {
$this->builder->setStyle($theme_name_exploded[2]);
} catch (\OutOfBoundsException $e) {
// just let it go with default on getStyle()
}
}
// KEEP THIS IN SYNC WITH THE ONE IN THE POSTS ADMIN PANEL
$to_bind = [
'context' => $this->getContext(),
'request' => $this->getRequest(),
'order' => false,
'modifiers' => [],
'backend_vars' => [
'site_url' => $this->uri->base(),
'default_url' => $this->uri->base(),
'archive_url' => $this->uri->base(),
'system_url' => $this->uri->base(),
'api_url' => $this->uri->base(),
'cookie_domain' => $this->config->get('foolz/foolframe', 'config', 'config.cookie_domain'),
'cookie_prefix' => $this->config->get('foolz/foolframe', 'config', 'config.cookie_prefix'),
'selected_theme' => $theme_name,
'csrf_token_key' => 'csrf_token',
'images' => [],
'gettext' => [
'submit_state' => _i('Submitting'),
'thread_is_real_time' => _i('This thread is being displayed in real time.'),
'update_now' => _i('Update now'),
'ghost_mode' => _i('This thread has entered ghost mode. Your reply will be marked as a ghost post and will only affect the ghost index.')
]
]
];
$this->param_manager->setParams($to_bind);
// $this->builder->createPartial('tools_modal', 'tools_modal');
// $this->builder->createPartial('tools_search', 'tools_search');
// $this->builder->createPartial('tools_advanced_search', 'advanced_search');
}
public function router($method, $parameters)
{
$request = $this->getRequest();
$this->request = $request;
$this->response = new Response();
$this->builder->getProps()->addTitle($this->preferences->get('foolframe.gen.website_title', $this->preferences->get('foolslide.gen.website_title')));
if (method_exists($this, 'action_'.$method)) {
return [$this, 'action_'.$method, $parameters];
}
return [$this, 'action_404', []];
}
public function setLastModified($timestamp = 0, $max_age = 0)
{
$time = new \DateTime('@'.$timestamp);
$etag = md5($this->builder->getTheme()->getDir().$this->builder->getStyle().'|'.$timestamp.'|'.$max_age);
$this->response->headers->addCacheControlDirective('must-revalidate', true);
$this->response->setLastModified($time);
$this->response->setEtag($etag);
$this->response->setMaxAge($max_age);
}
public function action_index()
{
$this->builder->createPartial('body', 'index');
return $this->response->setContent('test');//$this->builder->build());
}
public function action_404($error = null)
{
return $this->error($error === null ? _i('Page not found. You can use the search if you were looking for something!') : $error, 404);
}
protected function error($error = null, $code = 200)
{
$this->builder->createPartial('body', 'error')
->getParamManager()
->setParams(['error' => $error === null ? _i('We encountered an unexpected error.') : $error]);
$this->response->setStatusCode($code);
if ($this->response instanceof StreamedResponse) {
$this->response->setCallback(function() {
$this->builder->stream();
});
} else {
$this->response->setContent($this->builder->build());
}
return $this->response;
}
protected function message($level = 'success', $message = null, $code = 200)
{
$this->builder->createPartial('body', 'message')
->getParamManager()
->setParams([
'level' => $level,
'message' => $message
]);
return $this->response->setContent($this->builder->build())->setStatusCode($code);
}
public function action_theme($vendor = 'foolz', $theme = 'foolslide-theme-default', $style = '')
{
$this->builder->getProps()->addTitle(_i('Changing Theme Settings'));
$theme = $vendor.'/'.$theme.'/'.$style;
$this->response->headers->setCookie(new Cookie($this->getContext(), 'theme', $theme, 31536000));
if ($this->getRequest()->headers->get('referer')) {
$url = $this->getRequest()->headers->get('referer');
} else {
$url = $this->uri->base();
}
$this->builder->createLayout('redirect')
->getParamManager()
->setParam('url', $url);
$this->builder->getProps()->addTitle(_i('Redirecting'));
return $this->response->setContent($this->builder->build());
}
public function action_language($language = 'en_EN')
{
$this->response->headers->setCookie(new Cookie($this->getContext(), 'language', $language, 31536000));
if ($this->getRequest()->headers->get('referer')) {
$url = $this->getRequest()->headers->get('referer');
} else {
$url = $this->uri->base();
}
$this->builder->createLayout('redirect')
->getParamManager()
->setParam('url', $url);
$this->builder->getProps()->addTitle(_i('Changing Language'));
return $this->response->setContent($this->builder->build());
}
public function action_opensearch()
{
$this->builder->createLayout('open_search');
return $this->response->setContent($this->builder->build());
}
}