Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

link_helper.php

Zuletzt modifiziert: 01.05.2026, 11:25 - Dateigröße: 3.50 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\textformatter\s9e;
 015   
 016  class link_helper
 017  {
 018      /**
 019      * Clean up and invalidate a LINK_TEXT tag if applicable
 020      *
 021      * Will invalidate the tag if its replacement text is the same as the original
 022      * text and would have no visible effect
 023      *
 024      * @param  \s9e\TextFormatter\Parser\Tag $tag    LINK_TEXT tag
 025      * @param  \s9e\TextFormatter\Parser     $parser Parser
 026      * @return void
 027      */
 028      public function cleanup_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\TextFormatter\Parser $parser)
 029      {
 030          // Invalidate if the content of the tag matches the text attribute
 031          $text = substr($parser->getText(), $tag->getPos(), $tag->getLen());
 032          if ($text === $tag->getAttribute('text'))
 033          {
 034              $tag->invalidate();
 035          }
 036      }
 037   
 038      /**
 039      * Create a LINK_TEXT tag inside of a link
 040      *
 041      * Meant to only apply to linkified URLs and [url] BBCodes without a parameter
 042      *
 043      * @param  \s9e\TextFormatter\Parser\Tag $tag    URL tag (start tag)
 044      * @param  \s9e\TextFormatter\Parser     $parser Parser
 045      * @return void
 046      */
 047      public function generate_link_text_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\TextFormatter\Parser $parser)
 048      {
 049          // Only create a LINK_TEXT tag if the start tag is paired with an end
 050          // tag, which is the case with tags from the Autolink plugins and with
 051          // the [url] BBCode when its content is used for the URL
 052          if (!$tag->getEndTag() || !$this->should_shorten($tag, $parser->getText()))
 053          {
 054              return;
 055          }
 056   
 057          // Capture the text between the start tag and its end tag
 058          $start  = $tag->getPos() + $tag->getLen();
 059          $end    = $tag->getEndTag()->getPos();
 060          $length = $end - $start;
 061          $text   = substr($parser->getText(), $start, $length);
 062   
 063          // Create a tag that consumes the link's text and make it depends on this tag
 064          $link_text_tag = $parser->addSelfClosingTag('LINK_TEXT', $start, $length, 10);
 065          $link_text_tag->setAttribute('text', $text);
 066          $tag->cascadeInvalidationTo($link_text_tag);
 067      }
 068   
 069      /**
 070      * Test whether we should shorten this tag's text
 071      *
 072      * Will test whether the tag either does not use any markup or uses a single
 073      * [url] BBCode
 074      *
 075      * @param  \s9e\TextFormatter\Parser\Tag $tag  URL tag
 076      * @param  string                        $text Original text
 077      * @return bool
 078      */
 079      protected function should_shorten(\s9e\TextFormatter\Parser\Tag $tag, $text)
 080      {
 081          return ($tag->getLen() === 0 || strtolower(substr($text, $tag->getPos(), $tag->getLen())) === '[url]');
 082      }
 083   
 084      /**
 085      * Remove the board's root URL from a the start of a string
 086      *
 087      * @param  \s9e\TextFormatter\Parser\Tag $tag       LINK_TEXT tag
 088      * @param  string                        $board_url Forum's root URL (with trailing slash)
 089      * @return void
 090      */
 091      public function truncate_local_url(\s9e\TextFormatter\Parser\Tag $tag, $board_url)
 092      {
 093          $text = $tag->getAttribute('text');
 094          if (stripos($text, $board_url) === 0 && strlen($text) > strlen($board_url))
 095          {
 096              $tag->setAttribute('text', substr($text, strlen($board_url)));
 097          }
 098      }
 099   
 100      /**
 101      * Truncate the replacement text set in a LINK_TEXT tag
 102      *
 103      * @param  \s9e\TextFormatter\Parser\Tag $tag LINK_TEXT tag
 104      * @return void
 105      */
 106      public function truncate_text(\s9e\TextFormatter\Parser\Tag $tag)
 107      {
 108          $text = $tag->getAttribute('text');
 109          if (utf8_strlen($text) > 55)
 110          {
 111              $text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10);
 112              $tag->setAttribute('text', $text);
 113          }
 114      }
 115  }
 116