-
Notifications
You must be signed in to change notification settings - Fork 0
/
Page.php
426 lines (357 loc) · 15.5 KB
/
Page.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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<?php
/**
* Blog\Page
* PHP version 7
*
* @category Controller
* @package Library
* @author Bill Rocha <prbr@ymail.com>
* @copyright 2016 Bill Rocha <http://google.com/+BillRocha>
* @license <https://opensource.org/licenses/MIT> MIT
* @version GIT: 0.0.1
* @link http://paulorocha.tk/devbr
*/
namespace Blog;
//use Resource\Main;
use Devbr\Database;
use Devbr\User;
/**
* Page Class
*
* @category Controller
* @package Library
* @author Bill Rocha <prbr@ymail.com>
* @license <https://opensource.org/licenses/MIT> MIT
* @link http://paulorocha.tk/devbr
*/
class Page
{
public $scripts = ['blog/1'];
public $styles = [];
public $patchHtml = __DIR__.'/Html/';
public $blogName = 'DBrasil';
public $blogDescription = 'O jeito brasileiro de ver o mundo.';
public $blogLink = _URL;
public $blogArticleLink = _URL.'a/';
public $blogMedia = _URL.'media/cover/destaque.jpg';
public $header = false;
public $footer = false;
public $pageName = null;
function index($rqst, $param)
{
//Data to template
$data = [ 'blogName' => $this->blogName,
'blogDescription' => $this->blogDescription,
'blogLink' => $this->blogLink,
'blogMedia' => $this->blogMedia
];
//USER
$user = User::this();
$base = new Model\Base();
$category = isset($_GET['category']) ? 0 + $_GET['category'] : 0;
$search = isset($_GET['search']) ? $_GET['search'] : '';
$data['destaques'] = '';
foreach ($base->listNews(0, 20, $category, $search) as $id => $row) {
$data['destaques'] .= '<a href="'.$this->blogArticleLink.$row['link'].'"><div class="item">'.
(isset($row['image']) ? '<img src="'._URL.trim($row['image'], "\\/ ").'">' : '').
'<span class="pubdata"><b>'.strtoupper($row['categoria'].':</b> '.$row['autor']).' - '.date('d/m H:i', strtotime($row['pubdate'])).'</span>'.
'<h2>'.$row['title'].'</h2>'.
'<span class="resume">'.$row['resume'].'</span></div></a>';
}
if ($data['destaques'] == '') {
$data['destaques'] = '<h2>Nenhuma publicação encontrada.</h2>';
}
//Categories
$data['categories']['data'][0] = 'Tudo...';
foreach ($base->getCategories() as $key => $value) {
$data['categories']['data'][$key] = $value;
}
$data['categories']['default'] = $category;
$data['search'] = $search;
$this->sendPage('cover', $data);
}
/**
* View article page
*
* @param string $rqst [description]
* @param array $param [description]
*
* @return void [description]
*/
function view($rqst, $param)
{
if ($param['id'] === '0') {
\App::go($this->blogLink);
}
$base = new Model\Base();
$article = new Model\Article($param['id']);
if ($article->get('id') === false || $article->get('status') != 1) {
\App::go($this->blogLink);
}
//Geting the first image in field "media" in database
$media = json_decode($article->get('media'));
$articleMedia = (isset($media[0]->src)) ? $media[0]->src : $this->blogMedia;
//USER
$user = User::this();
$user->getById($article->get('author'));
//Data to template
$data = [ 'blogName' => $this->blogName,
'blogDescription' => $article->get('resume').' - '.$this->blogDescription,
'blogLink' => $this->blogLink,
'blogMedia' => $this->blogMedia,
'authorName' => $user->get('name'),
'authorFoto' => _URL.'media/user/'.$user->get('id').'/1.jpg',
'authorLink' => _URL.'perfil', //'user/'.$user->get('login'),
'authorPubData' => date("d/m/Y à\s H:i", strtotime($article->get('pubdate'))),
'articleTitle' => $article->get('title'),
'articleResume' => $article->get('resume'),
'articleContent' => $article->get('content'),
'articleMedia' => $articleMedia,
'articleLink' => $this->blogArticleLink.$article->get('link'),
'articleViews' => number_format($article->get('access'), 0, ',', '.'),
'articleTags' => $article->get('tags'),
'articleCategory' => $base->getCategory($article->get('category'))['name'],
'articleDateTime' => date('c', strtotime($article->get('pubdate'))),
'articleEditLink' => $this->blogLink.'e/'.$article->get('link')
];
//Categories
$data['categories']['data'][0] = 'Tudo...';
foreach ($base->getCategories() as $key => $value) {
$data['categories']['data'][$key] = $value;
}
//Lib\App::e($data);
$this->sendPage('template', $data, ['aID'=>$article->get('id'),
'uID'=>$user->get('id')]);
}
function edit($rqst, $param)
{
//Impedindo que se acesse sem LOGIN...
\App::go('login');
//Checando se a rota está correta
if (!isset($param['id'])) {
\App::go($this->blogLink);
}
//USER
$user = User::this();
//$user->getMe();
$user->getById(7);
$aID = $param['id'] == 'new'
|| (is_numeric($param['id'])
&& $param['id'] == 0)
? 0
: $param['id'];
$page = $aID == 0 ? 'new' : 'edit';
$article = new Model\Article($aID);
$base = new Model\Base;
$aID = $article->get('id') + 0;
//Se não existir, cria um novo artigo.
$data['blogName'] = $this->blogName;
$data['authorName'] = $user->get('name');
$data['authorFoto'] = _URL.'media/user/'.$user->get('id').'/1.jpg';
$data['authorLink'] = _URL.'perfil'; //'user/'.$user->get('login');
$data['authorPubData'] = date("d/m/Y à\s H:i", strtotime($article->get('pubdate')));
$data['articleTitle'] = $article->get('title');
$data['articleResume'] = $article->get('resume');
$data['articleContent'] = $article->get('content');
$data['articleLink'] = $article->get('link');
$data['articleViewLink'] = $this->blogArticleLink.$article->get('link');
//Select CATEGORIES
$data['categoria']['data'] = $base->getCategories();
$data['categoria']['default'] = $article->get('category');
//Select STATUS
$data['status']['data'] = $base->getStatus();
$data['status']['default'] = $article->get('status');
//Tags
$data['articleTags'] = $article->get('tags');
//$this->styles = ['source/font-awesome.min'];
$this->scripts = ['blog/2'];
//Send page to user
$this->sendPage('page_'.$page, $data, ['aType'=>$page, 'aID'=>$aID, 'uID'=>$user->get('id'), 'pageLink'=>$article->get('link')]);
}
function login()
{
//exit('<pre>'.print_r($_SERVER, true));
//$this->styles = ['source/skell', 'source/login', 'source/login_doc'];
$this->scripts = ['blog/3'];
$key = str_replace(
array("\r","\n","-----BEGIN PUBLIC KEY-----","-----END PUBLIC KEY-----"), '',
file_get_contents(\App::Config().'Key/public.key'));
$this->sendPage('login', [], ['KEY'=>$key]);
}
function perfil()
{
//exit('<pre>'.print_r($_SERVER, true));
//$this->styles = ['source/skell', 'source/login', 'source/login_doc'];
$this->scripts = ['blog/3'];
$this->sendPage('perfil');
}
/**
* Utils
* @param [type] $page [description]
* @param [type] $data [description]
* @param [type] $jsvar [description]
* @return [type] [description]
*/
final public function sendPage($page, $data = null, $jsvar = null)
{
$html = new \Devbr\Html();
$html->setPathHtml($this->patchHtml)
->body($page)
->header($this->header)
->footer($this->footer)
->setName($this->pageName)
->insertScripts($this->scripts)
->insertStyles($this->styles)
->val($data)
->jsvar($jsvar)
->render()
->send();
}
//TEMP - de le te me
function tmp()
{
//$xlog = new Model\Xlog;
//$xlog->decodeAgent();
//Fazendo login
//Lib\User::this()->login('admin', 'admin#123');
//Lib\User::this()->setCriptoCookie();
//Lib\User::this()->unsetCriptoCookie();
$user = new Lib\User();
$user->login('jessica', 'jessica#123');
//$user->unsetCriptoCookie();
//
//
Lib\App::p($user->get(), true);
Lib\App::p(Lib\User::this()->get(), true);
Lib\App::p($_SERVER['REMOTE_ADDR'], true);
Lib\App::p($_SERVER['HTTP_USER_AGENT'], true);
Lib\App::p($_SERVER['HTTP_ACCEPT_LANGUAGE'], true);
echo "<br>OS: </b>".$this->operating_system_detection();
echo '<hr/>';
$jsonBrowser = json_encode(get_browser());
echo '<br><b>Tamanho do arquivo: </b>'.strlen($jsonBrowser).'<br>';
Lib\App::p(json_decode($jsonBrowser), true);
//Fazendo login
//Lib\User::this()->login('jessica', 'jessica#123');
//Lib\User::this()->setCriptoCookie();
//Lib\App::p(Lib\User::this()->get(), true);
echo "<hr/><b>Finished!</b>";
}
/* return Operating System */
function operating_system_detection()
{
if (isset( $_SERVER )) {
$agent = $_SERVER['HTTP_USER_AGENT'] ;
} else {
global $HTTP_SERVER_VARS ;
if (isset( $HTTP_SERVER_VARS )) {
$agent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'] ;
} else {
global $HTTP_USER_AGENT ;
$agent = $HTTP_USER_AGENT ;
}
}
$ros[] = array('Windows XP', 'Windows XP');
$ros[] = array('Windows NT 5.1|Windows NT5.1)', 'Windows XP');
$ros[] = array('Windows 2000', 'Windows 2000');
$ros[] = array('Windows NT 5.0', 'Windows 2000');
$ros[] = array('Windows NT 4.0|WinNT4.0', 'Windows NT');
$ros[] = array('Windows NT 5.2', 'Windows Server 2003');
$ros[] = array('Windows NT 6.0', 'Windows Vista');
$ros[] = array('Windows NT 7.0', 'Windows 7');
$ros[] = array('Windows NT 10.0', 'Windows 10');
$ros[] = array('Windows CE', 'Windows CE');
$ros[] = array('(media center pc).([0-9]{1,2}\.[0-9]{1,2})', 'Windows Media Center');
$ros[] = array('(win)([0-9]{1,2}\.[0-9x]{1,2})', 'Windows');
$ros[] = array('(win)([0-9]{2})', 'Windows');
$ros[] = array('(windows)([0-9x]{2})', 'Windows');
// Doesn't seem like these are necessary...not totally sure though..
//$ros[] = array('(winnt)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'Windows NT');
//$ros[] = array('(windows nt)(([0-9]{1,2}\.[0-9]{1,2}){0,1})', 'Windows NT'); // fix by bg
$ros[] = array('Windows ME', 'Windows ME');
$ros[] = array('Win 9x 4.90', 'Windows ME');
$ros[] = array('Windows 98|Win98', 'Windows 98');
$ros[] = array('Windows 95', 'Windows 95');
$ros[] = array('(windows)([0-9]{1,2}\.[0-9]{1,2})', 'Windows');
$ros[] = array('win32', 'Windows');
$ros[] = array('(java)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2})', 'Java');
$ros[] = array('(Solaris)([0-9]{1,2}\.[0-9x]{1,2}){0,1}', 'Solaris');
$ros[] = array('dos x86', 'DOS');
$ros[] = array('unix', 'Unix');
$ros[] = array('Mac OS X', 'Mac OS X');
$ros[] = array('Mac_PowerPC', 'Macintosh PowerPC');
$ros[] = array('(mac|Macintosh)', 'Mac OS');
$ros[] = array('(sunos)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'SunOS');
$ros[] = array('(beos)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'BeOS');
$ros[] = array('(risc os)([0-9]{1,2}\.[0-9]{1,2})', 'RISC OS');
$ros[] = array('os/2', 'OS/2');
$ros[] = array('freebsd', 'FreeBSD');
$ros[] = array('openbsd', 'OpenBSD');
$ros[] = array('netbsd', 'NetBSD');
$ros[] = array('irix', 'IRIX');
$ros[] = array('plan9', 'Plan9');
$ros[] = array('osf', 'OSF');
$ros[] = array('aix', 'AIX');
$ros[] = array('GNU Hurd', 'GNU Hurd');
$ros[] = array('(fedora)', 'Linux - Fedora');
$ros[] = array('(kubuntu)', 'Linux - Kubuntu');
$ros[] = array('(ubuntu)', 'Linux - Ubuntu');
$ros[] = array('(debian)', 'Linux - Debian');
$ros[] = array('(CentOS)', 'Linux - CentOS');
$ros[] = array('(Mandriva).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)', 'Linux - Mandriva');
$ros[] = array('(SUSE).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)', 'Linux - SUSE');
$ros[] = array('(Dropline)', 'Linux - Slackware (Dropline GNOME)');
$ros[] = array('(ASPLinux)', 'Linux - ASPLinux');
$ros[] = array('(Red Hat)', 'Linux - Red Hat');
// Loads of Linux machines will be detected as unix.
// Actually, all of the linux machines I've checked have the 'X11' in the User Agent.
//$ros[] = array('X11', 'Unix');
$ros[] = array('(linux)', 'Linux');
$ros[] = array('(amigaos)([0-9]{1,2}\.[0-9]{1,2})', 'AmigaOS');
$ros[] = array('amiga-aweb', 'AmigaOS');
$ros[] = array('amiga', 'Amiga');
$ros[] = array('AvantGo', 'PalmOS');
//$ros[] = array('(Linux)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3}(rel\.[0-9]{1,2}){0,1}-([0-9]{1,2}) i([0-9]{1})86){1}', 'Linux');
//$ros[] = array('(Linux)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3}(rel\.[0-9]{1,2}){0,1} i([0-9]{1}86)){1}', 'Linux');
//$ros[] = array('(Linux)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3}(rel\.[0-9]{1,2}){0,1})', 'Linux');
$ros[] = array('[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3})', 'Linux');
$ros[] = array('(webtv)/([0-9]{1,2}\.[0-9]{1,2})', 'WebTV');
$ros[] = array('Dreamcast', 'Dreamcast OS');
$ros[] = array('GetRight', 'Windows');
$ros[] = array('go!zilla', 'Windows');
$ros[] = array('gozilla', 'Windows');
$ros[] = array('gulliver', 'Windows');
$ros[] = array('ia archiver', 'Windows');
$ros[] = array('NetPositive', 'Windows');
$ros[] = array('mass downloader', 'Windows');
$ros[] = array('microsoft', 'Windows');
$ros[] = array('offline explorer', 'Windows');
$ros[] = array('teleport', 'Windows');
$ros[] = array('web downloader', 'Windows');
$ros[] = array('webcapture', 'Windows');
$ros[] = array('webcollage', 'Windows');
$ros[] = array('webcopier', 'Windows');
$ros[] = array('webstripper', 'Windows');
$ros[] = array('webzip', 'Windows');
$ros[] = array('wget', 'Windows');
$ros[] = array('Java', 'Unknown');
$ros[] = array('flashget', 'Windows');
// delete next line if the script show not the right OS
//$ros[] = array('(PHP)/([0-9]{1,2}.[0-9]{1,2})', 'PHP');
$ros[] = array('MS FrontPage', 'Windows');
$ros[] = array('(msproxy)/([0-9]{1,2}.[0-9]{1,2})', 'Windows');
$ros[] = array('(msie)([0-9]{1,2}.[0-9]{1,2})', 'Windows');
$ros[] = array('libwww-perl', 'Unix');
$ros[] = array('UP.Browser', 'Windows CE');
$ros[] = array('NetAnts', 'Windows');
$file = count ( $ros );
$os = '';
for ($n=0; $n<$file; $n++) {
if (preg_match('/'.$ros[$n][0].'/i', $agent, $name)) {
$os = @$ros[$n][1].' '.@$name[2];
break;
}
}
return trim ( $os );
}
}