forked from GNUsocial/gnu-social
[UTIL] Add utility to flatten the result of note queries
This commit is contained in:
parent
74f477489b
commit
687b2e2bc7
@ -267,4 +267,19 @@ abstract class Common
|
|||||||
return filter_var($url, FILTER_VALIDATE_URL)
|
return filter_var($url, FILTER_VALIDATE_URL)
|
||||||
&& preg_match($regex, parse_url($url, PHP_URL_SCHEME));
|
&& preg_match($regex, parse_url($url, PHP_URL_SCHEME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flatten an array of ['note' => note, 'replies' => [notes]] to an array of notes
|
||||||
|
*/
|
||||||
|
public static function flattenNoteArray(array $a): array
|
||||||
|
{
|
||||||
|
$notes = [];
|
||||||
|
foreach ($a as $n) {
|
||||||
|
$notes[] = $n['note'];
|
||||||
|
if (isset($n['replies'])) {
|
||||||
|
$notes = array_merge($notes, static::flattenNoteArray($n['replies']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $notes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user