mirror of
https://github.com/sorenpeter/timeline.git
synced 2025-12-15 19:07:01 +00:00
Change the top nav
This commit is contained in:
parent
c65003e3db
commit
773df6f9d3
6 changed files with 343 additions and 22 deletions
78
libs/__Thumbnail.php
Normal file
78
libs/__Thumbnail.php
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
// Based on: https://github.com/Francesco-Chen/Thumbnail-Gallery-PHP
|
||||
|
||||
function createThumbnail($src, $dest, $thumbHeight) {
|
||||
list($width, $height, $type) = getimagesize($src);
|
||||
$aspectRatio = $width / $height;
|
||||
$thumbWidth = $thumbHeight * $aspectRatio;
|
||||
|
||||
switch ($type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
$image = imagecreatefromjpeg($src);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$image = imagecreatefrompng($src);
|
||||
break;
|
||||
case IMAGETYPE_WEBP: // Support webp format
|
||||
$image = imagecreatefromwebp($src);
|
||||
break;
|
||||
default:
|
||||
return false; // Unsupported image type
|
||||
}
|
||||
|
||||
$thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
|
||||
|
||||
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, $height);
|
||||
|
||||
switch ($type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
imagejpeg($thumb, $dest);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
imagepng($thumb, $dest);
|
||||
break;
|
||||
case IMAGETYPE_WEBP: // Support webp format
|
||||
imagewebp($thumb, $dest);
|
||||
break;
|
||||
}
|
||||
|
||||
imagedestroy($thumb);
|
||||
imagedestroy($image);
|
||||
return true;
|
||||
}
|
||||
|
||||
$galleryDir = "gallery/";
|
||||
$thumbDir = "thumb/";
|
||||
$allowedExtensions = array("jpg", "jpeg", "png", "gif", "webp"); // Remove "mp4" from allowed extensions
|
||||
|
||||
// Check and create the "thumb" directory if it doesn't exist
|
||||
if (!file_exists($thumbDir)) {
|
||||
mkdir($thumbDir);
|
||||
}
|
||||
|
||||
$galleryFiles = scandir($galleryDir);
|
||||
|
||||
foreach ($galleryFiles as $file) {
|
||||
$extension = pathinfo($file, PATHINFO_EXTENSION);
|
||||
if (in_array(strtolower($extension), $allowedExtensions)) {
|
||||
$imageURL = $galleryDir . $file;
|
||||
$thumbURL = $thumbDir . $file;
|
||||
|
||||
if (!file_exists($thumbURL)) {
|
||||
createThumbnail($imageURL, $thumbURL, 200); // The thumbnail will have a height of 200 pixels.
|
||||
}
|
||||
|
||||
echo '
|
||||
<a
|
||||
data-fancybox="gallery"
|
||||
data-src="' . $imageURL . '"
|
||||
data-caption="' . $file . '"
|
||||
>
|
||||
<img src="' . $thumbURL . '" height="200" />
|
||||
</a>
|
||||
';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
211
libs/thumb.php
Normal file
211
libs/thumb.php
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Simplified version of http://github.com/jamiebicknell/Thumb:
|
||||
EXIF, bw and sharpening features removed
|
||||
*/
|
||||
|
||||
define('THUMB_CACHE', 'thucache/'); // Path to cache directory (must be writeable)
|
||||
define('THUMB_CACHE_AGE', 86400); // Duration of cached files in seconds
|
||||
define('THUMB_BROWSER_CACHE', true); // Browser cache true or false
|
||||
define('JPEG_QUALITY', 90); // Quality of generated JPEGs (0 - 100; 100 being best)
|
||||
|
||||
|
||||
$src = isset($_GET['src']) ? $_GET['src'] : false;
|
||||
$size = isset($_GET['size']) ? str_replace(array('<', 'x'), '', $_GET['size']) != '' ? $_GET['size'] : 100 : 100;
|
||||
$crop = isset($_GET['crop']) ? max(0, min(1, $_GET['crop'])) : 1;
|
||||
$trim = isset($_GET['trim']) ? max(0, min(1, $_GET['trim'])) : 0;
|
||||
$zoom = isset($_GET['zoom']) ? max(0, min(1, $_GET['zoom'])) : 0;
|
||||
$align = isset($_GET['align']) ? $_GET['align'] : false;
|
||||
$sharpen = isset($_GET['sharpen']) ? max(0, min(100, $_GET['sharpen'])) : 0;
|
||||
$gray = isset($_GET['gray']) ? max(0, min(1, $_GET['gray'])) : 0;
|
||||
$ignore = isset($_GET['ignore']) ? max(0, min(1, $_GET['ignore'])) : 0;
|
||||
$path = parse_url($src);
|
||||
|
||||
if (isset($path['scheme'])) {
|
||||
$base = parse_url('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
||||
if (preg_replace('/^www\./i', '', $base['host']) == preg_replace('/^www\./i', '', $path['host'])) {
|
||||
$base = explode('/', preg_replace('/\/+/', '/', $base['path']));
|
||||
$path = explode('/', preg_replace('/\/+/', '/', $path['path']));
|
||||
$temp = $path;
|
||||
$part = count($base);
|
||||
foreach ($base as $k => $v) {
|
||||
if ($v == $path[$k]) {
|
||||
array_shift($temp);
|
||||
} else {
|
||||
if ($part - $k > 1) {
|
||||
$temp = array_pad($temp, 0 - (count($temp) + ($part - $k) - 1), '..');
|
||||
break;
|
||||
} else {
|
||||
$temp[0] = './' . $temp[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
$src = implode('/', $temp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!extension_loaded('gd')) {
|
||||
die('GD extension is not installed');
|
||||
}
|
||||
if (!is_writable(THUMB_CACHE)) {
|
||||
die('Cache not writable');
|
||||
}
|
||||
if (isset($path['scheme']) || !file_exists($src)) {
|
||||
die('File cannot be found');
|
||||
}
|
||||
if (!in_array(strtolower(substr(strrchr($src, '.'), 1)), array('gif', 'jpg', 'jpeg', 'png'))) {
|
||||
die('File is not an image');
|
||||
}
|
||||
|
||||
|
||||
$file_salt = 'v1.0.5';
|
||||
$file_size = filesize($src);
|
||||
$file_time = filemtime($src);
|
||||
$file_date = gmdate('D, d M Y H:i:s T', $file_time);
|
||||
$file_type = strtolower(substr(strrchr($src, '.'), 1));
|
||||
$file_hash = md5($file_salt . ($src.$size.$crop.$trim.$zoom.$align.$sharpen.$gray.$ignore) . $file_time);
|
||||
$file_temp = THUMB_CACHE . $file_hash . '.img.txt';
|
||||
$file_name = basename(substr($src, 0, strrpos($src, '.')) . strtolower(strrchr($src, '.')));
|
||||
|
||||
|
||||
if (!file_exists(THUMB_CACHE . 'index.html')) {
|
||||
touch(THUMB_CACHE . 'index.html');
|
||||
}
|
||||
if (($fp = fopen(THUMB_CACHE . 'index.html', 'r')) !== false) {
|
||||
if (flock($fp, LOCK_EX)) {
|
||||
if (time() - THUMB_CACHE_AGE > filemtime(THUMB_CACHE . 'index.html')) {
|
||||
$files = glob(THUMB_CACHE . '*.img.txt');
|
||||
if (is_array($files) && count($files) > 0) {
|
||||
foreach ($files as $file) {
|
||||
if (time() - THUMB_CACHE_AGE > filemtime($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
touch(THUMB_CACHE . 'index.html');
|
||||
}
|
||||
flock($fp, LOCK_UN);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
|
||||
if (THUMB_BROWSER_CACHE && (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH']))) {
|
||||
if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $file_date && $_SERVER['HTTP_IF_NONE_MATCH'] == $file_hash) {
|
||||
header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!file_exists($file_temp)) {
|
||||
list($w0, $h0, $type) = getimagesize($src);
|
||||
$data = file_get_contents($src);
|
||||
if ($ignore && $type == 1) {
|
||||
if (preg_match('/\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)/s', $data)) {
|
||||
header('Content-Type: image/gif');
|
||||
header('Content-Length: ' . $file_size);
|
||||
header('Content-Disposition: inline; filename="' . $file_name . '"');
|
||||
header('Last-Modified: ' . $file_date);
|
||||
header('ETag: ' . $file_hash);
|
||||
header('Accept-Ranges: none');
|
||||
if (THUMB_BROWSER_CACHE) {
|
||||
header('Cache-Control: max-age=604800, must-revalidate');
|
||||
header('Expires: ' . gmdate('D, d M Y H:i:s T', strtotime('+7 days')));
|
||||
} else {
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
||||
header('Expires: ' . gmdate('D, d M Y H:i:s T'));
|
||||
header('Pragma: no-cache');
|
||||
}
|
||||
die($data);
|
||||
}
|
||||
}
|
||||
$oi = imagecreatefromstring($data);
|
||||
|
||||
list($w,$h) = explode('x', str_replace('<', '', $size) . 'x');
|
||||
$w = ($w != '') ? floor(max(8, min(1500, $w))) : '';
|
||||
$h = ($h != '') ? floor(max(8, min(1500, $h))) : '';
|
||||
if (strstr($size, '<')) {
|
||||
$h = $w;
|
||||
$crop = 0;
|
||||
$trim = 1;
|
||||
} elseif (!strstr($size, 'x')) {
|
||||
$h = $w;
|
||||
} elseif ($w == '' || $h == '') {
|
||||
$w = ($w == '') ? ($w0 * $h) / $h0 : $w;
|
||||
$h = ($h == '') ? ($h0 * $w) / $w0 : $h;
|
||||
$crop = 0;
|
||||
$trim = 1;
|
||||
}
|
||||
$trim_w = ($trim) ? 1 : ($w == '') ? 1 : 0;
|
||||
$trim_h = ($trim) ? 1 : ($h == '') ? 1 : 0;
|
||||
if ($crop) {
|
||||
$w1 = (($w0 / $h0) > ($w / $h)) ? floor($w0 * $h / $h0) : $w;
|
||||
$h1 = (($w0 / $h0) < ($w / $h)) ? floor($h0 * $w / $w0) : $h;
|
||||
if (!$zoom) {
|
||||
if ($h0 < $h || $w0 < $w) {
|
||||
$w1 = $w0;
|
||||
$h1 = $h0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$w1 = (($w0 / $h0) < ($w / $h)) ? floor($w0 * $h / $h0) : floor($w);
|
||||
$h1 = (($w0 / $h0) > ($w / $h)) ? floor($h0 * $w / $w0) : floor($h);
|
||||
$w = floor($w);
|
||||
$h = floor($h);
|
||||
if (!$zoom) {
|
||||
if ($h0 < $h && $w0 < $w) {
|
||||
$w1 = $w0;
|
||||
$h1 = $h0;
|
||||
}
|
||||
}
|
||||
}
|
||||
$w = ($trim_w) ? (($w0 / $h0) > ($w / $h)) ? min($w, $w1) : $w1 : $w;
|
||||
$h = ($trim_h) ? (($w0 / $h0) < ($w / $h)) ? min($h, $h1) : $h1 : $h;
|
||||
|
||||
$x = strpos($align, 'l') !== false ? 0 : (strpos($align, 'r') !== false ? $w - $w1 : ($w - $w1) / 2);
|
||||
$y = strpos($align, 't') !== false ? 0 : (strpos($align, 'b') !== false ? $h - $h1 : ($h - $h1) / 2);
|
||||
$im = imagecreatetruecolor($w, $h);
|
||||
$bg = imagecolorallocate($im, 255, 255, 255);
|
||||
imagefill($im, 0, 0, $bg);
|
||||
switch ($type) {
|
||||
case 1:
|
||||
imagecopyresampled($im, $oi, $x, $y, 0, 0, $w1, $h1, $w0, $h0);
|
||||
imagegif($im, $file_temp);
|
||||
break;
|
||||
case 2:
|
||||
imagecopyresampled($im, $oi, $x, $y, 0, 0, $w1, $h1, $w0, $h0);
|
||||
imagejpeg($im, $file_temp, JPEG_QUALITY);
|
||||
break;
|
||||
case 3:
|
||||
imagefill($im, 0, 0, imagecolorallocatealpha($im, 0, 0, 0, 127));
|
||||
imagesavealpha($im, true);
|
||||
imagealphablending($im, false);
|
||||
imagecopyresampled($im, $oi, $x, $y, 0, 0, $w1, $h1, $w0, $h0);
|
||||
imagepng($im, $file_temp);
|
||||
break;
|
||||
}
|
||||
imagedestroy($im);
|
||||
imagedestroy($oi);
|
||||
}
|
||||
|
||||
|
||||
header('Content-Type: image/' . $file_type);
|
||||
header('Content-Length: ' . filesize($file_temp));
|
||||
header('Content-Disposition: inline; filename="' . $file_name . '"');
|
||||
header('Last-Modified: ' . $file_date);
|
||||
header('ETag: ' . $file_hash);
|
||||
header('Accept-Ranges: none');
|
||||
if (THUMB_BROWSER_CACHE) {
|
||||
header('Cache-Control: max-age=604800, must-revalidate');
|
||||
header('Expires: ' . gmdate('D, d M Y H:i:s T', strtotime('+7 days')));
|
||||
} else {
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
||||
header('Expires: ' . gmdate('D, d M Y H:i:s T'));
|
||||
header('Pragma: no-cache');
|
||||
}
|
||||
|
||||
|
||||
readfile($file_temp);
|
||||
|
|
@ -17,9 +17,13 @@ $profile = getTwtsFromTwtxtString($config['public_txt_url']);
|
|||
|
||||
<header>
|
||||
<p>
|
||||
<a href="<?= $baseURL ?>">
|
||||
<a href="/">
|
||||
<img class="avatar" src="<?= $profile->avatar ?>" alt="" loading="lazy">
|
||||
<?= $profile->nick ?></a>@<?= parse_url($profile->mainURL, PHP_URL_HOST); ?>
|
||||
<?= parse_url($profile->mainURL, PHP_URL_HOST); ?>
|
||||
</a>
|
||||
<!-- <a href="<?= $baseURL ?>">
|
||||
<img class="avatar" src="<?= $profile->avatar ?>" alt="" loading="lazy">
|
||||
<?= $profile->nick ?></a>@<?= parse_url($profile->mainURL, PHP_URL_HOST); ?> -->
|
||||
</p>
|
||||
<nav>
|
||||
|
||||
|
|
@ -27,14 +31,16 @@ $profile = getTwtsFromTwtxtString($config['public_txt_url']);
|
|||
<?php //if ($validSession) { // TODO: Make login seqcure ?>
|
||||
<?php if( isset($_SESSION['password'])) { /*
|
||||
if($_SESSION['password']=="$password") {*/ // Hacky login ?>
|
||||
<li><?php include 'partials/lists.php'; ?></li>
|
||||
<li><a href="<?= $baseURL ?>/refresh?url=<?= $url ?>">Refresh</a></li>
|
||||
<li><a href="<?= $baseURL ?>/following">Following <?php // echo count($twtFollowingList); ?></a></li>
|
||||
<li><a href="<?= $baseURL ?>/add">Add feed</a></li>
|
||||
<li><a href="<?= $baseURL ?>">Timeline</a></li>
|
||||
<li><a href="<?= $baseURL ?>?profile=<?=$url ?>">Profile</a></li>
|
||||
<li><a href="<?= $baseURL ?>/gallery?profile=<?= $profile->mainURL ?>">Gallery</a></li>
|
||||
<li><a href="<?= $baseURL ?>/following">Following <?php // echo count($twtFollowingList); ?></a></li>
|
||||
<li><a href="<?= $baseURL ?>/add">Add feed</a></li>
|
||||
<li><a href="<?= $baseURL ?>/logout">Log Out</a></li>
|
||||
<li><?php include 'partials/lists.php'; ?></li>
|
||||
<?php /*}*/ } else { ?>
|
||||
<li><a href="<?= $baseURL ?>">Timeline</a></li>
|
||||
<li><a href="<?= $baseURL ?>?profile=<?= $url ?>">Profile</a></li>
|
||||
<li><a href="<?= $baseURL ?>/gallery?profile=<?= $profile->mainURL ?>">Gallery</a></li>
|
||||
<li><a href="<?= $baseURL ?>/following">Following <?php // echo count($twtFollowingList); ?></a></li>
|
||||
|
|
|
|||
51
style.css
51
style.css
|
|
@ -1,19 +1,41 @@
|
|||
/* === SimpleCSS overwrites === */
|
||||
:root, ::backdrop {
|
||||
|
||||
/* Default (light) theme */
|
||||
--sans-font: -apple-system,BlinkMacSystemFont,"Avenir Next",Avenir,"Nimbus Sans L",Roboto,"Noto Sans","Segoe UI",Arial,Helvetica,"Helvetica Neue",sans-serif;
|
||||
--mono-font: Consolas,Menlo,Monaco,"Andale Mono","Ubuntu Mono",monospace;
|
||||
--standard-border-radius: 0.5rem;
|
||||
--bg: #fff;
|
||||
--accent-bg: #f5f7ff;
|
||||
--text: #212121;
|
||||
--text-light: #585858;
|
||||
--border: #d8dae1; /*#898EA4;*/
|
||||
--accent: #0d47a1;
|
||||
--code: #d81b60;
|
||||
--preformatted: #444;
|
||||
--marked: #ffdd33;
|
||||
--disabled: #efefef;
|
||||
}
|
||||
|
||||
::backdrop, :root {
|
||||
--sans-font: -apple-system,BlinkMacSystemFont,"Avenir Next",Avenir,"Nimbus Sans L",Roboto,"Noto Sans","Segoe UI",Arial,Helvetica,"Helvetica Neue",sans-serif;
|
||||
--mono-font: Consolas,Menlo,Monaco,"Andale Mono","Ubuntu Mono",monospace;
|
||||
--standard-border-radius: 0.5rem;
|
||||
--bg: #fff;
|
||||
--accent-bg: #f5f7ff;
|
||||
--text: #212121;
|
||||
--text-light: #585858;
|
||||
--border: #d8dae1; /*#898EA4;*/
|
||||
--accent: #0d47a1;
|
||||
--code: #d81b60;
|
||||
--preformatted: #444;
|
||||
--marked: #ffdd33;
|
||||
--disabled: #efefef;
|
||||
/* Dark theme */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root,
|
||||
::backdrop {
|
||||
color-scheme: dark;
|
||||
--bg: #212121;
|
||||
--accent-bg: #2b2b2b;
|
||||
--text: #dcdcdc;
|
||||
--text-light: #ababab;
|
||||
--accent: #ffb300;
|
||||
--code: #f06292;
|
||||
--preformatted: #ccc;
|
||||
--disabled: #111;
|
||||
}
|
||||
/* Add a bit of transparency so light media isn't so glaring in dark mode */
|
||||
img,
|
||||
video {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
|
||||
body > header {
|
||||
|
|
@ -117,6 +139,7 @@ img {
|
|||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 0.25rem;
|
||||
border: thin solid var(--border);
|
||||
}
|
||||
|
||||
img.avatar {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ include 'partials/header.php';
|
|||
?>
|
||||
|
||||
<center>
|
||||
<h1>Following <?php echo count($twtFollowingList); ?> feeds</h1>
|
||||
<h1><?= $profile->nick ?> follows <?php echo count($twtFollowingList); ?> feeds</h1>
|
||||
|
||||
<table>
|
||||
|
||||
|
|
|
|||
|
|
@ -35,13 +35,16 @@ if (!empty($_GET['profile'])) { // Show twts for some user
|
|||
<div class="gallery">
|
||||
|
||||
<?php
|
||||
|
||||
foreach ($twts as $twt) {
|
||||
$img_array = getImagesFromTwt($twt->content);
|
||||
|
||||
foreach ($img_array as $img) {
|
||||
//echo '<a href="'.$baseURL.'/post/'.$twt->hash.'">'.$img[0].'</a>';
|
||||
$img_link = $img[0];
|
||||
|
||||
echo '<a href="'.$baseURL.'/post/'.$twt->hash.'">'.$img_link.'</a>';
|
||||
// Workaround until cache issue is resolved
|
||||
echo '<a href="'.$baseURL.'/?profile='.$twt->mainURL.'#'.$twt->hash.'">'.$img[0].'</a>';
|
||||
//echo '<a href="'.$baseURL.'/?profile='.$twt->mainURL.'#'.$twt->hash.'">'.$img[0].'</a>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
Loading…
Reference in a new issue