-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·137 lines (113 loc) · 3.3 KB
/
index.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
<?php
require 'config.inc.php';
// Kickstart the framework
$f3=require('lib/base.php');
$f3->set('DEBUG', DEBUG);
if ((float)PCRE_VERSION<7.9)
trigger_error('PCRE version is out of date');
// Load configuration
$f3->config('config.ini');
$db=new DB\SQL(
'mysql:host='.DB_HOST.';port=3306;dbname='.DB_NAME,
DB_USER,
DB_PASSWORD
);
/**********************************************
ROUTES
**********************************************/
$f3->route('GET /',
function($f3) {
if(empty($f3->get('SESSION.first'))){
$f3->set('SESSION.first', "sweet child o' mine");
}
$f3->set('user', $f3->get('SESSION'));
$f3->set('content', 'home.htm');
$f3->set('menu_active', 'home');
echo View::instance()->render('layout.htm');
}
);
/*
$f3->route('GET /offline.html',
function($f3) {
$f3->set('content', 'home.htm');
$f3->set('menu_active', 'home');
echo View::instance()->render('layout.htm');
}
);
*/
$f3->route('POST /synchronise-memo',
function($f3) {
global $db;
// if user EMAIL matches user ID, update its memo
$username = $f3->get('POST.email');
$id = $f3->get('POST.id');
$memo = $f3->get('POST.memo');
$lastModified = $f3->get('POST.last_modified');
if(empty($username)){
die("no user email sent.");
}
$user = new DB\SQL\Mapper($db, 'memos');
$user->load(array('email = :username AND id= :id LIMIT 0,1', ':username'=>$username, ':id'=> $id ));
if($user->dry()){
die("non existing user.");
}
if($user->last_modified <= $lastModified){
// Save Data
$memo = str_replace(array("\n", "\r","\t"), '', $memo);
$user->memo = json_encode($memo);
$user->last_modified = $lastModified;
$user->save();
$result = array('last_modified'=> $user->last_modified);
$f3->set('SESSION.memo', stripslashes($user->memo));
} else{
// Send Data
$result = array('memo'=>$user->memo, 'last_modified'=> $user->last_modified);
}
echo json_encode($result);
exit;
});
$f3->route('POST /scrape-url',function($f3){
$url = $f3->get('POST.url');
require './classes/SimpleScraper.class.php';
$url = isset($url) ? $url : '';
$scraper = new SimpleScraper($url);
$data = $scraper->getAllData();
$response = array(
'success' => true,
'ogp' => $data['ogp'],
'dump' => print_r($data, true)
);
echo json_encode($response);
});
$f3->route('GET /tips',
function($f3) {
if(empty($f3->get('SESSION.first'))){
$f3->set('SESSION.first', "sweet child o' mine");
}
$f3->set('user', $f3->get('SESSION'));
$f3->set('content', 'tips.htm');
$f3->set('menu_active', 'tips');
echo View::instance()->render('layout.htm');
}
);
$f3->route('GET /about',
function($f3) {
if(empty($f3->get('SESSION.first'))){
$f3->set('SESSION.first', "sweet child o' mine");
}
$f3->set('user', $f3->get('SESSION'));
$f3->set('content', 'about.htm');
$f3->set('menu_active', 'about');
echo View::instance()->render('layout.htm');
}
);
$f3->route('GET /logout',
function($f3) {
$f3->clear('SESSION');
$f3->reroute('/');
});
$f3->route('GET @auth: /auth', function($f3){
require 'controllers/hybridauth/index.php';
});
$f3->route('GET @auth_action: /auth/@action', function($f3){ require 'controllers/auth-action.get.php';});
$f3->run();