Pith - miter
miter/front/tenons.php [3.6 kb]
Modified: 15:06:41 131 026 (28 Jul 026)
33 Days Ago
<?php 
$var_sort = $_GET['sort'] ?? 'abc'; 
$is_logged_in = ($login ?? false) === true;

function formatbytes(int $bytes, int $precision = 2): string { 
	$units = array('b', 'kb', 'mb', 'gb', 'tb'); 
	$bytes = max($bytes, 0); 
	$pow = floor(($bytes ? log($bytes) : 0) / log(1024)); 
	$pow = (int)min($pow, count($units) - 1); 
	$bytes /= (1 << (10 * $pow)); 
	return round($bytes, $precision) . ' ' . $units[$pow]; 
}

if (!function_exists('calculate_directory_size')) {
	function calculate_directory_size(string $dir): int {
		$total_size = 0;
		$files = glob($dir . '/*');
		if ($files !== false) {
			foreach ($files as $path) {
				if (is_file($path)) {
					$total_size += filesize($path);
				} elseif (is_dir($path) && function_exists('get_dir_size')) {
					$total_size += get_dir_size($path);
				}
			}
		}
		return $total_size;
	}
}
$tenon_dir_size = calculate_directory_size('tenons');
$tenon_size = formatbytes($tenon_dir_size);
?>
<div class="tenon_header">
	<div class="tenon_header_td_left">
		<span class="title">Tenons <span style='opacity: 0.5;'>| <?php echo $tenon_count . " - " . $tenon_size; ?></span></span>
	</div>
	<div class="tenon_header_td_right">
		<?php if ($var_sort === 'date'): ?>
			<a href="?l&sort=abc">
				<span role="img" aria-label="Sort A-Z" class="tenon_list_button" style="-webkit-mask:url(images/icons/sort_abc.png) no-repeat center / contain;mask:url(images/icons/sort_abc.png) no-repeat center / contain;"></span>
			</a> 
			<span role="img" aria-label="Sort by Date" class="tenon_list_button" style="-webkit-mask:url(images/icons/sort_date.png) no-repeat center / contain;mask:url(images/icons/sort_date.png) no-repeat center / contain;"></span>
		<?php else: ?>
			<span role="img" aria-label="Sort A-Z" class="tenon_list_button" style="-webkit-mask:url(images/icons/sort_abc.png) no-repeat center / contain;mask:url(images/icons/sort_abc.png) no-repeat center / contain;"></span>
			<a href="?l&sort=date">
				<span role="img" aria-label="Sort by Date" class="tenon_list_button" style="-webkit-mask:url(images/icons/sort_date.png) no-repeat center / contain;mask:url(images/icons/sort_date.png) no-repeat center / contain;"></span>
			</a>
		<?php endif; ?>
	</div>
</div>

<div class="tenon_table">
	<div class="tenon_td">
<?php
	$is_mobile = function_exists('isMobile') ? isMobile() : false;
	$char_count = $is_mobile ? 30 : 50;
	
	$i = 1;
	$file_list = glob("tenons/*.txt");
	
	if ($file_list !== false) {

		if ($var_sort === 'date') {
			usort($file_list, function($newest, $oldest) {
				return filemtime($newest) < filemtime($oldest);
			});
		}
		
		foreach($file_list as $file_name) {

			$raw_name = str_replace(["tenons/", ".txt"], "", $file_name);
			$file_print = str_replace("_", " ", $raw_name);
			
			$safe_url = htmlspecialchars(urlencode($raw_name), ENT_QUOTES, 'UTF-8');
			$safe_print = htmlspecialchars(substr($file_print, 0, $char_count), ENT_QUOTES, 'UTF-8');
?>
<div class="list_doc">
    <div class="list_doc_left">
        <span class="text"><?php echo $i++; ?>. </span><a href="index.php?t=<?php echo $safe_url; ?>"><?php echo $safe_print; ?></a>
    </div>

<?php if ($is_logged_in): ?>
    <div class="span_right">
        <a href="back/tenon/delete_tenon_list.php?d=<?php echo urlencode($safe_url); ?>" onclick="return confirm_delete()">
            <span role="img" aria-label="Delete" class="tenon_list_button_end" style="-webkit-mask:url(images/icons/delete_line.png) no-repeat center / contain;mask:url(images/icons/delete_line.png) no-repeat center / contain;"></span>
        </a>
    </div>
    <?php endif; ?>
</div>
<?php
		}
	}
?> 
	</div>
</div>
Updates
Stave - Android 158.026
Kerf - Android 157.026
Kiln - Android 157.026
Wedge - Android 156.026
Whittle - Linux 155.026

Menu
Calendar
Project Tin (024/029)
Miter
RSS Feed
User Avatar
@vgmlr
=SUM(parts)
0.00306
260,554 (+968)