Commit 1c1801a9 authored by MBoretto's avatar MBoretto

Some cleanup

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