-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
105 lines (90 loc) · 3.71 KB
/
Copy pathplugin.php
File metadata and controls
105 lines (90 loc) · 3.71 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
<?php
class BluditToTelegram extends Plugin {
public function init()
{
// تنظیمات پیشفرض پلاگین
$this->dbFields = array(
'telegram_token' => '', // توکن ربات تلگرام
'chat_id' => '', // شناسهی چت یا کانال تلگرام
'enable_notifications' => true // فعال/غیرفعال کردن ارسال پیام
);
}
public function adminSidebar()
{
return '<a class="nav-link" href="#">Bludit to Telegram</a>';
}
public function form()
{
// دریافت مقادیر ذخیرهشده در تنظیمات
$telegramToken = $this->getValue('telegram_token');
$chatID = $this->getValue('chat_id');
$enableNotifications = $this->getValue('enable_notifications');
// نمایش فرم تنظیمات در پنل مدیریت
$html = '
<h2>Bludit to Telegram</h2>
<p>Enter your Telegram bot token and chat ID to enable notifications.</p>
<div>
<label>توکن ربات تلگرام:</label>
<input name="telegram_token" type="text" value="'.$telegramToken.'" class="form-control">
</div>
<div>
<label>شناسهی چت (chat ID):</label>
<input name="chat_id" type="text" value="'.$chatID.'" class="form-control">
</div>
<div>
<label>ارسال پیام فعال باشد؟</label>
<select name="enable_notifications" class="form-control">
<option value="1" '.($enableNotifications ? 'selected' : '').'>بله</option>
<option value="0" '.(!$enableNotifications ? 'selected' : '').'>خیر</option>
</select>
</div>
';
return $html;
}
// 📌 متد برای ارسال پیام به تلگرام
private function sendToTelegram($message)
{
if (!$this->getValue('enable_notifications')) {
return; // اگر ارسال پیام غیرفعال باشد، کاری انجام نمیشود.
}
$telegramToken = $this->getValue('telegram_token');
$chatID = $this->getValue('chat_id');
if (empty($telegramToken) || empty($chatID)) {
return; // اگر تنظیمات وارد نشده باشد، پیام ارسال نشود.
}
$url = "https://api.telegram.org/bot{$telegramToken}/sendMessage";
$data = [
'chat_id' => $chatID,
'text' => $message,
'parse_mode' => 'HTML'
];
$options = [
'http' => [
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
]
];
$context = stream_context_create($options);
file_get_contents($url, false, $context);
}
// 📌 ارسال پیام هنگام ایجاد مقاله جدید
public function afterPageCreate($key)
{
$page = new Page($key);
$message = "🆕 <b>مقاله جدید منتشر شد:</b>\n"
. "📌 <b>عنوان:</b> " . $page->title() . "\n"
. "🔗 <a href='" . $page->permalink() . "'>مشاهده مقاله</a>";
$this->sendToTelegram($message);
}
// 📌 ارسال پیام هنگام بهروزرسانی مقاله
public function afterPageModify($key)
{
$page = new Page($key);
$message = "✏️ <b>مقاله بهروزرسانی شد:</b>\n"
. "📌 <b>عنوان:</b> " . $page->title() . "\n"
. "🔗 <a href='" . $page->permalink() . "'>مشاهده مقاله</a>";
$this->sendToTelegram($message);
}
}
?>