noHTML() public static method

Prevents XSS attacks.
public static noHTML ( string $untrusted ) : string
$untrusted string
return string
Ejemplo n.º 1
0
 /**
  * Insert a CSRF token to a form
  *
  * @param string $lockTo This CSRF token is only valid for this HTTP request endpoint
  * @param bool $echo if true, echo instead of returning
  * @return string
  */
 public function insertToken(string $lockTo = '', bool $echo = true) : string
 {
     $ret = '<input type="hidden"' . ' name="' . Util::noHTML(self::FORM_TOKEN) . '"' . ' value="' . $this->getTokenString($lockTo) . '"' . ' />';
     if ($echo) {
         echo $ret;
         return '';
     }
     return $ret;
 }
Ejemplo n.º 2
0
 /**
  * @route my/files/{string}/info
  * @param string $cabin
  */
 public function getFileInfo(string $cabin = '')
 {
     $this->files->ensureDirExists($this->root_dir, $cabin);
     $dir = $this->determinePath($cabin);
     if (empty($_GET['file'])) {
         \Airship\redirect($this->airship_cabin_prefix . '/my_files/' . \urlencode($cabin), ['dir' => $dir]);
     }
     if (!\in_array($cabin, $this->getCabinNamespaces())) {
         \Airship\redirect($this->airship_cabin_prefix);
     }
     $this->storeLensVar('title', \__('%s', 'default', Util::noHTML(!empty($dir) ? $dir . '/' . $_GET['file'] : $_GET['file'])));
     $this->commonGetFileInfo($_GET['file'], $dir, $cabin);
 }
Ejemplo n.º 3
0
 /**
  * @param string $cabinName
  * @route gadgets/cabin/{string}
  */
 public function manageForCabin(string $cabinName = '')
 {
     $cabins = $this->getCabinNamespaces();
     if (!\in_array($cabinName, $cabins)) {
         \Airship\redirect($this->airship_cabin_prefix . '/gadgets');
     }
     if (!$this->can('update')) {
         \Airship\redirect($this->airship_cabin_prefix . '/gadgets');
     }
     $gadgets = \Airship\loadJSON(ROOT . '/Cabin/' . $cabinName . '/config/gadgets.json');
     $post = $this->post(GadgetsFilter::fromConfig(\array_keys($gadgets)));
     if ($post) {
         if ($this->updateCabinGadgets($gadgets, $post, $cabinName)) {
             \Airship\clear_cache();
             \Airship\redirect($this->airship_cabin_prefix . '/gadgets/cabin/' . $cabinName);
         }
     }
     $this->lens('gadget_manage', ['cabins' => $cabins, 'gadgets' => $gadgets, 'title' => \__('Gadgets for %s', 'default', Util::noHTML($cabinName))]);
 }
Ejemplo n.º 4
0
 /**
  * View a version of a blog post.
  *
  * @param string $postID
  * @param string $uniqueID
  *
  * @route blog/post/history/{id}/view/{string}
  */
 public function postHistoryView(string $postID = '', string $uniqueID = '')
 {
     $postID = (int) $postID;
     $blog = $this->blog->getBlogPostById($postID);
     if (!$blog || !$this->can('read')) {
         \Airship\redirect($this->airship_cabin_prefix . '/blog/post');
     }
     $blog['tags'] = $this->blog->getTagsForPost($postID);
     $version = $this->blog->getBlogPostVersionByUniqueId($uniqueID);
     if ((int) $version['postid'] !== $postID || empty($version)) {
         \Airship\redirect($this->airship_cabin_prefix . '/blog/post/history/' . $postID);
     }
     if ($this->isSuperUser()) {
         $authors = $this->author->getAll();
     } else {
         $authors = $this->author->getForUser($this->getActiveUserId());
     }
     $categories = $this->blog->getCategoryTree();
     $tags = $this->blog->getTags();
     $this->lens('blog/post_history_view', ['active_link' => 'bridge-link-blog-posts', 'authors' => $authors, 'blogpost' => $blog, 'categories' => $categories, 'tags' => $tags, 'title' => \__('Revision for  Blog Post "%s"', 'default', Util::noHTML($blog['title'])), 'prev_uniqueid' => $this->blog->getPrevVersionUniqueId($postID, (int) $version['versionid']), 'next_uniqueid' => $this->blog->getNextVersionUniqueId($postID, (int) $version['versionid']), 'version' => $version]);
 }
Ejemplo n.º 5
0
 /**
  * @route motifs/{string}
  *
  * @param string $cabinName
  */
 public function manage(string $cabinName = '')
 {
     $cabins = $this->getCabinNamespaces();
     if (!\in_array($cabinName, $cabins)) {
         \Airship\redirect($this->airship_cabin_prefix . '/motifs');
     }
     if (!$this->can('update')) {
         \Airship\redirect($this->airship_cabin_prefix . '/motifs');
     }
     $motifs = \Airship\loadJSON(ROOT . '/Cabin/' . $cabinName . '/config/motifs.json');
     $post = $this->post(MotifsFilter::fromConfig(\array_keys($motifs)));
     if ($post) {
         if ($this->updateMotifs($motifs, $post, $cabinName)) {
             \Airship\clear_cache();
             \Airship\redirect($this->airship_cabin_prefix . '/motifs/cabin/' . $cabinName);
         }
     }
     $this->lens('motif_manage', ['cabin_name' => $cabinName, 'cabins' => $cabins, 'motifs' => $motifs, 'title' => \__('Motifs for %s', 'default', Util::noHTML($cabinName))]);
 }
Ejemplo n.º 6
0
 /**
  * Loads all the necessary information for this author
  *
  * @param int $authorId
  */
 protected function loadAuthorInfo(int $authorId)
 {
     $this->authorId = $authorId;
     $this->authorName = $this->author->getName($authorId);
     $this->authorSlug = $this->author->getSlug($authorId);
     $this->storeLensVar('header', \__('Files for Author "%s"', 'default', Util::noHTML($this->authorName)));
     $this->storeLensVar('title', \__('Files for Author "%s"', 'default', Util::noHTML($this->authorName)));
     $this->root_dir = 'author/' . $this->authorSlug;
     $this->path_middle = 'author/files/' . $authorId;
     $this->storeLensVar('path_middle', $this->path_middle);
     $userId = $this->getActiveUserId();
     $this->attribution = ['author' => $authorId, 'uploaded_by' => $userId];
 }
Ejemplo n.º 7
0
 /**
  * List all of the blog posts for a given year
  * @param string $year
  * @route blog/{year}
  */
 public function listYear(string $year)
 {
     list($offset, $limit) = $this->getOffsetAndLimit();
     $count = $this->blog->countByYear($year);
     $blogRoll = $this->blog->listByYear($year, $limit, $offset);
     $mathJAX = false;
     foreach ($blogRoll as $i => $blog) {
         $blogRoll[$i] = $this->blog->getSnippet($blog);
         if (Binary::safeStrlen($blogRoll[$i]['snippet']) !== Binary::safeStrlen($blog['body'])) {
             $blogRoll[$i]['snippet'] = \rtrim($blogRoll[$i]['snippet'], "\n");
         }
         $mathJAX = $mathJAX || \strpos($blog['body'], '$$') !== false;
     }
     $dt = new \DateTime("{$year}-01-01");
     $page = (int) \ceil($offset / ($limit ?? 1)) + 1;
     $args = ['blogroll' => $blogRoll, 'mathjax' => $mathJAX, 'pageTitle' => \__('Blog Posts in the Year %s (Page %d)', 'default', Util::noHTML($dt->format('Y')), $page), 'pagination' => ['base' => \Airship\LensFunctions\cabin_url() . 'blog/' . $year, 'suffix' => '/?page=', 'count' => $count, 'page' => $page, 'per_page' => $limit]];
     $this->config('blog.cachelists') ? $this->stasis('blog/list', $args) : $this->lens('blog/list', $args);
 }