Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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: 09.10.2024, 12:54 - Dateigröße: 3.70 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 bool                                  Whether the tag is valid
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   
033          return ($text !== $tag->getAttribute('text'));
034      }
035   
036      /**
037      * Create a LINK_TEXT tag inside of a link
038      *
039      * Meant to only apply to linkified URLs and [url] BBCodes without a parameter
040      *
041      * @param  \s9e\TextFormatter\Parser\Tag $tag    URL tag (start tag)
042      * @param  \s9e\TextFormatter\Parser     $parser Parser
043      * @return bool                                  Always true to indicate that the tag is valid
044      */
045      public function generate_link_text_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\TextFormatter\Parser $parser)
046      {
047          // Only create a LINK_TEXT tag if the start tag is paired with an end
048          // tag, which is the case with tags from the Autolink plugins and with
049          // the [url] BBCode when its content is used for the URL
050          if (!$tag->getEndTag() || !$this->should_shorten($tag, $parser->getText()))
051          {
052              return true;
053          }
054   
055          // Capture the text between the start tag and its end tag
056          $start  = $tag->getPos() + $tag->getLen();
057          $end    = $tag->getEndTag()->getPos();
058          $length = $end - $start;
059          $text   = substr($parser->getText(), $start, $length);
060   
061          // Create a tag that consumes the link's text
062          $parser->addSelfClosingTag('LINK_TEXT', $start, $length)->setAttribute('text', $text);
063   
064          return true;
065      }
066   
067      /**
068      * Test whether we should shorten this tag's text
069      *
070      * Will test whether the tag either does not use any markup or uses a single
071      * [url] BBCode
072      *
073      * @param  \s9e\TextFormatter\Parser\Tag $tag  URL tag
074      * @param  string                        $text Original text
075      * @return bool
076      */
077      protected function should_shorten(\s9e\TextFormatter\Parser\Tag $tag, $text)
078      {
079          return ($tag->getLen() === 0 || strtolower(substr($text, $tag->getPos(), $tag->getLen())) === '[url]');
080      }
081   
082      /**
083      * Remove the board's root URL from a the start of a string
084      *
085      * @param  \s9e\TextFormatter\Parser\Tag $tag       LINK_TEXT tag
086      * @param  string                        $board_url Forum's root URL (with trailing slash)
087      * @return bool                                     Always true to indicate that the tag is valid
088      */
089      public function truncate_local_url(\s9e\TextFormatter\Parser\Tag $tag, $board_url)
090      {
091          $text = $tag->getAttribute('text');
092          if (stripos($text, $board_url) === 0 && strlen($text) > strlen($board_url))
093          {
094              $tag->setAttribute('text', substr($text, strlen($board_url)));
095          }
096   
097          return true;
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 bool                               Always true to indicate that the tag is valid
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          }
113   
114          $tag->setAttribute('text', $text);
115   
116          return true;
117      }
118  }
119