forked from glacjay/mreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmr-common.php
97 lines (85 loc) · 2.32 KB
/
mr-common.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
<?php
require_once 'config';
#$db_file = dirname(__FILE__) . '/reader.db';
$env = json_decode(file_get_contents("/home/dotcloud/environment.json"), true);
$dsn = "mysql:host=".$env['DOTCLOUD_DB_MYSQL_HOST'].
";port=".$env['DOTCLOUD_DB_MYSQL_PORT'].
";dbname=mreader";
try
{
#$db = new PDO("sqlite:$db_file");
$db = new PDO($dsn, 'glacjay', 'fuckgfw');
}
catch (PDOException $ex)
{
die("Open database failed: " . $ex->getMessage());
}
#ini_set('session.save_handler', 'sqlite');
#ini_set('session.save_path', dirname(__FILE__) . '/session.db');
ini_set('session.gc_maxlifetime', 60 * 60 * 24 * 7);
ini_set('session.cookie_lifetime', 60 * 60 * 24 * 365);
session_start();
function destroySession()
{
$_SESSION = array();
session_destroy();
}
function logout()
{
destroySession();
die("<meta http-equiv='Refresh' content='0; url=mr-login.php' />");
}
function dieOnDb()
{
$error = $db->errorInfo();
die('database error: ' . $error[2]);
}
function saveConfig($key, $value)
{
global $db;
$key = $db->quote($key);
$value = $db->quote($value);
$stmt = $db->query("select value from config where name=$key");
if ($stmt === false)
dieOnDb();
elseif ($stmt->fetch(PDO::FETCH_NUM) === false)
{
$stmt->closeCursor();
$db->exec("insert into config values ($key, $value)");
}
else
{
$stmt->closeCursor();
$db->exec("update config set value=$value where name=$key");
}
}
function fetchConfig($key)
{
global $db;
$key = $db->quote($key);
$stmt = $db->query("select value from config where name=$key");
if ($stmt === false)
dieOnDb();
$result = $stmt->fetch(PDO::FETCH_NUM);
if ($result === false)
return null;
else
return $result[0];
}
$ignoreList[] = 'http://www.verycd.com';
$ignoreList[] = 'http://www.daomubiji.com';
$ignoreList[] = 'http://www.bengou.com';
$ignoreList[] = 'http://www.youtube.com';
$ignoreList[] = 'http://www.hexieshe.com';
$ignoreList[] = 'http://golangwiki.org';
function ignoreItem($item)
{
global $ignoreList;
$url = $item['origin']['htmlUrl'];
foreach ($ignoreList as $ignored)
if (strlen($ignored) <= strlen($url) &&
substr_compare($url, $ignored, 0, strlen($ignored)) == 0)
return true;
return false;
}
?>