add all files

This commit is contained in:
Rucus
2026-02-17 09:29:34 -06:00
parent b8c8d67c67
commit 782d203799
21925 changed files with 2433086 additions and 0 deletions

View File

@@ -0,0 +1,119 @@
<?php
// phpcs:ignoreFile
function grower_format_datetime($value)
{
if ($value === null || $value === '' || $value === '0000-00-00 00:00:00') {
return 'Never';
}
$timestamp = strtotime((string) $value);
if ($timestamp === false) {
return (string) $value;
}
return date('F j, Y g:i A', $timestamp);
}
function grower_member_defaults($member)
{
$defaults = array(
'email' => '',
'phone' => '',
'growername' => '',
'last_login_at' => '',
'password_last_changed' => ''
);
if (!is_array($member)) {
return $defaults;
}
return array_merge($defaults, $member);
}
function grower_recent_files($username, $limit = 6)
{
if ($username === '') {
return array();
}
$rootDir = dirname(__DIR__);
$baseDir = $rootDir . '/growers/' . $username;
if (!is_dir($baseDir)) {
return array();
}
$files = array();
$directoryIterator = new RecursiveDirectoryIterator($baseDir, FilesystemIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($iterator as $fileInfo) {
if (!$fileInfo->isFile()) {
continue;
}
$basename = $fileInfo->getBasename();
$extension = strtolower($fileInfo->getExtension());
if ($extension !== 'pdf') {
continue;
}
if (strtolower($basename) === 'index.php') {
continue;
}
$pathName = $fileInfo->getPathname();
$relative = substr($pathName, strlen($rootDir));
$files[] = array(
'name' => $basename,
'path' => '/' . ltrim(str_replace(DIRECTORY_SEPARATOR, '/', $relative), '/'),
'modified' => $fileInfo->getMTime()
);
}
if (empty($files)) {
return array();
}
usort($files, function ($a, $b) {
if ($a['modified'] === $b['modified']) {
return strcmp($a['path'], $b['path']);
}
return ($a['modified'] > $b['modified']) ? -1 : 1;
});
if ($limit > 0 && count($files) > $limit) {
$files = array_slice($files, 0, $limit);
}
return $files;
}
function grower_format_filesize($bytes)
{
if (!is_numeric($bytes) || $bytes < 0) {
return '0 B';
}
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
$value = (float) $bytes;
$power = 0;
while ($value >= 1024 && $power < count($units) - 1) {
$value /= 1024;
$power++;
}
if ($power === 0) {
return number_format($value, 0) . ' ' . $units[$power];
}
return number_format($value, 2) . ' ' . $units[$power];
}