This repository has been archived by the owner on Jan 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Bootstrap.php
executable file
·55 lines (48 loc) · 2.06 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('__COMMENT2TELEGRAM_PLUGIN_ROOT__', __DIR__);
require_once __COMMENT2TELEGRAM_PLUGIN_ROOT__ . '/lib/Const.php';
require_once __COMMENT2TELEGRAM_PLUGIN_ROOT__ . '/lib/TelegramModel.php';
$GLOBALS['options'] = Helper::options();
$all = Typecho_Plugin::export();
if (array_key_exists('Comment2Telegram', $all['activated'])) {
$_cfg = Helper::options()->plugin('Comment2Telegram');
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;
}
}