. * * @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\ApiWrappers; use Amp\Promise; use danog\MadelineProto\Lang; use function Amp\ByteStream\getOutputBufferStream; trait Templates { /** * API template. * * @var string */ private $webApiTemplate = 'legacy'; /** * Generate page from template. * * @param string $message Message * @param string $form Form * * @return string */ private function webAPIEchoTemplate(string $message, string $form): string { return \sprintf($this->webApiTemplate, $message, $form, Lang::$current_lang['go']); } /** * Get web API login HTML template string. * * @return string */ public function getWebAPITemplate(): string { return $this->webApiTemplate; } /** * Set web API login HTML template string. * * @return void */ public function setWebAPITemplate(string $template): void { $this->webApiTemplate = $template; } /** * Echo to browser. * * @param string $message Message to echo * * @return Promise */ private function webAPIEcho(string $message = ''): Promise { $message = \htmlentities($message); if (!isset($this->myTelegramOrgWrapper)) { if (isset($_POST['type'])) { if ($_POST['type'] === 'manual') { $title = \htmlentities(Lang::$current_lang['apiManualWeb']); $title .= "
$message"; $title .= "
    "; $title .= "
  1. ".\htmlentities(Lang::$current_lang['apiManualInstructions0'])."
  2. "; $title .= "
  3. ".\htmlentities(Lang::$current_lang['apiManualInstructions1'])."
  4. "; $title .= "
    • "; foreach (['App title', 'Short name', 'URL', 'Platform', 'Description'] as $k => $key) { $title .= "
    • $key: "; $title .= \htmlentities(Lang::$current_lang["apiAppInstructionsManual$k"]); $title .= "
    • "; } $title .= "
    "; $title .= "
  5. ".\htmlentities(Lang::$current_lang['apiManualInstructions2'])."
  6. "; $title .= "
"; $form = ''; $form .= ''; } else { $title = Lang::$current_lang['apiAutoWeb']; $title .= "
$message"; $phone = \htmlentities(Lang::$current_lang['loginUserPhoneWeb']); $form = ""; } } else { if ($message) { $message = '

'.$message; } $title = \htmlentities(Lang::$current_lang['apiChooseManualAutoWeb']); $title .= "
"; $title .= \sprintf(Lang::$current_lang['apiChooseManualAutoTipWeb'], 'https://docs.madelineproto.xyz/docs/SETTINGS.html#settingsapp_infoapi_id'); $title .= "$message"; $automatically = \htmlentities(Lang::$current_lang['apiChooseAutomaticallyWeb']); $manually = \htmlentities(Lang::$current_lang['apiChooseManuallyWeb']); $form = ""; } } else { if (!$this->myTelegramOrgWrapper->loggedIn()) { $title = \htmlentities(Lang::$current_lang['loginUserCode']); $title .= "
$message"; $code = \htmlentities(Lang::$current_lang['loginUserPhoneCodeWeb']); $form = ""; } else { $title = \htmlentities(Lang::$current_lang['apiAppWeb']); $title .= "
$message"; $form = ''; foreach (['app_title', 'app_shortname', 'app_url', 'app_platform', 'app_desc'] as $k => $field) { $desc = \htmlentities(Lang::$current_lang["apiAppInstructionsAuto$k"]); if ($field == 'app_platform') { $form .= "$desc
"; foreach ([ 'android' => 'Android', 'ios' => 'iOS', 'wp' => 'Windows Phone', 'bb' => 'BlackBerry', 'desktop' => 'Desktop', 'web' => 'Web', 'ubp' => 'Ubuntu phone', 'other' => \htmlentities(Lang::$current_lang['apiAppInstructionsAutoTypeOther']) ] as $key => $desc) { $form .= ""; } } elseif ($field === 'app_desc') { $form .= "$desc


"; } else { $form .= "$desc


"; } } } } return getOutputBufferStream()->write($this->webAPIEchoTemplate($title, $form)); } }