Add option to include article content in message
A configurable number of characters of article content can now be included in sent messages. Preferences layout is also adjusted a bit.
This commit is contained in:
parent
1904e3084f
commit
5001b7516d
20
init.php
20
init.php
|
@ -2,6 +2,7 @@
|
||||||
class Discord_Webhook extends Plugin {
|
class Discord_Webhook extends Plugin {
|
||||||
private $host;
|
private $host;
|
||||||
private $discord_api_url = "https://discordapp.com/api/webhooks/";
|
private $discord_api_url = "https://discordapp.com/api/webhooks/";
|
||||||
|
private $default_content_length = 0;
|
||||||
|
|
||||||
function about() {
|
function about() {
|
||||||
return array(1.0,
|
return array(1.0,
|
||||||
|
@ -66,6 +67,22 @@ class Discord_Webhook extends Plugin {
|
||||||
$payload = array();
|
$payload = array();
|
||||||
$payload["content"] = $article["title"] . " " . $article["link"];
|
$payload["content"] = $article["title"] . " " . $article["link"];
|
||||||
|
|
||||||
|
$content_length = $this->host->get($this, 'content_length');
|
||||||
|
if (!is_numeric($content_length))
|
||||||
|
$content_length = $this->default_content_length;
|
||||||
|
|
||||||
|
if ($content_length > 0) {
|
||||||
|
$content_stripped = preg_replace('#<br\s*/?>#i', "\n", $article["content"]);
|
||||||
|
$content_stripped = strip_tags($content_stripped);
|
||||||
|
$content_stripped = trim($content_stripped);
|
||||||
|
|
||||||
|
if (strlen($content_stripped) > $content_length) {
|
||||||
|
$payload["content"] .= "\n_" . substr($content_stripped, 0, $content_length) . "..._";
|
||||||
|
} else {
|
||||||
|
$payload["content"] .= "\n_" . $content_stripped . "_";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("SELECT title FROM ttrss_feeds WHERE id = ?");
|
$sth = $this->pdo->prepare("SELECT title FROM ttrss_feeds WHERE id = ?");
|
||||||
$sth->execute([$article["feed"]["id"]]);
|
$sth->execute([$article["feed"]["id"]]);
|
||||||
|
|
||||||
|
@ -92,6 +109,8 @@ class Discord_Webhook extends Plugin {
|
||||||
|
|
||||||
$replacements = array(
|
$replacements = array(
|
||||||
'{webhook_url}' => $this->host->get($this, 'webhook_url'),
|
'{webhook_url}' => $this->host->get($this, 'webhook_url'),
|
||||||
|
'{content_length}' => $this->host->get($this, 'content_length'),
|
||||||
|
'{default_content_length}' => $this->default_content_length,
|
||||||
'{discord_api_url}' => $this->discord_api_url
|
'{discord_api_url}' => $this->discord_api_url
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -103,6 +122,7 @@ class Discord_Webhook extends Plugin {
|
||||||
function save()
|
function save()
|
||||||
{
|
{
|
||||||
$this->host->set($this, 'webhook_url', $_POST['webhook_url']);
|
$this->host->set($this, 'webhook_url', $_POST['webhook_url']);
|
||||||
|
$this->host->set($this, 'content_length', $_POST['content_length']);
|
||||||
echo __("Configuration saved");
|
echo __("Configuration saved");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,14 @@
|
||||||
<input dojoType="dijit.form.TextBox" type="hidden" name="op" value="pluginhandler">
|
<input dojoType="dijit.form.TextBox" type="hidden" name="op" value="pluginhandler">
|
||||||
<input dojoType="dijit.form.TextBox" type="hidden" name="method" value="save">
|
<input dojoType="dijit.form.TextBox" type="hidden" name="method" value="save">
|
||||||
<input dojoType="dijit.form.TextBox" type="hidden" name="plugin" value="discord_webhook">
|
<input dojoType="dijit.form.TextBox" type="hidden" name="plugin" value="discord_webhook">
|
||||||
<input dojoType="dijit.form.ValidationTextBox" id="discord_webhook_url" type="url" required="1" pattern="{discord_api_url}.+" title="{discord_api_url}..." placeholder="{discord_api_url}..." name="webhook_url" value="{webhook_url}">
|
<fieldset class="prefs">
|
||||||
|
<label>Webhook URL:</label>
|
||||||
|
<input dojoType="dijit.form.ValidationTextBox" id="discord_webhook_url" type="url" required="1" pattern="{discord_api_url}.+" placeholder="{discord_api_url}..." name="webhook_url" value="{webhook_url}">
|
||||||
|
</fieldset>
|
||||||
|
<fieldset class="prefs">
|
||||||
|
<label>Include characters of article content:</label>
|
||||||
|
<input dojoType="dijit.form.NumberSpinner" constraints="{min:0}" id="discord_content_length" placeholder="{default_content_length}" name="content_length" value="{content_length}">
|
||||||
|
</fieldset>
|
||||||
<br><br>
|
<br><br>
|
||||||
<button dojoType="dijit.form.Button" type="submit">Save</button>
|
<button dojoType="dijit.form.Button" type="submit">Save</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in a new issue