+ ', $result);
+ $asd = explode("", $cose["1"]);
+ $api_hash = $asd["0"];
+ }
+
+}
diff --git a/src/danog/MadelineProto/Wrappers/ApiStart.php b/src/danog/MadelineProto/Wrappers/ApiStart.php
new file mode 100644
index 000000000..5c871724c
--- /dev/null
+++ b/src/danog/MadelineProto/Wrappers/ApiStart.php
@@ -0,0 +1,112 @@
+.
+*/
+
+namespace danog\MadelineProto\Wrappers;
+
+/**
+ * Manages simple logging in and out.
+ */
+trait ApiStart
+{
+ public function api_start()
+ {
+ if (php_sapi_name() === 'cli') {
+ if (!function_exists('readline')) {
+ function readline($prompt = null)
+ {
+ if ($prompt) {
+ echo $prompt;
+ }
+ $fp = fopen('php://stdin', 'r');
+ $line = rtrim(fgets($fp, 1024));
+
+ return $line;
+ }
+ }
+ if (strpos($res = readline('You did not define a valid API ID/API hash. Do you want to define it now manually, or automatically? (m/a): '), 'm') !== false) {
+ echo '1) Login to my.telegram.org
+2) Go to API development tools
+3) App title: your app\'s name, can be anything
+ Short name: your app\'s short name, can be anything
+ URL: your app/website\'s URL, or t.me/yourusername
+ Platform: Web
+ Description: Describe your app here
+4) Click on create application'.PHP_EOL;
+ $app['api_id'] = readline('5) Enter your API ID: ');
+ $app['api_hash'] = readline('6) Enter your API hash: ');
+ return $app;
+ } else {
+ $this->my_telegram_org_wrapper = new \danog\MadelineProto\MyTelegramOrgWrapper();
+ $this->my_telegram_org_wrapper->phone_login(readline('Enter a phone number that is already registered on Telegram: '));
+ $this->my_telegram_org_wrapper->complete_login(readline('Enter the verification code you received in telegram: '));
+ if (!$this->my_telegram_org_wrapper->has_app()) {
+ $app = $this->my_telegram_org_wrapper->create_app(['app_name' => 'MadelineProto app', 'app_shortname' => 'MadelineProtoApp', 'app_url' => 'https://madelineproto.xyz', 'app_platform' => 'web', 'app_desc' => 'MadelineProto application']);
+ } else {
+ $app = $this->my_telegram_org_wrapper->get_app();
+ }
+ return $app;
+ }
+ } else {
+ $this->getting_api_id = true;
+ if (!isset($this->my_telegram_org_wrapper)) {
+ if (isset($_POST['api_id']) && isset($_POST['api_hash'])) {
+ $app['api_id'] = (int) $_POST['api_id'];
+ $app['api_hash'] = $_POST['api_hash'];
+ $this->getting_api_id = false;
+ return $app;
+ } else if (isset($_POST['phone_number'])) {
+ $this->web_api_phone_login();
+ } else {
+ $this->web_api_echo();
+ }
+ } else if (!$this->my_telegram_org_wrapper->logged_in()) {
+ if (isset($_POST['code'])) {
+ $app = $this->web_api_complete_login();
+ $this->getting_api_id = false;
+ return $app;
+ } else {
+ $this->web_api_echo("You didn't provide a phone code!");
+ }
+ }
+ exit;
+ }
+ }
+ public function web_api_phone_login()
+ {
+ try {
+ $this->my_telegram_org_wrapper = new \danog\MadelineProto\MyTelegramOrgWrapper($_POST['phone_number']);
+ $this->web_api_echo();
+ } catch (\danog\MadelineProto\RPCErrorException $e) {
+ $this->web_api_echo('ERROR: '.$e->getMessage().'. Try again.');
+ } catch (\danog\MadelineProto\Exception $e) {
+ $this->web_api_echo('ERROR: '.$e->getMessage().'. Try again.');
+ }
+ }
+
+ public function web_api_complete_login()
+ {
+ try {
+ $this->my_telegram_org_wrapper->complete_login($_POST['code']);
+ if (!$this->my_telegram_org_wrapper->has_app()) {
+ $app = $this->my_telegram_org_wrapper->create_app(['app_name' => 'MadelineProto app', 'app_shortname' => 'MadelineProtoApp', 'app_url' => 'https://madelineproto.xyz', 'app_platform' => 'web', 'app_desc' => 'MadelineProto application']);
+ } else {
+ $app = $this->my_telegram_org_wrapper->get_app();
+ }
+ return $app;
+ } catch (\danog\MadelineProto\RPCErrorException $e) {
+ $this->web_api_echo('ERROR: '.$e->getMessage().'. Try again.');
+ } catch (\danog\MadelineProto\Exception $e) {
+ $this->web_api_echo('ERROR: '.$e->getMessage().'. Try again.');
+ }
+ }
+}
diff --git a/src/danog/MadelineProto/Wrappers/ApiTemplates.php b/src/danog/MadelineProto/Wrappers/ApiTemplates.php
new file mode 100644
index 000000000..e2ce15518
--- /dev/null
+++ b/src/danog/MadelineProto/Wrappers/ApiTemplates.php
@@ -0,0 +1,62 @@
+.
+*/
+
+namespace danog\MadelineProto\Wrappers;
+
+trait ApiTemplates
+{
+ private $web_api_template = '
+
+
+ MadelineProto
+
+
+
MadelineProto
+
+
%s
+
+ ';
+
+ public function web_api_echo_template($message, $form)
+ {
+ return sprintf($this->web_api_template, $form, $message);
+ }
+ public function get_web_api_template() {
+ return $this->web_template;
+ }
+ public function set_web_api_template($template) {
+ $this->web_template = $template;
+ }
+
+
+ public function web_api_echo($message = '')
+ {
+ if (!isset($this->my_telegram_org_wrapper)) {
+ if (isset($_POST['type'])) {
+ if ($_POST['type'] === 'manual') {
+ echo $this->web_api_echo_template('Enter your API ID and API hash '.$message.'', '');
+ } else {
+ echo $this->web_api_echo_template('Enter your phone number '.$message.'', '');
+ }
+ } else {
+ echo $this->web_api_echo_template('Do you want to enter the API id and the API hash manually or automatically? '.$message.'', '');
+ }
+ } else {
+ echo $this->web_api_echo_template('Enter your code '.$message.'', '');
+ }
+ }
+
+}