Skip to content

Commit c31cb72

Browse files
committed
Fix the filter action where the ntfy tag is not assigned.
1 parent 7b940c8 commit c31cb72

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

init.php

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public function init($host) {
3434
$host->add_hook($host::HOOK_PREFS_EDIT_FEED, $this);
3535
$host->add_hook($host::HOOK_PREFS_SAVE_FEED, $this);
3636
$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"));
3839
}
3940

4041
public function hook_prefs_tab($args) {
@@ -149,49 +150,48 @@ public function hook_article_filter($article) {
149150
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
150151
*/
151152
public function hook_article_filter_action($article, $action) {
152-
$this->send_notification($article);
153+
return $this->send_notification($article);
153154
}
154155

155156
public function send_notification($article) {
156157
// check if the article ntfy tag exists
157158
$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");
164163

165-
$ch = curl_init();
164+
$ch = curl_init();
166165

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;
171170

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+
}
176175

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+
}
195195
return $article;
196196
}
197197

0 commit comments

Comments
 (0)