@@ -34,7 +34,8 @@ public function init($host) {
34
34
$ host ->add_hook ($ host ::HOOK_PREFS_EDIT_FEED , $ this );
35
35
$ host ->add_hook ($ host ::HOOK_PREFS_SAVE_FEED , $ this );
36
36
$ host ->add_hook ($ host ::HOOK_PREFS_TAB , $ this );
37
- $ host ->add_filter_action ($ this , "Notification " , __ ("Send Notification " ));
37
+
38
+ $ host ->add_filter_action ($ this , "ntfy " , __ ("Send Notification " ));
38
39
}
39
40
40
41
public function hook_prefs_tab ($ args ) {
@@ -149,49 +150,48 @@ public function hook_article_filter($article) {
149
150
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
150
151
*/
151
152
public function hook_article_filter_action ($ article , $ action ) {
152
- $ this ->send_notification ($ article );
153
+ return $ this ->send_notification ($ article );
153
154
}
154
155
155
156
public function send_notification ($ article ) {
156
157
// check if the article ntfy tag exists
157
158
$ tags = (is_array ($ article ["tags " ])) ? $ article ["tags " ] : array ();
158
- if (in_array ("ntfy " , $ tags )) {
159
- return $ article ;
160
- }
161
- $ ntfy_server = $ this ->host ->get ($ this , "ntfy_server " );
162
- $ ntfy_topic = $ this ->host ->get ($ this , "ntfy_topic " );
163
- $ ntfy_token = $ this ->host ->get ($ this , "ntfy_token " );
159
+ if (!in_array ("ntfy " , $ tags )) {
160
+ $ ntfy_server = $ this ->host ->get ($ this , "ntfy_server " );
161
+ $ ntfy_topic = $ this ->host ->get ($ this , "ntfy_topic " );
162
+ $ ntfy_token = $ this ->host ->get ($ this , "ntfy_token " );
164
163
165
- $ ch = curl_init ();
164
+ $ ch = curl_init ();
166
165
167
- $ content = $ this ->clean_html ($ article ['content ' ]);
168
- $ truncatedContent = strlen ($ content ) > 500
169
- ? mb_substr ($ content , 0 , 500 , 'UTF-8 ' ) . "... "
170
- : $ content ;
166
+ $ content = $ this ->clean_html ($ article ['content ' ]);
167
+ $ truncatedContent = strlen ($ content ) > 500
168
+ ? mb_substr ($ content , 0 , 500 , 'UTF-8 ' ) . "... "
169
+ : $ content ;
171
170
172
- $ headers = [];
173
- if (strlen (trim ($ ntfy_token )) > 0 ) {
174
- $ headers [] = "Authorization: Bearer " . $ ntfy_token ;
175
- }
171
+ $ headers = [];
172
+ if (strlen (trim ($ ntfy_token )) > 0 ) {
173
+ $ headers [] = "Authorization: Bearer " . $ ntfy_token ;
174
+ }
176
175
177
- // get article feed title
178
- $ title = "【 " . Feeds::_get_title ($ article ["feed " ]["id " ]) . "】 " . $ article ["title " ];
179
- $ jsonData = json_encode ([
180
- "topic " => $ ntfy_topic ,
181
- "message " => $ truncatedContent ,
182
- "title " => $ title ,
183
- "tags " => ["mailbox_with_mail " ],
184
- "click " => $ article ["link " ],
185
- ]);
186
- curl_setopt ($ ch , CURLOPT_URL , $ ntfy_server );
187
- curl_setopt ($ ch , CURLOPT_POST , true );
188
- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
189
- curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ jsonData );
190
- curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ headers );
191
- curl_exec ($ ch );
192
- curl_close ($ ch );
193
-
194
- array_push ($ article ["tags " ], "ntfy " );
176
+ // get article feed title
177
+ $ title = "【 " . Feeds::_get_title ($ article ["feed " ]["id " ]) . "】 " . $ article ["title " ];
178
+ $ jsonData = json_encode ([
179
+ "topic " => $ ntfy_topic ,
180
+ "message " => $ truncatedContent ,
181
+ "title " => $ title ,
182
+ "tags " => ["mailbox_with_mail " ],
183
+ "click " => $ article ["link " ],
184
+ ]);
185
+ curl_setopt ($ ch , CURLOPT_URL , $ ntfy_server );
186
+ curl_setopt ($ ch , CURLOPT_POST , true );
187
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
188
+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ jsonData );
189
+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ headers );
190
+ curl_exec ($ ch );
191
+ curl_close ($ ch );
192
+
193
+ array_push ($ article ["tags " ], "ntfy " );
194
+ }
195
195
return $ article ;
196
196
}
197
197
0 commit comments