Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions.php web log #88

Merged
merged 13 commits into from
Mar 29, 2022
39 changes: 28 additions & 11 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
// On Pi's, this placeholder gets replaced with ${ALLSKY_CONFIG}.
// On other machines it won't and references to it will silently fail.
define('ALLSKY_CONFIG', 'XX_ALLSKY_CONFIG_XX');
// The issue is how to determine if we're on a Pi without using
// the exec() function which is often disabled on remote machines.
// And we can't do @exec() to see if it works because that can
// display a message in the user's browser window.
// To avoid that message, assume if we're not on a Pi that exec() doesn't work.
// TODO: make this a user setting if exec() works???
// If you can think of a better way than to check for a hard-coded
// path, please update the code.

// If on a Pi, check that the placholder was replaced.
exec("grep -q 'Model.*: Raspberry' /proc/cpuinfo", $none, $return);
// Split the placeholder so it doesn't get replaced if the update script is run multiple times.
// Note: return code 0 == a match, return code 1 == no match
if ($return==0 && ALLSKY_CONFIG == "XX_ALLSKY_CONFIG" . "_XX") {
$exec_works = file_exists('/var/www/html/allsky/config.js'); // YUCK!
if ($exec_works && ALLSKY_CONFIG == "XX_ALLSKY_CONFIG" . "_XX") {
// This file hasn't been updated yet after installation.
echo "<div style='font-size: 200%;'>";
echo "<span style='color: red'>";
echo "Please run the following from the 'allsky' directory before using the Website:";
echo "</span>";
echo "<code> website/install.sh --update</code>";
echo "<br><br><code> website/install.sh --update</code>";
echo "</div>";
exit;
}
Expand Down Expand Up @@ -104,6 +110,12 @@ function make_thumb($src, $dest, $desired_width)
// Similar to make_thumb() but using a video for the input file.
function make_thumb_from_video($src, $dest, $desired_width)
{
global $exec_works;
if (! $exec_works) {
// echo "Can't make video thumbnail - exec_works=$exec_works";
return(false);
}

// start 5 seconds in to skip any auto-exposure changes at the beginning. This of course assumes the video is at least 5 sec long.
// "-1" scales the height to the original aspect ratio.
exec("ffmpeg -ss 00:00:05 -i '$src' -frames:v 1 -filter:v scale='$desired_width:-1' -frames:v 1 '$dest'");
Expand All @@ -118,19 +130,24 @@ function make_thumb_from_video($src, $dest, $desired_width)
function display_thumbnails($image_type)
{
global $back_button;
$image_type_len = strlen($image_type);
// The name of the timelapse video file is "allsky-yyyymmdd.xxx" but the $image_type is "Timelapse" which is more meaningful for users.
// For startrails and keograms, the prefix and the $image_type are the same.
if ($image_type == "Timelapse") {
$file_prefix = "allsky";
$ext = "/\.(mp4|webm)$/";
} else {
$file_prefix = $image_type;
$ext = "/\.(jpg|jpeg|png)$/";
}
$file_prefix_len = strlen($file_prefix);


$num_files = 0;
$files = array();
if ($handle = opendir('.')) {
while (false !== ($entry = readdir($handle))) {
if ( preg_match( $ext, $entry ) ) {
$files[] = $entry;;
$files[] = $entry;
$num_files++;
}
}
Expand Down Expand Up @@ -171,11 +188,11 @@ function display_thumbnails($image_type)
}
}
}
$year = substr($file, $image_type_len + 1, 4);
$month = substr($file, $image_type_len + 5, 2);
$day = substr($file, $image_type_len + 7, 2);
$year = substr($file, $file_prefix_len + 1, 4);
$month = substr($file, $file_prefix_len + 5, 2);
$day = substr($file, $file_prefix_len + 7, 2);
$date = $year.$month.$day;
echo "<a href='./$file'><div class='day-container'><div class='image-container'><img id=".$date." src='$thumbnail' title='$image_type-$year-$month-$day'/></div><div class='day-text'>$year-$month-$day</div></div></a>";
echo "<a href='./$file'><div class='day-container'><div class='image-container'><img id=".$date." src='$thumbnail' title='$file_prefix-$year-$month-$day'/></div><div class='day-text'>$year-$month-$day</div></div></a>";
}
echo "</div>";
}
Expand Down