Skip to content

Commit

Permalink
rudimentary php file splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
zleyyij committed Dec 23, 2024
1 parent e6fe423 commit 2112da4
Show file tree
Hide file tree
Showing 126 changed files with 15,977 additions and 0 deletions.
71 changes: 71 additions & 0 deletions new/apps/web/src/php/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Page Not Found</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="assets/specify-glass-dynamic.svg" />
<link rel="icon" href="assets/specify-glass-black-256x256.png" media="(prefers-color-scheme light)" />
<link rel="icon" href="assets/specify-glass-black-256x256.png" media="(prefers-color-scheme dark)" />
<style>

* {
line-height: 1.2;
margin: 0;
}

html {
display: table;
font-family: sans-serif;
height: 100%;
text-align: center;
width: 100%;
}

body {
background-color: #3B4252;
display: table-cell;
vertical-align: middle;
margin: 2em auto;
}

h1 {
color: #e0e2e4;
font-size: 2em;
font-weight: 400;
}

p {
color: #e0e2e4;
margin: 0 auto;
width: 280px;
}

@media only screen and (max-width: 280px) {

body,
p {
width: 95%;
}

h1 {
font-size: 1.5em;
margin: 0 0 0.3em;
}

}
</style>
</head>

<body>

<div>
<img src="assets/logo.png">
</div>

<h1>Page Not Found</h1>
<p>Sorry, but the view you were trying to access has expired or is invalid.</p>
</body>

</html>
13 changes: 13 additions & 0 deletions new/apps/web/src/php/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# specified
An Open Source viewer engine for Specify JSON exports. See [Specify](https://github.com/Spec-ify/specify) for more information.

Written mostly in PHP, visually based (in large) on <a href="https://spark.lucko.me/" target="_blank">Spark</a>


## Style guide
You should prefer to conform to the style of the surrounding code over personal preference.

### Language Conventions
Language specific styling should conform to the [Wordpress Developer Style Guide](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/), with the following changes:

- Shorthand PHP tags are allowed
57 changes: 57 additions & 0 deletions new/apps/web/src/php/archive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
//Shutting out error printing because the two vars will be unset a lot of the time and php will complain
ini_set('display_errors', 0);
include('archive_secret.php');
$login_user = $_POST['user'];
$login_pass = $_POST['pass'];

//Checking if given username and pw are correct
if($login_user == $user
&& $login_pass == $pass)
{
include("rudimentary.php");
die;
}
else
{
//Else, printing out the login page. It's a simple form that just posts back on itself to run the check again.
if(isset($_POST))
{echo '
<meta content="text/html;charset=UTF-8" http-equiv="content-type"/>
<head>
<meta charset="utf-8"/>
<title>Specified</title>
<meta content="width=device-width,initial-scale=1" name="viewport"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css"/>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/5.0.0/mdb.dark.min.css" rel="stylesheet">
<link href="static/css/themes.css" rel="stylesheet" >
<link href="static/css/main.css" rel="stylesheet">
</head>
<div class="textbox metadata-detail tablebox widget json-data" id="login-form">
<h1>Specify Archive Login</h1>
<form method="POST" action="archive">
<div class="form-outline mb-4">
<input type="text" name="user" class="form-control" id="login-form-user"></input><br/>
<label class="form-label" for="login-form-user">Username</label>
</div>
<div class="form-outline mb-4">
<input type="password" name="pass" class="form-control" id="login-form-pass"></input><br/>
<label class="form-label" for="login-form-pass">Password</label>
</div>
<button type="submit" name="submit" class="btn btn-primary btn-block">Login</button>
</form>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.2/jquery.min.js" integrity="sha512-tWHlutFnuG0C6nQRlpvrEhE4QpkG1nn2MOUMWmUeRePl4e3Aki0VB6W1v3oLjFtd0hVOtRQ9PHpSfN6u6/QXkQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/5.0.0/mdb.min.js"
type="text/javascript"
></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs5/dt-1.13.1/sc-2.0.7/datatables.min.js"></script>
<script defer="defer" src="static/js/main.js"></script>';
}
}
?>
Binary file added new/apps/web/src/php/assets/brave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added new/apps/web/src/php/assets/chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added new/apps/web/src/php/assets/dl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added new/apps/web/src/php/assets/edge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added new/apps/web/src/php/assets/firefox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added new/apps/web/src/php/assets/gx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added new/apps/web/src/php/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions new/apps/web/src/php/assets/specify-glass-dynamic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added new/apps/web/src/php/assets/vivaldi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 128 additions & 0 deletions new/apps/web/src/php/common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
// functions that are common to multiple viewer modes

//XDDDDD
function bytesToGigabytes($bytes)
{
// 1073741824 = 1024 * 1024 * 1024
return $bytes / 1073741824;
}

function bytesToMegabytes($bytes)
{
// 1073741824 = 1024 * 1024
return $bytes / 1048576;
}

function getDriveUsed($driveinput)
{
$driveused = 0;
foreach ($driveinput['Partitions'] as $partition) {
$driveused += $partition['PartitionCapacity'] - $partition['PartitionFree'];
}
return $driveused;
}

function getDriveFree($driveinput)
{
$drivefree = $driveinput['DiskCapacity'] - getDriveUsed($driveinput);
return $drivefree;
}

function getDriveCapacity($driveinput)
{
$partitioncap = 0;
foreach ($driveinput['Partitions'] as $partition) {
$partitioncap += $partition['PartitionCapacity'];
}
return $partitioncap;
}

/**
* This is to prevent TypeErrors on malformed jsons where an array is null
*/
function safe_count($arr): int {
if (is_countable($arr)) {
return count($arr);
} else {
$bt = debug_backtrace();
trigger_error("safe_count called on null in {$bt['file']} on line {$bt['line']}", E_USER_NOTICE);
return 0;
}
}

function safe_implode(string $separator, $arr): string {
if (is_array($arr)) {
return implode($separator, $arr);
} else {
$bt = debug_backtrace()[0];
trigger_error("safe_implode called on null in {$bt['file']} on line {$bt['line']}", E_USER_NOTICE);
return '';
}
}

function timeConvert($time)
{

$timeString = "";

$days = floor($time / (60 * 60 * 24));
$hours = floor(($time % (60 * 60 * 24)) / (60 * 60));
$minutes = floor(($time % (60 * 60)) / 60);
$seconds = $time % 60;

// Initialize the string with the number of days

if ($days) {
$timeString = '<span';
if ($days > 3) $timeString .= ' style="color:#BF616A;"';
$timeString .= '>' . $days . ' day';
if ($days != 1) {
$timeString .= 's';
}
$timeString .= ', ';
}


// Add the number of hours to the string
if ($hours) {
$timeString .= $hours . ' hour';
if ($hours != 1) {
$timeString .= 's';
}
$timeString .= ', ';
}

// Add the number of minutes to the string
if ($minutes) {
$timeString .= $minutes . ' minute';
if ($minutes != 1) {
$timeString .= 's';
}
$timeString .= ', ';
}
// Add the number of seconds to the string A3BE8C
if ($seconds) {
if ($days || $hours || $minutes) $timeString .= 'and ';
$timeString .= $seconds . ' second';
if ($seconds != 1) {
$timeString .= 's</span>';
}
}

return $timeString;
}

// https://maxchadwick.xyz/blog/stripping-a-query-parameter-from-a-url-in-php
function http_strip_query_param($url, $param)
{
$pieces = parse_url($url);
$query = [];
if ($pieces['query']) {
parse_str($pieces['query'], $query);
unset($query[$param]);
$pieces['query'] = http_build_query($query);
}

return $pieces['path'] . ($pieces['query'] ? '?' : '') . $pieces['query'];
}
12 changes: 12 additions & 0 deletions new/apps/web/src/php/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "spec-ify/specified",
"description": "A web viewer for Specify",
"type": "project",
"require-dev": {
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-strict-rules": "^1.6"
},
"require": {
"basuke/sveltekit-php-backend": "^1.0"
}
}
Loading

0 comments on commit 2112da4

Please sign in to comment.