-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
175 lines (147 loc) · 5.17 KB
/
functions.php
File metadata and controls
175 lines (147 loc) · 5.17 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
// دوال مساعدة للبوت - Helper Functions for the Bot
require_once 'config.php';
/**
* إرسال رسالة إلى تيليجرام - Send message to Telegram
*/
function sendTelegramMessage($chat_id, $text, $parse_mode = 'HTML') {
$url = "https://api.telegram.org/bot" . BOT_TOKEN . "/sendMessage";
$params = [
'chat_id' => $chat_id,
'text' => $text,
'parse_mode' => $parse_mode
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
/**
* نشر محتوى في القناة - Post content to the channel
*/
function postToChannel($content) {
// تعديل استخدام وضع تنسيق ماركداون - Use Markdown parse mode
$response = sendTelegramMessage(CHANNEL_ID, $content, 'Markdown');
// تسجيل المنشور في سجل النشر - Log the post
logPosting([
'time' => time(),
'status' => isset($response['ok']) && $response['ok'] ? 'success' : 'failed',
'content' => $content,
'response' => $response
]);
return $response;
}
/**
* تسجيل عملية النشر - Log posting activity
*/
function logPosting($logData) {
$logs = json_decode(file_get_contents(POSTING_LOG_FILE), true);
$logs[] = $logData;
// الاحتفاظ فقط بآخر 100 سجل - Keep only the last 100 logs
if (count($logs) > 100) {
$logs = array_slice($logs, -100);
}
file_put_contents(POSTING_LOG_FILE, json_encode($logs));
}
/**
* الحصول على الإعدادات - Get settings
*/
function getSettings() {
return json_decode(file_get_contents(SETTINGS_FILE), true);
}
/**
* تحديث الإعدادات - Update settings
*/
function updateSettings($newSettings) {
$currentSettings = getSettings();
$updatedSettings = array_merge($currentSettings, $newSettings);
$updatedSettings['last_updated'] = time();
file_put_contents(SETTINGS_FILE, json_encode($updatedSettings));
return $updatedSettings;
}
/**
* جدولة منشور جديد - Schedule a new post
*/
function schedulePost($content, $postTime) {
$scheduledPosts = json_decode(file_get_contents(SCHEDULED_POSTS_FILE), true);
$newPost = [
'id' => uniqid(),
'content' => $content,
'scheduled_time' => $postTime,
'created_at' => time(),
'status' => 'pending'
];
$scheduledPosts[] = $newPost;
// ترتيب المنشورات حسب موعد النشر - Sort posts by scheduled time
usort($scheduledPosts, function($a, $b) {
return $a['scheduled_time'] - $b['scheduled_time'];
});
file_put_contents(SCHEDULED_POSTS_FILE, json_encode($scheduledPosts));
return $newPost;
}
/**
* الحصول على المنشورات المجدولة - Get scheduled posts
*/
function getScheduledPosts() {
return json_decode(file_get_contents(SCHEDULED_POSTS_FILE), true);
}
/**
* تحديث حالة منشور مجدول - Update scheduled post status
*/
function updatePostStatus($postId, $status) {
$scheduledPosts = getScheduledPosts();
foreach ($scheduledPosts as &$post) {
if ($post['id'] === $postId) {
$post['status'] = $status;
if ($status === 'published') {
$post['published_at'] = time();
}
break;
}
}
file_put_contents(SCHEDULED_POSTS_FILE, json_encode($scheduledPosts));
}
/**
* التحقق من صلاحيات المشرف - Check admin permissions
*/
function isAdmin($userId) {
return $userId == ADMIN_ID;
}
/**
* تنسيق التاريخ والوقت بالعربية - Format date and time in Arabic
*/
function formatArabicDateTime($timestamp) {
$months = [
'يناير', 'فبراير', 'مارس', 'إبريل', 'مايو', 'يونيو',
'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر'
];
$days = [
'الأحد', 'الإثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت'
];
$dayName = $days[date('w', $timestamp)];
$day = date('j', $timestamp);
$month = $months[date('n', $timestamp) - 1];
$year = date('Y', $timestamp);
$time = date('H:i', $timestamp);
return "$dayName $day $month $year - $time";
}
/**
* تسجيل الأخطاء - Log errors
*/
function logError($message, $details = '') {
$logEntry = [
'time' => time(),
'message' => $message,
'details' => $details
];
// إرسال إشعار للمشرف - Send notification to admin
sendTelegramMessage(ADMIN_ID,
"❌ خطأ في البوت:\n" .
"الرسالة: $message\n" .
($details ? "التفاصيل: $details" : "")
);
// يمكن إضافة التسجيل في ملف - Could add file logging here
}
?>