* Return mimetype based on file extension
*
* @param string $filename filename
+ *
* @return mixed array or string
*/
public static function getContentType(string $filename)
* and check DNS to see if it's real (or check if is a valid IP address)
*
* @param string $url The URL to be validated
+ *
* @return string|boolean The actual working URL, false else
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
*
* @param string $domain
* @param array $domain_list
+ *
* @return boolean
*/
public static function isDomainAllowed(string $domain, array $domain_list): bool
* Remove Google Analytics and other tracking platforms params from URL
*
* @param string $url Any user-submitted URL that may contain tracking params
+ *
* @return string The same URL stripped of tracking parameters
*/
public static function stripTrackingQueryParams(string $url): string
*
* @param string $url
* @param string $basepath
+ *
* @return string url
*/
- public static function addBasePath(string $url, string $basepath)
+ public static function addBasePath(string $url, string $basepath): string
{
if (!empty(parse_url($url, PHP_URL_SCHEME)) || empty(parse_url($basepath, PHP_URL_SCHEME)) || empty($url) || empty(parse_url($url))) {
return $url;
*
* @param string $url1
* @param string $url2
+ *
* @return string The matching part or empty string on error
*/
public static function getUrlMatch(string $url1, string $url2): string
* Glue url parts together
*
* @param array $parsed URL parts
+ *
* @return string|null The glued URL or null on error
* @deprecated since version 2021.12, use GuzzleHttp\Psr7\Uri::fromParts($parts) instead
*/
* Convert an URI to an IDN compatible URI
*
* @param string $uri
+ *
* @return string
*/
public static function convertToIdn(string $uri): string
* Switch the scheme of an url between http and https
*
* @param string $url
+ *
* @return string Switched URL
*/
public static function switchScheme(string $url): string
*
* @param string $path
* @param array $additionalParams Associative array of parameters
+ *
* @return string
*/
public static function appendQueryParam(string $path, array $additionalParams): string
*
* @param string $etag The page etag
* @param string $last_modified The page last modification UTC date
+ *
* @return void
* @throws \Exception
*/
* Check if the given URL is a local link
*
* @param string $url
+ *
* @return bool
*/
public static function isLocalLink(string $url): bool
* </body>
* @endverbatim
*/
- public static function getSiteinfo(string $url, bool $do_oembed = true, int $count = 1)
+ public static function getSiteinfo(string $url, bool $do_oembed = true, int $count = 1): array
{
if (empty($url)) {
return [
* Convert tags from CSV to an array
*
* @param string $string Tags
+ *
* @return array with formatted Hashtags
*/
public static function convertTagsToArray(string $string): array
*
* @param string $tag The pure tag name
* @param int $k Counter for internal use
+ *
* @return void
*/
private static function arrAddHashes(string &$tag, int $k)
*
* @param array $siteinfo
* @param array $jsonld
+ *
* @return array siteinfo
*/
private static function parseParts(array $siteinfo, array $jsonld): array
*
* @param array $siteinfo
* @param array $jsonld
+ *
* @return array siteinfo
*/
private static function parseJsonLd(array $siteinfo, array $jsonld): array
*
* @param array $siteinfo
* @param array $jsonld
+ *
* @return array siteinfo
*/
private static function parseJsonLdAuthor(array $siteinfo, array $jsonld): array
*
* @param array $siteinfo
* @param array $jsonld
+ *
* @return array siteinfo
*/
private static function parseJsonLdArticle(array $siteinfo, array $jsonld): array
*
* @param array $siteinfo
* @param array $jsonld
+ *
* @return array siteinfo
*/
private static function parseJsonLdWebPage(array $siteinfo, array $jsonld): array
*
* @param array $siteinfo
* @param array $jsonld
+ *
* @return array siteinfo
*/
private static function parseJsonLdWebSite(array $siteinfo, array $jsonld): array
*
* @param array $siteinfo
* @param array $jsonld
+ *
* @return array siteinfo
*/
private static function parseJsonLdWebOrganization(array $siteinfo, array $jsonld): array
*
* @param array $siteinfo
* @param array $jsonld
+ *
* @return array siteinfo
*/
private static function parseJsonLdWebPerson(array $siteinfo, array $jsonld): array
*
* @param array $siteinfo
* @param array $jsonld
+ *
* @return array siteinfo
*/
private static function parseJsonLdMediaObject(array $siteinfo, array $jsonld, string $name): array
*
* @return boolean|string PID or "false" if not existent
*/
- static private function pidFromFile($file) {
+ private static function pidFromFile(string $file)
+ {
if (!file_exists($file)) {
return false;
}
*
* @return boolean Is it running?
*/
- static public function isRunningProcess($file) {
+ public static function isRunningProcess(string $file): bool
+ {
$pid = self::pidFromFile($file);
if (!$pid) {
*
* @return boolean Was it killed successfully?
*/
- static public function killProcess($file) {
+ public static function killProcess(string $file): bool
+ {
$pid = self::pidFromFile($file);
// We don't have a process id? then we quit
*
* @return boolean|string PID or "false" if not created
*/
- static public function create(string $file)
+ public static function create(string $file)
{
$pid = self::pidFromFile($file);
*
* @return boolean Is it running?
*/
- static public function delete(string $file): bool
+ public static function delete(string $file): bool
{
return @unlink($file);
}
*
* @return bool
*/
- public function isRendertime()
+ public function isRendertime(): bool
{
return $this->rendertime;
}
* Start a profiler recording
*
* @param string $value
+ *
* @return void
*/
public function startRecording(string $value)
* Stop a profiler recording
*
* @param string $callstack
+ *
* @return void
*/
public function stopRecording(string $callstack = '')
* @param int $timestamp the Timestamp
* @param string $value A value to profile
* @param string $callstack A callstack string, generated if absent
+ *
+ * @return void
*/
- public function saveTimestamp($timestamp, $value, $callstack = '')
+ public function saveTimestamp(int $timestamp, string $value, string $callstack = '')
{
if (!$this->enabled) {
return;
/**
* Resets the performance and callstack profiling
+ *
+ * @return void
*/
public function reset()
{
/**
* Resets the performance profiling data
+ *
+ * @return void
*/
public function resetPerformance()
{
/**
* Resets the callstack profiling data
+ *
+ * @return void
*/
public function resetCallstack()
{
*
* @return string the rendertime
*/
- public function getRendertimeString(float $limit = 0)
+ public function getRendertimeString(float $limit = 0): string
{
$output = '';
return $output;
}
- if (isset($this->callstack["database"])) {
+ if (isset($this->callstack['database'])) {
$output .= "\nDatabase Read:\n";
- foreach ($this->callstack["database"] as $func => $time) {
+ foreach ($this->callstack['database'] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
- $output .= $func . ": " . $time . "\n";
+ $output .= $func . ': ' . $time . "\n";
}
}
}
- if (isset($this->callstack["database_write"])) {
+
+ if (isset($this->callstack['database_write'])) {
$output .= "\nDatabase Write:\n";
- foreach ($this->callstack["database_write"] as $func => $time) {
+ foreach ($this->callstack['database_write'] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
- $output .= $func . ": " . $time . "\n";
+ $output .= $func . ': ' . $time . "\n";
}
}
}
- if (isset($this->callstack["cache"])) {
+
+ if (isset($this->callstack['cache'])) {
$output .= "\nCache Read:\n";
- foreach ($this->callstack["cache"] as $func => $time) {
+ foreach ($this->callstack['cache'] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
- $output .= $func . ": " . $time . "\n";
+ $output .= $func . ': ' . $time . "\n";
}
}
}
- if (isset($this->callstack["cache_write"])) {
+
+ if (isset($this->callstack['cache_write'])) {
$output .= "\nCache Write:\n";
- foreach ($this->callstack["cache_write"] as $func => $time) {
+ foreach ($this->callstack['cache_write'] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
- $output .= $func . ": " . $time . "\n";
+ $output .= $func . ': ' . $time . "\n";
}
}
}
- if (isset($this->callstack["network"])) {
+
+ if (isset($this->callstack['network'])) {
$output .= "\nNetwork:\n";
- foreach ($this->callstack["network"] as $func => $time) {
+ foreach ($this->callstack['network'] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
- $output .= $func . ": " . $time . "\n";
+ $output .= $func . ': ' . $time . "\n";
}
}
}
- if (isset($this->callstack["rendering"])) {
+ if (isset($this->callstack['rendering'])) {
$output .= "\nRendering:\n";
- foreach ($this->callstack["rendering"] as $func => $time) {
+ foreach ($this->callstack['rendering'] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
- $output .= $func . ": " . $time . "\n";
+ $output .= $func . ': ' . $time . "\n";
}
}
}
*
* @param LoggerInterface $logger The logger to save the current log
* @param string $message Additional message for the log
+ *
+ * @return void
*/
- public function saveLog(LoggerInterface $logger, $message = '')
+ public function saveLog(LoggerInterface $logger, string $message = '')
{
$duration = microtime(true) - $this->get('start');
$logger->info(
*
* @return int Entry.
*/
- public function get($id)
+ public function get(string $id): int
{
if (!$this->has($id)) {
return 0;
}
}
- public function set($timestamp, $id)
+ public function set($timestamp, string $id)
{
$this->performance[$id] = $timestamp;
}
*
* @return bool
*/
- public function has($id)
+ public function has(string $id): bool
{
return isset($this->performance[$id]);
}
* proxy storage directory.
*
* @param string $html Un-proxified HTML code
+ *
* @return string Proxified HTML code
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
* Checks if the URL is a local URL.
*
* @param string $url
+ *
* @return boolean
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
* Return the array of query string parameters from a URL
*
* @param string $url URL to parse
+ *
* @return array Associative array of query string parameters
*/
private static function parseQuery(string $url): array
* Call-back method to replace the UR
*
* @param array $matches Matches from preg_replace_callback()
+ *
* @return string Proxified HTML image tag
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
* Generates a pseudo-random string of hexadecimal characters
*
* @param int $size Size of string (default: 64)
+ *
* @return string Pseudo-random string
* @throws \Exception
*/
*
* @param string $network Network name of the contact (e.g. dfrn, rss and so on)
* @param string $url The contact url
+ *
* @return string Formatted network name
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
* Check if the trimmed provided string is starting with one of the provided characters
*
* @param string $string
- * @param array $chars
+ * @param array $chars
+ *
* @return bool
*/
public static function startsWithChars(string $string, array $chars): bool
* @see http://maettig.com/code/php/php-performance-benchmarks.php#endswith
* @param string $string
* @param string $end
+ *
* @return bool
*/
- public static function endsWith(string $string, string $end): string
+ public static function endsWith(string $string, string $end): bool
{
- $return = substr_compare($string, $end, -strlen($end)) === 0;
-
- return $return;
+ return (substr_compare($string, $end, -strlen($end)) === 0);
}
/**
/**
* Ensures a single path item doesn't contain any path-traversing characters
*
- * @see https://stackoverflow.com/a/46097713
* @param string $pathItem
+ *
+ * @see https://stackoverflow.com/a/46097713
* @return string
*/
public static function sanitizeFilePathItem(string $pathItem): string
* @param string $replacement
* @param int $start
* @param int|null $length
+ *
* @return string
* @see substr_replace()
*/
* @param string $text
* @param string $regex
* @param callable $callback
+ *
* @return string
*/
public static function performWithEscapedBlocks(string $text, string $regex, callable $callback): string
*
* @param string $a
* @param string $b
+ *
* @return int
*/
- private static function timezoneCompareCallback($a, $b)
+ private static function timezoneCompareCallback(string $a, string $b): int
{
if (strstr($a, '/') && strstr($b, '/')) {
if (DI::l10n()->t($a) == DI::l10n()->t($b)) {
* Emit a timezone selector grouped (primarily) by continent
*
* @param string $current Timezone
+ *
* @return string Parsed HTML output
*/
- public static function getTimezoneSelect($current = 'America/Los_Angeles')
+ public static function getTimezoneSelect(string $current = 'America/Los_Angeles'): string
{
$timezone_identifiers = DateTimeZone::listIdentifiers();
* @return string Parsed HTML
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function getTimezoneField($name = 'timezone', $label = '', $current = 'America/Los_Angeles', $help = '')
+ public static function getTimezoneField(string $name = 'timezone', string $label = '', string $current = 'America/Los_Angeles', string $help = ''): string
{
$options = self::getTimezoneSelect($current);
$options = str_replace('<select id="timezone_select" name="timezone">', '', $options);
*
* @param string $dob Date of Birth
* @param string $timezone
+ *
* @return string Formatted HTML
* @throws \Exception
*/
- public static function getDateofBirthField(string $dob, string $timezone = 'UTC')
+ public static function getDateofBirthField(string $dob, string $timezone = 'UTC'): string
{
list($year, $month, $day) = sscanf($dob, '%4d-%2d-%2d');
* @return string Parsed HTML output.
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function getDateField($min, $max, $default, $id = 'datepicker')
+ public static function getDateField(DateTime $min, DateTime $max, DateTime $default, string $id = 'datepicker'): string
{
return self::getDateTimeField($min, $max, $default, '', $id, true, false, '', '');
}
* @return string Parsed HTML output.
* @throws \Exception
*/
- public static function getTimeField($h, $m, $id = 'timepicker')
+ public static function getTimeField(string $h, string $m, string $id = 'timepicker'): string
{
return self::getDateTimeField(new DateTime(), new DateTime(), new DateTime("$h:$m"), '', $id, false, true);
}
DateTime $maxDate,
DateTime $defaultDate = null,
$label,
- $id = 'datetimepicker',
- $pickdate = true,
- $picktime = true,
- $minfrom = '',
- $maxfrom = '',
- $required = false)
+ string $id = 'datetimepicker',
+ bool $pickdate = true,
+ bool $picktime = true,
+ string $minfrom = '',
+ string $maxfrom = '',
+ bool $required = false): string
{
// First day of the week (0 = Sunday)
$firstDay = DI::pConfig()->get(local_user(), 'system', 'first_day_of_week', 0);
// Check if the detected language is supported by the picker
if (!in_array($lang,
- ["ar", "ro", "id", "bg", "fa", "ru", "uk", "en", "el", "de", "nl", "tr", "fr", "es", "th", "pl", "pt", "ch", "se", "kr",
- "it", "da", "no", "ja", "vi", "sl", "cs", "hu"])) {
+ ['ar', 'ro', 'id', 'bg', 'fa', 'ru', 'uk', 'en', 'el', 'de', 'nl', 'tr', 'fr', 'es', 'th', 'pl', 'pt', 'ch', 'se', 'kr',
+ 'it', 'da', 'no', 'ja', 'vi', 'sl', 'cs', 'hu'])) {
$lang = 'en';
}
*
* @return string with relative date
*/
- public static function getRelativeDate($posted_date, $format = null)
+ public static function getRelativeDate(string $posted_date, string $format = null): string
{
$localtime = $posted_date . ' UTC';
$isfuture = true;
}
- $a = [12 * 30 * 24 * 60 * 60 => [DI::l10n()->t('year'), DI::l10n()->t('years')],
+ $a = [
+ 12 * 30 * 24 * 60 * 60 => [DI::l10n()->t('year'), DI::l10n()->t('years')],
30 * 24 * 60 * 60 => [DI::l10n()->t('month'), DI::l10n()->t('months')],
7 * 24 * 60 * 60 => [DI::l10n()->t('week'), DI::l10n()->t('weeks')],
24 * 60 * 60 => [DI::l10n()->t('day'), DI::l10n()->t('days')],
60 * 60 => [DI::l10n()->t('hour'), DI::l10n()->t('hours')],
60 => [DI::l10n()->t('minute'), DI::l10n()->t('minutes')],
- 1 => [DI::l10n()->t('second'), DI::l10n()->t('seconds')]
+ 1 => [DI::l10n()->t('second'), DI::l10n()->t('seconds')],
];
foreach ($a as $secs => $str) {
*
* @return int Number of days in the given month
*/
- public static function getDaysInMonth($y, $m)
+ public static function getDaysInMonth(int $y, int $m): int
{
return date('t', mktime(0, 0, 0, $m, 1, $y));
}
* @return string day 0 = Sunday through 6 = Saturday
* @throws \Exception
*/
- private static function getFirstDayInMonth($y, $m)
+ private static function getFirstDayInMonth(int $y, int $m): string
{
$d = sprintf('%04d-%02d-01 00:00', intval($y), intval($m));
* @throws \Exception
* @todo Provide (prev, next) links, define class variations for different size calendars
*/
- public static function getCalendarTable($y = 0, $m = 0, $links = null, $class = '')
+ public static function getCalendarTable(int $y = 0, int $m = 0, array $links = null, string $class = ''): string
{
// month table - start at 1 to match human usage.
$mtab = [' ',