public function e($text, $context = null, $echo = null) { if ($context === null) { $context = $this->defaultEscapingContext; } if ($echo === null) { $echo = $this->defaultEcho; } if ($context == 'html') { $text = StringTools::escapeHtml($text); } else { if ($context == 'js') { $text = StringTools::escapeJs($text); } else { if ($context == 'url') { $text = urlencode($text); } } } if ($echo) { echo $text; return null; } else { return $text; } }
public function parseTask() { /** @var $m LoggingModule */ $m = $this->task->module; $mode = $this->request()->get->get('mode'); $status = null; if ($mode == 'clear') { file_put_contents($m->moduleConfig->file, ''); $status = 'All logs have been cleared.'; } $logs = is_file($m->moduleConfig->file) ? file_get_contents($m->moduleConfig->file) : ''; $logs = StringTools::escapeHtml($logs); $content = <<<CNT <!DOCTYPE html> <body> <div> <a href="?">Show logs</a> <a href="?mode=clear">Clear logs</a> </div> <div><strong> {$status} </strong></div> <hr> <pre> {$logs} </pre> </body> CNT; $this->task->response->postContent($content, ContentType::TYPE_HTML_UTF8); }
public function parseTask() { /** @var $m ErrorReportingModule */ $m = $this->task->module; $mode = $this->request()->get->get('mode'); $status = null; if ($mode == 'clear') { file_put_contents($m->moduleConfig->file, ''); $status = 'All errors have been cleared.'; } elseif ($mode == 'trigger') { $this->app->events->trigger('logException', new \Exception('A test error has been triggered.')); $status = 'The test error has been triggered.'; } elseif ($mode == 'toggle') { if (!is_file($m->moduleConfig->file)) { file_put_contents($m->moduleConfig->file, 'disabled'); $status = 'Error reporting has been disabled.'; } else { $f = fopen($m->moduleConfig->file, 'r+'); if (fread($f, 8) == 'disabled') { ftruncate($f, 0); $status = 'Error reporting has been enabled.'; } else { ftruncate($f, 0); fseek($f, 0); fwrite($f, 'disabled'); $status = 'Error reporting has been disabled.'; } fclose($f); } } $errors = is_file($m->moduleConfig->file) ? file_get_contents($m->moduleConfig->file) : ''; if (substr($errors, 0, 8) == 'disabled') { $toggleLabel = 'Enable reporting'; } else { $toggleLabel = 'Disable reporting'; } $errors = StringTools::escapeHtml($errors); $content = <<<CNT <!DOCTYPE html> <body style="margin:0;padding:0"> <div style="position:fixed;width:100%;background:white;padding:10px;border-bottom:solid 1px black"> <a href="?">Show errors</a> <a href="?mode=clear">Clear errors</a> <a href="?mode=trigger">Trigger error</a> <a href="?mode=toggle">{$toggleLabel}</a> <br /> <strong> {$status} </strong> </div> <div style="padding-top: 100px;"> <pre> {$errors} </pre> </div> </body> CNT; $this->task->response->postContent($content, ContentType::TYPE_HTML_UTF8); }
public function render($mode) { if ($mode == Set::MODE_EXPORT || !$this->escapeContent) { return $this->content; } else { return StringTools::escapeHtml($this->content); } }
public function render($mode) { $date = $this->_data ? $this->_data->format($this->format) : ''; if ($mode == Set::MODE_EXPORT) { return $date; } else { return '<p>' . StringTools::escapeHtml($date) . '</p>'; } }
public function render($mode) { $isChecked = $this->_data == $this->value; if ($mode == Set::MODE_EXPORT) { return $isChecked ? $this->label : ''; } $attributes = $isChecked ? ' checked="checked"' : ''; if ($mode == Set::MODE_SHOW || $mode == Set::MODE_LIST || $mode == Set::MODE_DELETE || !$this->editable) { $attributes .= ' disabled="disabled"'; } $id = 'c' . StringTools::random(15); $c = '<input id="' . $id . '" type="checkbox" name="' . $this->name . '" value="' . StringTools::escapeHtml($this->value) . '"' . $attributes . ' />'; if ($this->label != '') { $c .= '<label for="' . $id . '">' . StringTools::escapeHtml($this->label) . '</label>'; } return $c; }
public function render($mode) { if ($mode == Set::MODE_EXPORT) { return $this->options[$this->_data]; } if ($mode == Set::MODE_SHOW || $mode == Set::MODE_DELETE || $mode == Set::MODE_LIST || !$this->editable) { return '<p>' . StringTools::escapeHtml($this->options[$this->_data]) . '</p>'; } elseif ($mode == Set::MODE_EDIT || $mode == Set::MODE_ADD) { $c = '<select name="' . $this->name . '">'; $data = strval($this->_data); foreach ($this->options as $key => $value) { $selected = strval($key) === $data ? ' selected="selected"' : ''; $c .= '<option value="' . StringTools::escapeHtml($key) . '"' . $selected . '>' . StringTools::escapeHtml($value) . '</option>'; } $c .= '</select>'; return $c; } return $this->options[$this->_data]; }
public function __toString() { $cnt = ''; if ($this->tag) { $cnt = '<' . $this->tag; if ($this->attributes) { foreach ($this->attributes as $atbName => $atbValue) { if ($atbValue !== null) { $cnt .= ' ' . $atbName . '="' . StringTools::escapeHtml($atbValue) . '"'; } } } } if ($this->contents !== null) { if ($this->tag) { $cnt .= '>'; } if (is_string($this->contents)) { $cnt .= $this->escapeContent ? StringTools::escapeHtml($this->contents) : $this->contents; } else { if (is_array($this->contents)) { $c = ''; foreach ($this->contents as $content) { $c .= $content; } $cnt .= $this->escapeContent ? StringTools::escapeHtml($c) : $c; } } if ($this->tag) { $cnt .= '</' . $this->tag . '>'; } } else { if ($this->tag) { if ($this->quickClose) { $cnt .= ' />'; } else { $cnt .= '></' . $this->tag . '>'; } } } return $cnt; }
public function parseTask() { /** @var BasicLoginModule $module */ $module = $this->task->module; $name = StringTools::escapeHtml($this->task->route->data->get('name', $module->moduleConfig->realm)); $url = $this->task->url; $content = <<<HTML <!doctype html> <html> <body> <h1>Access denied</h1> <p>Login to access “{$name}”.</p> <form action="{$url}" method="post"> Username: <input type="text" name="username"><br> Password: <input type="password" name="password"><br> <input type="submit" name="login" value="Login"> </form> </body> </html> HTML; $this->setResult($content, null, ResponseCode::CODE_401); }
public function render($mode) { $url = $this->_getFileUrl(); if ($mode == Set::MODE_EXPORT) { return $url ? $url : $this->_data; } if ($this->editable && ($mode == Set::MODE_ADD || $mode == Set::MODE_EDIT)) { $c = '<input type="file" name="' . $this->name . '" />'; } else { $c = ''; } if ($this->_data) { if ($c != '') { $c .= '<br /><br />'; } if ($url) { $c .= '<a href="' . StringTools::escapeHtml($url) . '" target="_blank">' . StringTools::escapeHtml($url) . '</a>'; } else { $c .= StringTools::escapeHtml($this->_data); } } return $c; }
public function render($mode) { $url = $this->_getImageUrl(); if ($mode == Set::MODE_EXPORT) { return $url ? $url : $this->_data; } if ($this->editable && ($mode == Set::MODE_ADD || $mode == Set::MODE_EDIT)) { $c = '<input type="file" name="' . $this->name . '" />'; } else { $c = ''; } if ($this->_data) { if ($c) { $c .= '<br /><br />'; } if ($url) { $c .= '<img id="' . $this->name . '_preview" src="' . StringTools::escapeHtml($url) . '" alt="" />'; } else { $c .= StringTools::escapeHtml($this->_data); } } return $c; }
public function showHeadline($title, $rawTitle = false, $level = 2) { $this->show('<h' . $level . '>' . ($rawTitle ? $title : StringTools::escapeHtml($title)) . '</h' . $level . '>', true); }
public function parseTask() { /** @var $m MailModule */ $m = $this->task->module; $mode = $this->request()->get->get('mode'); $status = null; if ($m->moduleConfig->mode != MailModule::MODE_DIRECTORY) { $this->setResult('Directory logging is disabled.'); return; } $directory = $m->moduleConfig->directory; $content = ''; if ($mode == 'clear') { FileTools::deleteContents($directory); $status = 'All mails have been cleared.'; } elseif ($mode == 'showhtml') { $id = $this->task->request->get->asString('mail')->asInput(128)->value; if (preg_match('!^[a-zA-Z0-9_+ -]+$!', $id) && is_file($directory . $id . '.htm')) { $this->setResult(file_get_contents($directory . $id . '.htm'), ContentType::TYPE_HTML_UTF8); return; } else { $content = 'Mail does not exist'; } } elseif ($mode == 'show') { $id = $this->task->request->get->asString('mail')->asInput(128)->value; if (preg_match('!^[a-zA-Z0-9_+ -]+$!', $id)) { if ($id != 'latest' && !is_file($directory . $id . '.txt')) { $content = 'Mail does not exist.'; } else { if ($id == 'latest') { $files = scandir($directory); $id = null; foreach ($files as $file) { if ($file == '.' || $file == '..' || !preg_match('!^(.*)\\.txt$!', $file, $fileData)) { continue; } $id = $fileData[1]; } } if (!$id) { $content = 'Mail does not exist'; } else { $content = StringTools::escapeHtml(file_get_contents($directory . $id . '.txt')); $content = preg_replace('![a-zA-Z0-9]+://[^\\s\\(\\)]+!', '<a href="\\0" target="_blank">\\0</a>', $content); $content = '<pre>' . $content . '</pre>'; if (is_file($directory . $id . '.htm')) { $content .= '<iframe src="?mode=showhtml&mail=' . rawurlencode($id) . '" width="900" height="600"></iframe>'; } } } } else { $content = 'Please enter a valid id.'; } } else { $files = FileTools::listDirectory($directory, false); $mailList = array(); foreach ($files as $file) { if (preg_match('!^(.+)\\.([a-zA-Z0-9]+)$!', $file, $fileData)) { if (in_array($fileData[2], array('txt', 'htm'))) { $mailList[$fileData[1]] = true; } } } krsort($mailList); $ui = new Ui(); $content = '<ul>'; foreach ($mailList as $mailId => $foo) { $content .= '<li>' . $ui->link('?mode=show&mail=' . rawurlencode($mailId), $mailId) . '</li>'; } $content .= '</ul>'; } $content = <<<CNT <!DOCTYPE html> <body> <div> <a href="?">Show mails</a> <a href="?mode=show&mail=latest">Show latest mail</a> <a href="?mode=clear">Clear mails</a> </div> <div><strong> {$status} </strong></div> <hr> {$content} </table> </pre> </body> CNT; $this->task->response->postContent($content, ContentType::TYPE_HTML_UTF8); }
public function render($mode) { if ($mode == Set::MODE_EXPORT) { return $this->_data; } if ($mode == Set::MODE_SHOW || $mode == Set::MODE_DELETE || $mode == Set::MODE_LIST || !$this->editable) { return '<p>' . StringTools::escapeHtml($this->_data) . '</p>'; } $additionalAttributes = ''; $attributes = $this->config->get('attributes'); if ($attributes) { foreach ($attributes as $key => $value) { $additionalAttributes .= " {$key}=\"" . StringTools::escapeHtml($value) . "\""; } } if ($this->password) { return '<input type="password" name="' . $this->name . '" value=""' . $additionalAttributes . ' />'; } if ($this->multiline) { return '<textarea name="' . $this->name . '"' . $additionalAttributes . '>' . StringTools::escapeHtml($this->_data) . '</textarea>'; } return '<input type="text" name="' . $this->name . '" value="' . StringTools::escapeHtml($this->_data) . '"' . $additionalAttributes . ' />'; }
public function pageSelector($pages, $link, $attributes = null) { $currentPage = $pages['currentPage']; $pages = $pages['pages']; $defaultAttributes = array('pagePlaceholder' => '%page%', 'additionalLinkClasses' => ''); $attributes = $attributes ? array_merge($defaultAttributes, $attributes) : $defaultAttributes; $pagePlaceholder = $attributes['pagePlaceholder']; $additionalLinkClasses = $attributes['additionalLinkClasses']; if ($additionalLinkClasses != '') { $additionalLinkClasses = ' ' . $additionalLinkClasses; } $link = StringTools::escapeHtml($link); $s = ''; $el = new UiElement('div', array('class' => 'GroutPageSelector')); if ($currentPage > 1) { $s .= '<a class="previousPage' . $additionalLinkClasses . '" href="' . str_replace($pagePlaceholder, $currentPage - 1, $link) . '">‹</a>'; } $page = 0; foreach ($pages as $page) { if ($page == '.') { $s .= '<span class="pageGap">...</span>'; } else { if ($page == $currentPage) { $s .= '<a class="currentPage' . $additionalLinkClasses . '" href="' . str_replace($pagePlaceholder, $page, $link) . '">'; } else { $s .= '<a ' . ($additionalLinkClasses != '' ? 'class="' . $additionalLinkClasses . '" ' : '') . 'href="' . str_replace($pagePlaceholder, $page, $link) . '">'; } $s .= $page . '</a>'; } } if ($currentPage < $page) { $s .= '<a class="nextPage' . $additionalLinkClasses . '" href="' . str_replace($pagePlaceholder, $currentPage + 1, $link) . '">›</a>'; } $el->contents = $s; return $el; }