|
@@ -32,6 +32,75 @@ class Score
|
|
|
return self::$tmpArray;
|
|
return self::$tmpArray;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+function getContainsByText(?string $text): array
|
|
|
|
|
+{
|
|
|
|
|
+ $h2Array = [];
|
|
|
|
|
+ $h3 = [];
|
|
|
|
|
+ $activeId = '';
|
|
|
|
|
+
|
|
|
|
|
+ preg_match_all('/<h2[^>]*>(.*?)<\/h2>|<h3[^>]*>(.*?)<\/h3>/i', $text, $matches);
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($matches[0])) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($matches[1] as $key => $textH2) {
|
|
|
|
|
+ if (empty($textH2) && isset($matches[2][$key]) && ! empty($matches[2][$key])) {
|
|
|
|
|
+ $h3[] = [
|
|
|
|
|
+ 'id' => Str::slug($matches[2][$key]),
|
|
|
|
|
+ 'text' => $matches[2][$key],
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (! empty($h3)) {
|
|
|
|
|
+ $h2Array[$activeId]['h3'] = $h3;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $h3 = [];
|
|
|
|
|
+ $activeText = $textH2;
|
|
|
|
|
+ $activeId = Str::slug($textH2);
|
|
|
|
|
+ $h2Array[$activeId] = [
|
|
|
|
|
+ 'id' => $activeId,
|
|
|
|
|
+ 'text' => $activeText,
|
|
|
|
|
+ 'h3' => $h3,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (! empty($h3)) {
|
|
|
|
|
+ $h2Array[$activeId]['h3'] = $h3;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $h2Array;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function addIdToHInText(?string $text, array $h2AnchorsArray = []): ?string
|
|
|
|
|
+{
|
|
|
|
|
+ if (empty($h2AnchorsArray)) {
|
|
|
|
|
+ $h2AnchorsArray = getContainsByText($text);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($h2AnchorsArray as $data) {
|
|
|
|
|
+ if (empty($data['text'])) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $h2Pattern = '/<h2([^>]*)>'.preg_quote($data['text'], '/').'<\/h2>/i';
|
|
|
|
|
+ $replacementH2 = "<h2\$1 id=\"{$data['id']}\">".str_replace('$', '\\$', $data['text']).'</h2>';
|
|
|
|
|
+ $text = preg_replace($h2Pattern, $replacementH2, $text);
|
|
|
|
|
+
|
|
|
|
|
+ if (! empty($data['h3'])) {
|
|
|
|
|
+ foreach ($data['h3'] as $h3data) {
|
|
|
|
|
+ $h3Pattern = '/<h3([^>]*)>'.preg_quote($h3data['text'], '/').'<\/h3>/i';
|
|
|
|
|
+ $replacementH3 = "<h3\$1 id=\"{$h3data['id']}\">".str_replace('$', '\\$', $h3data['text']).'</h3>';
|
|
|
|
|
+ $text = preg_replace($h3Pattern, $replacementH3, $text);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $text;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
function array_to_csv_download($array, $filename = "export.csv", $delimiter = ";") {
|
|
function array_to_csv_download($array, $filename = "export.csv", $delimiter = ";") {
|
|
|
$maxArray = [];
|
|
$maxArray = [];
|