-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
106 lines (100 loc) · 3.07 KB
/
functions.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
<?php
function savejson($names){
$json = json_encode(array_values($names));
$fp = fopen("names.json", "w");
fwrite($fp, $json);
fclose($fp);
}
function savejsonexceptions($names){
$json = json_encode($names);
$fp = fopen("exceptions.json", "w");
fwrite($fp, $json);
fclose($fp);
}
function uploadimage($file){
$client_id = IMGUR_CLIENT_ID;
$image = implode('', file($file));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode($image)));
$reply = curl_exec($ch);
curl_close($ch);
$reply = json_decode($reply);
if ($reply->data->link != ""){
if (REMOVE_IMAGE == "yes"){
unlink($file);
}
return $reply->data->link;
}else{
return false;
}
}
function getimage(){
$url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); //Script URL
$data = json_decode(send("http://api.rest7.com/v1/html_to_image.php?url=".$url."/table.php&format=png"));
if (@$data->success !== 1){
return false;
}else{
$image = send($data->file);
if (!is_dir('images')) {
mkdir('images', 0775, true);
}
$name = "images/".date('YmdHis').'.png';
file_put_contents($name, $image);
return $name;
}
}
function sendTwitter($string,$image){
include("codebird.php");
\Codebird\Codebird::setConsumerKey(API_KEY, API_SECRET_KEY);
$cb = \Codebird\Codebird::getInstance();
$cb->setToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
if ($image != ""){
$reply = $cb->media_upload([
'media' => $image
]);
$media_id = $reply->media_id_string;
$params = [
'media_ids' => $media_id,
'status' => $string
];
}
$reply = $cb->statuses_update($params);
if ($reply->created_at != ""){
return true;
}else{
return false;
}
}
function send($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function sendTelegram($string,$image,$options=array("")){
$url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if (IMGUR_CLIENT_ID != ""){
$image_url = uploadimage($image);
}else{
$image_url = $url.'/'.$image;
}
if ($image_url != ""){
$string = '<a href="'.$image_url.'">✨</a> '.$string;
$defaults = ['parse_mode' => 'html'];
$options = ['disable_notification' => true];
$params = array_merge($defaults, $options);
$url = 'https://api.telegram.org/bot' . TELEGRAM_TOKEN. '/sendMessage?text='.urlencode($string).'&chat_id='.CHANNEL_ID.'&'.http_build_query($params);
return send($url);
}else{
return false;
}
}
?>