diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c8fe9a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+nbproject/
+test.php
+core/config/common.config.php
+plugins
+sftp-config.json
+.project
\ No newline at end of file
diff --git a/core/ajax/telegram.ajax.php b/core/ajax/telegram.ajax.php
deleted file mode 100644
index 084493a..0000000
--- a/core/ajax/telegram.ajax.php
+++ /dev/null
@@ -1,33 +0,0 @@
-.
- */
-
-try {
- require_once dirname(__FILE__) . '/../../../../core/php/core.inc.php';
- include_file('core', 'authentification', 'php');
-
- if (!isConnect('admin')) {
- throw new Exception(__('401 - Accès non autorisé', __FILE__));
- }
-
-
- throw new Exception(__('Aucune methode correspondante à : ', __FILE__) . init('action'));
- /* * *********Catch exeption*************** */
-} catch (Exception $e) {
- ajax::error(displayExeption($e), $e->getCode());
-}
-?>
diff --git a/core/api/jeeTelegram.php b/core/api/jeeTelegram.php
index 2f4c5cc..80be5e4 100644
--- a/core/api/jeeTelegram.php
+++ b/core/api/jeeTelegram.php
@@ -15,12 +15,12 @@
* You should have received a copy of the GNU General Public License
* along with Jeedom. If not, see .
*/
-header('Content-type: application/json');
+header("Content-Type: application/json");
require_once dirname(__FILE__) . "/../../../../core/php/core.inc.php";
if (!jeedom::apiAccess(init('apikey'), 'telegram')) {
- echo __('Clef API non valide, vous n\'êtes pas autorisé à effectuer cette action (telegram)', __FILE__);
- die();
+ echo __('Clef API non valide, vous n\'êtes pas autorisé à effectuer cette action (telegram)', __FILE__);
+ die();
}
$content = file_get_contents('php://input');
@@ -37,150 +37,129 @@
$parameters = array();
if ($json["message"]["chat"]["type"] == 'private') {
- if (isset($json["message"]["from"]["username"])) {
- $username = $json["message"]["from"]["username"];
- } else {
- $username = $json["message"]["from"]["first_name"];
- }
+ $username = isset($json["message"]["from"]["username"]) ? $json["message"]["from"]["username"] : $json["message"]["from"]["first_name"];
} else if ($json["message"]["chat"]["type"] == 'group') {
- $username = $json["message"]["chat"]["title"];
+ $username = $json["message"]["chat"]["title"];
} else {
- log::add('telegram', 'debug', 'Message non supporté');
- return;
+ log::add('telegram', 'debug', 'Message non supporté');
+ die();
}
log::add('telegram', 'debug', 'Recu message de ' . $username);
-$username = strtolower(strtr(utf8_decode($username), utf8_decode('ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïñòóôõöøùúûüýÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƒƠơƯưǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǺǻǼǽǾǿ'), 'AAAAAAAECEEEEIIIIDNOOOOOOUUUUYsaaaaaaaeceeeeiiiinoooooouuuuyyAaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIJijJjKkLlLlLlLlllNnNnNnnOoOoOoOEoeRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzsfOoUuAaIiOoUuUuUuUuUuAaAEaeOo'));
-$user = user::byLogin($username);
+
+$cmd_user = $eqLogic->getCmd('action', $json["message"]["chat"]["id"]);
+$parameters['reply_cmd'] = $cmd_user;
+$user = user::byId($cmd_user->getConfiguration('user'));
if (is_object($user)) {
- $parameters['profile'] = $username;
- $parameters['reply_cmd'] = $eqLogic->getCmd('action', $json["message"]["chat"]["id"]);
+ $parameters['profile'] = $user->getLogin();
}
foreach ($eqLogic->getCmd('action') as $cmd) {
if ($json["message"]["chat"]["id"] == $cmd->getConfiguration('chatid') && $cmd->getCache('storeVariable', 'none') != 'none') {
- $dataStore = new dataStore();
- $dataStore->setType('scenario');
- $dataStore->setKey($cmd->getCache('storeVariable', 'none'));
- $dataStore->setValue($json["message"]["text"]);
- $dataStore->setLink_id(-1);
- $dataStore->save();
- $cmd->setCache('storeVariable', 'none');
- $cmd->save();
+ $cmd->askResponse($json["message"]["text"]);
echo json_encode(array('text' => ''));
- return;
+ die();
}
}
$eqLogic->checkAndUpdateCmd('sender', trim($json["message"]["from"]["id"]));
$eqLogic->checkAndUpdateCmd('chat', trim($json["message"]["chat"]["id"]));
if (isset($json["message"]["text"])) {
- $eqLogic->checkAndUpdateCmd('text', $json["message"]["text"]);
-
- $cmd_user = $eqLogic->getCmd('action', $json["message"]["chat"]["id"]);
- if (!is_object($cmd_user)) {
- if ($eqLogic->getConfiguration('isAccepting') == 1) {
- $cmd_user = new telegramCmd();
- $cmd_user->setLogicalId($json["message"]["chat"]["id"]);
- $cmd_user->setIsVisible(1);
- $cmd_user->setName($username . ' - ' . $json["message"]["chat"]["id"]);
- $cmd_user->setConfiguration('interact',0);
- $cmd_user->setConfiguration('chatid',$json["message"]["chat"]["id"]);
- $cmd_user->setType('action');
- $cmd_user->setSubType('message');
- $cmd_user->setEqLogic_id($eqLogic->getId());
- $cmd_user->setDisplay('title_disable', 1);
- $cmd_user->setDisplay('message_placeholder','message');
- } else {
- return;
- }
- }
- if (isset($json["message"]["chat"]["title"])) {
- $cmd_user->setConfiguration('title',$json["message"]["chat"]["title"]);
- $cmd_user->save();
- } else {
- if (isset($json["message"]["from"]["username"])) {
- $cmd_user->setConfiguration('username',$json["message"]["from"]["username"]);
- $cmd_user->save();
- }
- if (isset($json["message"]["from"]["first_name"])) {
- $cmd_user->setConfiguration('last_name',$json["message"]["from"]["first_name"]);
- }
- if (isset($json["message"]["from"]["last_name"])) {
- $cmd_user->setConfiguration('last_name',$json["message"]["from"]["last_name"]);
- }
- }
- $cmd_user->save();
-
- if (isset($json["message"]["reply_to_message"])) {
- return;
- }
+ $eqLogic->checkAndUpdateCmd('text', $json["message"]["text"]);
+ if (!is_object($cmd_user)) {
+ if ($eqLogic->getConfiguration('isAccepting') != 1) {
+ die();
+ }
+ $cmd_user = new telegramCmd();
+ $cmd_user->setLogicalId($json["message"]["chat"]["id"]);
+ $cmd_user->setIsVisible(1);
+ $cmd_user->setName($username . ' - ' . $json["message"]["chat"]["id"]);
+ $cmd_user->setConfiguration('interact', 1);
+ $cmd_user->setConfiguration('chatid', $json["message"]["chat"]["id"]);
+ $cmd_user->setType('action');
+ $cmd_user->setSubType('message');
+ $cmd_user->setEqLogic_id($eqLogic->getId());
+ $cmd_user->setDisplay('message_placeholder', __('Options', __FILE__));
+ }
+ if (isset($json["message"]["chat"]["title"])) {
+ $cmd_user->setConfiguration('title', $json["message"]["chat"]["title"]);
+ } else {
+ if (isset($json["message"]["from"]["username"])) {
+ $cmd_user->setConfiguration('username', $json["message"]["from"]["username"]);
+ }
+ if (isset($json["message"]["from"]["first_name"])) {
+ $cmd_user->setConfiguration('last_name', $json["message"]["from"]["first_name"]);
+ }
+ if (isset($json["message"]["from"]["last_name"])) {
+ $cmd_user->setConfiguration('last_name', $json["message"]["from"]["last_name"]);
+ }
+ }
+ $cmd_user->save();
+ if (isset($json["message"]["reply_to_message"])) {
+ die();
+ }
- if ($cmd_user->getConfiguration('interact') == 1) {
- $reply = interactQuery::tryToReply(trim($json["message"]["text"]), $parameters);
- } else {
- $reply['reply'] = $eqLogic->getConfiguration('reply', 'Message recu');
- }
- $file_id = '';
-}
-if (isset($json["message"]["document"])) {
- $file_id = $json["message"]["document"]["file_id"];
- $file_name = $json["message"]["document"]["file_name"];
- $reply['reply'] = $eqLogic->getConfiguration('reply', 'Message recu') . ' (Document)';
-}
-if (isset($json["message"]["photo"])) {
- $file_id = $json["message"]["photo"]["file_id"];
- $file_name = $username . '.png';
- $reply['reply'] = $eqLogic->getConfiguration('reply', 'Message recu') . ' (Photo)';
-}
-if (isset($json["message"]["video"])) {
- $file_id = $json["message"]["video"]["file_id"];
- $file_name = $username . '.mp4';
- $reply['reply'] = $eqLogic->getConfiguration('reply', 'Message recu') . ' (Vidéo)';
-}
-if (isset($json["message"]["location"])) {
- $file_id = '';
- $cmd_user = $eqLogic->getCmd('action', $json["message"]["chat"]["id"]);
- if (is_object($cmd_user)) {
- $geoloc = str_replace('#','',$cmd_user->getConfiguration('cmdgeoloc', ''));
- //log::add('telegram', 'debug', $geoloc);
- $geolocCmd = geolocCmd::byId($geoloc);
- if (is_object($geolocCmd)) {
- $geolocCmd->event($json["message"]["location"]["latitude"] . ',' . $json["message"]["location"]["longitude"]);
- $geolocCmd->save();
- }
- }
- $reply['reply'] = $eqLogic->getConfiguration('reply', 'Message recu') . ' (Localisation)';
+ if ($cmd_user->getConfiguration('interact') == 1) {
+ $reply = interactQuery::tryToReply(trim($json["message"]["text"]), $parameters);
+ } else {
+ $reply['reply'] = $eqLogic->getConfiguration('reply', 'Message recu');
+ }
+ $file_id = '';
+} else if (isset($json["message"]["document"])) {
+ $file_id = $json["message"]["document"]["file_id"];
+ $file_name = $json["message"]["document"]["file_name"];
+ $reply['reply'] = $eqLogic->getConfiguration('reply', 'Message recu') . ' (Document)';
+} else if (isset($json["message"]["photo"])) {
+ $file_id = $json["message"]["photo"]["file_id"];
+ $file_name = $username . '.png';
+ $reply['reply'] = $eqLogic->getConfiguration('reply', 'Message recu') . ' (Photo)';
+} else if (isset($json["message"]["video"])) {
+ $file_id = $json["message"]["video"]["file_id"];
+ $file_name = $username . '.mp4';
+ $reply['reply'] = $eqLogic->getConfiguration('reply', 'Message recu') . ' (Vidéo)';
+} else if (isset($json["message"]["location"])) {
+ $file_id = '';
+ $cmd_user = $eqLogic->getCmd('action', $json["message"]["chat"]["id"]);
+ if (is_object($cmd_user)) {
+ $geoloc = str_replace('#', '', $cmd_user->getConfiguration('cmdgeoloc', ''));
+ $geolocCmd = geolocCmd::byId($geoloc);
+ if (is_object($geolocCmd)) {
+ $geolocCmd->event($json["message"]["location"]["latitude"] . ',' . $json["message"]["location"]["longitude"]);
+ $geolocCmd->save();
+ }
+ }
+ $reply['reply'] = $eqLogic->getConfiguration('reply', 'Message recu') . ' (Localisation)';
}
if ($eqLogic->getConfiguration('noreply')) {
- return;
+ die();
}
-$answer = array('method' => 'sendMessage', 'chat_id' => $json["message"]["chat"]["id"], "reply_to_message_id" => $json["message"]["message_id"], "text" => $reply['reply']);
-header("Content-Type: application/json");
+$answer = array(
+ 'method' => 'sendMessage',
+ 'chat_id' => $json['message']['chat']['id'],
+ 'text' => $reply['reply'],
+);
+
echo json_encode($answer);
-if ($file_id != '' && $eqLogic->getConfiguration('savepath','') != '') {
- $url = "https://api.telegram.org/bot" . trim($eqLogic->getConfiguration('bot_token')) . '/getFile';
- $post_fields['file_id'] = $file_id;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
- $output = json_decode(curl_exec($ch), true);
- $local_file_path = $eqLogic->getConfiguration('savepath') . '/' . $file_name;
- $file_url = "https://api.telegram.org/file/bot" . trim($eqLogic->getConfiguration('bot_token')) . "/" . $output["result"]["file_path"];
- $in = fopen($file_url, "rb");
- $out = fopen($local_file_path, "wb");
- while ($chunk = fread($in, 8192)) {
- fwrite($out, $chunk, 8192);
- }
- fclose($in);
- fclose($out);
- $eqLogic->checkAndUpdateCmd('text', 'file:' . $local_file_path);
+if ($file_id != '' && $eqLogic->getConfiguration('savepath', '') != '') {
+ $url = "https://api.telegram.org/bot" . trim($eqLogic->getConfiguration('bot_token')) . '/getFile';
+ $post_fields['file_id'] = $file_id;
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
+ $output = json_decode(curl_exec($ch), true);
+ $local_file_path = $eqLogic->getConfiguration('savepath') . '/' . $file_name;
+ $file_url = "https://api.telegram.org/file/bot" . trim($eqLogic->getConfiguration('bot_token')) . "/" . $output["result"]["file_path"];
+ $in = fopen($file_url, "rb");
+ $out = fopen($local_file_path, "wb");
+ while ($chunk = fread($in, 8192)) {
+ fwrite($out, $chunk, 8192);
+ }
+ fclose($in);
+ fclose($out);
+ $eqLogic->checkAndUpdateCmd('text', 'file:' . $local_file_path);
}
-
-return true;
-
-?>
+die();
\ No newline at end of file
diff --git a/core/class/.htaccess b/core/class/.htaccess
new file mode 100644
index 0000000..7d3aaf1
--- /dev/null
+++ b/core/class/.htaccess
@@ -0,0 +1,2 @@
+Order allow,deny
+Deny from all
\ No newline at end of file
diff --git a/core/class/telegram.class.php b/core/class/telegram.class.php
index b60455c..4df7898 100644
--- a/core/class/telegram.class.php
+++ b/core/class/telegram.class.php
@@ -1,285 +1,250 @@
.
-*/
+ *
+ * Jeedom is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Jeedom is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jeedom. If not, see .
+ */
require_once dirname(__FILE__) . '/../../../../core/php/core.inc.php';
class telegram extends eqLogic {
- public static function health() {
- $return = array();
- if (strpos(network::getNetworkAccess('external'),'https') !== false) {
- $https = true;
- } else {
- $https = false;
- }
- $return[] = array(
- 'test' => __('HTTPS', __FILE__),
- 'result' => ($https) ? __('OK', __FILE__) : __('NOK', __FILE__),
- 'advice' => ($https) ? '' : __('Votre Jeedom ne permet pas le fonctionnement de Telegram sans HTTPS', __FILE__),
- 'state' => $https,
- );
- return $return;
- }
- public function postSave() {
- $text = $this->getCmd(null, 'text');
- if (!is_object($text)) {
- $text = new telegramCmd();
- $text->setLogicalId('text');
- $text->setIsVisible(0);
- $text->setName(__('Message', __FILE__));
- }
- $text->setType('info');
- $text->setSubType('string');
- $text->setEqLogic_id($this->getId());
- $text->save();
-
- $sender = $this->getCmd(null, 'sender');
- if (!is_object($sender)) {
- $sender = new telegramCmd();
- $sender->setLogicalId('sender');
- $sender->setIsVisible(0);
- $sender->setName(__('Expediteur', __FILE__));
- }
- $sender->setType('info');
- $sender->setSubType('string');
- $sender->setEqLogic_id($this->getId());
- $sender->save();
-
- $sender = $this->getCmd(null, 'chat');
- if (!is_object($sender)) {
- $sender = new telegramCmd();
- $sender->setLogicalId('chat');
- $sender->setIsVisible(0);
- $sender->setName(__('Chat', __FILE__));
- }
- $sender->setType('info');
- $sender->setSubType('string');
- $sender->setEqLogic_id($this->getId());
- $sender->save();
-
- $alluser = $this->getCmd(null, 'alluser');
- if (!is_object($alluser)) {
- $alluser = new telegramCmd();
- $alluser->setLogicalId('alluser');
- $alluser->setIsVisible(1);
- $alluser->setName(__('Tous', __FILE__));
- $alluser->setType('action');
- $alluser->setConfiguration('chatid','Tous les utilisateurs');
- $alluser->setConfiguration('firstname','Tous les utilisateurs');
- $alluser->setConfiguration('username','Tous les utilisateurs');
- $alluser->setSubType('message');
- $alluser->setEqLogic_id($this->getId());
- $alluser->setDisplay('title_disable', 1);
- $alluser->setDisplay('message_placeholder','message');
- $alluser->save();
- }
-
- $url = network::getNetworkAccess('external') . '/plugins/telegram/core/api/jeeTelegram.php?apikey=' . jeedom::getApiKey('telegram') . '&id=' . $this->getId();
- $token = trim($this->getConfiguration('bot_token'));
-
- $request_http = new com_http('https://api.telegram.org/bot' . $token . '/setWebhook');
- log::add('telegram', 'debug', $url);
- $post = array(
- 'url' => $url
- );
-
- $request_http->setPost($post);
- try {
- $result = $request_http->exec(60, 1);
- } catch (Exception $e) {
- }
- log::add('telegram', 'debug', $result);
-
- }
+ /* * *************************Attributs****************************** */
+
+ /* * ***********************Methode static*************************** */
+
+ public static function health() {
+ $https = strpos(network::getNetworkAccess('external'), 'https') !== false;
+ $return[] = array(
+ 'test' => __('HTTPS', __FILE__),
+ 'result' => ($https) ? __('OK', __FILE__) : __('NOK', __FILE__),
+ 'advice' => ($https) ? '' : __('Votre Jeedom ne permet pas le fonctionnement de Telegram sans HTTPS', __FILE__),
+ 'state' => $https,
+ );
+ return $return;
+ }
+
+ /* * *********************Methode d'instance************************* */
+
+ public function postSave() {
+ $text = $this->getCmd(null, 'text');
+ if (!is_object($text)) {
+ $text = new telegramCmd();
+ $text->setLogicalId('text');
+ $text->setIsVisible(0);
+ $text->setName(__('Message', __FILE__));
+ }
+ $text->setType('info');
+ $text->setSubType('string');
+ $text->setEqLogic_id($this->getId());
+ $text->save();
+
+ $sender = $this->getCmd(null, 'sender');
+ if (!is_object($sender)) {
+ $sender = new telegramCmd();
+ $sender->setLogicalId('sender');
+ $sender->setIsVisible(0);
+ $sender->setName(__('Expediteur', __FILE__));
+ }
+ $sender->setType('info');
+ $sender->setSubType('string');
+ $sender->setEqLogic_id($this->getId());
+ $sender->save();
+
+ $sender = $this->getCmd(null, 'chat');
+ if (!is_object($sender)) {
+ $sender = new telegramCmd();
+ $sender->setLogicalId('chat');
+ $sender->setIsVisible(0);
+ $sender->setName(__('Chat', __FILE__));
+ }
+ $sender->setType('info');
+ $sender->setSubType('string');
+ $sender->setEqLogic_id($this->getId());
+ $sender->save();
+
+ $alluser = $this->getCmd(null, 'alluser');
+ if (!is_object($alluser)) {
+ $alluser = new telegramCmd();
+ $alluser->setLogicalId('alluser');
+ $alluser->setIsVisible(1);
+ $alluser->setName(__('Tous', __FILE__));
+ $alluser->setType('action');
+ $alluser->setConfiguration('chatid', 'Tous les utilisateurs');
+ $alluser->setConfiguration('firstname', 'Tous les utilisateurs');
+ $alluser->setConfiguration('username', 'Tous les utilisateurs');
+ $alluser->setSubType('message');
+ $alluser->setEqLogic_id($this->getId());
+ $alluser->setDisplay('message_placeholder', __('Options', __FILE__));
+ $alluser->save();
+ }
+ $url = network::getNetworkAccess('external') . '/plugins/telegram/core/api/jeeTelegram.php?apikey=' . jeedom::getApiKey('telegram') . '&id=' . $this->getId();
+ $token = trim($this->getConfiguration('bot_token'));
+ $request_http = new com_http('https://api.telegram.org/bot' . $token . '/setWebhook');
+ log::add('telegram', 'debug', $url);
+ $post = array(
+ 'url' => $url,
+ );
+ $request_http->setPost($post);
+ try {
+ $result = $request_http->exec(60, 1);
+ } catch (Exception $e) {
+ }
+ log::add('telegram', 'debug', $result);
+ }
+
+ /* * **********************Getteur Setteur*************************** */
}
class telegramCmd extends cmd {
- public function preSave() {
- if ($this->getSubtype() == 'message') {
- $this->setDisplay('title_disable', 0);
- }
- }
-
- public function sendTelegram($url,$type,$post_fields) {
- $ch = curl_init();
- if ($type == 'file') {
- $header = "Content-Type:multipart/form-data";
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- $header
- ));
- }/* else {
- $header = "Content-Type:application/x-www-form-urlencoded";
- }*/
-
- log::add('telegram', 'debug',$url);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
- //curl_setopt($ch, CURLOPT_TIMEOUT, 60);
- $output = curl_exec($ch);
- }
-
- public function execute($_options = array()) {
- $eqLogic = $this->getEqLogic();
- $toSend = array();
- if ($this->getLogicalId() == 'alluser'){
- foreach($eqLogic->getCmd('action') as $cmd){
- if ($cmd->getLogicalId() != 'alluser'){
- $toSend[]= $cmd->getConfiguration('chatid');
- }
- }
- } else {
- $toSend[] = $this->getConfiguration('chatid');
- }
- $request_http = "https://api.telegram.org/bot" . trim($eqLogic->getConfiguration('bot_token'));
-
- foreach ($toSend as $chatid){
- $data = array(
- 'chat_id' => $chatid
- );
- $data['chat_id'] = $chatid;
- $options = arg2array($_options['message']);
- if ($eqLogic->getConfiguration('silentnotif') == true || (isset($options['notify']) && $options['notify'] == 0)) {
- $data['disable_notification'] = 1;
- }
- if (isset($_options['answer'])) {
- $replyMarkup = array(
- 'keyboard' => array(
- $_options['answer']
- ),
- 'one_time_keyboard' => true,
- 'resize_keyboard' => true
- );
- $encodedMarkup = json_encode($replyMarkup);
- //$data['reply_markup'] = '{"keyboard": [["' . implode('""],["', $_options['answer']) . '"]],"one_time_keyboard": true}';
- $data['reply_markup'] = $encodedMarkup;
- log::add('telegram', 'debug', $data['reply_markup']);
- }
-
- if (isset($options['location'])) {
- if (strrpos($options['location'],'#') !== false) {
- $geolocCmd = geolocCmd::byId(str_replace('#','',$options['location']));
- if ($geolocCmd->getConfiguration('mode') == 'fixe') {
- $geolocval = $geolocCmd->getConfiguration('coordinate');
- } else {
- $geolocval = $geolocCmd->execCmd();
- }
- } else {
- $geolocval = $options['location'];
- }
- $coordinate = explode(',',$geolocval);
- $data['latitude'] = $coordinate[0];
- $data['longitude'] = $coordinate[1];
- $url = $request_http . "/sendLocation";
- //log::add('telegram', 'debug', print_r($data, true));
- $this->sendTelegram($url,'message',$data);
- }
-
- if (isset($options['tts'])) {
- if (is_file(realpath($options['tts']))) {
- $data['voice'] = new CURLFile(realpath($options['tts']));
- } else {
- exec("pico2wave -l fr-FR -w /tmp/voice.wav \"" . $options['tts'] . "\"");
- exec("opusenc --bitrate 64 /tmp/voice.wav /tmp/voice.ogg");
- $data['voice'] = new CURLFile(realpath('/tmp/voice.ogg'));
- }
- $url = $request_http . "/sendVoice";
- $this->sendTelegram($url,'file',$data);
- return;
- }
-
- if (isset($options['file'])) {
- if (strrpos($options['file'],',') !== false) {
- $files = explode(',',$options['file']);
- foreach ($files as $file) {
- $_options['files'][] = $file;
- }
- } else {
- $_options['files'][] = $options['file'];
- }
- }
-
- if (isset($options['message'])) {
- $_options['message'] = $options['message'];
- }
-
- if (!isset($_options['files']) || !is_array($_options['files']) || (isset($options['message']) && count($options) > 0)) {
- $data['text'] = trim($_options['message']);
- if ($eqLogic->getConfiguration('nohtml') == true || (isset($options['html']) && $options['html'] == 0)) {
- $data['parse_mode'] = 'HTML';
- }
- $url = $request_http . "/sendMessage";
- //log::add('telegram', 'debug', print_r($data, true));
- $this->sendTelegram($url,'message',$data);
- }
- //log::add('telegram', 'debug', print_r($result, true));
-
- if (isset($_options['files']) && is_array($_options['files'])) {
- foreach ($_options['files'] as $file) {
- $ext = pathinfo($file, PATHINFO_EXTENSION);
- if ($ext == 'mp4'){
- copy($file , substr($file,0,-3) . 'mkv');
- $file = substr($file,0,-3) . 'mkv';
- }
- $photolist = "gif,jpeg,jpg,png";
- $videolist = "avi,mpeg,mpg,mkv,mp4,mpe";
- $audiolist = "ogg,mp3";
- if (strpos($photolist,$ext) !== false) {
- $post_fields = array('chat_id' => $chatid,
- 'text' => trim($_options['message']),
- 'photo' => new CURLFile(realpath($file)),
- 'caption' => pathinfo($file, PATHINFO_FILENAME)
- );
- $url = $request_http . "/sendPhoto?chat_id=" . $chatid;
- } else if (strpos($audiolist,$ext) !== false) {
- $post_fields = array('chat_id' => $chatid,
- 'text' => trim($_options['title'] . ' ' . $_options['message']),
- 'audio' => new CURLFile(realpath($file)),
- 'title' => pathinfo($file, PATHINFO_FILENAME)
- );
- $url = $request_http . "/sendAudio";
- } else if (strpos($videolist,$ext) !== false) {
- $post_fields = array('chat_id' => $chatid,
- 'text' => trim($_options['title'] . ' ' . $_options['message']),
- 'video' => new CURLFile(realpath($file)),
- 'caption' => pathinfo($file, PATHINFO_FILENAME)
- );
- $url = $request_http . "/sendVideo";
- } else {
- $post_fields = array('chat_id' => $chatid,
- 'text' => trim($_options['title'] . ' ' . $_options['message']),
- 'document' => new CURLFile(realpath($file)),
- 'caption' => pathinfo($file, PATHINFO_FILENAME)
- );
- $url = $request_http . "/sendDocument";
- }
- $this->sendTelegram($url,'file',$post_fields);
- if ($ext == 'mp4'){
- unlink($file);
- }
- }
- }
- }
-}
-
-}
-
-?>
+ /* * *************************Attributs****************************** */
+
+ /* * ***********************Methode static*************************** */
+
+ /* * *********************Methode d'instance************************* */
+
+ public function sendTelegram($_url, $_type, $_to, $_data) {
+ foreach ($_to as $chatid) {
+ $_data['chat_id'] = $chatid;
+ $request_http = new com_http($_url);
+ if ($_type == 'file') {
+ $request_http->setHeader(array("Content-Type:multipart/form-data"));
+ }
+ $request_http->setPost($_data);
+ log::add('telegram', 'debug', 'Call url ' . $_url . ' with option ' . print_r($_data, true));
+ $output = $request_http->exec();
+ log::add('telegram', 'debug', 'Result : ' . $output);
+ if (!is_json($output)) {
+ throw new Exception(__('Erreur lors de l\'envoi telegram : ', __FILE__) . $output);
+ }
+ $result = json_decode($output, true);
+ if (!$result['ok']) {
+ throw new Exception(__('Erreur lors de l\'envoi telegram : ', __FILE__) . $output);
+ }
+ }
+ }
+
+ public function execute($_options = array()) {
+ if ($this->getType() == 'info') {
+ return;
+ }
+ $data = array();
+ $options = arg2array($_options['message']);
+ $eqLogic = $this->getEqLogic();
+ $to = array();
+ if ($this->getLogicalId() == 'alluser') {
+ foreach ($eqLogic->getCmd('action') as $cmd) {
+ if ($cmd->getLogicalId() != 'alluser') {
+ $to[] = $cmd->getConfiguration('chatid');
+ }
+ }
+ } else {
+ $to[] = $this->getConfiguration('chatid');
+ }
+ $request_http = "https://api.telegram.org/bot" . trim($eqLogic->getConfiguration('bot_token'));
+ $data['disable_notification'] = (isset($options['disable_notify'])) ? $options['disable_notify'] : $eqLogic->getConfiguration('disable_notify', 0);
+ $data['parse_mode'] = (isset($options['parse_mode'])) ? $options['parse_mode'] : $eqLogic->getConfiguration('parse_mode', 'HTML');
+
+ if (isset($_options['answer'])) {
+ $data['reply_markup'] = json_encode(array(
+ 'keyboard' => array($_options['answer']),
+ 'one_time_keyboard' => true,
+ 'resize_keyboard' => true,
+ ));
+ }
+
+ if (isset($_options['title']) && $_options['title'] != '') {
+ $data['text'] = trim($_options['title']);
+ $url = $request_http . "/sendMessage";
+ $this->sendTelegram($url, 'message', $to, $data);
+ }
+
+ if (isset($options['location'])) {
+ if (strrpos($options['location'], '#') !== false) {
+ $geolocCmd = geolocCmd::byId(str_replace('#', '', $options['location']));
+ $geolocval = ($geolocCmd->getConfiguration('mode') == 'fixe') ? $geolocCmd->getConfiguration('coordinate') : $geolocCmd->execCmd();
+ } else {
+ $geolocval = $options['location'];
+ }
+ $coordinate = explode(',', $geolocval);
+ $data['latitude'] = $coordinate[0];
+ $data['longitude'] = $coordinate[1];
+ $url = $request_http . "/sendLocation";
+ $this->sendTelegram($url, 'message', $to, $data);
+ }
+
+ if (isset($options['tts'])) {
+ if (is_file(realpath($options['tts']))) {
+ $data['voice'] = new CURLFile(realpath($options['tts']));
+ } else {
+ exec("pico2wave -l fr-FR -w /tmp/voice.wav \"" . $options['tts'] . "\"");
+ exec("opusenc --bitrate 64 /tmp/voice.wav /tmp/voice.ogg");
+ $data['voice'] = new CURLFile(realpath('/tmp/voice.ogg'));
+ }
+ $url = $request_http . "/sendVoice";
+ $this->sendTelegram($url, 'file', $to, $data);
+ }
+
+ if (isset($options['file'])) {
+ $_options['files'] = explode(',', $options['file']);
+ }
+
+ if (isset($_options['files']) && is_array($_options['files'])) {
+ foreach ($_options['files'] as $file) {
+ $ext = pathinfo($file, PATHINFO_EXTENSION);
+ if ($ext == 'mp4') {
+ copy($file, substr($file, 0, -3) . 'mkv');
+ $file = substr($file, 0, -3) . 'mkv';
+ }
+ if (in_array($ext, array('gif', 'jpeg', 'jpg', 'png'))) {
+ $post_fields = array('chat_id' => $chatid,
+ 'text' => trim($_options['message']),
+ 'photo' => new CURLFile(realpath($file)),
+ 'caption' => pathinfo($file, PATHINFO_FILENAME),
+ );
+ $url = $request_http . "/sendPhoto?chat_id=" . $chatid;
+ } else if (in_array($ext, array('ogg', 'mp3'))) {
+ $post_fields = array('chat_id' => $chatid,
+ 'text' => trim($_options['title'] . ' ' . $_options['message']),
+ 'audio' => new CURLFile(realpath($file)),
+ 'title' => pathinfo($file, PATHINFO_FILENAME),
+ );
+ $url = $request_http . "/sendAudio";
+ } else if (in_array($ext, array('avi', 'mpeg', 'mpg', 'mkv', 'mp4', 'mpe'))) {
+ $post_fields = array('chat_id' => $chatid,
+ 'text' => trim($_options['title'] . ' ' . $_options['message']),
+ 'video' => new CURLFile(realpath($file)),
+ 'caption' => pathinfo($file, PATHINFO_FILENAME),
+ );
+ $url = $request_http . "/sendVideo";
+ } else {
+ $post_fields = array('chat_id' => $chatid,
+ 'text' => trim($_options['title'] . ' ' . $_options['message']),
+ 'document' => new CURLFile(realpath($file)),
+ 'caption' => pathinfo($file, PATHINFO_FILENAME),
+ );
+ $url = $request_http . "/sendDocument";
+ }
+ $this->sendTelegram($url, 'file', $to, $post_fields);
+ if ($ext == 'mp4') {
+ unlink($file);
+ }
+ }
+ }
+ }
+
+ /* * **********************Getteur Setteur*************************** */
+
+}
\ No newline at end of file
diff --git a/core/i18n/.htaccess b/core/i18n/.htaccess
new file mode 100644
index 0000000..7d3aaf1
--- /dev/null
+++ b/core/i18n/.htaccess
@@ -0,0 +1,2 @@
+Order allow,deny
+Deny from all
\ No newline at end of file
diff --git a/desktop/js/telegram.js b/desktop/js/telegram.js
index 729119d..b7cb0a1 100644
--- a/desktop/js/telegram.js
+++ b/desktop/js/telegram.js
@@ -33,29 +33,25 @@ function addCmdToTable(_cmd) {
tr += '
';
tr += ' ';
tr += ' ';
- if (isset(_cmd.type) && _cmd.type == 'info') {
- tr += ' ';
- }else{
- tr += ' ';
- }
+ tr += ' ';
tr += ' ';
tr += ' ';
if (!isset(_cmd.type) || _cmd.type == 'action') {
- tr += '';
- tr += 'Action ';
- tr += ' ';
- tr += '';
- tr += ' ';
- tr += ' ';
tr += '';
tr += ' ';
tr += ' ';
tr += '';
- tr += ' ';
+ if(_cmd.logicalId != 'alluser'){
+ tr += ' ';
+ }
tr += ' ';
tr += '';
- tr += ' ';
- tr += ' {{Rechercher équipement}} ';
+ tr += '';
tr += ' ';
tr += '';
tr += ' ';
@@ -64,11 +60,6 @@ function addCmdToTable(_cmd) {
tr += ' ';
tr += ' ';
} else {
- tr += '';
- tr += 'Info ';
- tr += ' ';
- tr += '';
- tr += ' ';
tr += '';
tr += ' ';
tr += '';
@@ -96,6 +87,21 @@ function addCmdToTable(_cmd) {
tr += '';
$('#table_cmd tbody').append(tr);
$('#table_cmd tbody tr:last').setValues(_cmd, '.cmdAttr');
+ var tr = $('#table_cmd tbody tr:last');
+ jeedom.user.all({
+ error: function (error) {
+ $('#div_alert').showAlert({message: error.message, level: 'danger'});
+ },
+ success: function (data) {
+ var option = 'Aucun ';
+ for (var i in data) {
+ option += '' + data[i].login + ' ';
+ }
+ tr.find('.cmdAttr[data-l1key=configuration][data-l2key=user]').empty().append(option);
+ tr.setValues(_cmd, '.cmdAttr');
+ modifyWithoutSave = false;
+ }
+});
if (isset(_cmd.type)) {
$('#table_cmd tbody tr:last .cmdAttr[data-l1key=type]').value(init(_cmd.type));
}
diff --git a/desktop/php/telegram.php b/desktop/php/telegram.php
index 3e2dd39..e94744b 100644
--- a/desktop/php/telegram.php
+++ b/desktop/php/telegram.php
@@ -1,11 +1,11 @@
getId());
+$eqLogics = eqLogic::byType($plugin->getId());
?>
-
-
-
-
{{Mes Telegram}}
-
-
-
-
-
-
- Ajouter
-
- getIsEnable()) ? '' : jeedom::getConfiguration('eqLogic:style:noactive');
- echo '
';
- echo "
";
- echo ' ';
- echo " ";
- echo '
' . $eqLogic->getHumanName(true, true) . ' ';
- echo '
';
- }
- ?>
+foreach ($eqLogics as $eqLogic) {
+ echo '
' . $eqLogic->getHumanName(true) . ' ';
+}
+?>
+
+
+
+
+
+
{{Mes Telegrams}}
+
+
+ getIsEnable()) ? '' : jeedom::getConfiguration('eqLogic:style:noactive');
+ echo '
';
+ echo "
";
+ echo ' ';
+ echo " ";
+ echo '
' . $eqLogic->getHumanName(true, true) . ' ';
+ echo '
';
+}
+?>
+
+
-
-
+
+
diff --git a/plugin_info/.htaccess b/plugin_info/.htaccess
new file mode 100644
index 0000000..ccc3363
--- /dev/null
+++ b/plugin_info/.htaccess
@@ -0,0 +1,5 @@
+Order allow,deny
+
+ allow from all
+
+Deny from all
\ No newline at end of file