|
1 | | -<?php |
| 1 | +// <?php |
2 | 2 |
|
3 | | -namespace UnityWebPortal\lib; |
| 3 | +// namespace UnityWebPortal\lib; |
4 | 4 |
|
5 | | -class UnityWebhook |
6 | | -{ |
7 | | - private $template_dir; |
8 | | - private $override_template_dir; |
9 | | - private $url; |
10 | | - private $MSG_LINKREF; |
| 5 | +// class UnityWebhook |
| 6 | +// { |
| 7 | +// private $template_dir; |
| 8 | +// private $override_template_dir; |
| 9 | +// private $url; |
| 10 | +// private $MSG_LINKREF; |
11 | 11 |
|
12 | | - public function __construct( |
13 | | - $template_dir, |
14 | | - $override_template_dir, |
15 | | - $url, |
16 | | - $msg_linkref |
17 | | - ) { |
18 | | - $this->template_dir = $template_dir; |
19 | | - $this->override_template_dir = $override_template_dir; |
20 | | - $this->url = $url; |
21 | | - $this->MSG_LINKREF = $msg_linkref; |
22 | | - } |
| 12 | +// public function __construct( |
| 13 | +// $template_dir, |
| 14 | +// $override_template_dir, |
| 15 | +// $url, |
| 16 | +// $msg_linkref |
| 17 | +// ) { |
| 18 | +// $this->template_dir = $template_dir; |
| 19 | +// $this->override_template_dir = $override_template_dir; |
| 20 | +// $this->url = $url; |
| 21 | +// $this->MSG_LINKREF = $msg_linkref; |
| 22 | +// } |
23 | 23 |
|
24 | | - public function htmlToMarkdown($html) |
25 | | - { |
26 | | - // Define regex patterns for each markdown format |
27 | | - $bold = '/<(b|strong)\b[^>]*>(.*?)<\/(b|strong)>/s'; |
28 | | - $italic = '/<i\b[^>]*>(.*?)<\/i>/s'; |
29 | | - $strikethrough = '/<del\b[^>]*>(.*?)<\/del>/s'; |
30 | | - $link = '/<a\b[^>]*href=["\']?([^"\'\s]*)[^>]*>(.*?)<\/a>/s'; |
| 24 | +// public function htmlToMarkdown($html) |
| 25 | +// { |
| 26 | +// // Define regex patterns for each markdown format |
| 27 | +// $bold = '/<(b|strong)\b[^>]*>(.*?)<\/(b|strong)>/s'; |
| 28 | +// $italic = '/<i\b[^>]*>(.*?)<\/i>/s'; |
| 29 | +// $strikethrough = '/<del\b[^>]*>(.*?)<\/del>/s'; |
| 30 | +// $link = '/<a\b[^>]*href=["\']?([^"\'\s]*)[^>]*>(.*?)<\/a>/s'; |
31 | 31 |
|
32 | | - // Replace each HTML tag with its corresponding markdown format |
33 | | - $md = preg_replace($bold, '*$2*', $html); |
34 | | - $md = preg_replace($italic, '_$1_', $md); |
35 | | - $md = preg_replace($strikethrough, '~$1~', $md); |
36 | | - $md = preg_replace($link, '$2: $1', $md); |
| 32 | +// // Replace each HTML tag with its corresponding markdown format |
| 33 | +// $md = preg_replace($bold, '*$2*', $html); |
| 34 | +// $md = preg_replace($italic, '_$1_', $md); |
| 35 | +// $md = preg_replace($strikethrough, '~$1~', $md); |
| 36 | +// $md = preg_replace($link, '$2: $1', $md); |
37 | 37 |
|
38 | | - // Replace any remaining HTML tags with an empty string |
39 | | - $md = strip_tags($md); |
| 38 | +// // Replace any remaining HTML tags with an empty string |
| 39 | +// $md = strip_tags($md); |
40 | 40 |
|
41 | | - return $md; |
42 | | - } |
| 41 | +// return $md; |
| 42 | +// } |
43 | 43 |
|
44 | | - public function sendWebhook($template = null, $data = null) |
45 | | - { |
46 | | - $template_filename = $template . ".php"; |
47 | | - if (file_exists($this->override_template_dir . "/" . $template_filename)) { |
48 | | - $template_path = $this->override_template_dir . "/" . $template_filename; |
49 | | - } else { |
50 | | - $template_path = $this->template_dir . "/" . $template_filename; |
51 | | - } |
| 44 | +// public function sendWebhook($template = null, $data = null) |
| 45 | +// { |
| 46 | +// $template_filename = $template . ".php"; |
| 47 | +// if (file_exists($this->override_template_dir . "/" . $template_filename)) { |
| 48 | +// $template_path = $this->override_template_dir . "/" . $template_filename; |
| 49 | +// } else { |
| 50 | +// $template_path = $this->template_dir . "/" . $template_filename; |
| 51 | +// } |
52 | 52 |
|
53 | | - ob_start(); |
54 | | - include $template_path; |
55 | | - $mes_html = ob_get_clean(); |
| 53 | +// ob_start(); |
| 54 | +// include $template_path; |
| 55 | +// $mes_html = ob_get_clean(); |
56 | 56 |
|
57 | | - $message = $this->htmlToMarkdown($mes_html); |
| 57 | +// $message = $this->htmlToMarkdown($mes_html); |
58 | 58 |
|
59 | | - $ch = curl_init(); |
60 | | - curl_setopt($ch, CURLOPT_URL, $this->url); |
61 | | - curl_setopt($ch, CURLOPT_POST, 1); |
62 | | - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); |
63 | | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
64 | | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('text' => $message))); |
65 | | - $result = curl_exec($ch); |
66 | | - curl_close($ch); |
67 | | - return $result; |
68 | | - } |
69 | | -} |
| 59 | +// $ch = curl_init(); |
| 60 | +// curl_setopt($ch, CURLOPT_URL, $this->url); |
| 61 | +// curl_setopt($ch, CURLOPT_POST, 1); |
| 62 | +// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); |
| 63 | +// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 64 | +// curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('text' => $message))); |
| 65 | +// $result = curl_exec($ch); |
| 66 | +// curl_close($ch); |
| 67 | +// return $result; |
| 68 | +// } |
| 69 | +// } |
0 commit comments