예제 #1
0
 /**
  * Inject dynamic metadata into QUOTE tags in given XML
  *
  * @param  string $xml Original XML
  * @return string      Modified XML
  */
 public function inject_metadata($xml)
 {
     $post_url = $this->post_url;
     $profile_url = $this->profile_url;
     $user = $this->user;
     return \s9e\TextFormatter\Utils::replaceAttributes($xml, 'QUOTE', function ($attributes) use($post_url, $profile_url, $user) {
         if (isset($attributes['post_id'])) {
             $attributes['post_url'] = str_replace('{POST_ID}', $attributes['post_id'], $post_url);
         }
         if (isset($attributes['time'])) {
             $attributes['date'] = $user->format_date($attributes['time']);
         }
         if (isset($attributes['user_id'])) {
             $attributes['profile_url'] = str_replace('{USER_ID}', $attributes['user_id'], $profile_url);
         }
         return $attributes;
     });
 }
 /**
  * @param Post $reply
  */
 protected function replyBecameVisible(Post $reply)
 {
     $mentioned = Utils::getAttributeValues($reply->parsedContent, 'POSTMENTION', 'id');
     $this->sync($reply, $mentioned);
 }
 /**
  * @param Post $post
  */
 protected function postBecameVisible(Post $post)
 {
     $mentioned = Utils::getAttributeValues($post->parsedContent, 'USERMENTION', 'id');
     $this->sync($post, $mentioned);
 }
예제 #4
0
파일: utils.php 프로젝트: binano/phpbb
 /**
  * Remove given BBCode and its content, at given nesting depth
  *
  * @param  string  $xml         Parsed text
  * @param  string  $bbcode_name BBCode's name
  * @param  integer $depth       Minimum nesting depth (number of parents of the same name)
  * @return string               Parsed text
  */
 public function remove_bbcode($xml, $bbcode_name, $depth = 0)
 {
     return \s9e\TextFormatter\Utils::removeTag($xml, strtoupper($bbcode_name), $depth);
 }
예제 #5
0
 /**
  * @testdox replaceAttributes() tests
  * @dataProvider getReplaceAttributesTests
  */
 public function testReplaceAttributes($original, $expected, $tagName, $callback)
 {
     $this->assertSame($expected, Utils::replaceAttributes($original, $tagName, $callback));
 }
예제 #6
0
 protected function finalizeOutput()
 {
     $this->outputText($this->textLen, 0, \true);
     do {
         $this->output = \preg_replace('(<([^ />]+)></\\1>)', '', $this->output, -1, $cnt);
     } while ($cnt > 0);
     if (\strpos($this->output, '</i><i>') !== \false) {
         $this->output = \str_replace('</i><i>', '', $this->output);
     }
     $this->output = Utils::encodeUnicodeSupplementaryCharacters($this->output);
     $tagName = $this->isRich ? 'r' : 't';
     $tmp = '<' . $tagName;
     foreach (\array_keys($this->namespaces) as $prefix) {
         $tmp .= ' xmlns:' . $prefix . '="urn:s9e:TextFormatter:' . $prefix . '"';
     }
     $this->output = $tmp . '>' . $this->output . '</' . $tagName . '>';
 }
예제 #7
0
 /**
  * Finalize the output by appending the rest of the unprocessed text and create the root node
  *
  * @return void
  */
 protected function finalizeOutput()
 {
     // Output the rest of the text and close the last paragraph
     $this->outputText($this->textLen, 0, true);
     // Remove empty tag pairs, e.g. <I><U></U></I> as well as empty paragraphs
     do {
         $this->output = preg_replace('(<([^ />]+)></\\1>)', '', $this->output, -1, $cnt);
     } while ($cnt > 0);
     // Merge consecutive <i> tags
     if (strpos($this->output, '</i><i>') !== false) {
         $this->output = str_replace('</i><i>', '', $this->output);
     }
     // Encode Unicode characters that are outside of the BMP
     $this->output = Utils::encodeUnicodeSupplementaryCharacters($this->output);
     // Use a <r> root if the text is rich, or <t> for plain text (including <p></p> and <br/>)
     $tagName = $this->isRich ? 'r' : 't';
     // Prepare the root node with all the namespace declarations
     $tmp = '<' . $tagName;
     foreach (array_keys($this->namespaces) as $prefix) {
         $tmp .= ' xmlns:' . $prefix . '="urn:s9e:TextFormatter:' . $prefix . '"';
     }
     $this->output = $tmp . '>' . $this->output . '</' . $tagName . '>';
 }