This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
forked from Adoream/typecho-plugin-comment2telegram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bootstrap.php
executable file
·55 lines (48 loc) · 2.02 KB
/
Bootstrap.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
<?php
define('__TGNOTIFY_PLUGIN_ROOT__', __DIR__);
require_once __TGNOTIFY_PLUGIN_ROOT__ . '/lib/Const.php';
require_once __TGNOTIFY_PLUGIN_ROOT__ . '/lib/TelegramModel.php';
$GLOBALS['options'] = Helper::options();
$all = Typecho_Plugin::export();
if (array_key_exists('TgNotify', $all['activated'])) {
$_cfg = Helper::options()->plugin('TgNotify');
if (isset($_cfg->Token)) {
$GLOBALS['telegramModel'] = new TelegramModel($_cfg->Token, $_cfg->MasterID);
if ($_cfg->mode == 1 || $_POST['mode'] == 1) {
$GLOBALS['route'] = [
'Add' => md5 ($_SERVER['HTTP_HOST'] . $_cfg->Token . $_cfg->MasterID),
'Del' => md5 (md5 ($_SERVER['HTTP_HOST'] . $_cfg->Token . $_cfg->MasterID)),
'Mark' => md5 (md5 (md5 ($_SERVER['HTTP_HOST'] . $_cfg->Token . $_cfg->MasterID)))
];
}
} else {
$GLOBALS['telegramModel'] = NULL;
}
} else {
$GLOBALS['telegramModel'] = NULL;
}
class Bootstrap {
public static function fetch ($url, $postdata = null, $method = 'GET') {
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, $url);
switch ($method) {
case 'GET':
break;
case 'POST':
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postdata));
break;
case 'PUT':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
break;
case 'DELETE':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
}
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$re = curl_exec ($ch);
curl_close ($ch);
return $re;
}
}