@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function __construct(string $style = 'HTML') |
| 31 | 31 | { |
| 32 | - $this->style = $style; |
|
| 32 | + $this->style = $style; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function decode($message): string |
| 42 | 42 | { |
| 43 | - if(!is_object($message)) |
|
| 43 | + if (!is_object($message)) |
|
| 44 | 44 | { |
| 45 | 45 | throw new Exception('message must be an object'); |
| 46 | 46 | } |
| 47 | 47 | //Get available entities (for text or for attachment like photo, document, etc.) |
| 48 | - if(!empty($message->entities)) |
|
| 48 | + if (!empty($message->entities)) |
|
| 49 | 49 | $this->entities = $message->entities; |
| 50 | - if(!empty($message->caption_entities)) |
|
| 50 | + if (!empty($message->caption_entities)) |
|
| 51 | 51 | $this->entities = $message->caption_entities; |
| 52 | 52 | //Get internal encoding |
| 53 | 53 | $prevencoding = mb_internal_encoding(); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | $textToDecode = (!empty($message->text) ? $message->text : (!empty($message->caption) ? $message->caption : "")); |
| 58 | 58 | //if the message has no entities or no text return the original text |
| 59 | 59 | if (empty($this->entities) || $textToDecode == "") { |
| 60 | - if($prevencoding) |
|
| 60 | + if ($prevencoding) |
|
| 61 | 61 | mb_internal_encoding($prevencoding); |
| 62 | 62 | return $textToDecode; |
| 63 | 63 | } |
@@ -68,13 +68,13 @@ discard block |
||
| 68 | 68 | $openedEntities = []; |
| 69 | 69 | $currenPosition = 0; |
| 70 | 70 | //Cycle characters one by one to calculate begins and ends of entities and escape special chars |
| 71 | - for($i = 0; $i < count($arrayText); $i++) { |
|
| 71 | + for ($i = 0; $i < count($arrayText); $i++) { |
|
| 72 | 72 | $offsetAndLength = $currenPosition + $arrayText[$i]['length']; |
| 73 | 73 | $entityCheckStart = $this->checkForEntityStart($currenPosition); |
| 74 | 74 | $entityCheckStop = $this->checkForEntityStop($offsetAndLength); |
| 75 | - if($entityCheckStart !== false) |
|
| 75 | + if ($entityCheckStart !== false) |
|
| 76 | 76 | { |
| 77 | - foreach($entityCheckStart as $stEntity) |
|
| 77 | + foreach ($entityCheckStart as $stEntity) |
|
| 78 | 78 | { |
| 79 | 79 | $startChar = $this->getEntityStartString($stEntity); |
| 80 | 80 | $openedEntities[] = $stEntity; |
@@ -82,40 +82,40 @@ discard block |
||
| 82 | 82 | } |
| 83 | 83 | $finalText .= $this->escapeSpecialChars($arrayText[$i]['char'], true, $openedEntities); |
| 84 | 84 | } |
| 85 | - if($entityCheckStop !== false) |
|
| 85 | + if ($entityCheckStop !== false) |
|
| 86 | 86 | { |
| 87 | - if($entityCheckStart === false) |
|
| 87 | + if ($entityCheckStart === false) |
|
| 88 | 88 | $finalText .= $this->escapeSpecialChars($arrayText[$i]['char'], true, $openedEntities); |
| 89 | - if($this->style == 'MarkdownV2' && $this->checkMarkdownV2AmbiguousEntities($entityCheckStop)) |
|
| 89 | + if ($this->style == 'MarkdownV2' && $this->checkMarkdownV2AmbiguousEntities($entityCheckStop)) |
|
| 90 | 90 | { |
| 91 | 91 | $stopChar = "_\r__"; |
| 92 | 92 | $finalText .= $stopChar; |
| 93 | 93 | array_pop($openedEntities); |
| 94 | 94 | array_pop($openedEntities); |
| 95 | 95 | } |
| 96 | - foreach($entityCheckStop as $stEntity) |
|
| 96 | + foreach ($entityCheckStop as $stEntity) |
|
| 97 | 97 | { |
| 98 | 98 | $stopChar = $this->getEntityStopString($stEntity); |
| 99 | 99 | $finalText .= $stopChar; |
| 100 | 100 | array_pop($openedEntities); |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | - if($entityCheckStart === false && $entityCheckStop === false) |
|
| 103 | + if ($entityCheckStart === false && $entityCheckStop === false) |
|
| 104 | 104 | { |
| 105 | 105 | $isEntityOpen = count($openedEntities) > 0; |
| 106 | 106 | $finalText .= $this->escapeSpecialChars($arrayText[$i]['char'], $isEntityOpen, $openedEntities); |
| 107 | 107 | } |
| 108 | 108 | $currenPosition = $offsetAndLength; |
| 109 | 109 | } |
| 110 | - if(count($openedEntities) > 0) |
|
| 110 | + if (count($openedEntities) > 0) |
|
| 111 | 111 | { |
| 112 | 112 | $openedEntities = array_reverse($openedEntities); |
| 113 | - foreach($openedEntities as $oe) |
|
| 113 | + foreach ($openedEntities as $oe) |
|
| 114 | 114 | { |
| 115 | 115 | $finalText .= $this->getEntityStopString($oe); |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | - if($prevencoding) |
|
| 118 | + if ($prevencoding) |
|
| 119 | 119 | mb_internal_encoding($prevencoding); |
| 120 | 120 | |
| 121 | 121 | return $finalText; |
@@ -130,36 +130,36 @@ discard block |
||
| 130 | 130 | $str_split_unicode = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY); |
| 131 | 131 | $new_string_split = []; |
| 132 | 132 | $joiner = false; |
| 133 | - for($i = 0; $i<count($str_split_unicode); $i++) //loop the array |
|
| 133 | + for ($i = 0; $i < count($str_split_unicode); $i++) //loop the array |
|
| 134 | 134 | { |
| 135 | - $codepoint = bin2hex(mb_convert_encoding($str_split_unicode[$i], 'UTF-16')); //Get the string rappresentation of the unicode char |
|
| 136 | - if($codepoint == "fe0f" || $codepoint == "1f3fb" || $codepoint == "1f3fc" || $codepoint == "1f3fd" || $codepoint == "1f3fe" || $codepoint == "1f3ff") //Manage the modifiers |
|
| 135 | + $codepoint = bin2hex(mb_convert_encoding($str_split_unicode[$i], 'UTF-16')); //Get the string rappresentation of the unicode char |
|
| 136 | + if ($codepoint == "fe0f" || $codepoint == "1f3fb" || $codepoint == "1f3fc" || $codepoint == "1f3fd" || $codepoint == "1f3fe" || $codepoint == "1f3ff") //Manage the modifiers |
|
| 137 | 137 | { |
| 138 | - $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend the modifier to the previous char |
|
| 138 | + $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend the modifier to the previous char |
|
| 139 | 139 | } |
| 140 | 140 | else |
| 141 | 141 | { |
| 142 | - if($codepoint == "200d") //Manage the Zero Width Joiner |
|
| 142 | + if ($codepoint == "200d") //Manage the Zero Width Joiner |
|
| 143 | 143 | { |
| 144 | 144 | $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend the ZWJ to the previous char |
| 145 | 145 | $joiner = true; |
| 146 | 146 | } |
| 147 | 147 | else |
| 148 | 148 | { |
| 149 | - if($joiner) //If previous one was a ZWJ |
|
| 149 | + if ($joiner) //If previous one was a ZWJ |
|
| 150 | 150 | { |
| 151 | - $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend to the previous char |
|
| 151 | + $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend to the previous char |
|
| 152 | 152 | $joiner = false; |
| 153 | 153 | } |
| 154 | 154 | else |
| 155 | 155 | { |
| 156 | - $new_string_split[] = $str_split_unicode[$i]; //New char |
|
| 156 | + $new_string_split[] = $str_split_unicode[$i]; //New char |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | $data = []; |
| 162 | - foreach($new_string_split as $s) |
|
| 162 | + foreach ($new_string_split as $s) |
|
| 163 | 163 | { |
| 164 | 164 | $data[] = ["char" => $s, "length" => $this->getUTF16CodePointsLength($s)]; |
| 165 | 165 | } |
@@ -170,14 +170,14 @@ discard block |
||
| 170 | 170 | * Apply Telegram escape rules for the choosen style |
| 171 | 171 | */ |
| 172 | 172 | protected function escapeSpecialChars($char, $isEntityOpen, $entities) { |
| 173 | - if($this->style == 'Markdown') |
|
| 173 | + if ($this->style == 'Markdown') |
|
| 174 | 174 | { |
| 175 | - if($isEntityOpen) |
|
| 175 | + if ($isEntityOpen) |
|
| 176 | 176 | { |
| 177 | 177 | $entity = $entities[0]; |
| 178 | - if($char == '*' || $char == '_') |
|
| 178 | + if ($char == '*' || $char == '_') |
|
| 179 | 179 | { |
| 180 | - if($char == $this->getEntityStartString($entity)) |
|
| 180 | + if ($char == $this->getEntityStartString($entity)) |
|
| 181 | 181 | { |
| 182 | 182 | return $char."\\".$char.$char; |
| 183 | 183 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | } |
| 194 | 194 | else |
| 195 | 195 | { |
| 196 | - if($char == '*' || $char == '_' || $char == '[' || $char == '`') |
|
| 196 | + if ($char == '*' || $char == '_' || $char == '[' || $char == '`') |
|
| 197 | 197 | { |
| 198 | 198 | return "\\".$char; |
| 199 | 199 | } |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | - else if($this->style == 'HTML') |
|
| 206 | + else if ($this->style == 'HTML') |
|
| 207 | 207 | { |
| 208 | 208 | return ($char == '<' ? '<' : ($char == '>' ? '>' : ($char == '&' ? '&' : $char))); |
| 209 | 209 | } |
| 210 | - else if($this->style == 'MarkdownV2') |
|
| 210 | + else if ($this->style == 'MarkdownV2') |
|
| 211 | 211 | { |
| 212 | 212 | return (in_array($char, array('_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\')) ? '\\'.$char : $char); |
| 213 | 213 | } |
@@ -223,9 +223,9 @@ discard block |
||
| 223 | 223 | protected function getEntityStartString($entity) |
| 224 | 224 | { |
| 225 | 225 | $startString = ''; |
| 226 | - if($this->style == 'Markdown') |
|
| 226 | + if ($this->style == 'Markdown') |
|
| 227 | 227 | { |
| 228 | - switch($entity->type) |
|
| 228 | + switch ($entity->type) |
|
| 229 | 229 | { |
| 230 | 230 | case 'bold': |
| 231 | 231 | { |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | case 'pre': |
| 246 | 246 | { |
| 247 | 247 | $startString = '```'; |
| 248 | - if(isset($entity->language)) |
|
| 248 | + if (isset($entity->language)) |
|
| 249 | 249 | { |
| 250 | 250 | $startString .= $entity->language; |
| 251 | 251 | } |
@@ -259,9 +259,9 @@ discard block |
||
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | - else if($this->style == 'HTML') |
|
| 262 | + else if ($this->style == 'HTML') |
|
| 263 | 263 | { |
| 264 | - switch($entity->type) |
|
| 264 | + switch ($entity->type) |
|
| 265 | 265 | { |
| 266 | 266 | case 'bold': |
| 267 | 267 | { |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | case 'pre': |
| 297 | 297 | { |
| 298 | 298 | $startString = '<pre>'; |
| 299 | - if(isset($entity->language)) |
|
| 299 | + if (isset($entity->language)) |
|
| 300 | 300 | { |
| 301 | 301 | $startString .= '<code class="language-'.$entity->language.'">'; |
| 302 | 302 | } |
@@ -314,9 +314,9 @@ discard block |
||
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | - else if($this->style == 'MarkdownV2') |
|
| 317 | + else if ($this->style == 'MarkdownV2') |
|
| 318 | 318 | { |
| 319 | - switch($entity->type) |
|
| 319 | + switch ($entity->type) |
|
| 320 | 320 | { |
| 321 | 321 | case 'bold': |
| 322 | 322 | { |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | case 'pre': |
| 342 | 342 | { |
| 343 | 343 | $startString = '```'; |
| 344 | - if(isset($entity->language)) |
|
| 344 | + if (isset($entity->language)) |
|
| 345 | 345 | { |
| 346 | 346 | $startString .= $entity->language; |
| 347 | 347 | } |
@@ -378,17 +378,17 @@ discard block |
||
| 378 | 378 | protected function checkForEntityStart($pos) |
| 379 | 379 | { |
| 380 | 380 | $entities = []; |
| 381 | - foreach($this->entities as $entity) |
|
| 381 | + foreach ($this->entities as $entity) |
|
| 382 | 382 | { |
| 383 | - if($entity->offset == $pos) |
|
| 383 | + if ($entity->offset == $pos) |
|
| 384 | 384 | { |
| 385 | - if(in_array($entity->type, array('bold', 'italic', 'code', 'pre', 'text_mention', 'text_link', 'strikethrough', 'underline', 'spoiler'))) |
|
| 385 | + if (in_array($entity->type, array('bold', 'italic', 'code', 'pre', 'text_mention', 'text_link', 'strikethrough', 'underline', 'spoiler'))) |
|
| 386 | 386 | { |
| 387 | 387 | $entities[] = $entity; |
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | - if(count($entities) > 0) |
|
| 391 | + if (count($entities) > 0) |
|
| 392 | 392 | return $entities; |
| 393 | 393 | else |
| 394 | 394 | return false; |
@@ -400,9 +400,9 @@ discard block |
||
| 400 | 400 | protected function getEntityStopString($entity) |
| 401 | 401 | { |
| 402 | 402 | $stopString = ''; |
| 403 | - if($this->style == 'Markdown') |
|
| 403 | + if ($this->style == 'Markdown') |
|
| 404 | 404 | { |
| 405 | - switch($entity->type) |
|
| 405 | + switch ($entity->type) |
|
| 406 | 406 | { |
| 407 | 407 | case 'bold': |
| 408 | 408 | { |
@@ -436,9 +436,9 @@ discard block |
||
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | - else if($this->style == 'HTML') |
|
| 439 | + else if ($this->style == 'HTML') |
|
| 440 | 440 | { |
| 441 | - switch($entity->type) |
|
| 441 | + switch ($entity->type) |
|
| 442 | 442 | { |
| 443 | 443 | case 'bold': |
| 444 | 444 | { |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | } |
| 473 | 473 | case 'pre': |
| 474 | 474 | { |
| 475 | - if(isset($entity->language)) |
|
| 475 | + if (isset($entity->language)) |
|
| 476 | 476 | { |
| 477 | 477 | $stopString = '</code>'; |
| 478 | 478 | } |
@@ -487,9 +487,9 @@ discard block |
||
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | - else if($this->style == 'MarkdownV2') |
|
| 490 | + else if ($this->style == 'MarkdownV2') |
|
| 491 | 491 | { |
| 492 | - switch($entity->type) |
|
| 492 | + switch ($entity->type) |
|
| 493 | 493 | { |
| 494 | 494 | case 'bold': |
| 495 | 495 | { |
@@ -551,17 +551,17 @@ discard block |
||
| 551 | 551 | protected function checkForEntityStop($pos) |
| 552 | 552 | { |
| 553 | 553 | $entities = []; |
| 554 | - foreach($this->entities as $entity) |
|
| 554 | + foreach ($this->entities as $entity) |
|
| 555 | 555 | { |
| 556 | - if($entity->offset + $entity->length == $pos) |
|
| 556 | + if ($entity->offset + $entity->length == $pos) |
|
| 557 | 557 | { |
| 558 | - if(in_array($entity->type, array('bold', 'italic', 'code', 'pre', 'text_mention', 'text_link', 'strikethrough', 'underline', 'spoiler'))) |
|
| 558 | + if (in_array($entity->type, array('bold', 'italic', 'code', 'pre', 'text_mention', 'text_link', 'strikethrough', 'underline', 'spoiler'))) |
|
| 559 | 559 | { |
| 560 | 560 | $entities[] = $entity; |
| 561 | 561 | } |
| 562 | 562 | } |
| 563 | 563 | } |
| 564 | - if(count($entities) > 0) |
|
| 564 | + if (count($entities) > 0) |
|
| 565 | 565 | return array_reverse($entities); |
| 566 | 566 | else |
| 567 | 567 | return false; |
@@ -575,19 +575,19 @@ discard block |
||
| 575 | 575 | $result = false; |
| 576 | 576 | $newEntities = []; |
| 577 | 577 | $foundIndex = 0; |
| 578 | - foreach($entitiesToCheck as $ec) |
|
| 578 | + foreach ($entitiesToCheck as $ec) |
|
| 579 | 579 | { |
| 580 | - if($ec->type == 'italic' || $ec->type == 'underline') |
|
| 580 | + if ($ec->type == 'italic' || $ec->type == 'underline') |
|
| 581 | 581 | { |
| 582 | 582 | $foundIndex++; |
| 583 | 583 | } |
| 584 | 584 | } |
| 585 | - if($foundIndex == 2) |
|
| 585 | + if ($foundIndex == 2) |
|
| 586 | 586 | { |
| 587 | 587 | $result = true; |
| 588 | - foreach($entitiesToCheck as $ec) |
|
| 588 | + foreach ($entitiesToCheck as $ec) |
|
| 589 | 589 | { |
| 590 | - if($ec->type != 'italic' && $ec->type != 'underline') |
|
| 590 | + if ($ec->type != 'italic' && $ec->type != 'underline') |
|
| 591 | 591 | { |
| 592 | 592 | $newEntities[] = $ec; |
| 593 | 593 | } |
@@ -45,10 +45,12 @@ discard block |
||
| 45 | 45 | throw new Exception('message must be an object'); |
| 46 | 46 | } |
| 47 | 47 | //Get available entities (for text or for attachment like photo, document, etc.) |
| 48 | - if(!empty($message->entities)) |
|
| 49 | - $this->entities = $message->entities; |
|
| 50 | - if(!empty($message->caption_entities)) |
|
| 51 | - $this->entities = $message->caption_entities; |
|
| 48 | + if(!empty($message->entities)) { |
|
| 49 | + $this->entities = $message->entities; |
|
| 50 | + } |
|
| 51 | + if(!empty($message->caption_entities)) { |
|
| 52 | + $this->entities = $message->caption_entities; |
|
| 53 | + } |
|
| 52 | 54 | //Get internal encoding |
| 53 | 55 | $prevencoding = mb_internal_encoding(); |
| 54 | 56 | //Set encoding to UTF-8 |
@@ -57,8 +59,9 @@ discard block |
||
| 57 | 59 | $textToDecode = (!empty($message->text) ? $message->text : (!empty($message->caption) ? $message->caption : "")); |
| 58 | 60 | //if the message has no entities or no text return the original text |
| 59 | 61 | if (empty($this->entities) || $textToDecode == "") { |
| 60 | - if($prevencoding) |
|
| 61 | - mb_internal_encoding($prevencoding); |
|
| 62 | + if($prevencoding) { |
|
| 63 | + mb_internal_encoding($prevencoding); |
|
| 64 | + } |
|
| 62 | 65 | return $textToDecode; |
| 63 | 66 | } |
| 64 | 67 | //split text in char array with UTF-16 code units length |
@@ -84,8 +87,9 @@ discard block |
||
| 84 | 87 | } |
| 85 | 88 | if($entityCheckStop !== false) |
| 86 | 89 | { |
| 87 | - if($entityCheckStart === false) |
|
| 88 | - $finalText .= $this->escapeSpecialChars($arrayText[$i]['char'], true, $openedEntities); |
|
| 90 | + if($entityCheckStart === false) { |
|
| 91 | + $finalText .= $this->escapeSpecialChars($arrayText[$i]['char'], true, $openedEntities); |
|
| 92 | + } |
|
| 89 | 93 | if($this->style == 'MarkdownV2' && $this->checkMarkdownV2AmbiguousEntities($entityCheckStop)) |
| 90 | 94 | { |
| 91 | 95 | $stopChar = "_\r__"; |
@@ -115,8 +119,9 @@ discard block |
||
| 115 | 119 | $finalText .= $this->getEntityStopString($oe); |
| 116 | 120 | } |
| 117 | 121 | } |
| 118 | - if($prevencoding) |
|
| 119 | - mb_internal_encoding($prevencoding); |
|
| 122 | + if($prevencoding) { |
|
| 123 | + mb_internal_encoding($prevencoding); |
|
| 124 | + } |
|
| 120 | 125 | |
| 121 | 126 | return $finalText; |
| 122 | 127 | } |
@@ -130,28 +135,37 @@ discard block |
||
| 130 | 135 | $str_split_unicode = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY); |
| 131 | 136 | $new_string_split = []; |
| 132 | 137 | $joiner = false; |
| 133 | - for($i = 0; $i<count($str_split_unicode); $i++) //loop the array |
|
| 138 | + for($i = 0; $i<count($str_split_unicode); $i++) { |
|
| 139 | + //loop the array |
|
| 134 | 140 | { |
| 135 | - $codepoint = bin2hex(mb_convert_encoding($str_split_unicode[$i], 'UTF-16')); //Get the string rappresentation of the unicode char |
|
| 136 | - if($codepoint == "fe0f" || $codepoint == "1f3fb" || $codepoint == "1f3fc" || $codepoint == "1f3fd" || $codepoint == "1f3fe" || $codepoint == "1f3ff") //Manage the modifiers |
|
| 141 | + $codepoint = bin2hex(mb_convert_encoding($str_split_unicode[$i], 'UTF-16')); |
|
| 142 | + } |
|
| 143 | + //Get the string rappresentation of the unicode char |
|
| 144 | + if($codepoint == "fe0f" || $codepoint == "1f3fb" || $codepoint == "1f3fc" || $codepoint == "1f3fd" || $codepoint == "1f3fe" || $codepoint == "1f3ff") { |
|
| 145 | + //Manage the modifiers |
|
| 137 | 146 | { |
| 138 | - $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend the modifier to the previous char |
|
| 147 | + $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; |
|
| 139 | 148 | } |
| 140 | - else |
|
| 149 | + //Apppend the modifier to the previous char |
|
| 150 | + } else |
|
| 141 | 151 | { |
| 142 | - if($codepoint == "200d") //Manage the Zero Width Joiner |
|
| 152 | + if($codepoint == "200d") { |
|
| 153 | + //Manage the Zero Width Joiner |
|
| 143 | 154 | { |
| 144 | - $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend the ZWJ to the previous char |
|
| 145 | - $joiner = true; |
|
| 155 | + $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; |
|
| 146 | 156 | } |
| 147 | - else |
|
| 157 | + //Apppend the ZWJ to the previous char |
|
| 158 | + $joiner = true; |
|
| 159 | + } else |
|
| 148 | 160 | { |
| 149 | - if($joiner) //If previous one was a ZWJ |
|
| 161 | + if($joiner) { |
|
| 162 | + //If previous one was a ZWJ |
|
| 150 | 163 | { |
| 151 | - $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend to the previous char |
|
| 152 | - $joiner = false; |
|
| 164 | + $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; |
|
| 153 | 165 | } |
| 154 | - else |
|
| 166 | + //Apppend to the previous char |
|
| 167 | + $joiner = false; |
|
| 168 | + } else |
|
| 155 | 169 | { |
| 156 | 170 | $new_string_split[] = $str_split_unicode[$i]; //New char |
| 157 | 171 | } |
@@ -180,38 +194,31 @@ discard block |
||
| 180 | 194 | if($char == $this->getEntityStartString($entity)) |
| 181 | 195 | { |
| 182 | 196 | return $char."\\".$char.$char; |
| 183 | - } |
|
| 184 | - else |
|
| 197 | + } else |
|
| 185 | 198 | { |
| 186 | 199 | return $char; |
| 187 | 200 | } |
| 188 | - } |
|
| 189 | - else |
|
| 201 | + } else |
|
| 190 | 202 | { |
| 191 | 203 | return $char; |
| 192 | 204 | } |
| 193 | - } |
|
| 194 | - else |
|
| 205 | + } else |
|
| 195 | 206 | { |
| 196 | 207 | if($char == '*' || $char == '_' || $char == '[' || $char == '`') |
| 197 | 208 | { |
| 198 | 209 | return "\\".$char; |
| 199 | - } |
|
| 200 | - else |
|
| 210 | + } else |
|
| 201 | 211 | { |
| 202 | 212 | return $char; |
| 203 | 213 | } |
| 204 | 214 | } |
| 205 | - } |
|
| 206 | - else if($this->style == 'HTML') |
|
| 215 | + } else if($this->style == 'HTML') |
|
| 207 | 216 | { |
| 208 | 217 | return ($char == '<' ? '<' : ($char == '>' ? '>' : ($char == '&' ? '&' : $char))); |
| 209 | - } |
|
| 210 | - else if($this->style == 'MarkdownV2') |
|
| 218 | + } else if($this->style == 'MarkdownV2') |
|
| 211 | 219 | { |
| 212 | 220 | return (in_array($char, array('_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\')) ? '\\'.$char : $char); |
| 213 | - } |
|
| 214 | - else |
|
| 221 | + } else |
|
| 215 | 222 | { |
| 216 | 223 | return $char; |
| 217 | 224 | } |
@@ -258,8 +265,7 @@ discard block |
||
| 258 | 265 | break; |
| 259 | 266 | } |
| 260 | 267 | } |
| 261 | - } |
|
| 262 | - else if($this->style == 'HTML') |
|
| 268 | + } else if($this->style == 'HTML') |
|
| 263 | 269 | { |
| 264 | 270 | switch($entity->type) |
| 265 | 271 | { |
@@ -313,8 +319,7 @@ discard block |
||
| 313 | 319 | break; |
| 314 | 320 | } |
| 315 | 321 | } |
| 316 | - } |
|
| 317 | - else if($this->style == 'MarkdownV2') |
|
| 322 | + } else if($this->style == 'MarkdownV2') |
|
| 318 | 323 | { |
| 319 | 324 | switch($entity->type) |
| 320 | 325 | { |
@@ -364,8 +369,7 @@ discard block |
||
| 364 | 369 | break; |
| 365 | 370 | } |
| 366 | 371 | } |
| 367 | - } |
|
| 368 | - else |
|
| 372 | + } else |
|
| 369 | 373 | { |
| 370 | 374 | //Exception |
| 371 | 375 | } |
@@ -388,10 +392,11 @@ discard block |
||
| 388 | 392 | } |
| 389 | 393 | } |
| 390 | 394 | } |
| 391 | - if(count($entities) > 0) |
|
| 392 | - return $entities; |
|
| 393 | - else |
|
| 394 | - return false; |
|
| 395 | + if(count($entities) > 0) { |
|
| 396 | + return $entities; |
|
| 397 | + } else { |
|
| 398 | + return false; |
|
| 399 | + } |
|
| 395 | 400 | } |
| 396 | 401 | |
| 397 | 402 | /** |
@@ -435,8 +440,7 @@ discard block |
||
| 435 | 440 | break; |
| 436 | 441 | } |
| 437 | 442 | } |
| 438 | - } |
|
| 439 | - else if($this->style == 'HTML') |
|
| 443 | + } else if($this->style == 'HTML') |
|
| 440 | 444 | { |
| 441 | 445 | switch($entity->type) |
| 442 | 446 | { |
@@ -486,8 +490,7 @@ discard block |
||
| 486 | 490 | break; |
| 487 | 491 | } |
| 488 | 492 | } |
| 489 | - } |
|
| 490 | - else if($this->style == 'MarkdownV2') |
|
| 493 | + } else if($this->style == 'MarkdownV2') |
|
| 491 | 494 | { |
| 492 | 495 | switch($entity->type) |
| 493 | 496 | { |
@@ -537,8 +540,7 @@ discard block |
||
| 537 | 540 | break; |
| 538 | 541 | } |
| 539 | 542 | } |
| 540 | - } |
|
| 541 | - else |
|
| 543 | + } else |
|
| 542 | 544 | { |
| 543 | 545 | //Exception |
| 544 | 546 | } |
@@ -561,10 +563,11 @@ discard block |
||
| 561 | 563 | } |
| 562 | 564 | } |
| 563 | 565 | } |
| 564 | - if(count($entities) > 0) |
|
| 565 | - return array_reverse($entities); |
|
| 566 | - else |
|
| 567 | - return false; |
|
| 566 | + if(count($entities) > 0) { |
|
| 567 | + return array_reverse($entities); |
|
| 568 | + } else { |
|
| 569 | + return false; |
|
| 570 | + } |
|
| 568 | 571 | } |
| 569 | 572 | |
| 570 | 573 | /** |