mirror of
https://codeberg.org/vegvisir/vegvisir.git
synced 2025-09-13 20:43:40 +02:00
Initial commit
This commit is contained in:
commit
588dc99596
17 changed files with 1320 additions and 0 deletions
4
.env.example.ini
Normal file
4
.env.example.ini
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
; Pragma environment variables
|
||||||
|
|
||||||
|
; Absolute path to your site contents.
|
||||||
|
SITE_PATH=""
|
50
.gitignore
vendored
Normal file
50
.gitignore
vendored
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
# Bootstrapping #
|
||||||
|
#################
|
||||||
|
/node_modules
|
||||||
|
/public/hot
|
||||||
|
/public/storage
|
||||||
|
/storage/*.key
|
||||||
|
/vendor
|
||||||
|
.env
|
||||||
|
.env.ini
|
||||||
|
.env.backup
|
||||||
|
.phpunit.result.cache
|
||||||
|
Homestead.json
|
||||||
|
Homestead.yaml
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
public/robots.txt
|
||||||
|
|
||||||
|
# OS generated files #
|
||||||
|
######################
|
||||||
|
.DS_Store
|
||||||
|
.DS_Store?
|
||||||
|
._*
|
||||||
|
.Spotlight-V100
|
||||||
|
.Trashes
|
||||||
|
Icon?
|
||||||
|
ehthumbs.db
|
||||||
|
Thumbs.db
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Tool specific files #
|
||||||
|
#######################
|
||||||
|
# vim
|
||||||
|
*~
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
# sublime text & textmate
|
||||||
|
*.sublime-*
|
||||||
|
*.stTheme.cache
|
||||||
|
*.tmlanguage.cache
|
||||||
|
*.tmPreferences.cache
|
||||||
|
# Eclipse
|
||||||
|
.settings/*
|
||||||
|
# JetBrains, aka PHPStorm, IntelliJ IDEA
|
||||||
|
.idea/*
|
||||||
|
# NetBeans
|
||||||
|
nbproject/*
|
||||||
|
# Visual Studio Code
|
||||||
|
.vscode
|
||||||
|
# Sass preprocessor
|
||||||
|
.sass-cache/
|
339
LICENSE
Normal file
339
LICENSE
Normal file
|
@ -0,0 +1,339 @@
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
License is intended to guarantee your freedom to share and change free
|
||||||
|
software--to make sure the software is free for all its users. This
|
||||||
|
General Public License applies to most of the Free Software
|
||||||
|
Foundation's software and to any other program whose authors commit to
|
||||||
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
|
the GNU Lesser General Public License instead.) You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
this service if you wish), that you receive source code or can get it
|
||||||
|
if you want it, that you can change the software or use pieces of it
|
||||||
|
in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
|
These restrictions translate to certain responsibilities for you if you
|
||||||
|
distribute copies of the software, or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must give the recipients all the rights that
|
||||||
|
you have. You must make sure that they, too, receive or can get the
|
||||||
|
source code. And you must show them these terms so they know their
|
||||||
|
rights.
|
||||||
|
|
||||||
|
We protect your rights with two steps: (1) copyright the software, and
|
||||||
|
(2) offer you this license which gives you legal permission to copy,
|
||||||
|
distribute and/or modify the software.
|
||||||
|
|
||||||
|
Also, for each author's protection and ours, we want to make certain
|
||||||
|
that everyone understands that there is no warranty for this free
|
||||||
|
software. If the software is modified by someone else and passed on, we
|
||||||
|
want its recipients to know that what they have is not the original, so
|
||||||
|
that any problems introduced by others will not reflect on the original
|
||||||
|
authors' reputations.
|
||||||
|
|
||||||
|
Finally, any free program is threatened constantly by software
|
||||||
|
patents. We wish to avoid the danger that redistributors of a free
|
||||||
|
program will individually obtain patent licenses, in effect making the
|
||||||
|
program proprietary. To prevent this, we have made it clear that any
|
||||||
|
patent must be licensed for everyone's free use or not licensed at all.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License applies to any program or other work which contains
|
||||||
|
a notice placed by the copyright holder saying it may be distributed
|
||||||
|
under the terms of this General Public License. The "Program", below,
|
||||||
|
refers to any such program or work, and a "work based on the Program"
|
||||||
|
means either the Program or any derivative work under copyright law:
|
||||||
|
that is to say, a work containing the Program or a portion of it,
|
||||||
|
either verbatim or with modifications and/or translated into another
|
||||||
|
language. (Hereinafter, translation is included without limitation in
|
||||||
|
the term "modification".) Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running the Program is not restricted, and the output from the Program
|
||||||
|
is covered only if its contents constitute a work based on the
|
||||||
|
Program (independent of having been made by running the Program).
|
||||||
|
Whether that is true depends on what the Program does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Program's
|
||||||
|
source code as you receive it, in any medium, provided that you
|
||||||
|
conspicuously and appropriately publish on each copy an appropriate
|
||||||
|
copyright notice and disclaimer of warranty; keep intact all the
|
||||||
|
notices that refer to this License and to the absence of any warranty;
|
||||||
|
and give any other recipients of the Program a copy of this License
|
||||||
|
along with the Program.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and
|
||||||
|
you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Program or any portion
|
||||||
|
of it, thus forming a work based on the Program, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) You must cause the modified files to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
b) You must cause any work that you distribute or publish, that in
|
||||||
|
whole or in part contains or is derived from the Program or any
|
||||||
|
part thereof, to be licensed as a whole at no charge to all third
|
||||||
|
parties under the terms of this License.
|
||||||
|
|
||||||
|
c) If the modified program normally reads commands interactively
|
||||||
|
when run, you must cause it, when started running for such
|
||||||
|
interactive use in the most ordinary way, to print or display an
|
||||||
|
announcement including an appropriate copyright notice and a
|
||||||
|
notice that there is no warranty (or else, saying that you provide
|
||||||
|
a warranty) and that users may redistribute the program under
|
||||||
|
these conditions, and telling the user how to view a copy of this
|
||||||
|
License. (Exception: if the Program itself is interactive but
|
||||||
|
does not normally print such an announcement, your work based on
|
||||||
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Program,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Program, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Program.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Program
|
||||||
|
with the Program (or with a work based on the Program) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may copy and distribute the Program (or a work based on it,
|
||||||
|
under Section 2) in object code or executable form under the terms of
|
||||||
|
Sections 1 and 2 above provided that you also do one of the following:
|
||||||
|
|
||||||
|
a) Accompany it with the complete corresponding machine-readable
|
||||||
|
source code, which must be distributed under the terms of Sections
|
||||||
|
1 and 2 above on a medium customarily used for software interchange; or,
|
||||||
|
|
||||||
|
b) Accompany it with a written offer, valid for at least three
|
||||||
|
years, to give any third party, for a charge no more than your
|
||||||
|
cost of physically performing source distribution, a complete
|
||||||
|
machine-readable copy of the corresponding source code, to be
|
||||||
|
distributed under the terms of Sections 1 and 2 above on a medium
|
||||||
|
customarily used for software interchange; or,
|
||||||
|
|
||||||
|
c) Accompany it with the information you received as to the offer
|
||||||
|
to distribute corresponding source code. (This alternative is
|
||||||
|
allowed only for noncommercial distribution and only if you
|
||||||
|
received the program in object code or executable form with such
|
||||||
|
an offer, in accord with Subsection b above.)
|
||||||
|
|
||||||
|
The source code for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For an executable work, complete source
|
||||||
|
code means all the source code for all modules it contains, plus any
|
||||||
|
associated interface definition files, plus the scripts used to
|
||||||
|
control compilation and installation of the executable. However, as a
|
||||||
|
special exception, the source code distributed need not include
|
||||||
|
anything that is normally distributed (in either source or binary
|
||||||
|
form) with the major components (compiler, kernel, and so on) of the
|
||||||
|
operating system on which the executable runs, unless that component
|
||||||
|
itself accompanies the executable.
|
||||||
|
|
||||||
|
If distribution of executable or object code is made by offering
|
||||||
|
access to copy from a designated place, then offering equivalent
|
||||||
|
access to copy the source code from the same place counts as
|
||||||
|
distribution of the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
|
except as expressly provided under this License. Any attempt
|
||||||
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
|
void, and will automatically terminate your rights under this License.
|
||||||
|
However, parties who have received copies, or rights, from you under
|
||||||
|
this License will not have their licenses terminated so long as such
|
||||||
|
parties remain in full compliance.
|
||||||
|
|
||||||
|
5. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Program or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Program (or any work based on the
|
||||||
|
Program), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Program or works based on it.
|
||||||
|
|
||||||
|
6. Each time you redistribute the Program (or any work based on the
|
||||||
|
Program), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute or modify the Program subject to
|
||||||
|
these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties to
|
||||||
|
this License.
|
||||||
|
|
||||||
|
7. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Program at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Program by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Program.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under
|
||||||
|
any particular circumstance, the balance of the section is intended to
|
||||||
|
apply and the section as a whole is intended to apply in other
|
||||||
|
circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system, which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Program under this License
|
||||||
|
may add an explicit geographical distribution limitation excluding
|
||||||
|
those countries, so that distribution is permitted only in or among
|
||||||
|
countries not thus excluded. In such case, this License incorporates
|
||||||
|
the limitation as if written in the body of this License.
|
||||||
|
|
||||||
|
9. The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies a version number of this License which applies to it and "any
|
||||||
|
later version", you have the option of following the terms and conditions
|
||||||
|
either of that version or of any later version published by the Free
|
||||||
|
Software Foundation. If the Program does not specify a version number of
|
||||||
|
this License, you may choose any version ever published by the Free Software
|
||||||
|
Foundation.
|
||||||
|
|
||||||
|
10. If you wish to incorporate parts of the Program into other free
|
||||||
|
programs whose distribution conditions are different, write to the author
|
||||||
|
to ask for permission. For software which is copyrighted by the Free
|
||||||
|
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||||
|
make exceptions for this. Our decision will be guided by the two goals
|
||||||
|
of preserving the free status of all derivatives of our free software and
|
||||||
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||||
|
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||||
|
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||||
|
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||||
|
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||||
|
REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||||
|
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||||
|
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||||
|
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||||
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program is interactive, make it output a short notice like this
|
||||||
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
|
Gnomovision version 69, Copyright (C) year name of author
|
||||||
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, the commands you use may
|
||||||
|
be called something other than `show w' and `show c'; they could even be
|
||||||
|
mouse-clicks or menu items--whatever suits your program.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||||
|
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1989
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
This General Public License does not permit incorporating your program into
|
||||||
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
|
consider it more useful to permit linking proprietary applications with the
|
||||||
|
library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License.
|
4
README.md
Normal file
4
README.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# Pragma
|
||||||
|
Another framework for building websites with PHP.
|
||||||
|
|
||||||
|
> Docs coming in the next commit!
|
5
composer.json
Normal file
5
composer.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"matthiasmullie/minify": "^1.3"
|
||||||
|
}
|
||||||
|
}
|
142
composer.lock
generated
Normal file
142
composer.lock
generated
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
{
|
||||||
|
"_readme": [
|
||||||
|
"This file locks the dependencies of your project to a known state",
|
||||||
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
|
"This file is @generated automatically"
|
||||||
|
],
|
||||||
|
"content-hash": "e7806260d775937d439159cde5165225",
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "matthiasmullie/minify",
|
||||||
|
"version": "1.3.69",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/matthiasmullie/minify.git",
|
||||||
|
"reference": "a61c949cccd086808063611ef9698eabe42ef22f"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/matthiasmullie/minify/zipball/a61c949cccd086808063611ef9698eabe42ef22f",
|
||||||
|
"reference": "a61c949cccd086808063611ef9698eabe42ef22f",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-pcre": "*",
|
||||||
|
"matthiasmullie/path-converter": "~1.1",
|
||||||
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"friendsofphp/php-cs-fixer": "~2.0",
|
||||||
|
"matthiasmullie/scrapbook": "dev-master",
|
||||||
|
"phpunit/phpunit": ">=4.8"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"psr/cache-implementation": "Cache implementation to use with Minify::cache"
|
||||||
|
},
|
||||||
|
"bin": [
|
||||||
|
"bin/minifycss",
|
||||||
|
"bin/minifyjs"
|
||||||
|
],
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"MatthiasMullie\\Minify\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Matthias Mullie",
|
||||||
|
"email": "minify@mullie.eu",
|
||||||
|
"homepage": "http://www.mullie.eu",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "CSS & JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.",
|
||||||
|
"homepage": "http://www.minifier.org",
|
||||||
|
"keywords": [
|
||||||
|
"JS",
|
||||||
|
"css",
|
||||||
|
"javascript",
|
||||||
|
"minifier",
|
||||||
|
"minify"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/matthiasmullie/minify/issues",
|
||||||
|
"source": "https://github.com/matthiasmullie/minify/tree/1.3.69"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/matthiasmullie",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2022-08-01T09:00:18+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "matthiasmullie/path-converter",
|
||||||
|
"version": "1.1.3",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/matthiasmullie/path-converter.git",
|
||||||
|
"reference": "e7d13b2c7e2f2268e1424aaed02085518afa02d9"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/matthiasmullie/path-converter/zipball/e7d13b2c7e2f2268e1424aaed02085518afa02d9",
|
||||||
|
"reference": "e7d13b2c7e2f2268e1424aaed02085518afa02d9",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-pcre": "*",
|
||||||
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "~4.8"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"MatthiasMullie\\PathConverter\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Matthias Mullie",
|
||||||
|
"email": "pathconverter@mullie.eu",
|
||||||
|
"homepage": "http://www.mullie.eu",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Relative path converter",
|
||||||
|
"homepage": "http://github.com/matthiasmullie/path-converter",
|
||||||
|
"keywords": [
|
||||||
|
"converter",
|
||||||
|
"path",
|
||||||
|
"paths",
|
||||||
|
"relative"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/matthiasmullie/path-converter/issues",
|
||||||
|
"source": "https://github.com/matthiasmullie/path-converter/tree/1.1.3"
|
||||||
|
},
|
||||||
|
"time": "2019-02-05T23:41:09+00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": [],
|
||||||
|
"aliases": [],
|
||||||
|
"minimum-stability": "stable",
|
||||||
|
"stability-flags": [],
|
||||||
|
"prefer-stable": false,
|
||||||
|
"prefer-lowest": false,
|
||||||
|
"platform": [],
|
||||||
|
"platform-dev": [],
|
||||||
|
"plugin-api-version": "2.0.0"
|
||||||
|
}
|
8
public/index.php
Normal file
8
public/index.php
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once "../src/Init.php";
|
||||||
|
require_once Path::pragma("src/request/Request.php");
|
||||||
|
|
||||||
|
// Start the request processor. This is how Pragma gets initialized
|
||||||
|
// from an HTTP request.
|
||||||
|
(new Request());
|
39
src/Init.php
Normal file
39
src/Init.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Global paths
|
||||||
|
final class Path {
|
||||||
|
// Get root of Pragma installation for accesing framework files
|
||||||
|
public static function pragma(string $crumbs = ""): string {
|
||||||
|
return dirname(__DIR__) . "/" . $crumbs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get root of user site folder
|
||||||
|
public static function root(string $crumbs = ""): string {
|
||||||
|
return $_ENV["SITE_PATH"] . "/" . $crumbs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the contents of a path
|
||||||
|
public static function contents(string $path): array|null {
|
||||||
|
$dir = scandir($path);
|
||||||
|
|
||||||
|
// Remove "." and ".." if is dir
|
||||||
|
if (!empty($dir)) {
|
||||||
|
array_shift($dir);
|
||||||
|
array_shift($dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load Composer dependencies
|
||||||
|
require_once Path::pragma("vendor/autoload.php");
|
||||||
|
|
||||||
|
// Put environment variables from INI into superglobal
|
||||||
|
$_ENV = parse_ini_file(Path::pragma(".env.ini"), true);
|
||||||
|
|
||||||
|
// Merge environment variables from site contents with Pragma default.
|
||||||
|
// Site content variables will override default, by default.
|
||||||
|
if (file_exists(Path::root(".env.ini"))) {
|
||||||
|
$_ENV = array_merge($_ENV, parse_ini_file(Path::root(".env.ini"), true));
|
||||||
|
}
|
60
src/frontend/js/modules/Interactions.js
Normal file
60
src/frontend/js/modules/Interactions.js
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
// Event handler for interactive components page
|
||||||
|
class Interactions {
|
||||||
|
constructor(scope, methods = {}, autoBind = true) {
|
||||||
|
// Default "built-in" interactions
|
||||||
|
this.methods = {
|
||||||
|
nav: (event) => {
|
||||||
|
new Navigation(event);
|
||||||
|
},
|
||||||
|
void: () => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge incoming- and default interactions
|
||||||
|
Object.assign(this.methods, methods);
|
||||||
|
|
||||||
|
this.scope = scope;
|
||||||
|
this.elements = new Set();
|
||||||
|
|
||||||
|
// Bind elements on startup
|
||||||
|
if (autoBind) {
|
||||||
|
this.bindAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return default method name by element type
|
||||||
|
defaultActionFromType(element) {
|
||||||
|
switch (typeof element) {
|
||||||
|
case HTMLAnchorElement:
|
||||||
|
return "nav";
|
||||||
|
|
||||||
|
default:
|
||||||
|
console.warn("Undefined interaction", element);
|
||||||
|
return "void";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind interactive components to an element
|
||||||
|
bind(element) {
|
||||||
|
// Call method when element is interacted with
|
||||||
|
if ("action" in element.dataset) {
|
||||||
|
// Action requested but method name not provided, attempt to resolve from element type
|
||||||
|
if (element.dataset.action.length < 1) {
|
||||||
|
element.dataset.action = this.defaultActionFromType(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call method when element is interacted with
|
||||||
|
element.addEventListener("click", event => {
|
||||||
|
event.stopPropagation(); // Don't bubble interaction to parent elements
|
||||||
|
this.methods[element.dataset.action](event);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.elements.add(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find and bind all interactive elements on page
|
||||||
|
bindAll() {
|
||||||
|
const elements = [...document.querySelectorAll(`[data-trigger="${this.scope}"]`)];
|
||||||
|
elements.forEach(element => this.bind(element));
|
||||||
|
}
|
||||||
|
}
|
72
src/frontend/js/modules/KvStore.js
Normal file
72
src/frontend/js/modules/KvStore.js
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
// Basic virtual KV store with Storage API (and cookies)
|
||||||
|
class KvStore {
|
||||||
|
constructor(namespace = "kvstore", medium = null) {
|
||||||
|
this.namespace = namespace;
|
||||||
|
this.storage = medium; // Storage API interface (or document.cookie)
|
||||||
|
|
||||||
|
// Use LocalStorage as the default medium if none specified
|
||||||
|
if (!this.storage && localStorage in globalThis) {
|
||||||
|
this.storage = globalThis.localStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create polyfill for cookie storage
|
||||||
|
if (this.storage === document.cookie) {
|
||||||
|
this.cookieStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
|
||||||
|
// Initialize virtual KV store
|
||||||
|
if (!this.get("kvstore")) {
|
||||||
|
this.set("kvstore", {
|
||||||
|
version: "1.0"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Polyfill Storage API with cookies
|
||||||
|
cookieStorage() {
|
||||||
|
this.storage = {
|
||||||
|
// Get cookie value from namespace by key
|
||||||
|
getItem: (key) => {
|
||||||
|
let data = document.cookie.split("; ").find(cookie => cookie.startsWith(key + "="))?.split("=")[1] ?? null;
|
||||||
|
data = decodeURIComponent(data);
|
||||||
|
|
||||||
|
return JSON.stringify(data);
|
||||||
|
},
|
||||||
|
// Create/replace new namespaced cookie with key
|
||||||
|
setItem: (key, value, expires = null) => {
|
||||||
|
expires = expires ?? 60 * 60 * 24 * 365; // Cookie expires in 1 year by default
|
||||||
|
value = encodeURIComponent(value);
|
||||||
|
|
||||||
|
document.cookie = `${key}=${value}; max-age=${expires}; Path=/`;
|
||||||
|
},
|
||||||
|
// Remove namespaced cookie by key
|
||||||
|
removeItem: (key) => {
|
||||||
|
this.storage.setItem(key, "", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepend namespace prefix to key
|
||||||
|
key(key) {
|
||||||
|
return [this.namespace, key].join("_");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- */
|
||||||
|
|
||||||
|
// Get value by key
|
||||||
|
get(key) {
|
||||||
|
return JSON.parse(this.storage.getItem(this.key(key)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set value by key
|
||||||
|
set(key, value) {
|
||||||
|
return this.storage.setItem(this.key(key), JSON.stringify(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove entry by key
|
||||||
|
remove(key) {
|
||||||
|
return this.storage.removeItem(this.key(key));
|
||||||
|
}
|
||||||
|
}
|
222
src/frontend/js/modules/Navigation.js
Normal file
222
src/frontend/js/modules/Navigation.js
Normal file
|
@ -0,0 +1,222 @@
|
||||||
|
class Navigation {
|
||||||
|
constructor(source) {
|
||||||
|
this.worker = new Worker("/workers/NavigationWorker.js");
|
||||||
|
this.worker.addEventListener("message", event => this.messageHandler(event));
|
||||||
|
|
||||||
|
// The root element used for top navigations (and the default target)
|
||||||
|
this.main = document.getElementsByTagName("main")[0];
|
||||||
|
|
||||||
|
// Create URL object from string or event
|
||||||
|
if (!(source instanceof URL)) {
|
||||||
|
if (typeof source === "string") {
|
||||||
|
this.url = this.urlFromString(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle events
|
||||||
|
if (source instanceof Event) {
|
||||||
|
this.eventHandler(source);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Source is a URL object, use it directly
|
||||||
|
this.url = source;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push new entry with History API
|
||||||
|
historyPush(url) {
|
||||||
|
// Create URL object from string
|
||||||
|
url = url instanceof URL ? url : new URL(url);
|
||||||
|
|
||||||
|
if (url.pathname.substring(0, 6) === "/error") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url.pathname === "/index") {
|
||||||
|
url.pathname = "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
url: url.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
history.pushState(state, "", url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace inner DOM of target with an SVG spinner
|
||||||
|
waiting(target) {
|
||||||
|
this.setTargetHtml(target, globalThis.spinnerSvg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scroll to anchor element in DOM
|
||||||
|
scrollToAnchor() {
|
||||||
|
const hash = window.location.hash.substring(1);
|
||||||
|
const anchor = document.getElementById(hash) ?? null;
|
||||||
|
|
||||||
|
// Scroll top to anchor element if it exists in the DOM
|
||||||
|
if (anchor !== null) {
|
||||||
|
const top = document.getElementById("top");
|
||||||
|
top.scrollTo(0, anchor.offsetTop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace inner DOM of target element with stringified HTML
|
||||||
|
setTargetHtml(target, html) {
|
||||||
|
target = target instanceof HTMLElement ? target : document.querySelector(target);
|
||||||
|
target.innerHTML = html;
|
||||||
|
|
||||||
|
target.scrollTo(0, 0); // Reset scroll position of wrapper
|
||||||
|
target.parentElement.parentElement.scrollTo(0, 0); // Also reset scroll position for root element (Safari)
|
||||||
|
|
||||||
|
// Rebuild script tags as they don't execute with innerHTML per the HTML spec
|
||||||
|
const scripts = [...target.getElementsByTagName("script")];
|
||||||
|
scripts.forEach(script => {
|
||||||
|
const tag = document.createElement("script");
|
||||||
|
|
||||||
|
// Assign element attributes
|
||||||
|
for (const attribute of script.getAttributeNames()) {
|
||||||
|
tag.setAttribute(attribute, script.getAttribute(attribute));
|
||||||
|
}
|
||||||
|
|
||||||
|
tag.innerHTML = `{${script.innerText}}`;
|
||||||
|
|
||||||
|
script.remove();
|
||||||
|
target.appendChild(tag);
|
||||||
|
});
|
||||||
|
|
||||||
|
// URL is a top navigation and contains a hash
|
||||||
|
if (target.id == "top" && window.location.hash.length > 0) {
|
||||||
|
this.scrollToAnchor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Turn URL string or pathname into a URL object
|
||||||
|
urlFromString(string) {
|
||||||
|
let url = undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
|
url = new URL(string);
|
||||||
|
} catch {
|
||||||
|
// Treat invalid URL as a pathname
|
||||||
|
url = new URL(window.location.href);
|
||||||
|
url.pathname = string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carry existing top searchParams to new location
|
||||||
|
url.search = new URLSearchParams({
|
||||||
|
...Object.fromEntries(new URLSearchParams(window.location.search)),
|
||||||
|
...Object.fromEntries(new URLSearchParams(url.search))
|
||||||
|
}).toString();
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract URL and target from received event
|
||||||
|
eventHandler(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
// Is activation type event
|
||||||
|
if (event.constructor === PointerEvent || event.constructor === MouseEvent) {
|
||||||
|
const element = event.target.closest("a");
|
||||||
|
let target = element.getAttribute("target");
|
||||||
|
|
||||||
|
this.url = this.urlFromString(element.href);
|
||||||
|
|
||||||
|
// Use the target attribute of the element to determine where to inject loaded content
|
||||||
|
switch (target) {
|
||||||
|
// Replace inner DOM of the the clicked element
|
||||||
|
case "_self":
|
||||||
|
target = event.target;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Replace inner DOM of target's closest parent element (will remove clicked element from DOM)
|
||||||
|
case "_parent":
|
||||||
|
target = element.parentElement;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Replace element inner DOM by id, or default to #top (#top will update URL and History API)
|
||||||
|
case "_top":
|
||||||
|
default:
|
||||||
|
target = document.getElementById(target) ?? document.getElementById("top");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.navigate(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get CSS Selector from DOM node
|
||||||
|
getCssSelector(element) {
|
||||||
|
// Traverse the node tree backwards from target element
|
||||||
|
const path = [];
|
||||||
|
while (element.parentNode) {
|
||||||
|
// We found an id, stop here and use it as the entry point
|
||||||
|
if (element.id) {
|
||||||
|
path.unshift("#" + element.id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parent = element.parentElement;
|
||||||
|
const index = [...parent.children]?.indexOf(element) + 1;
|
||||||
|
|
||||||
|
if (parent === document.documentElement) {
|
||||||
|
path.unshift(element.tagName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
path.unshift(`${element.tagName}:nth-child(${index})`);
|
||||||
|
element = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.join(" > ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle generic messages from Worker
|
||||||
|
messageHandler(event) {
|
||||||
|
switch (event.data[0]) {
|
||||||
|
case "META":
|
||||||
|
console.log("Metadata received");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform SPA navigation by fetching new page and modifing DOM
|
||||||
|
async navigate(target = null, rejectOnFail = false) {
|
||||||
|
target = target ?? this.main;
|
||||||
|
|
||||||
|
// Tell Worker to fetch page
|
||||||
|
const selector = this.getCssSelector(target);
|
||||||
|
this.worker.postMessage([selector, this.url.toString()]);
|
||||||
|
|
||||||
|
const respTimeout = setTimeout(() => this.waiting(target), 300);
|
||||||
|
|
||||||
|
// Wait for Worker to fetch page
|
||||||
|
const nav = await new Promise((resolve) => {
|
||||||
|
this.worker.addEventListener("message", (event) => {
|
||||||
|
clearTimeout(respTimeout);
|
||||||
|
let [target, body, status, url] = event.data;
|
||||||
|
url = new URL(url);
|
||||||
|
|
||||||
|
// Target is a valid top navigation, do some stuff
|
||||||
|
if (status === 200 && (target === "main")) {
|
||||||
|
// Add loaded URL to history
|
||||||
|
this.historyPush(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update DOM and resolve this and outer Promise
|
||||||
|
this.setTargetHtml(target, body);
|
||||||
|
resolve(event.data);
|
||||||
|
}, { once: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create new Respone and pass HTTP status code
|
||||||
|
const resp = new Response(nav[1], { status: nav[2]});
|
||||||
|
|
||||||
|
// Resolve Promise with Response
|
||||||
|
if (!rejectOnFail) {
|
||||||
|
return Promise.resolve(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Align Promise completion with Response status
|
||||||
|
return resp.ok ? Promise.resolve(resp) : Promise.reject(resp);
|
||||||
|
}
|
||||||
|
}
|
17
src/frontend/js/pragma.js
Normal file
17
src/frontend/js/pragma.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// Pragma frontend initializer.
|
||||||
|
// This script depends on "./Interactions.js" and "./Navigation.js" being
|
||||||
|
// present in the same scope duing initialization.
|
||||||
|
|
||||||
|
// Functions and classes accessible by all scripts
|
||||||
|
globalThis.pragma = {
|
||||||
|
// Bind core features to global scope
|
||||||
|
Interactions: (...args) => new Interactions(...args),
|
||||||
|
Navigation: (...args) => new Navigation(...args)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle browser back/forward buttons
|
||||||
|
window.addEventListener("popstate", (event) => {
|
||||||
|
if ("url" in event.state) {
|
||||||
|
globalThis.pragma.Navigation(event.state.url).navigate();
|
||||||
|
}
|
||||||
|
});
|
51
src/frontend/js/workers/LogWorker.js
Normal file
51
src/frontend/js/workers/LogWorker.js
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
class Log {
|
||||||
|
constructor(data) {
|
||||||
|
this.endpoint = "https://api.icellate.com/log";
|
||||||
|
this.payload = {
|
||||||
|
host: globalThis.location.host,
|
||||||
|
ua: this.getUaString(),
|
||||||
|
time: performance.now(),
|
||||||
|
data: data
|
||||||
|
};
|
||||||
|
|
||||||
|
this.dispatch();
|
||||||
|
|
||||||
|
// Timeout and self-terminate after 10 seconds
|
||||||
|
setTimeout(() => this.destroy(), 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Terminate the log worker
|
||||||
|
destroy() {
|
||||||
|
globalThis.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
getUaString() {
|
||||||
|
// Browser doesn't support/expose a NavigatorUAData object on global in this scope
|
||||||
|
if (!"userAgentData" in globalThis.navigator) {
|
||||||
|
return globalThis.navigator.userAgent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get low-entropy values of the user agent
|
||||||
|
return JSON.stringify(globalThis.navigator.userAgentData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send log data to endpoint
|
||||||
|
async dispatch() {
|
||||||
|
const log = await fetch(this.endpoint, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify(this.payload)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Program will normally exit here on a successful log
|
||||||
|
if (log.ok) {
|
||||||
|
return this.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(log, this.payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.addEventListener("message", event => new Log(event.data));
|
100
src/frontend/js/workers/NavigationWorker.js
Normal file
100
src/frontend/js/workers/NavigationWorker.js
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
class NavigationWorker {
|
||||||
|
constructor(event) {
|
||||||
|
this.options = {
|
||||||
|
headers: {
|
||||||
|
// Tell the backend we only want page content, no app shell
|
||||||
|
"X-Navigation-Type": "contained"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getPage(event.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an empty Response with a status code only
|
||||||
|
newEmptyResponse(code = 500, message = "NavigationWorker: Internal Server Error") {
|
||||||
|
return new Response(null, {
|
||||||
|
status: code,
|
||||||
|
statusText: message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new error Response from a recieved Response
|
||||||
|
async error(resp, data = ["main"]) {
|
||||||
|
const target = data[0];
|
||||||
|
|
||||||
|
// Simulate Response from server if error is internal
|
||||||
|
if (!resp instanceof Response) {
|
||||||
|
resp = this.newEmptyResponse(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to load custom error page
|
||||||
|
const errorPage = await this.getPage([target, "/error/404"]);
|
||||||
|
if (errorPage.ok) {
|
||||||
|
return errorPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new Response with error HTML and forward HTTP status data
|
||||||
|
const html = `<main><h1>Error</h1><p>${resp.statusText}</main>`;
|
||||||
|
return new Response(html, {
|
||||||
|
status: resp.status,
|
||||||
|
statusText: resp.statusText
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
|
||||||
|
// Request metadata for page from backend
|
||||||
|
async getMeta(page) {
|
||||||
|
let options = {
|
||||||
|
headers: {
|
||||||
|
// Tell the backend we only want metadata for the page
|
||||||
|
"X-Navigation-Type": "meta"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(options, this.options);
|
||||||
|
|
||||||
|
const req = new Request(page, options);
|
||||||
|
const resp = await fetch(req);
|
||||||
|
|
||||||
|
const json = await resp.json();
|
||||||
|
console.log("meta", json);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request page from back-end
|
||||||
|
async getPage(data) {
|
||||||
|
const target = data[0];
|
||||||
|
const page = data[1];
|
||||||
|
|
||||||
|
const req = new Request(page, this.options);
|
||||||
|
let resp = await fetch(req);
|
||||||
|
|
||||||
|
// Request failed, so show error page with status code
|
||||||
|
if(!resp.ok) {
|
||||||
|
resp = this.error(resp, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fetch response body as plaintext and send to main thread
|
||||||
|
* so the browser can start parsing and painting the page ASAP
|
||||||
|
*/
|
||||||
|
const body = await resp.text();
|
||||||
|
|
||||||
|
// Send response back to initiator thread
|
||||||
|
globalThis.postMessage([
|
||||||
|
data[0], // Target element selector
|
||||||
|
body, // Page body
|
||||||
|
resp.status, // HTTP status code
|
||||||
|
resp.url // Loaded URL (after redirection etc.)
|
||||||
|
]);
|
||||||
|
|
||||||
|
// .. Get metadata for the page, such as <title> and more in the meantime
|
||||||
|
if (target === "main") {
|
||||||
|
this.getMeta(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.addEventListener("message", event => new NavigationWorker(event));
|
3
src/frontend/pragma.php
Normal file
3
src/frontend/pragma.php
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?= Page::js("modules/Navigation.js") ?>
|
||||||
|
<?= Page::js("modules/Interactions.js") ?>
|
||||||
|
<?= Page::js("pragma.js") ?>
|
133
src/request/Page.php
Normal file
133
src/request/Page.php
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use MatthiasMullie\Minify;
|
||||||
|
|
||||||
|
class Page {
|
||||||
|
public function __construct($page = "document") {
|
||||||
|
// Check if request is for partial content
|
||||||
|
if (array_key_exists("HTTP_X_NAVIGATION_TYPE", $_SERVER)) {
|
||||||
|
switch ($_SERVER["HTTP_X_NAVIGATION_TYPE"]) {
|
||||||
|
// Request is for a page
|
||||||
|
case "contained":
|
||||||
|
Page::include($page, true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
http_response_code(422);
|
||||||
|
die("NAVIGATION_TYPE not supported");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Serve the whole document on (re)load
|
||||||
|
Page::include("document");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return absolute path to asset on disk.
|
||||||
|
// The function takes a "scope" in the form of a $folder name relative to the asset root
|
||||||
|
// to prevent this function from reading anywhere on disk.
|
||||||
|
private static function get_asset_path(string $folder, string $file): string {
|
||||||
|
// Append name of folder as file extension if omitted.
|
||||||
|
// This may or may not resolve into an existing file. But for common web assets like
|
||||||
|
// JS and CSS it works rather fine.
|
||||||
|
if (strpos($file, ".") === false) {
|
||||||
|
$file .= "." . $folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to read asset from user site first
|
||||||
|
$path = Path::root("assets/${folder}/${file}");
|
||||||
|
if (is_file($path)) {
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to framework static asset if no user site asset found
|
||||||
|
return Path::pragma("src/frontend/${folder}/${file}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set or get locale cookie from reference list of hostnames
|
||||||
|
private static function get_locale(string $locale = null): string {
|
||||||
|
// Locale arg not provided, use the first locale in user content pages
|
||||||
|
// as default.
|
||||||
|
if (empty($locale) && empty($_COOKIE["user_locale"])) {
|
||||||
|
$locales = Path::contents(Path::root("pages"));
|
||||||
|
if (empty($locales)) {
|
||||||
|
http_response_code(404);
|
||||||
|
die("No pages defined");
|
||||||
|
}
|
||||||
|
|
||||||
|
$locale = $locales[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set and return locale cookie if provided
|
||||||
|
if (!empty($locale)) {
|
||||||
|
setcookie("user_locale", $locale, 0, "/");
|
||||||
|
return $locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return already set locale cookie
|
||||||
|
return $_COOKIE["user_locale"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// These functions are exposed to all pages. They can be called
|
||||||
|
// with the static reference Page::<method> anywhere on the page.
|
||||||
|
|
||||||
|
// Return minified CSS from file
|
||||||
|
public static function css(string $file): string {
|
||||||
|
$file = Page::get_asset_path("css", $file);
|
||||||
|
|
||||||
|
if(!is_file($file)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
$minifier = new Minify\CSS($file);
|
||||||
|
return $minifier->minify();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return minified JS from file
|
||||||
|
public static function js(string $file): string {
|
||||||
|
$file = Page::get_asset_path("js", $file);
|
||||||
|
|
||||||
|
if(!is_file($file)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
$minifier = new Minify\JS($file);
|
||||||
|
return $minifier->minify();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return contents of media file as base64-encoded string unless whitelisted
|
||||||
|
// for assets that should be read as-is, such as SVG.
|
||||||
|
public static function media(string $file): string {
|
||||||
|
$file = file_get_contents(Page::get_asset_path("media", $file));
|
||||||
|
|
||||||
|
// Invalid file returns empty string
|
||||||
|
if ($file === false) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Base64-encode everything that isn't in whitelist array
|
||||||
|
if (!in_array(substr($file, -1, 4), [".svg"])) {
|
||||||
|
$file = base64_encode($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load an external document into the current document
|
||||||
|
public static function include(string $name) {
|
||||||
|
// Rewrite root to /main page
|
||||||
|
if ($name === "/") {
|
||||||
|
$name = "/index";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to load from user content pages
|
||||||
|
$locale = Page::get_locale();
|
||||||
|
$file = Path::root("pages/${locale}/${name}.php");
|
||||||
|
|
||||||
|
// If user content page does not exist, try to load from framework
|
||||||
|
if (!is_file($file)) {
|
||||||
|
$file = Path::pragma("src/frontend/${name}.php");
|
||||||
|
}
|
||||||
|
|
||||||
|
include $file;
|
||||||
|
}
|
||||||
|
}
|
71
src/request/Request.php
Normal file
71
src/request/Request.php
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once Path::pragma("src/request/Page.php");
|
||||||
|
|
||||||
|
class Request {
|
||||||
|
|
||||||
|
private static $preg_worker = "/^\/worker\/*/";
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
// Get pathname from request URI
|
||||||
|
$this->path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
|
||||||
|
|
||||||
|
$this->router();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request router
|
||||||
|
private function router() {
|
||||||
|
switch ($this->path) {
|
||||||
|
// Return script to be run in a JS Worker
|
||||||
|
case (preg_match(Request::$preg_worker, $this->path) ? true : false):
|
||||||
|
return $this->worker();
|
||||||
|
|
||||||
|
// Ignore requests to /favicon.ico which sometimes gets sent automatically
|
||||||
|
// by browsers when a an icon meta tag is not specified. We don't want to prepare
|
||||||
|
// a whole page instance for this.
|
||||||
|
case "/favicon.ico":
|
||||||
|
return $this->void();
|
||||||
|
|
||||||
|
// Pass request to Page() initializer
|
||||||
|
default:
|
||||||
|
return new Page($this->get_requested_path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_requested_path(): string {
|
||||||
|
$path = $this->path;
|
||||||
|
|
||||||
|
// Requests to root of user content path should be rewritten to /index
|
||||||
|
if ($this->path === "/") {
|
||||||
|
$path = "index";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip leading slash
|
||||||
|
if (strpos($this->path, "/") === 1) {
|
||||||
|
$path = substr($this->path, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return empty response
|
||||||
|
private function void(): never {
|
||||||
|
// No content
|
||||||
|
http_response_code(204);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return contents of a JS file to be run inside a JS Worker
|
||||||
|
private function worker(): never {
|
||||||
|
// Check if worker script exists
|
||||||
|
$file = Path::pragma("src/frontend/js{$this->path}");
|
||||||
|
if (!is_file($file)) {
|
||||||
|
http_response_code(404);
|
||||||
|
die("Not a worker");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return worker script contents
|
||||||
|
header("Content-Type: text/javascript");
|
||||||
|
exit(file_get_contents($file));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue