. * * @author Daniil Gentili * @copyright 2016-2020 Daniil Gentili * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 * * @link https://docs.madelineproto.xyz MadelineProto documentation */ namespace danog\MadelineProto\Wrappers; use \danog\MadelineProto\MTProto; use danog\MadelineProto\Ipc\Client; use danog\MadelineProto\Lang; use function Amp\ByteStream\getOutputBufferStream; trait Templates { /** * Echo page to console. * * @param string $message Error message * * @return \Generator */ private function webEcho(string $message = ''): \Generator { $auth = yield $this->getAuthorization(); $form = null; if ($auth === MTProto::NOT_LOGGED_IN) { if (isset($_POST['type'])) { if ($_POST['type'] === 'phone') { $title = \str_replace(':', '', Lang::$current_lang['loginUser']); $phone = \htmlentities(Lang::$current_lang['loginUserPhoneWeb']); $form = ""; } else { $title = \str_replace(':', '', Lang::$current_lang['loginBot']); $token = \htmlentities(Lang::$current_lang['loginBotTokenWeb']); $form = ""; } } else { $title = Lang::$current_lang['loginChoosePromptWeb']; $optionBot = \htmlentities(Lang::$current_lang['loginOptionBot']); $optionUser = \htmlentities(Lang::$current_lang['loginOptionUser']); $form = ""; } } elseif ($auth === MTProto::WAITING_CODE) { $title = \str_replace(':', '', Lang::$current_lang['loginUserCode']); $phone = \htmlentities(Lang::$current_lang['loginUserPhoneCodeWeb']); $form = ""; } elseif ($auth === MTProto::WAITING_PASSWORD) { $title = Lang::$current_lang['loginUserPassWeb']; $hint = \htmlentities(\sprintf( Lang::$current_lang['loginUserPassHint'], $this instanceof Client ? yield from $this->getHint() : $this->getHint() )); $form = ""; } elseif ($auth === MTProto::WAITING_SIGNUP) { $title = Lang::$current_lang['signupWeb']; $firstName = Lang::$current_lang['signupFirstNameWeb']; $lastName = Lang::$current_lang['signupLastNameWeb']; $form = ""; } else { $title = ''; } $title = \htmlentities($title); $message = \htmlentities($message); return getOutputBufferStream()->write($this->webEchoTemplate("$title
$message", $form)); } /** * Web template. * * @var string */ private $webTemplate = 'legacy'; /** * Format message according to template. * * @param string $message Message * @param string $form Form contents * * @return string */ private function webEchoTemplate(string $message, string $form): string { return \sprintf($this->webTemplate, $message, $form, Lang::$current_lang['go']); } /** * Get web template. * * @return string */ public function getWebTemplate(): string { return $this->webTemplate; } /** * Set web template. * * @param string $template Template * * @return void */ public function setWebTemplate(string $template): void { $this->webTemplate = $template; } }