Commit 1c1801a9 authored by MBoretto's avatar MBoretto

Some cleanup

parent 1d79ce65
...@@ -31,7 +31,7 @@ class DB ...@@ -31,7 +31,7 @@ class DB
* *
* @var array * @var array
*/ */
static protected $mysql_credentials = array(); static protected $mysql_credentials = [];
/** /**
* PDO object * PDO object
...@@ -65,8 +65,8 @@ class DB ...@@ -65,8 +65,8 @@ class DB
try { try {
$pdo = new \PDO($dsn, $credentials['user'], $credentials['password'], $options); $pdo = new \PDO($dsn, $credentials['user'], $credentials['password'], $options);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
//Define table
//Define table
if (!defined('TB_MESSAGES')) { if (!defined('TB_MESSAGES')) {
define('TB_MESSAGES', self::$table_prefix.'messages'); define('TB_MESSAGES', self::$table_prefix.'messages');
} }
...@@ -122,16 +122,12 @@ class DB ...@@ -122,16 +122,12 @@ class DB
$query = 'SELECT * FROM `'.TB_MESSAGES.'`'; $query = 'SELECT * FROM `'.TB_MESSAGES.'`';
$query .= ' ORDER BY '.TB_MESSAGES.'.`update_id` DESC'; $query .= ' ORDER BY '.TB_MESSAGES.'.`update_id` DESC';
$tokens = [];
if (!is_null($limit)) { if (!is_null($limit)) {
//$query .=' LIMIT :limit '; $query .=' LIMIT :limit ';
//$tokens[':limit'] = $limit;
$query .=' LIMIT '.$limit;
} }
//echo $query;
$sth = self::$pdo->prepare($query); $sth = self::$pdo->prepare($query);
//$sth->execute($tokens); $sth->bindParam(':limit', $limit, \PDO::PARAM_STR);
$sth->execute(); $sth->execute();
$results = $sth->fetchAll(\PDO::FETCH_ASSOC); $results = $sth->fetchAll(\PDO::FETCH_ASSOC);
...@@ -189,7 +185,6 @@ class DB ...@@ -189,7 +185,6 @@ class DB
$status = $sth1->execute(); $status = $sth1->execute();
} catch (PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
...@@ -217,7 +212,6 @@ class DB ...@@ -217,7 +212,6 @@ class DB
} }
/** /**
* Insert request in db * Insert request in db
* *
...@@ -234,7 +228,6 @@ class DB ...@@ -234,7 +228,6 @@ class DB
$from = $message->getFrom(); $from = $message->getFrom();
$chat = $message->getChat(); $chat = $message->getChat();
$chat_id = $chat->getId(); $chat_id = $chat->getId();
$date = self::toTimestamp($message->getDate()); $date = self::toTimestamp($message->getDate());
...@@ -246,7 +239,7 @@ class DB ...@@ -246,7 +239,7 @@ class DB
$new_chat_photo = $message->getNewChatPhoto(); $new_chat_photo = $message->getNewChatPhoto();
$left_chat_participant = $message->getLeftChatParticipant(); $left_chat_participant = $message->getLeftChatParticipant();
//inser user and the relation with the chat //insert user and the relation with the chat
self::insertUser($from, $date, $chat); self::insertUser($from, $date, $chat);
//Insert the forwarded message user in users table //Insert the forwarded message user in users table
...@@ -323,7 +316,6 @@ class DB ...@@ -323,7 +316,6 @@ class DB
$delete_chat_photo = $message->getDeleteChatPhoto(); $delete_chat_photo = $message->getDeleteChatPhoto();
$group_chat_created = $message->getGroupChatCreated(); $group_chat_created = $message->getGroupChatCreated();
$sth->bindParam(':update_id', $update_id, \PDO::PARAM_INT); $sth->bindParam(':update_id', $update_id, \PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, \PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, \PDO::PARAM_INT);
$sth->bindParam(':user_id', $from_id, \PDO::PARAM_INT); $sth->bindParam(':user_id', $from_id, \PDO::PARAM_INT);
...@@ -357,8 +349,8 @@ class DB ...@@ -357,8 +349,8 @@ class DB
$sth->bindParam(':new_chat_participant', $new_chat_paticipant, \PDO::PARAM_STR); $sth->bindParam(':new_chat_participant', $new_chat_paticipant, \PDO::PARAM_STR);
$sth->bindParam(':left_chat_participant', $left_chat_paticipant, \PDO::PARAM_STR); $sth->bindParam(':left_chat_participant', $left_chat_paticipant, \PDO::PARAM_STR);
$sth->bindParam(':new_chat_title', $new_chat_title, \PDO::PARAM_STR); $sth->bindParam(':new_chat_title', $new_chat_title, \PDO::PARAM_STR);
//Array of Photosize
//Array of Photosize
$var = []; $var = [];
if (is_array($new_chat_photo)) { if (is_array($new_chat_photo)) {
foreach ($new_chat_photo as $elm) { foreach ($new_chat_photo as $elm) {
...@@ -443,7 +435,6 @@ class DB ...@@ -443,7 +435,6 @@ class DB
} }
$query .= ' ORDER BY '.TB_CHATS.'.`updated_at` ASC'; $query .= ' ORDER BY '.TB_CHATS.'.`updated_at` ASC';
//echo $query."\n";
$sth = self::$pdo->prepare($query); $sth = self::$pdo->prepare($query);
$sth->execute($tokens); $sth->execute($tokens);
......
...@@ -32,7 +32,7 @@ class Chat extends Entity ...@@ -32,7 +32,7 @@ class Chat extends Entity
//$this->type = isset($data['type']) ? $data['type'] : null; //$this->type = isset($data['type']) ? $data['type'] : null;
if ( isset($data['type']) ) { if (isset($data['type'])) {
$this->type = $data['type']; $this->type = $data['type'];
} else { } else {
if ($this->isPrivateChat()) { if ($this->isPrivateChat()) {
......
...@@ -85,16 +85,13 @@ class Telegram ...@@ -85,16 +85,13 @@ class Telegram
* *
* @var string * @var string
*/ */
protected $upload_path; protected $upload_path;
/** /**
* Dowload Path * Dowload Path
* *
* @var string * @var string
*/ */
protected $download_path; protected $download_path;
/** /**
...@@ -110,6 +107,7 @@ class Telegram ...@@ -110,6 +107,7 @@ class Telegram
* @var boolean * @var boolean
*/ */
protected $mysql_enabled = false; protected $mysql_enabled = false;
/** /**
* PDO object * PDO object
* *
...@@ -124,7 +122,6 @@ class Telegram ...@@ -124,7 +122,6 @@ class Telegram
*/ */
protected $commands_config; protected $commands_config;
/** /**
* Message types * Message types
* *
...@@ -141,7 +138,6 @@ class Telegram ...@@ -141,7 +138,6 @@ class Telegram
*/ */
protected $admins_list = []; protected $admins_list = [];
/** /**
* Admin * Admin
* *
...@@ -150,7 +146,6 @@ class Telegram ...@@ -150,7 +146,6 @@ class Telegram
protected $admin_enabled = false; protected $admin_enabled = false;
/** /**
* Constructor * Constructor
* *
...@@ -326,7 +321,6 @@ class Telegram ...@@ -326,7 +321,6 @@ class Telegram
return $this; return $this;
} }
/** /**
* Get custom update string for debug purposes * Get custom update string for debug purposes
* *
...@@ -337,7 +331,6 @@ class Telegram ...@@ -337,7 +331,6 @@ class Telegram
return $this->update; return $this->update;
} }
/** /**
* Handle getUpdates method * Handle getUpdates method
* *
...@@ -355,7 +348,7 @@ class Telegram ...@@ -355,7 +348,7 @@ class Telegram
} else { } else {
$offset = null; $offset = null;
} }
//arrive a server Response object
$ServerResponse = Request::getUpdates([ $ServerResponse = Request::getUpdates([
'offset' => $offset , 'offset' => $offset ,
'limit' => $limit, 'limit' => $limit,
...@@ -405,11 +398,11 @@ class Telegram ...@@ -405,11 +398,11 @@ class Telegram
public function processUpdate(update $update) public function processUpdate(update $update)
{ {
//Load admin Commands //Load admin Commands
if ($this->admin_enabled) { if ($this->admin_enabled) {
$message = $update->getMessage(); $message = $update->getMessage();
//Admin command avaiable in any chats
//$from = $message->getFrom(); //$from = $message->getFrom();
//$user_id = $from->getId(); //$user_id = $from->getId();
...@@ -470,7 +463,6 @@ class Telegram ...@@ -470,7 +463,6 @@ class Telegram
{ {
$class = $this->getCommandClass($command, $update); $class = $this->getCommandClass($command, $update);
//print_r($class);
if (!$class) { if (!$class) {
//handle a generic command or non existing one //handle a generic command or non existing one
return $this->executeCommand('Generic', $update); return $this->executeCommand('Generic', $update);
...@@ -480,8 +472,8 @@ class Telegram ...@@ -480,8 +472,8 @@ class Telegram
return false; return false;
} }
//execute methods will be execute after preexecution //execute() methods will be execute after preexecute() methods
//this for prevent to execute db query witout connection //this for prevent to execute db query without connection
return $class->preExecute(); return $class->preExecute();
} }
...@@ -533,7 +525,6 @@ class Telegram ...@@ -533,7 +525,6 @@ class Telegram
protected function sanitizeCommand($string, $capitalizeFirstCharacter = false) protected function sanitizeCommand($string, $capitalizeFirstCharacter = false)
{ {
$str = str_replace(' ', '', ucwords(str_replace('_', ' ', $string))); $str = str_replace(' ', '', ucwords(str_replace('_', ' ', $string)));
//$str[0] = strtolower($str[0]);
return $str; return $str;
} }
...@@ -596,11 +587,6 @@ class Telegram ...@@ -596,11 +587,6 @@ class Telegram
*/ */
public function setUploadPath($folder) public function setUploadPath($folder)
{ {
//if (!is_dir($folder)) {
// if(!mkdir($folder, 0755, true)) {
// throw new TelegramException('Directory '.$folder.' cant be created');
// }
//}
$this->upload_path = $folder; $this->upload_path = $folder;
return $this; return $this;
} }
...@@ -622,11 +608,6 @@ class Telegram ...@@ -622,11 +608,6 @@ class Telegram
*/ */
public function setDownloadPath($folder) public function setDownloadPath($folder)
{ {
//if (!is_dir($folder)) {
// if(!mkdir($folder, 0755, true)) {
// throw new TelegramException('Directory '.$folder.' cant be created');
// }
//}
$this->download_path = $folder; $this->download_path = $folder;
return $this; return $this;
} }
...@@ -732,6 +713,7 @@ class Telegram ...@@ -732,6 +713,7 @@ class Telegram
return $result; return $result;
} }
/** /**
* Get available message types * Get available message types
* *
...@@ -741,6 +723,7 @@ class Telegram ...@@ -741,6 +723,7 @@ class Telegram
{ {
return $this->message_types; return $this->message_types;
} }
/** /**
* Get list of admins * Get list of admins
* *
......
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