protected function execute(InputInterface $input, OutputInterface $output) { $lrPadding = $input->getOption('lr'); $tbPadding = $input->getOption('tb'); if ($input->getOption('stdin')) { $text = ''; while ($line = fgets(STDIN)) { $text .= $line; } } else { $text = $input->getOption('text'); } if (empty($text)) { $output->getErrorOutput()->writeln('<error>Convert text cannot be empty</error>'); return; } $map = array(0 => '<whitec> </whitec>', 1 => '<blackc> </blackc>'); $this->initStyle($output); $text = QRcode::text($text); $length = strlen($text[0]); $screenSize = $this->getTTYSize(); if (!$screenSize) { $output->getErrorOutput()->writeln('<comment>Get Screen Size Failed</comment>'); } else { list($maxLines, $maxCols) = $screenSize; $qrCols = 2 * ($length + $lrPadding * 2); $qrLines = count($text) + $tbPadding * 2; if ($qrCols > $maxCols || $qrLines > $maxLines) { $output->getErrorOutput()->writeln('<error>Max Lines/Columns Reached</error>'); return; } } $paddingLine = str_repeat($map[0], $length + $lrPadding * 2) . "\n"; $after = $before = str_repeat($paddingLine, $tbPadding); $output->write($before); foreach ($text as $line) { $output->write(str_repeat($map[0], $lrPadding)); for ($i = 0; $i < $length; $i++) { $type = substr($line, $i, 1); $output->write($map[$type]); } $output->writeln(str_repeat($map[0], $lrPadding)); } $output->write($after); }
/** * Generate QR code * * @return void */ public function qrcodeTask() { $no_html = Request::getInt('no_html', 0); $code = Request::getVar('code'); if (!$code) { throw new Exception(Lang::txt('No code provided'), 500); } $url = rtrim(Request::base(), '/') . '/' . ltrim(Route::url('index.php?option=' . $this->_option . '&controller=courses&task=redeem&code=' . $code), '/'); if ($no_html) { echo QRcode::png($url); return; } echo QRcode::text($url); }