Fix code standards
This commit is contained in:
parent
e807da9d66
commit
2f7e22c4f7
1 changed files with 38 additions and 37 deletions
|
@ -32,7 +32,7 @@ use Friendica\Model\Post;
|
||||||
*/
|
*/
|
||||||
class NPF
|
class NPF
|
||||||
{
|
{
|
||||||
static $heading_subtype = [];
|
private static $heading_subtype = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert BBCode into NPF (Tumblr Neue Post Format)
|
* Convert BBCode into NPF (Tumblr Neue Post Format)
|
||||||
|
@ -41,7 +41,7 @@ class NPF
|
||||||
* @param integer $uri_id
|
* @param integer $uri_id
|
||||||
* @return array NPF
|
* @return array NPF
|
||||||
*/
|
*/
|
||||||
static public function fromBBCode(string $bbcode, int $uri_id): array
|
public static function fromBBCode(string $bbcode, int $uri_id): array
|
||||||
{
|
{
|
||||||
$bbcode = self::prepareBody($bbcode);
|
$bbcode = self::prepareBody($bbcode);
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ class NPF
|
||||||
}
|
}
|
||||||
|
|
||||||
$doc = new DOMDocument();
|
$doc = new DOMDocument();
|
||||||
|
|
||||||
$doc->formatOutput = true;
|
$doc->formatOutput = true;
|
||||||
if (!@$doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'))) {
|
if (!@$doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'))) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -71,7 +72,7 @@ class NPF
|
||||||
* @param DOMDocument $doc
|
* @param DOMDocument $doc
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
static function setHeadingSubStyles(DOMDocument $doc)
|
private static function setHeadingSubStyles(DOMDocument $doc)
|
||||||
{
|
{
|
||||||
self::$heading_subtype = [];
|
self::$heading_subtype = [];
|
||||||
foreach (['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as $element) {
|
foreach (['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as $element) {
|
||||||
|
@ -91,7 +92,7 @@ class NPF
|
||||||
* @param string $bbcode
|
* @param string $bbcode
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
static private function prepareBody(string $bbcode): string
|
private static function prepareBody(string $bbcode): string
|
||||||
{
|
{
|
||||||
$shared = BBCode::fetchShareAttributes($bbcode);
|
$shared = BBCode::fetchShareAttributes($bbcode);
|
||||||
if (!empty($shared)) {
|
if (!empty($shared)) {
|
||||||
|
@ -140,7 +141,7 @@ class NPF
|
||||||
* @param array $formatting
|
* @param array $formatting
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
static private function routeChildren(DOMElement $element, int $uri_id, bool $parse_structure, array $callstack, array $npf = [], string $text = '', array $formatting = []): array
|
private static function routeChildren(DOMElement $element, int $uri_id, bool $parse_structure, array $callstack, array $npf = [], string $text = '', array $formatting = []): array
|
||||||
{
|
{
|
||||||
if ($parse_structure && $text) {
|
if ($parse_structure && $text) {
|
||||||
list($npf, $text, $formatting) = self::addBlock($text, $formatting, $npf, $callstack);
|
list($npf, $text, $formatting) = self::addBlock($text, $formatting, $npf, $callstack);
|
||||||
|
@ -217,7 +218,7 @@ class NPF
|
||||||
* @param array $callstack
|
* @param array $callstack
|
||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
static private function getLevelByCallstack(array $callstack): int
|
private static function getLevelByCallstack(array $callstack): int
|
||||||
{
|
{
|
||||||
$level = 0;
|
$level = 0;
|
||||||
foreach ($callstack as $entry) {
|
foreach ($callstack as $entry) {
|
||||||
|
@ -235,7 +236,7 @@ class NPF
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
static private function getSubTypeByCallstack(array $callstack, string $text): string
|
private static function getSubTypeByCallstack(array $callstack, string $text): string
|
||||||
{
|
{
|
||||||
$subtype = '';
|
$subtype = '';
|
||||||
foreach ($callstack as $entry) {
|
foreach ($callstack as $entry) {
|
||||||
|
@ -300,9 +301,10 @@ class NPF
|
||||||
* @param array $formatting
|
* @param array $formatting
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
static private function addFormatting(DOMElement $element, int $uri_id, string $type, array $callstack, array $npf, string $text, array $formatting): array
|
private static function addFormatting(DOMElement $element, int $uri_id, string $type, array $callstack, array $npf, string $text, array $formatting): array
|
||||||
{
|
{
|
||||||
$start = mb_strlen($text);
|
$start = mb_strlen($text);
|
||||||
|
|
||||||
list($npf, $text, $formatting) = self::routeChildren($element, $uri_id, false, $callstack, $npf, $text, $formatting);
|
list($npf, $text, $formatting) = self::routeChildren($element, $uri_id, false, $callstack, $npf, $text, $formatting);
|
||||||
|
|
||||||
if (!empty($type)) {
|
if (!empty($type)) {
|
||||||
|
@ -326,9 +328,10 @@ class NPF
|
||||||
* @param array $formatting
|
* @param array $formatting
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
static private function addInlineLink(DOMElement $element, int $uri_id, array $callstack, array $npf, string $text, array $formatting): array
|
private static function addInlineLink(DOMElement $element, int $uri_id, array $callstack, array $npf, string $text, array $formatting): array
|
||||||
{
|
{
|
||||||
$start = mb_strlen($text);
|
$start = mb_strlen($text);
|
||||||
|
|
||||||
list($npf, $text, $formatting) = self::routeChildren($element, $uri_id, false, $callstack, $npf, $text, $formatting);
|
list($npf, $text, $formatting) = self::routeChildren($element, $uri_id, false, $callstack, $npf, $text, $formatting);
|
||||||
|
|
||||||
$attributes = [];
|
$attributes = [];
|
||||||
|
@ -355,7 +358,7 @@ class NPF
|
||||||
* @param array $callstack
|
* @param array $callstack
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
static private function addBlock(string $text, array $formatting, array $npf, array $callstack): array
|
private static function addBlock(string $text, array $formatting, array $npf, array $callstack): array
|
||||||
{
|
{
|
||||||
$block = [
|
$block = [
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
|
@ -380,9 +383,7 @@ class NPF
|
||||||
}
|
}
|
||||||
|
|
||||||
$npf[] = $block;
|
$npf[] = $block;
|
||||||
$text = '';
|
return [$npf, '', []];
|
||||||
$formatting = [];
|
|
||||||
return [$npf, $text, $formatting];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -392,7 +393,7 @@ class NPF
|
||||||
* @param array $block
|
* @param array $block
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
static private function addPoster(array $media, array $block): array
|
private static function addPoster(array $media, array $block): array
|
||||||
{
|
{
|
||||||
$poster = [];
|
$poster = [];
|
||||||
if (!empty($media['preview'])) {
|
if (!empty($media['preview'])) {
|
||||||
|
@ -418,7 +419,7 @@ class NPF
|
||||||
* @param array $npf
|
* @param array $npf
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
static private function addLinkBlockForUriId(int $uri_id, int $level, array $npf): array
|
private static function addLinkBlockForUriId(int $uri_id, int $level, array $npf): array
|
||||||
{
|
{
|
||||||
foreach (Post\Media::getByURIId($uri_id, [Post\Media::HTML]) as $link) {
|
foreach (Post\Media::getByURIId($uri_id, [Post\Media::HTML]) as $link) {
|
||||||
$host = parse_url($link['url'], PHP_URL_HOST);
|
$host = parse_url($link['url'], PHP_URL_HOST);
|
||||||
|
@ -477,7 +478,7 @@ class NPF
|
||||||
* @param array $npf
|
* @param array $npf
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
static private function addImageBlock(DOMElement $element, int $uri_id, int $level, array $npf): array
|
private static function addImageBlock(DOMElement $element, int $uri_id, int $level, array $npf): array
|
||||||
{
|
{
|
||||||
$attributes = [];
|
$attributes = [];
|
||||||
foreach ($element->attributes as $key => $attribute) {
|
foreach ($element->attributes as $key => $attribute) {
|
||||||
|
@ -546,7 +547,7 @@ class NPF
|
||||||
* @param array $npf
|
* @param array $npf
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
static private function addMediaBlock(DOMElement $element, int $uri_id, int $level, array $npf): array
|
private static function addMediaBlock(DOMElement $element, int $uri_id, int $level, array $npf): array
|
||||||
{
|
{
|
||||||
$attributes = [];
|
$attributes = [];
|
||||||
foreach ($element->attributes as $key => $attribute) {
|
foreach ($element->attributes as $key => $attribute) {
|
||||||
|
|
Loading…
Reference in a new issue