diff options
Diffstat (limited to 'app/Integration')
-rw-r--r-- | app/Integration/HipchatWebhook.php | 93 | ||||
-rw-r--r-- | app/Integration/Jabber.php | 126 | ||||
-rw-r--r-- | app/Integration/SlackWebhook.php | 126 |
3 files changed, 0 insertions, 345 deletions
diff --git a/app/Integration/HipchatWebhook.php b/app/Integration/HipchatWebhook.php deleted file mode 100644 index 6f789718..00000000 --- a/app/Integration/HipchatWebhook.php +++ /dev/null @@ -1,93 +0,0 @@ -<?php - -namespace Kanboard\Integration; - -/** - * Hipchat webhook - * - * @package integration - * @author Frederic Guillot - */ -class HipchatWebhook extends \Kanboard\Core\Base -{ - /** - * Return true if Hipchat is enabled for this project or globally - * - * @access public - * @param integer $project_id - * @return boolean - */ - public function isActivated($project_id) - { - return $this->config->get('integration_hipchat') == 1 || $this->projectIntegration->hasValue($project_id, 'hipchat', 1); - } - - /** - * Get API parameters - * - * @access public - * @param integer $project_id - * @return array - */ - public function getParameters($project_id) - { - if ($this->config->get('integration_hipchat') == 1) { - return array( - 'api_url' => $this->config->get('integration_hipchat_api_url'), - 'room_id' => $this->config->get('integration_hipchat_room_id'), - 'room_token' => $this->config->get('integration_hipchat_room_token'), - ); - } - - $options = $this->projectIntegration->getParameters($project_id); - - return array( - 'api_url' => $options['hipchat_api_url'], - 'room_id' => $options['hipchat_room_id'], - 'room_token' => $options['hipchat_room_token'], - ); - } - - /** - * Send the notification if activated - * - * @access public - * @param integer $project_id Project id - * @param integer $task_id Task id - * @param string $event_name Event name - * @param array $event Event data - */ - public function notify($project_id, $task_id, $event_name, array $event) - { - if ($this->isActivated($project_id)) { - $params = $this->getParameters($project_id); - $project = $this->project->getbyId($project_id); - - $event['event_name'] = $event_name; - $event['author'] = $this->user->getFullname($this->session['user']); - - $html = '<img src="http://kanboard.net/assets/img/favicon-32x32.png"/>'; - $html .= '<strong>'.$project['name'].'</strong>'.(isset($event['task']['title']) ? '<br/>'.$event['task']['title'] : '').'<br/>'; - $html .= $this->projectActivity->getTitle($event); - - if ($this->config->get('application_url')) { - $html .= '<br/><a href="'.$this->helper->url->href('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id), false, '', true).'">'; - $html .= t('view the task on Kanboard').'</a>'; - } - - $payload = array( - 'message' => $html, - 'color' => 'yellow', - ); - - $url = sprintf( - '%s/v2/room/%s/notification?auth_token=%s', - $params['api_url'], - $params['room_id'], - $params['room_token'] - ); - - $this->httpClient->postJson($url, $payload); - } - } -} diff --git a/app/Integration/Jabber.php b/app/Integration/Jabber.php deleted file mode 100644 index d776e560..00000000 --- a/app/Integration/Jabber.php +++ /dev/null @@ -1,126 +0,0 @@ -<?php - -namespace Kanboard\Integration; - -use Exception; -use Fabiang\Xmpp\Options; -use Fabiang\Xmpp\Client; -use Fabiang\Xmpp\Protocol\Message; -use Fabiang\Xmpp\Protocol\Presence; - -/** - * Jabber - * - * @package integration - * @author Frederic Guillot - */ -class Jabber extends \Kanboard\Core\Base -{ - /** - * Return true if Jabber is enabled for this project or globally - * - * @access public - * @param integer $project_id - * @return boolean - */ - public function isActivated($project_id) - { - return $this->config->get('integration_jabber') == 1 || $this->projectIntegration->hasValue($project_id, 'jabber', 1); - } - - /** - * Get connection parameters - * - * @access public - * @param integer $project_id - * @return array - */ - public function getParameters($project_id) - { - if ($this->config->get('integration_jabber') == 1) { - return array( - 'server' => $this->config->get('integration_jabber_server'), - 'domain' => $this->config->get('integration_jabber_domain'), - 'username' => $this->config->get('integration_jabber_username'), - 'password' => $this->config->get('integration_jabber_password'), - 'nickname' => $this->config->get('integration_jabber_nickname'), - 'room' => $this->config->get('integration_jabber_room'), - ); - } - - $options = $this->projectIntegration->getParameters($project_id); - - return array( - 'server' => $options['jabber_server'], - 'domain' => $options['jabber_domain'], - 'username' => $options['jabber_username'], - 'password' => $options['jabber_password'], - 'nickname' => $options['jabber_nickname'], - 'room' => $options['jabber_room'], - ); - } - - /** - * Build and send the message - * - * @access public - * @param integer $project_id Project id - * @param integer $task_id Task id - * @param string $event_name Event name - * @param array $event Event data - */ - public function notify($project_id, $task_id, $event_name, array $event) - { - if ($this->isActivated($project_id)) { - $project = $this->project->getbyId($project_id); - - $event['event_name'] = $event_name; - $event['author'] = $this->user->getFullname($this->session['user']); - - $payload = '['.$project['name'].'] '.str_replace('"', '"', $this->projectActivity->getTitle($event)).(isset($event['task']['title']) ? ' ('.$event['task']['title'].')' : ''); - - if ($this->config->get('application_url')) { - $payload .= ' '.$this->helper->url->to('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id), '', true); - } - - $this->sendMessage($project_id, $payload); - } - } - - /** - * Send message to the XMPP server - * - * @access public - * @param integer $project_id - * @param string $payload - */ - public function sendMessage($project_id, $payload) - { - try { - $params = $this->getParameters($project_id); - - $options = new Options($params['server']); - $options->setUsername($params['username']); - $options->setPassword($params['password']); - $options->setTo($params['domain']); - $options->setLogger($this->container['logger']); - - $client = new Client($options); - - $channel = new Presence; - $channel->setTo($params['room'])->setNickName($params['nickname']); - $client->send($channel); - - $message = new Message; - $message->setMessage($payload) - ->setTo($params['room']) - ->setType(Message::TYPE_GROUPCHAT); - - $client->send($message); - - $client->disconnect(); - } catch (Exception $e) { - $this->container['logger']->error('Jabber error: '.$e->getMessage()); - } - } -} diff --git a/app/Integration/SlackWebhook.php b/app/Integration/SlackWebhook.php deleted file mode 100644 index 8f4eb422..00000000 --- a/app/Integration/SlackWebhook.php +++ /dev/null @@ -1,126 +0,0 @@ -<?php - -namespace Kanboard\Integration; - -/** - * Slack Webhook - * - * @package integration - * @author Frederic Guillot - */ -class SlackWebhook extends \Kanboard\Core\Base -{ - /** - * Return true if Slack is enabled for this project or globally - * - * @access public - * @param integer $project_id - * @return boolean - */ - public function isActivated($project_id) - { - return $this->config->get('integration_slack_webhook') == 1 || $this->projectIntegration->hasValue($project_id, 'slack', 1); - } - - /** - * Get wehbook url - * - * @access public - * @param integer $project_id - * @return string - */ - public function getWebhookUrl($project_id) - { - if ($this->config->get('integration_slack_webhook') == 1) { - return $this->config->get('integration_slack_webhook_url'); - } - - $options = $this->projectIntegration->getParameters($project_id); - return isset($options['slack_webhook_url']) ? $options['slack_webhook_url'] : ''; - } - - /** - * Get optional Slack channel - * - * @access public - * @param integer $project_id - * @return string - */ - public function getChannel($project_id) - { - $channel = $this->config->get('integration_slack_webhook_channel'); - - if (! empty($channel)) { - return $channel; - } - - $options = $this->projectIntegration->getParameters($project_id); - return isset($options['slack_webhook_channel']) ? $options['slack_webhook_channel'] : ''; - } - - /** - * Send notification to Slack - * - * @access public - * @param integer $project_id Project id - * @param integer $task_id Task id - * @param string $event_name Event name - * @param array $event Event data - */ - public function notify($project_id, $task_id, $event_name, array $event) - { - if ($this->isActivated($project_id)) { - $project = $this->project->getbyId($project_id); - - $event['event_name'] = $event_name; - $event['author'] = $this->user->getFullname($this->session['user']); - - $message = '*['.$project['name'].']* '; - $message .= str_replace('"', '"', $this->projectActivity->getTitle($event)); - $message .= isset($event['task']['title']) ? ' ('.$event['task']['title'].')' : ''; - - if ($this->config->get('application_url')) { - $message .= ' - <'.$this->helper->url->href('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id), false, '', true); - $message .= '|'.t('view the task on Kanboard').'>'; - } - - $this->sendMessage($project_id, $message); - } - } - - /** - * Send message to Slack - * - * @access public - * @param integer $project_id - * @param string $message - */ - public function sendMessage($project_id, $message) - { - $payload = array( - 'text' => $message, - 'username' => 'Kanboard', - 'icon_url' => 'http://kanboard.net/assets/img/favicon.png', - ); - - $this->sendPayload($project_id, $payload); - } - - /** - * Send payload to Slack - * - * @access public - * @param integer $project_id - * @param array $payload - */ - public function sendPayload($project_id, array $payload) - { - $channel = $this->getChannel($project_id); - - if (! empty($channel)) { - $payload['channel'] = $channel; - } - - $this->httpClient->postJson($this->getWebhookUrl($project_id), $payload); - } -} |