forked from piterskiy/etuts-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.php
134 lines (121 loc) · 3.5 KB
/
utilities.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
<?php
function contains_word($source, $find) {
if (strpos($source, $find) !== false)
return true;
return false;
}
function convert_to_english($text) {
$persian = array('ض','ص','ث','ق','ف','غ','ع','ه','خ','ح','ج','چ','ش','س','ی','ب','ل','ا','ت','ن','م','ک','گ','ظ','ط','ز','ر','ذ','د','پ','و',' ');
$english = array('q','w','e','r','t','y','u','i','o','p','_1','_2','a','s','d','f','g','h','j','k','l','_3','_4','z','x','cv','b','n','m','_5','_');
return str_replace($persian, $english, $text);
}
// araye intory bar migardoone: [["0", "1"]
// ["2", "3"]] ...
function array_duplex($arr){
$ans = array();
$cnt = 0;
$i = -1;
foreach($arr as $ind){
if($cnt%2 == 0){
$i++;
array_push($ans, array());
}
array_push($ans[$i], $ind);
$cnt++;
}
return $ans;
}
function emoji($text){
$emoji = [
'laugh' => '😂',
'poker' => '😐',
':D' => '😁',
'thinking' => '🤔',
'like' => '👍',
'exact' => '👌',
'hand' => '✋',
'facepalm' => '😑',
'dislike' => '👎',
'image-icon' => '🖼',
'game' => '🎮',
'desktop' => '🖥',
'electricity' => '💡',
'mobile' => '📱',
'web' => '🌎',
'design' => '🎨',
'checked' => '✅',
'not_checked' => '◻️',
'alert' => '⚠️',
'robot' => '🤖',
'bullhorn' => '📣',
'note' => '📋',
'id' => '🆔',
'clock' => '🕒',
'blue_diamond' => '💠',
'post_letter_box' => '📮',
'user' => '👤',
'forbidden' => '🚫',
'trash' => '🗑',
'sand_clock' => '⏳',
'message' => '💬',
];
return $emoji[$text];
}
$lots_of_dots = str_repeat('.', 100);
function create_categories_keyboard_reply_markup($checked){
global $categories_array, $lots_of_dots;
$btns = [];
foreach($categories_array as $num => $category){
$txt = emoji($checked[$num] ? 'checked':'not_checked') . '. ' . emoji($category["emoji"]) . ' ' . $category["name"] . $lots_of_dots;
$btns[] = [create_glassy_btn($txt , 'chck_cats', ['t' => $num])];
}
return create_glassy_keyboard($btns);
}
function create_about_us_keyboard_reply_markup(){
global $lots_of_dots, $vahid, $mamad, $shahr, $url_vahid, $url_mamad, $url_shahr;
$btns = [];
$btns[] = [create_glassy_link_btn($vahid, $url_vahid)];
$btns[] = [create_glassy_link_btn($mamad, $url_mamad)];
$btns[] = [create_glassy_link_btn($shahr, $url_shahr)];
return create_glassy_keyboard($btns);
}
function send_post_to_site($post_title, $post_content, $author_id, $featured_image_link, $params) {
global $new_post_url;
// default values for optional params
$params = array_merge(array(
'post_type' => 'post',
'post_format' => 'standard',
'status' => 'pending',
), $params);
$form_params = [
'submit' => 'submit',
'title' => $post_title,
'content' => $post_content,
'wp_post_type' => $params['post_type'],
'author' => $author_id,
'wp_post_format' => $params['post_format'],
'wp_post_featured_image' => $featured_image_link,
'status' => $params['status'],
'client' => 'tbot',
];
if (isset($params['category']))
$form_params['category'] = $params['category'];
unset($params['category']);
unset($params['post_type']);
unset($params['post_format']);
$form_params['other_params'] = $params;
send_http_request($new_post_url, 'POST', $form_params);
}
function send_http_request($url, $method, $form_params) {
// Initialize Guzzle client
$client = new GuzzleHttp\Client();
// Create a POST request
$response = $client->request(
$method,
$url,
[
'form_params' => $form_params
]
);
return $response;
}