OK, it think I got it working. So if you want to be able to send an article/url to wallabag with a filter (using the invoke plugin action) you just have to add some code to the init.php file.
First add these two lines to the function init($host):
$host->add_hook($host::HOOK_ARTICLE_FILTER_ACTION, $this);
$host->add_filter_action($this, "send to Wallabag", "send to Wallabag");
and then add the function hook_article_filter_action($article, $action) somewhere:
function hook_article_filter_action($article, $action) {
if ($action == "send to Wallabag") {
$article_link = $article["link"];
$w_url = $this->host->get($this, "wallabag_url");
$w_cid = $this->host->get($this, "wallabag_client_id");
$w_cs = $this->host->get($this, "wallabag_client_secret");
if (function_exists('curl_init')) {
$w_access = $this->host->get($this, "wallabag_access_token");
$old_timeout = $this->host->get($this, "wallabag_access_token_timeout");
$now = time();
if( $old_timeout < $now ) {
$w_refresh = $this->host->get($this, "wallabag_refresh_token");
$old_rTimeout = $this->host->get($this, "wallabag_access_token_timeout");
if( $old_rTimeout < $now ) {
$w_user = $this->host->get($this, "wallabag_username");
$w_pass = $this->host->get($this, "wallabag_password");
$postfields = array(
"client_id" => $w_cid,
"client_secret" => $w_cs,
"username" => $w_user,
"password" => $w_pass,
"grant_type" => "password"
);
$OAcURL = curl_init();
curl_setopt($OAcURL, CURLOPT_URL, $w_url . '/oauth/v2/token');
curl_setopt($OAcURL, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded;charset=UTF-8'));
curl_setopt($OAcURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($OAcURL, CURLOPT_TIMEOUT, 30);
curl_setopt($OAcURL, CURLOPT_POST, true);
curl_setopt($OAcURL, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($OAcURL, CURLOPT_POSTFIELDS, http_build_query($postfields));
$OAresult = curl_exec($OAcURL);
$aTimeout = time() + 3600;
$rTimeout = time() + 1209600;
$OAstatus = curl_getinfo($OAcURL, CURLINFO_HTTP_CODE);
curl_close($OAcURL);
$OAresult = json_decode($OAresult,true);
$w_access = $OAresult["access_token"];
$w_refresh = $OAresult["refresh_token"];
if ($OAstatus == 200) {
$this->host->set($this, "wallabag_access_token", $w_access);
$this->host->set($this, "wallabag_access_token_timeout", $aTimeout);
$this->host->set($this, "wallabag_refresh_token", $w_refresh);
$this->host->set($this, "wallabag_refresh_token_timeout", $rTimeout);
}
} else {
$postfields = array(
"client_id" => $w_cid,
"client_secret" => $w_cs,
"refresh_token" => $w_refresh,
"grant_type" => "refresh_token"
);
$OAcURL = curl_init();
curl_setopt($OAcURL, CURLOPT_URL, $w_url . '/oauth/v2/token');
curl_setopt($OAcURL, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded;charset=UTF-8'));
curl_setopt($OAcURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($OAcURL, CURLOPT_TIMEOUT, 30);
curl_setopt($OAcURL, CURLOPT_POST, true);
curl_setopt($OAcURL, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($OAcURL, CURLOPT_POSTFIELDS, http_build_query($postfields));
$OAresult = curl_exec($OAcURL);
$OAstatus = curl_getinfo($OAcURL, CURLINFO_HTTP_CODE);
$new_timeout = time() + 3600;
curl_close($OAcURL);
$OAresult = json_decode($OAresult,true);
$w_access = $OAresult["access_token"];
$w_refresh = $OAresult["refresh_token"];
if ($OAstatus == 200) {
$this->host->set($this, "wallabag_access_token", $w_access);
$this->host->set($this, "wallabag_access_token_timeout", $new_timeout);
$this->host->set($this, "wallabag_refresh_token", $w_refresh);
}
}
}
}
$postfields = array(
'access_token' => $w_access,
'url' => $article_link
);
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $w_url.'/api/entries.json');
curl_setopt($cURL, CURLOPT_HEADER, 1);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded;charset=UTF-8'));
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_TIMEOUT, 30);
curl_setopt($cURL, CURLOPT_POST, 4);
curl_setopt($cURL, CURLOPT_POSTFIELDS, http_build_query($postfields));
$apicall = curl_exec($cURL);curl_close($cURL);
return $article;
}
}
Of course you can still use the button to add articles to wallabag.
@dariottolo @sunjam : maybe this is what you were looking for?