Commit 61d5adb5 authored by Francesco Iannuzzelli's avatar Francesco Iannuzzelli

Rocketchat notifications

parent 5e58ca16
......@@ -197,6 +197,7 @@ class Configuration
$values['fb_app_id'] = (isset($conf->fb_app_id) && $conf->fb_app_id != "")? $conf->fb_app_id : "";
$values['telegram_bot_api_key'] = (isset($conf->telegram_bot_api_key) && $conf->telegram_bot_api_key != "")? $conf->telegram_bot_api_key : "";
$values['telegram_callback_key'] = (isset($conf->telegram_callback_key) && $conf->telegram_callback_key != "")? $conf->telegram_callback_key : "";
$values['rocketchat_webhook'] = (isset($conf->rocketchat_webhook) && $conf->rocketchat_webhook != "")? $conf->rocketchat_webhook : "";
$values['dev'] = (isset($conf->dev) && is_bool($conf->dev))? $conf->dev : false;
$values['track'] = (isset($conf->track) && is_bool($conf->track))? $conf->track: false;
$values['track_exclude'] = (isset($conf->track_exclude) && is_array($conf->track_exclude))? $conf->track_exclude : array("127.0.0.1");
......
......@@ -873,22 +873,27 @@ class FileManager
* @param array $data Data to post
* @param boolean $use_cookie Whether to use cookies or not
* @param integer $timeout Timeout in seconds
* @param boolean $json Whether to encode payload in JSON
* @return string Page response
*/
public function PostData($host,$page,$data,$use_cookie=false,$timeout=10)
public function PostData($host,$page,$data,$use_cookie=false,$timeout=10,$json=false)
{
$content = false;
if ($host!="" && is_array($data) && count($data)>0)
{
$counter = 1;
$params = "";
$tot_data = count($data);
while((list($key,$value) = each($data))==true)
{
$params .= "$key=$value";
if ($counter < $tot_data)
$params .= "&";
$counter ++;
if($json) {
$params = json_encode($data);
} else {
$counter = 1;
$params = "";
$tot_data = count($data);
while((list($key,$value) = each($data))==true)
{
$params .= "$key=$value";
if ($counter < $tot_data)
$params .= "&";
$counter ++;
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST,1);
......@@ -897,8 +902,12 @@ class FileManager
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0 );
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
if($this->curl_proxy!="")
if($this->curl_proxy!="") {
curl_setopt($ch, CURLOPT_PROXY, $this->curl_proxy);
}
if($json) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,$timeout);
if($use_cookie)
......
......@@ -168,9 +168,7 @@ class PublishManager
if ((!($this->layout->article['published_ts'])>0) || $param=="new")
{
$a->PublishedSet();
include_once(SERVER_ROOT."/../classes/contribution.php");
$co = new Contribution("article");
$co->Notify($id_article,$url,$this->layout->article['headline']);
$this->ArticleNotify($id_article, $url, $this->layout->article['headline']);
}
include_once(SERVER_ROOT."/../classes/twitter.php");
$tw = new TwitterHelper();
......@@ -188,6 +186,20 @@ class PublishManager
}
unset($this->layout->article);
}
private function ArticleNotify($id_article,$url,$headline) {
include_once(SERVER_ROOT."/../classes/contribution.php");
$co = new Contribution("article");
$co->Notify($id_article,$url,$headline);
$conf = new Configuration();
if($conf->Get("rocketchat_webhook")!='') {
$webhook = parse_url($conf->Get("rocketchat_webhook"));
$data = array();
$data['url'] = $url;
$data['title'] = $headline;
$this->fm->PostData("{$webhook['scheme']}://{$webhook['host']}", $webhook['path'], $data, false, 15, true);
}
}
public function CrossDomain()
{
......@@ -1187,11 +1199,12 @@ class PublishManager
$this->layout->article = $a->ArticleGet();
if($this->layout->article['jump_to_source']!="1")
{
$this->Output("article",array('id'=>$article['id_article']));
}
if (!($this->layout->article['published_ts'])>0)
{
$a->PublishedSet();
$url = $this->Output("article",array('id'=>$article['id_article']));
if (!($this->layout->article['published_ts'])>0)
{
$a->PublishedSet();
$this->ArticleNotify($article['id_article'], $url, $this->layout->article['headline']);
}
}
unset($a);
unset($this->layout->article);
......
......@@ -1349,6 +1349,15 @@ class Config
*/
public $telegram_bot_api_key = "";
/**
* ROCKETCHAT WEBHOOK
* For notifications
* Default: ""
*
* @var string
*/
public $rocketchat_webhook = "";
/**
* RECAPTCHA
* Default: false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment