forked from projects/fipamo
Compare commits
1 commit
develop
...
toggle-but
Author | SHA1 | Date | |
---|---|---|---|
|
a687b50452 |
303 changed files with 37132 additions and 21734 deletions
|
@ -1,18 +0,0 @@
|
||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
charset = utf-8
|
|
||||||
end_of_line = lf
|
|
||||||
indent_size = 4
|
|
||||||
indent_style = space
|
|
||||||
insert_final_newline = true
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
|
|
||||||
[*.md]
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
|
|
||||||
[*.{yml,yaml}]
|
|
||||||
indent_size = 2
|
|
||||||
|
|
||||||
[docker-compose.yml]
|
|
||||||
indent_size = 4
|
|
74
.env.example
74
.env.example
|
@ -1,74 +0,0 @@
|
||||||
APP_NAME=Laravel
|
|
||||||
APP_ENV=local
|
|
||||||
APP_KEY=
|
|
||||||
APP_DEBUG=true
|
|
||||||
APP_URL=http://localhost
|
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
|
||||||
LOG_DEPRECATIONS_CHANNEL=null
|
|
||||||
LOG_LEVEL=debug
|
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
|
||||||
DB_HOST=127.0.0.1
|
|
||||||
DB_PORT=3306
|
|
||||||
DB_DATABASE=fipamo
|
|
||||||
DB_USERNAME=root
|
|
||||||
DB_PASSWORD=
|
|
||||||
|
|
||||||
BROADCAST_DRIVER=log
|
|
||||||
CACHE_DRIVER=file
|
|
||||||
FILESYSTEM_DISK=local
|
|
||||||
QUEUE_CONNECTION=sync
|
|
||||||
SESSION_DRIVER=file
|
|
||||||
SESSION_LIFETIME=120
|
|
||||||
|
|
||||||
MEMCACHED_HOST=127.0.0.1
|
|
||||||
|
|
||||||
REDIS_HOST=127.0.0.1
|
|
||||||
REDIS_PASSWORD=null
|
|
||||||
REDIS_PORT=6379
|
|
||||||
|
|
||||||
MAIL_MAILER=smtp
|
|
||||||
MAIL_HOST=mailpit
|
|
||||||
MAIL_PORT=1025
|
|
||||||
MAIL_USERNAME=null
|
|
||||||
MAIL_PASSWORD=null
|
|
||||||
MAIL_ENCRYPTION=null
|
|
||||||
MAIL_FROM_ADDRESS="hello@example.com"
|
|
||||||
MAIL_FROM_NAME="${APP_NAME}"
|
|
||||||
|
|
||||||
AWS_ACCESS_KEY_ID=
|
|
||||||
AWS_SECRET_ACCESS_KEY=
|
|
||||||
AWS_DEFAULT_REGION=us-east-1
|
|
||||||
AWS_BUCKET=
|
|
||||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
|
||||||
|
|
||||||
PUSHER_APP_ID=
|
|
||||||
PUSHER_APP_KEY=
|
|
||||||
PUSHER_APP_SECRET=
|
|
||||||
PUSHER_HOST=
|
|
||||||
PUSHER_PORT=443
|
|
||||||
PUSHER_SCHEME=https
|
|
||||||
PUSHER_APP_CLUSTER=mt1
|
|
||||||
|
|
||||||
VITE_APP_NAME="${APP_NAME}"
|
|
||||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
|
||||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
|
||||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
|
||||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
|
||||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
|
||||||
|
|
||||||
#------------------
|
|
||||||
# FIPAMO SETTINGS
|
|
||||||
#------------------
|
|
||||||
FIPAMO_DIR="../content"
|
|
||||||
PAGES_PATH="${FIPAMO_DIR}/pages"
|
|
||||||
THEMES_PATH="${FIPAMO_DIR}/themes"
|
|
||||||
FIPAMO_CONFIG="${FIPAMO_DIR}/config"
|
|
||||||
SETTINGS_PATH="${FIPAMO_CONFIG}/settings.json"
|
|
||||||
FOLKS_PATH="${FIPAMO_CONFIG}/folks.json"
|
|
||||||
TAGS_PATH="${FIPAMO_CONFIG}/tags.json"
|
|
||||||
FIPAMO_INIT="${FIPAMO_DIR}/init"
|
|
||||||
FIPAMO_BACKUPS="${FIPAMO_DIR}/backups"
|
|
||||||
# MAIL
|
|
||||||
ADMIN_EMAIL = "you@admin.email"
|
|
11
.gitattributes
vendored
11
.gitattributes
vendored
|
@ -1,11 +0,0 @@
|
||||||
* text=auto eol=lf
|
|
||||||
|
|
||||||
*.blade.php diff=html
|
|
||||||
*.css diff=css
|
|
||||||
*.html diff=html
|
|
||||||
*.md diff=markdown
|
|
||||||
*.php diff=php
|
|
||||||
|
|
||||||
/.github export-ignore
|
|
||||||
CHANGELOG.md export-ignore
|
|
||||||
.styleci.yml export-ignore
|
|
87
.gitignore
vendored
87
.gitignore
vendored
|
@ -1,74 +1,43 @@
|
||||||
/.phpunit.cache
|
node_modules/
|
||||||
/node_modules
|
src/node_modules/
|
||||||
/public/build
|
.parcel-cache/
|
||||||
/public/hot
|
.sass-cache/
|
||||||
/public/storage
|
.cache/
|
||||||
/public/reference
|
.nova/
|
||||||
/storage/*.key
|
|
||||||
/vendor
|
|
||||||
.env
|
|
||||||
.env.backup
|
|
||||||
.env.production
|
|
||||||
.phpunit.result.cache
|
|
||||||
Homestead.json
|
|
||||||
Homestead.yaml
|
|
||||||
auth.json
|
|
||||||
npm-debug.log
|
|
||||||
yarn-error.log
|
|
||||||
/.fleet
|
|
||||||
/.idea
|
|
||||||
/.vscode
|
|
||||||
|
|
||||||
/.parcel-cache
|
|
||||||
|
|
||||||
.env.local
|
|
||||||
/.env.local.php
|
|
||||||
/.env.*.local
|
|
||||||
/.nova
|
|
||||||
/public/bundles/
|
|
||||||
/public/assets/images/examples/
|
|
||||||
/var/
|
|
||||||
|
|
||||||
!public/
|
!public/
|
||||||
public/*
|
public/*
|
||||||
!public/favicon.ico
|
!public/favicon.ico
|
||||||
!public/index.php
|
!public/index.php
|
||||||
!public/assets/
|
!public/assets
|
||||||
public/assets/*
|
public/assets/*
|
||||||
!public/assets/css/
|
!public/assets/css
|
||||||
public/assets/css/*
|
public/assets/css/*
|
||||||
!public/assets/css/dash
|
!public/assets/css/dash
|
||||||
# ignore scripts/theme because contents will
|
!public/assets/scripts
|
||||||
# change based on theme
|
public/assets/scripts/*
|
||||||
!public/assets/scripts/
|
!public/assets/scripts/dash.js
|
||||||
public/assets/scripts/theme/*
|
!public/assets/scripts/dash.js.map
|
||||||
# images
|
!public/assets/images
|
||||||
!public/assets/images/
|
|
||||||
public/assets/images/*
|
public/assets/images/*
|
||||||
!public/assets/images/global/
|
!public/assets/images/global/
|
||||||
public/assets/images/global/*
|
!public/assets/images/global/*
|
||||||
# base assets used by the app
|
|
||||||
!public/assets/images/global/close.svg
|
|
||||||
!public/assets/images/global/default-avi.svg
|
|
||||||
!public/assets/images/global/default-avi-2.svg
|
|
||||||
!public/assets/images/global/default-bg.jpg
|
|
||||||
!public/assets/images/global/fipamo-logo-primary.svg
|
|
||||||
!public/assets/images/global/fipamo-logo-secondary.svg
|
|
||||||
!public/assets/images/global/menu.svg
|
|
||||||
!public/assets/images/global/sprite.svg
|
|
||||||
!public/assets/images/global/upload-audio.png
|
|
||||||
!public/assets/images/global/upload-doc.png
|
|
||||||
!public/assets/images/global/upload-video.png
|
|
||||||
|
|
||||||
|
|
||||||
!content/
|
!content/
|
||||||
content/*
|
content/*
|
||||||
!content/init
|
|
||||||
!content/themes
|
!content/themes
|
||||||
content/themes/*
|
content/themes/*
|
||||||
!content/themes/fipamo-default-v2
|
!content/themes/fipamo-default
|
||||||
!content/themes/fipamo-default-v2/*
|
!content/themes/fipamo-default/*
|
||||||
|
vendor/
|
||||||
|
cache/
|
||||||
|
_temp
|
||||||
|
.ftpconfig
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
config/settings.json
|
||||||
|
config/folks.json
|
||||||
|
config/pages.json
|
||||||
|
config/tags.json
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
*.codekit3
|
config.codekit3
|
||||||
|
/config/backups
|
|
@ -5,11 +5,11 @@
|
||||||
"options": { "parser": "json" }
|
"options": { "parser": "json" }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"files": "*.css",
|
"files": "*.scss",
|
||||||
"options": {
|
"options": {
|
||||||
"tabWidth": 2,
|
"tabWidth": 4,
|
||||||
"semi": false,
|
"semi": false,
|
||||||
"singleQuote": false,
|
"singleQuote": true,
|
||||||
"printWidth": 90
|
"printWidth": 90
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
3
.stylelintrc
Normal file
3
.stylelintrc
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"extends": ["stylelint-config-standard"]
|
||||||
|
}
|
|
@ -1,69 +0,0 @@
|
||||||
# Contribute to Fipamo
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
The Fipamo project is a project of h.i. which has the stated [intention](https://h-i.works/about.html) of creating human-centric, consent-based tools for dynamic communities. While Fipamo is a tech project, the goals it adheres to are not and serve to create a healthy environment that will guide development. Those who want to contribute to the project must adhere to the ideal of fostering an inclusive and safe environment.
|
|
||||||
|
|
||||||
## Code of Conduct
|
|
||||||
The culture of h.i. will guide all development and decision-making for the project. The goal of this idea is to create a dynamic environment where contributors can give their opinions and thoughts will be considered and discussed healthily and productively and features that are added to the project will follow this ethos. The following details will be points of priority that will help to maintain this culture.
|
|
||||||
|
|
||||||
- **Hate-free environment**. Sexism, racism, queerphobia, Islamaphobia, antisemitism, etc will not be tolerated. There will be no warning for contributors who exhibit this behavior and they will be permanently banned from the project.
|
|
||||||
- **All project features will be consent-based**, meaning opt-in by default. A feature that is opt-out by default will not be approved.
|
|
||||||
- **No external tracking**. Fipamo is for managing one's personal information, so tracking information for their content is fine, but this will not include tracking other people's information outside of the project.
|
|
||||||
- **Constructive criticism**. Contributors will not always agree on how to move forward, so disagreements are expected. These conflicts will be resolved with respectful discussion and engagement transparently so the community will be a part of the process.
|
|
||||||
|
|
||||||
## Who can contribute.
|
|
||||||
As Fipamo is a tech project with the stated goal of creating an independent self-hosted content management platform, people with a background in programming are appreciated. However, as the goal is also to create easy-to-use software that is humanistic in its approach, more than technical people will be needed to achieve this goal. Contributors can include:
|
|
||||||
- Community Organizers
|
|
||||||
- Researchers
|
|
||||||
- Differently abled users
|
|
||||||
- Graphic Designers
|
|
||||||
- Testers with little to no technical expertise
|
|
||||||
- Copywriters from multiple languages
|
|
||||||
- Digital Influencers
|
|
||||||
|
|
||||||
Fipamo is meant to be useful to people from a wide range of backgrounds and experiences, so it will require that range of perspectives. If you have an idea, don't be shy. Insight can come from anywhere.
|
|
||||||
|
|
||||||
## How to contribute
|
|
||||||
The first step in being able to contribute to the project is having an account with the h.i. community that houses all project-related discussions. To request an account, sign up at [awosanma.h-i.works](https://awosanma.h-i.works/) and then send a note to either [Are0h](https://h-i.social/@are0h) or the [Fipamo](https://h-i.social/@Fipamo) project account with a brief intro about you and what you'd like to contribute. Once you are approved, you will be added to the appropriate room.
|
|
||||||
|
|
||||||
### Non-technical contributions
|
|
||||||
Contributors who do not want to contribute code to the project can share their insights and questions in the Fipamo community room made for all contributors to the project. If an idea requires a specific focus, additional rooms can be created to accommodate these needs.
|
|
||||||
|
|
||||||
Feature requests, comments on existing features, bugs, etc, will originate in this room. Bugs and new features will be added to the Issues list located at the Fipamo code repository. Non-technical members are welcome to request an account at the repo to file Issues directly themselves.
|
|
||||||
|
|
||||||
### Technical contributions
|
|
||||||
Technical contributors are required to have an account at the Fipamo [repository](https://koodu.h-i.works/projects/fipamo). The repo is invite-only, so to request an account, speak to any moderator in a Fipamo community room.
|
|
||||||
|
|
||||||
#### Dependencies
|
|
||||||
|
|
||||||
Fipamo is a project based on [Laravel](https://laravel.com), so the only dependencies needed for the environment are PHP and Composer to install the necessary libraries.
|
|
||||||
|
|
||||||
[Herd](https://herd.laravel.com) is recommended to make this setup easy, but as long as these two requirements are available on your system, you should be good to go.
|
|
||||||
|
|
||||||
For details on how to set up a Fipamo instance, check the wiki.
|
|
||||||
|
|
||||||
For details on how to make code contributions to the project, read on.
|
|
||||||
|
|
||||||
#### Forking a project
|
|
||||||
The first step to contributing to an h.i. project is making a copy of it by forking it, which will create a new working instance of the current code without affecting the main codebase. This is accomplished by going to the project's main page and hitting the 'fork' button in the upper right corner of the page. Name your fork whatever you like and now you have a copy of the project that you can tinker with. Good job!
|
|
||||||
|
|
||||||
#### Cloning your fork and making a branch for edits
|
|
||||||
Now that your fork is ready, let's grab a copy of it so you can start making some cool changes. Open up your terminal and clone a copy of your fork to your machine. The URL of your fork can be found on your fork page.
|
|
||||||
|
|
||||||
`git clone https://koodu.h-i.works/YOURNAME/YOURFORKNAME.git`.
|
|
||||||
|
|
||||||
Assuming everything went well, you should now have a copy of your fork on your machine. Now you're ready to make changes.
|
|
||||||
|
|
||||||
To avoid conflicts with other people who will be contributing to your project as well, create a specific branch for the changes you want to make. The name of this branch should relate to the nature of the change you are making, for example, if you are updating the README, a good name for that branch could be `tweaking-the-readme`. It doesn't have to be fancy but what is being changed should be apparent at a glance. Once you've decided on the name create the branch and then check it out to work on it.
|
|
||||||
```
|
|
||||||
git branch YOUR-BRANCH-NAME
|
|
||||||
git checkout YOUR-BRANCH-NAME
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Making changes and adding them to the main branch
|
|
||||||
Now that you are in your branch for the changes you want to make, pop open your favorite text editor and hack away. As your changes are in your fork with its branch, you don't have to worry about interfering with another contributor's work.
|
|
||||||
|
|
||||||
Once you've made the changes you want to see, the next step is to have your changes evaluated to see if it is ready to add to the main project. To do this, create a Pull Request to signal you are ready for your changes to be reviewed. This can be accomplished by going to your fork repository page and hitting the 'Pull Request' tab. The main codebase is the `projects: develop` option and it will be pulling from the branch you created for the changes you made.
|
|
||||||
|
|
||||||
If your changes need some work, they will be listed in the pull request and you can make those edits at your convenience. Once the pull request is ready and validated, it will then be merged into the main codebase.
|
|
||||||
|
|
23
README.md
23
README.md
|
@ -1,22 +1,9 @@
|
||||||
# Fipamo
|
# Fipamo means to save
|
||||||
The Fipamo Project was originally a side project of [Ro](https://roiskinda.cool) to help make his development work easier by having a stable base to build from instead of having to build from scratch each time.
|
|
||||||
|
|
||||||
With the rise of independent social media becoming a permanent topic in mainstream tech discourse, the need for easy-to-use tools to create and maintain a personal online experience that the individual can control is a priority.
|
The Fipamo project was born from a need for a simple, easy to use no data blog platform that doesn't require much effort to set up and maintain. Fipamo uses Markdown to handle posts and renders them to flat html so you can serve them from anywhere. No complicated set ups. No long list of dependencies. Just set up and go.
|
||||||
|
|
||||||
To address this need, Fipamo has evolved into a self-hosted no-database content management platform that is accessible, easy to understand, and extendable.
|
Because nobody has time for all that.
|
||||||
|
|
||||||
# Fipamo Goals
|
## Check the (WIP) Docs to get you started. <br>
|
||||||
Fipamo will be a full-featured content management platform that makes it easy for people to create and manage their content and retain full control of their creations, with the ability to share their content with other platforms at their discretion.
|
|
||||||
## Fipamo Planned Features
|
|
||||||
- Blog-style posting with a variety of media types, i.e. text, images, video, sound, etc
|
|
||||||
- Micro-blog capabilities through Activity Pub integration
|
|
||||||
- Sharing content with any platform with any platform with an available API (Instagram, TikTok, WordPress, etc)
|
|
||||||
- Modern accessibility to serve the needs of differently-abled people.
|
|
||||||
- Plug-in system to extend functionality
|
|
||||||
- Easy data portability
|
|
||||||
|
|
||||||
# Contribute to Fipamo
|
|
||||||
Fipamo is a project that wants to foster a healthy community through the values of safety, ease of use, and transparency. The creation of a tool that promotes these attributes cannot be done by one person, so contributors from a variety of backgrounds are welcome to lend their expertise to accomplish this goal.
|
|
||||||
|
|
||||||
For details on how to lend a hand, check the [guide](https://koodu.h-i.works/projects/fipamo/src/branch/develop/CONTRIBUTING.md).
|
|
||||||
|
|
||||||
|
[Getting Started](https://koodu.ubiqueros.com/are0h/Fipamo/wiki/00---Start) <br>
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console;
|
|
||||||
|
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
|
||||||
|
|
||||||
class Kernel extends ConsoleKernel
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Define the application's command schedule.
|
|
||||||
*/
|
|
||||||
protected function schedule(Schedule $schedule): void
|
|
||||||
{
|
|
||||||
// $schedule->command('inspire')->hourly();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the commands for the application.
|
|
||||||
*/
|
|
||||||
protected function commands(): void
|
|
||||||
{
|
|
||||||
$this->load(__DIR__.'/Commands');
|
|
||||||
|
|
||||||
require base_path('routes/console.php');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Exceptions;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
|
||||||
use Throwable;
|
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The list of the inputs that are never flashed to the session on validation exceptions.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $dontFlash = [
|
|
||||||
'current_password',
|
|
||||||
'password',
|
|
||||||
'password_confirmation',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the exception handling callbacks for the application.
|
|
||||||
*/
|
|
||||||
public function register(): void
|
|
||||||
{
|
|
||||||
$this->reportable(function (Throwable $e) {
|
|
||||||
//
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
function delete_directory($dirPath, $catch = true)
|
|
||||||
{
|
|
||||||
if (is_dir($dirPath)) {
|
|
||||||
$objects = new DirectoryIterator($dirPath);
|
|
||||||
foreach ($objects as $object) {
|
|
||||||
if (!$object->isDot()) {
|
|
||||||
if ($object->isDir()) {
|
|
||||||
delete_directory($object->getPathname());
|
|
||||||
} else {
|
|
||||||
unlink($object->getPathname());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rmdir($dirPath);
|
|
||||||
} else {
|
|
||||||
if ($catch) {
|
|
||||||
throw new Exception(__FUNCTION__ . '(dirPath): dirPath is not a directory!');
|
|
||||||
} else {
|
|
||||||
//just keep going
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function copy_directory($src, $dst)
|
|
||||||
{
|
|
||||||
if (file_exists($dst)) {
|
|
||||||
rrmdir($dst);
|
|
||||||
}
|
|
||||||
if (is_dir($src)) {
|
|
||||||
mkdir($dst);
|
|
||||||
$files = scandir($src);
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if ($file != "." && $file != "..") {
|
|
||||||
copy_directory("$src/$file", "$dst/$file");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif (file_exists($src)) {
|
|
||||||
copy($src, $dst);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,80 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Encryption\Encrypter;
|
|
||||||
|
|
||||||
function createUUID()
|
|
||||||
{
|
|
||||||
if (function_exists('com_create_guid') === true) {
|
|
||||||
return trim(com_create_guid(), '{}');
|
|
||||||
}
|
|
||||||
|
|
||||||
return sprintf(
|
|
||||||
'%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
|
|
||||||
mt_rand(0, 65535),
|
|
||||||
mt_rand(0, 65535),
|
|
||||||
mt_rand(0, 65535),
|
|
||||||
mt_rand(16384, 20479),
|
|
||||||
mt_rand(32768, 49151),
|
|
||||||
mt_rand(0, 65535),
|
|
||||||
mt_rand(0, 65535),
|
|
||||||
mt_rand(0, 65535)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function safeString($string)
|
|
||||||
{
|
|
||||||
return strtolower(
|
|
||||||
trim(
|
|
||||||
preg_replace(
|
|
||||||
'~[^0-9a-z]+~i',
|
|
||||||
'_',
|
|
||||||
html_entity_decode(
|
|
||||||
preg_replace(
|
|
||||||
'~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i',
|
|
||||||
'$1',
|
|
||||||
htmlentities($string, ENT_QUOTES, 'UTF-8')
|
|
||||||
),
|
|
||||||
ENT_QUOTES,
|
|
||||||
'UTF-8'
|
|
||||||
)
|
|
||||||
),
|
|
||||||
'-'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function randomString(int $length)
|
|
||||||
{
|
|
||||||
$alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
||||||
$special = '*&!@%^#$';
|
|
||||||
$alphabet = $alphanum . $special;
|
|
||||||
$random = openssl_random_pseudo_bytes($length);
|
|
||||||
$alphabet_length = strlen($alphabet);
|
|
||||||
$string = '';
|
|
||||||
for ($i = 0; $i < $length; ++$i) {
|
|
||||||
$string .= $alphabet[ord($random[$i]) % $alphabet_length];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createAppKey()
|
|
||||||
{
|
|
||||||
return 'base64:' . base64_encode(Encrypter::generateKey(config('app.cipher')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function isHttps()
|
|
||||||
{
|
|
||||||
if (
|
|
||||||
(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) ||
|
|
||||||
(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https') ||
|
|
||||||
(isset($_SERVER['HTTP_X_FORWARDED_SCHEME']) && strtolower($_SERVER['HTTP_X_FORWARDED_SCHEME']) === 'https') ||
|
|
||||||
(isset($_SERVER['HTTP_X_FORWARDED_SSL']) && ($_SERVER['HTTP_X_FORWARDED_SSL'] === 'on' || $_SERVER['HTTP_X_FORWARDED_SSL'] == 1)) ||
|
|
||||||
(isset($_SERVER['REQUEST_SCHEME']) && strtolower($_SERVER['REQUEST_SCHEME']) === 'https') ||
|
|
||||||
(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\API;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class AuthAPIController extends Controller
|
|
||||||
{
|
|
||||||
protected $member;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
MemberRepositoryInterface $memberRepo
|
|
||||||
) {
|
|
||||||
$this->member = $memberRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function status(Request $request)
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
$data = json_decode($request->getContent());
|
|
||||||
if ($this->member::status()) {
|
|
||||||
$result = [
|
|
||||||
'message' => 'Authorized',
|
|
||||||
'type' => 'apiUseAuthorized',
|
|
||||||
'token' => session('token'),
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$result = [
|
|
||||||
'message' => 'Not Authorized',
|
|
||||||
'type' => 'apiUseNotAuthorized',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json($result);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\API;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Services\Assets\FileUploadService;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use App\Services\Data\SettingsService;
|
|
||||||
|
|
||||||
class FileUploadAPIController extends Controller
|
|
||||||
{
|
|
||||||
protected $upload;
|
|
||||||
protected $member;
|
|
||||||
protected $settings;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
FileUploadService $fileUploadService,
|
|
||||||
MemberRepositoryInterface $memberRepo,
|
|
||||||
SettingsService $settingsService
|
|
||||||
) {
|
|
||||||
$this->upload = $fileUploadService;
|
|
||||||
$this->member = $memberRepo;
|
|
||||||
$this->settings = $settingsService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function upload(Request $request)
|
|
||||||
{
|
|
||||||
$result = $this->upload->handleFile($request);
|
|
||||||
//update configs for specfic uploads
|
|
||||||
switch ($request['source']) {
|
|
||||||
case 'avatar-upload':
|
|
||||||
$member = [];
|
|
||||||
$member = session('member');
|
|
||||||
$member['avatar'] = $result['filePath'];
|
|
||||||
$member = (object) $member;
|
|
||||||
$this->member->update($member);
|
|
||||||
break;
|
|
||||||
case 'background-upload':
|
|
||||||
$this->settings->updateGlobalData('background', $result['filePath']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\API;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Services\Upkeep\InitService;
|
|
||||||
use App\Services\Upkeep\ResetService;
|
|
||||||
|
|
||||||
class InitAPIController extends Controller
|
|
||||||
{
|
|
||||||
protected $init;
|
|
||||||
protected $reset;
|
|
||||||
|
|
||||||
public function __construct(InitService $initService, ResetService $resetService)
|
|
||||||
{
|
|
||||||
$this->init = $initService;
|
|
||||||
$this->reset = $resetService;
|
|
||||||
}
|
|
||||||
|
|
||||||
//init stuff
|
|
||||||
public function setupFresh(Request $request)
|
|
||||||
{
|
|
||||||
$result = $this->init->fresh(json_decode($request->getContent()));
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setupRestore(Request $request)
|
|
||||||
{
|
|
||||||
$result = $this->init->restore($request);
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setupReset(Request $request)
|
|
||||||
{
|
|
||||||
$result = $this->reset->site($request);
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\API;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Mail;
|
|
||||||
use App\Mail\SystemEmail;
|
|
||||||
use Symfony\Component\Mailer\Exception\TransportException;
|
|
||||||
|
|
||||||
class MailAPIController extends Controller
|
|
||||||
{
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//init stuff
|
|
||||||
public function sendNotify(Request $request)
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
try {
|
|
||||||
Mail::to(env('ADMIN_EMAIL'))->send(new SystemEmail($request->content));
|
|
||||||
$result = [
|
|
||||||
'type' => 'mail_good',
|
|
||||||
'message' => 'Mail Sent',
|
|
||||||
];
|
|
||||||
} catch (TransportException $e) {
|
|
||||||
$result = [
|
|
||||||
'type' => 'mail_not_good',
|
|
||||||
'message' => 'Mail Not Sent. It\'s cool. Just check mail settings in the .env',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,108 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\API;
|
|
||||||
|
|
||||||
use App\Interfaces\PageRepositoryInterface;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Services\Assets\FileUploadService;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
use function _\find;
|
|
||||||
|
|
||||||
class PageAPIController extends Controller
|
|
||||||
{
|
|
||||||
protected $pages;
|
|
||||||
protected $member;
|
|
||||||
protected $upload;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
PageRepositoryInterface $pageRepository,
|
|
||||||
MemberRepositoryInterface $memberRepo,
|
|
||||||
FileUploadService $fileUploadService,
|
|
||||||
) {
|
|
||||||
$this->pages = $pageRepository;
|
|
||||||
$this->upload = $fileUploadService;
|
|
||||||
$this->member = $memberRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(Request $request)
|
|
||||||
{
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
//check to see if required fields are present
|
|
||||||
if ($body->uuid == '' || $body->uuid == null) {
|
|
||||||
$error = [
|
|
||||||
'message' => "[uuidx ] is a required field",
|
|
||||||
'type' => 'postError',
|
|
||||||
];
|
|
||||||
return response()->json($error)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
$apiKey = $request->header('fipamo-api-key');
|
|
||||||
$body->slug = strtolower(str_replace(' ', '-', $body->title));
|
|
||||||
if (!isset($body->imageList)) {
|
|
||||||
$body->imageList = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($body->fileList)) {
|
|
||||||
$body->fileList = '';
|
|
||||||
}
|
|
||||||
//find member based on key and create a session
|
|
||||||
$folks = $this->member->getAll();
|
|
||||||
$member = find($folks, ['key' => $apiKey]);
|
|
||||||
$request->session()->put('member', $member);
|
|
||||||
$result = $this->pages->update($body);
|
|
||||||
//clear session once page is created
|
|
||||||
session()->flush();
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create(Request $request)
|
|
||||||
{
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
//check to see if required fields are present
|
|
||||||
if ($body->title == '' || $body->title == null) {
|
|
||||||
$error = [
|
|
||||||
'message' => "[title] is a required field",
|
|
||||||
'type' => 'postError',
|
|
||||||
];
|
|
||||||
return response()->json($error)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
$apiKey = $request->header('fipamo-api-key');
|
|
||||||
$folks = $this->member->getAll();
|
|
||||||
$body->slug = strtolower(str_replace(' ', '-', $body->title));
|
|
||||||
if (!isset($body->imageList)) {
|
|
||||||
$body->imageList = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($body->fileList)) {
|
|
||||||
$body->fileList = '';
|
|
||||||
}
|
|
||||||
//find member based on key and create a session
|
|
||||||
$member = find($folks, ['key' => $apiKey]);
|
|
||||||
$request->session()->put('member', $member);
|
|
||||||
$result = $this->pages->create($body);
|
|
||||||
//clear session once page is created
|
|
||||||
session()->flush();
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete(Request $request)
|
|
||||||
{
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
//check to see if required fields are present
|
|
||||||
if ($body->uuid == '' || $body->uuid == null) {
|
|
||||||
$error = [
|
|
||||||
'message' => "[uuidx ] is a required field",
|
|
||||||
'type' => 'postError',
|
|
||||||
];
|
|
||||||
return response()->json($error)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
$apiKey = $request->header('fipamo-api-key');
|
|
||||||
$folks = $this->member->getAll();
|
|
||||||
$member = find($folks, ['key' => $apiKey]);
|
|
||||||
$request->session()->put('member', $member);
|
|
||||||
$result = $this->pages->delete($body);
|
|
||||||
session()->flush();
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,93 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\API;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Services\Data\SettingsService;
|
|
||||||
use App\Services\Assets\RenderService;
|
|
||||||
use App\Services\Upkeep\MaintenanceService;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use App\Services\Assets\AssetService;
|
|
||||||
|
|
||||||
class SettingsAPIController extends Controller
|
|
||||||
{
|
|
||||||
protected $settings;
|
|
||||||
protected $render;
|
|
||||||
protected $mainteance;
|
|
||||||
protected $member;
|
|
||||||
protected $assets;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
SettingsService $settingsService,
|
|
||||||
RenderService $renderService,
|
|
||||||
MaintenanceService $maintenanceService,
|
|
||||||
MemberRepositoryInterface $memberRepo,
|
|
||||||
AssetService $assetService
|
|
||||||
) {
|
|
||||||
$this->settings = $settingsService;
|
|
||||||
$this->render = $renderService;
|
|
||||||
$this->maintenance = $maintenanceService;
|
|
||||||
$this->member = $memberRepo;
|
|
||||||
$this->assets = $assetService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function publish(Request $request)
|
|
||||||
{
|
|
||||||
$this->assets->moveToTheme(true);
|
|
||||||
$result = $this->render->publishAll();
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function sync(Request $request)
|
|
||||||
{
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
//update member if needed
|
|
||||||
$this->member->update($body->member);
|
|
||||||
//sync settings
|
|
||||||
$result = $this->settings->sync($body);
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function navSync(Request $request)
|
|
||||||
{
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
$result = $this->settings->navSync($body);
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createBackup(Request $request)
|
|
||||||
{
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
if ($body->task == 'content_backup') {
|
|
||||||
return response()->json(
|
|
||||||
$this->maintenance->createContentBackUp()
|
|
||||||
)->header('Content-Type', 'application/json');
|
|
||||||
} else {
|
|
||||||
return response()->json(
|
|
||||||
$this->maintenance->createFileBackUp()
|
|
||||||
)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function downloadBackup(Request $request)
|
|
||||||
{
|
|
||||||
if ($this->member::status()) {
|
|
||||||
$latest = '';
|
|
||||||
$file = '';
|
|
||||||
if (explode('/', $request->getRequestUri())[4] == 'content-download') {
|
|
||||||
$latest = $this->settings->getGlobal()['last_content_backup'];
|
|
||||||
$file = 'backup-content-' . $latest . '.zip';
|
|
||||||
} else {
|
|
||||||
$latest = $this->settings->getGlobal()['last_files_backup'];
|
|
||||||
$file = 'backup-files-' . $latest . '.zip';
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->download(
|
|
||||||
'../content/backups/' . $file,
|
|
||||||
$file,
|
|
||||||
['Content-Type: application/zip']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class AuthController extends Controller
|
|
||||||
{
|
|
||||||
protected $member;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
MemberRepositoryInterface $memberRepository
|
|
||||||
) {
|
|
||||||
$this->member = $memberRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function enter(Request $request): Response
|
|
||||||
{
|
|
||||||
$token = csrf_token();
|
|
||||||
|
|
||||||
$credentials = $request->validate([
|
|
||||||
'handle' => ['required'],
|
|
||||||
'password' => ['required'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($credentials) {
|
|
||||||
$result = $this->member->auth($request);
|
|
||||||
if ($result['status']) {
|
|
||||||
//$request->session()->regenerate();
|
|
||||||
return redirect()->intended('dashboard/start');
|
|
||||||
} else {
|
|
||||||
return back()->withErrors([
|
|
||||||
'error' => $result['message'],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return back()->withErrors([
|
|
||||||
'error' => 'Nope. Check your crendtials, champ',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function exit(Request $request): Response
|
|
||||||
{
|
|
||||||
session()->flush();
|
|
||||||
return redirect()->intended('dashboard');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
||||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
||||||
use Illuminate\Routing\Controller as BaseController;
|
|
||||||
|
|
||||||
class Controller extends BaseController
|
|
||||||
{
|
|
||||||
use AuthorizesRequests, ValidatesRequests;
|
|
||||||
}
|
|
|
@ -1,143 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Interfaces\PageRepositoryInterface;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use App\Services\Data\ThemeService;
|
|
||||||
use App\Services\Data\SortingService;
|
|
||||||
|
|
||||||
class DashController extends Controller
|
|
||||||
{
|
|
||||||
protected PageRepositoryInterface $pages;
|
|
||||||
protected MemberRepositoryInterface $member;
|
|
||||||
protected ThemeService $themes;
|
|
||||||
protected SortingService $sort;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
PageRepositoryInterface $pageRepository,
|
|
||||||
MemberRepositoryInterface $memberRepo,
|
|
||||||
ThemeService $themeService,
|
|
||||||
SortingService $sortingService
|
|
||||||
) {
|
|
||||||
$this->pages = $pageRepository;
|
|
||||||
$this->member = $memberRepo;
|
|
||||||
$this->themes = $themeService;
|
|
||||||
$this->sort = $sortingService;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---
|
|
||||||
// GET
|
|
||||||
//---
|
|
||||||
|
|
||||||
public function init($second, $third, $fourth)
|
|
||||||
{
|
|
||||||
switch ($second) {
|
|
||||||
case 'settings':
|
|
||||||
return $this->settings();
|
|
||||||
break;
|
|
||||||
case 'navigation':
|
|
||||||
return $this->navigation();
|
|
||||||
break;
|
|
||||||
case 'pages':
|
|
||||||
($third == null) ? $third = 'all' : $third = $third;
|
|
||||||
($fourth == null) ? $fourth = 1 : $fourth = $fourth;
|
|
||||||
return $this->book($third, $fourth);
|
|
||||||
break;
|
|
||||||
case 'page':
|
|
||||||
return $this->page($third, $fourth);
|
|
||||||
break;
|
|
||||||
case 'logout':
|
|
||||||
return $this->logout();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return $this->start();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function start()
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
if ($this->member::status()) {
|
|
||||||
$result = $this->pages->getGroup(1, 4);
|
|
||||||
}
|
|
||||||
return view('back.start', [
|
|
||||||
"status" => $this->member::status(),
|
|
||||||
"result" => $result,
|
|
||||||
"title" => "Start"
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function book($pageFilter = 'all', $pageNum = 1)
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
if ($this->member::status()) {
|
|
||||||
$result = $this->pages->getGroup($pageNum, 4, $pageFilter);
|
|
||||||
}
|
|
||||||
return view('back.book', [
|
|
||||||
"status" => $this->member::status(),
|
|
||||||
"result" => $result,
|
|
||||||
"currentPage" => $pageNum,
|
|
||||||
"title" => "Pages"
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function page($mode, $uuid)
|
|
||||||
{
|
|
||||||
$title;
|
|
||||||
$page = [];
|
|
||||||
$views = [];
|
|
||||||
$mode == 'edit' ? $page = $this->pages->getByUuid($uuid) : $page = [];
|
|
||||||
$mode == 'edit' ? $title = $page['title'] : $title = 'Add New';
|
|
||||||
$mode == 'edit' ? $views = $this->themes->getCustomViews($page['layout']) : $views[] = 'page';
|
|
||||||
|
|
||||||
return view('back.page', [
|
|
||||||
"status" => $this->member::status(),
|
|
||||||
"mode" => $mode,
|
|
||||||
"page" => $page,
|
|
||||||
"views" => $views,
|
|
||||||
"title" => $title,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function navigation()
|
|
||||||
{
|
|
||||||
return view('back.navigation', $this->sort->navigation());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function settings()
|
|
||||||
{
|
|
||||||
return view('back.settings', $this->sort->settings());
|
|
||||||
}
|
|
||||||
|
|
||||||
//---
|
|
||||||
// POST
|
|
||||||
//---
|
|
||||||
|
|
||||||
//---
|
|
||||||
// PUT
|
|
||||||
//---
|
|
||||||
|
|
||||||
//---
|
|
||||||
// AUTH
|
|
||||||
//---
|
|
||||||
|
|
||||||
public function login()
|
|
||||||
{
|
|
||||||
if ($this->member::status()) {
|
|
||||||
return redirect('dashboard');
|
|
||||||
} else {
|
|
||||||
return view('back.login', [
|
|
||||||
"status" => $this->member::status(),
|
|
||||||
"title" => "Hi!"
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function logout()
|
|
||||||
{
|
|
||||||
session()->flush();
|
|
||||||
return redirect()->intended('dashboard');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,99 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Interfaces\PageRepositoryInterface;
|
|
||||||
use App\Services\Assets\AssetService;
|
|
||||||
use App\Services\Data\SettingsService;
|
|
||||||
use App\Services\Data\SortingService;
|
|
||||||
|
|
||||||
use function _\find;
|
|
||||||
|
|
||||||
class FrontController extends Controller
|
|
||||||
{
|
|
||||||
protected $settings;
|
|
||||||
protected PageRepositoryInterface $pages;
|
|
||||||
protected AssetService $assets;
|
|
||||||
protected SortingService $sort;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
PageRepositoryInterface $pageRepository,
|
|
||||||
SettingsService $settingsService,
|
|
||||||
AssetService $assetService,
|
|
||||||
SortingService $sortService,
|
|
||||||
) {
|
|
||||||
$this->pages = $pageRepository;
|
|
||||||
$this->settings = $settingsService;
|
|
||||||
$this->assets = $assetService;
|
|
||||||
$this->sort = $sortService;
|
|
||||||
}
|
|
||||||
|
|
||||||
//REFACTOR: there is some method overlap between index and pages, so that needs to be addressed
|
|
||||||
public function index($first = 00, $second = 00, $third = 00)
|
|
||||||
{
|
|
||||||
$global = $this->settings->getGlobal();
|
|
||||||
$currentTheme = $this->assets->getCurrentTheme();
|
|
||||||
$template;
|
|
||||||
$pageData = [];
|
|
||||||
$pages = $this->pages->getAll();
|
|
||||||
//check if configs are present
|
|
||||||
if (file_exists(env('FOLKS_PATH')) && file_exists(env('SETTINGS_PATH'))) {
|
|
||||||
if ($global['dynamicRender'] == 'true') {
|
|
||||||
if (is_numeric($first)) {
|
|
||||||
if ($first == 00 || !isset($first)) {
|
|
||||||
$page = $pages->where('id', 1)->first();
|
|
||||||
$pageData = $this->sort->page($page);
|
|
||||||
$template = $currentTheme . '.index';
|
|
||||||
} else {
|
|
||||||
$page = $this->pages->getBySlug($third);
|
|
||||||
$pageData = $this->sort->page($page);
|
|
||||||
$template = $currentTheme . '.' . $page['layout'];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($first == null || $first == '') {
|
|
||||||
$page = $pages->where('id', 1)->first();
|
|
||||||
$pageData = $this->sort->page($page);
|
|
||||||
$template = $currentTheme . '.index';
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return view($template, $pageData);
|
|
||||||
} else {
|
|
||||||
if (is_file('../public/index.html')) {
|
|
||||||
return response()->file('../public/index.html');
|
|
||||||
} else {
|
|
||||||
return redirect()->intended('dashboard/start');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return view('back.init', ["status" => false, "title" => "Set Up"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function page($first = 00, $second = 00, $third = 00)
|
|
||||||
{
|
|
||||||
$currentTheme = $this->assets->getCurrentTheme();
|
|
||||||
switch ($first) {
|
|
||||||
case 'archive':
|
|
||||||
case 'archives':
|
|
||||||
$template = $currentTheme . '.archive';
|
|
||||||
$pageData = $this->sort->archive();
|
|
||||||
break;
|
|
||||||
case 'tags':
|
|
||||||
$template = $currentTheme . '.tags';
|
|
||||||
$tags = $this->sort->tags(false);
|
|
||||||
$tagData = find($tags['tags'], ['tag_name' => $second]);
|
|
||||||
$pageData = [
|
|
||||||
'theme' => $currentTheme, // for theme kit
|
|
||||||
'title' => 'Pages Tagged as ' . $second,
|
|
||||||
'dynamicRender' => $tags['dynamicRender'],
|
|
||||||
'info' => $tags['info'],
|
|
||||||
'menu' => $tags['menu'],
|
|
||||||
'pages' => $tagData['pages'],
|
|
||||||
'media' => $tags['media'],
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return view($template, $pageData);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Interfaces\PageRepositoryInterface;
|
|
||||||
|
|
||||||
class RouteDeleteController extends Controller
|
|
||||||
{
|
|
||||||
protected $page;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
PageRepositoryInterface $pageRepo
|
|
||||||
) {
|
|
||||||
$this->page = $pageRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleRequest(Request $request)
|
|
||||||
{
|
|
||||||
$path = explode('/', $request->path());
|
|
||||||
switch ($path[0]) {
|
|
||||||
case 'page':
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
$result = $this->page->delete($body);
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,88 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use App\Services\Data\SettingsService;
|
|
||||||
|
|
||||||
class RouteGetController extends Controller
|
|
||||||
{
|
|
||||||
protected $dash;
|
|
||||||
protected $gate;
|
|
||||||
protected $theme;
|
|
||||||
protected $front;
|
|
||||||
protected $member;
|
|
||||||
protected $settings;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
DashController $dashController,
|
|
||||||
AuthController $authController,
|
|
||||||
ThemeController $themeController,
|
|
||||||
FrontController $frontController,
|
|
||||||
MemberRepositoryInterface $memberRepo,
|
|
||||||
SettingsService $settingsService,
|
|
||||||
) {
|
|
||||||
$this->dash = $dashController;
|
|
||||||
$this->gate = $authController;
|
|
||||||
$this->theme = $themeController;
|
|
||||||
$this->front = $frontController;
|
|
||||||
$this->member = $memberRepo;
|
|
||||||
$this->settings = $settingsService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleRequest($first = null, $second = null, $third = null, $fourth = null)
|
|
||||||
{
|
|
||||||
if (isset($first) && !is_numeric($first)) {
|
|
||||||
switch ($first) {
|
|
||||||
case 'dashboard':
|
|
||||||
if ($this->member::status()) {
|
|
||||||
return $this->dash->init($second, $third, $fourth);
|
|
||||||
} else {
|
|
||||||
return $this->dash->login();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'theme':
|
|
||||||
if ($this->member::status()) {
|
|
||||||
if (isset($second)) {
|
|
||||||
return $this->theme->getView($third, $fourth);
|
|
||||||
} else {
|
|
||||||
return $this->theme->start();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return $this->dash->login();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'tags':
|
|
||||||
case 'archives':
|
|
||||||
return $this->front->page($first, $second, $third);
|
|
||||||
break;
|
|
||||||
case 'backup':
|
|
||||||
return $this->downloadBackup($second);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return $this->front->index($first, $second, $third);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function downloadBackup($type)
|
|
||||||
{
|
|
||||||
if ($this->member::status()) {
|
|
||||||
$latest = '';
|
|
||||||
$file = '';
|
|
||||||
if ($type == 'content-download') {
|
|
||||||
$latest = $this->settings->getGlobal()['last_content_backup'];
|
|
||||||
$file = 'backup-content-' . $latest . '.zip';
|
|
||||||
} else {
|
|
||||||
$latest = $this->settings->getGlobal()['last_files_backup'];
|
|
||||||
$file = 'backup-files-' . $latest . '.zip';
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->download(
|
|
||||||
'../content/backups/' . $file,
|
|
||||||
$file,
|
|
||||||
['Content-Type: application/zip']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,122 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Mail;
|
|
||||||
use App\Mail\SystemEmail;
|
|
||||||
use App\Interfaces\PageRepositoryInterface;
|
|
||||||
use App\Services\Upkeep\MaintenanceService;
|
|
||||||
use App\Services\Assets\FileUploadService;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use App\Services\Data\SettingsService;
|
|
||||||
use App\Services\Upkeep\InitService;
|
|
||||||
use App\Services\Upkeep\ResetService;
|
|
||||||
|
|
||||||
class RoutePostController extends Controller
|
|
||||||
{
|
|
||||||
protected $page;
|
|
||||||
protected $gate;
|
|
||||||
protected $maintenance;
|
|
||||||
protected $upload;
|
|
||||||
protected $settings;
|
|
||||||
protected $member;
|
|
||||||
protected $init;
|
|
||||||
protected $reset;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
PageRepositoryInterface $pageRepo,
|
|
||||||
AuthController $authController,
|
|
||||||
MaintenanceService $maintenanceService,
|
|
||||||
FileUploadService $fileUploadService,
|
|
||||||
SettingsService $settingsService,
|
|
||||||
MemberRepositoryInterface $memberRepo,
|
|
||||||
InitService $initService,
|
|
||||||
ResetService $resetService,
|
|
||||||
) {
|
|
||||||
$this->page = $pageRepo;
|
|
||||||
$this->gate = $authController;
|
|
||||||
$this->maintenance = $maintenanceService;
|
|
||||||
$this->upload = $fileUploadService;
|
|
||||||
$this->settings = $settingsService;
|
|
||||||
$this->member = $memberRepo;
|
|
||||||
$this->init = $initService;
|
|
||||||
$this->reset = $resetService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleRequest(Request $request)
|
|
||||||
{
|
|
||||||
$path = explode('/', $request->path());
|
|
||||||
switch ($path[0]) {
|
|
||||||
case 'init':
|
|
||||||
return $this->initTask($path[1], $request);
|
|
||||||
break;
|
|
||||||
case 'login':
|
|
||||||
return $this->gate->enter($request);
|
|
||||||
break;
|
|
||||||
case 'page':
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
$result = $this->page->create($body);
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
break;
|
|
||||||
case 'settings':
|
|
||||||
if ($path[1] == 'mailer') {
|
|
||||||
return $this->sendNotify($request);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'upload':
|
|
||||||
$result = $result = $this->upload->handleFile($request);
|
|
||||||
//update configs for specfic uploads
|
|
||||||
switch ($request['source']) {
|
|
||||||
case 'avatar-upload':
|
|
||||||
$member = [];
|
|
||||||
$member = session('member');
|
|
||||||
$member['avatar'] = $result['filePath'];
|
|
||||||
$member = (object) $member;
|
|
||||||
$this->member->update($member);
|
|
||||||
break;
|
|
||||||
case 'background-upload':
|
|
||||||
$this->settings->updateGlobalData('background', $result['filePath']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function initTask($task, $request)
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
switch ($task) {
|
|
||||||
case 'fresh':
|
|
||||||
$result = $this->init->fresh(json_decode($request->getContent()));
|
|
||||||
break;
|
|
||||||
case 'restore':
|
|
||||||
$result = $this->init->restore($request);
|
|
||||||
break;
|
|
||||||
case 'reset':
|
|
||||||
$result = $this->reset->site($request);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function sendNotify($request)
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
try {
|
|
||||||
Mail::to(env('ADMIN_EMAIL'))->send(new SystemEmail($request->content));
|
|
||||||
$result = [
|
|
||||||
'type' => 'mail_good',
|
|
||||||
'message' => 'Mail Sent',
|
|
||||||
];
|
|
||||||
} catch (TransportException $e) {
|
|
||||||
$result = [
|
|
||||||
'type' => 'mail_not_good',
|
|
||||||
'message' => 'Mail Not Sent. It\'s cool. Just check mail settings in the .env',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,92 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Interfaces\PageRepositoryInterface;
|
|
||||||
use App\Services\Assets\AssetService;
|
|
||||||
use App\Services\Assets\RenderService;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use App\Services\Data\SettingsService;
|
|
||||||
use App\Services\Upkeep\MaintenanceService;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class RoutePutController extends Controller
|
|
||||||
{
|
|
||||||
protected $page;
|
|
||||||
protected $assets;
|
|
||||||
protected $render;
|
|
||||||
protected $settings;
|
|
||||||
protected $member;
|
|
||||||
protected $maintenance;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
PageRepositoryInterface $pageRepo,
|
|
||||||
AssetService $assetService,
|
|
||||||
RenderService $renderService,
|
|
||||||
SettingsService $settingsService,
|
|
||||||
MemberRepositoryInterface $memberRepo,
|
|
||||||
MaintenanceService $maintenanceService,
|
|
||||||
) {
|
|
||||||
$this->page = $pageRepo;
|
|
||||||
$this->assets = $assetService;
|
|
||||||
$this->render = $renderService;
|
|
||||||
$this->settings = $settingsService;
|
|
||||||
$this->member = $memberRepo;
|
|
||||||
$this->maintenance = $maintenanceService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleRequest(Request $request)
|
|
||||||
{
|
|
||||||
$path = explode('/', $request->path());
|
|
||||||
switch ($path[0]) {
|
|
||||||
case 'page':
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
$result = $this->page->update($body);
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
break;
|
|
||||||
case 'settings':
|
|
||||||
return $this->settingsTasks($request, $path[1]);
|
|
||||||
break;
|
|
||||||
case 'backup':
|
|
||||||
return $this->createBackup($request);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createBackup($request)
|
|
||||||
{
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
if ($body->task == 'content_backup') {
|
|
||||||
return response()->json(
|
|
||||||
$this->maintenance->createContentBackUp()
|
|
||||||
)->header('Content-Type', 'application/json');
|
|
||||||
} else {
|
|
||||||
return response()->json(
|
|
||||||
$this->maintenance->createFileBackUp()
|
|
||||||
)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function settingsTasks($request, $task)
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
switch ($task) {
|
|
||||||
case 'publish':
|
|
||||||
$this->assets->moveToTheme(true);
|
|
||||||
$result = $this->render->publishAll();
|
|
||||||
break;
|
|
||||||
case 'sync':
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
//update member if needed
|
|
||||||
$this->member->update($body->member);
|
|
||||||
//sync settings
|
|
||||||
$result = $this->settings->sync($body);
|
|
||||||
break;
|
|
||||||
case 'nav-sync':
|
|
||||||
$body = json_decode($request->getContent());
|
|
||||||
$result = $this->settings->navSync($body);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return response()->json($result)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Mail;
|
|
||||||
|
|
||||||
class SystemMailController extends Controller
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Send notification
|
|
||||||
*/
|
|
||||||
public function sendNotification()
|
|
||||||
{
|
|
||||||
$message = "This is something important. Probably";
|
|
||||||
Mail::to(env('ADMIN_EMAIL'))->send(new SystemEmail($message));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,99 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Interfaces\PageRepositoryInterface;
|
|
||||||
use App\Services\Assets\AssetService;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use App\Services\Data\SortingService;
|
|
||||||
use App\Services\Data\ThemeService;
|
|
||||||
|
|
||||||
class ThemeController extends Controller
|
|
||||||
{
|
|
||||||
protected PageRepositoryInterface $pages;
|
|
||||||
protected MemberRepositoryInterface $member;
|
|
||||||
protected AssetService $assets;
|
|
||||||
protected SortingService $sort;
|
|
||||||
protected ThemeService $themes;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
PageRepositoryInterface $pageRepository,
|
|
||||||
MemberRepositoryInterface $memberRepo,
|
|
||||||
AssetService $assetService,
|
|
||||||
SortingService $sortService,
|
|
||||||
ThemeService $themeService,
|
|
||||||
) {
|
|
||||||
$this->pages = $pageRepository;
|
|
||||||
$this->member = $memberRepo;
|
|
||||||
$this->assets = $assetService;
|
|
||||||
$this->sort = $sortService;
|
|
||||||
$this->themes = $themeService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function start()
|
|
||||||
{
|
|
||||||
if ($this->member::status()) {
|
|
||||||
return view('theme.start', [
|
|
||||||
"status" => $this->member::status(),
|
|
||||||
"title" => "Fipamo Theme Kit",
|
|
||||||
"pages" => $this->themes->getCustomViews('page')
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
return redirect('dashboard');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getView($view = 'index', $id = null)
|
|
||||||
{
|
|
||||||
//move assets to theme testing dir
|
|
||||||
$this->assets->moveToTheme();
|
|
||||||
$currentTheme = $this->assets->getCurrentTheme();
|
|
||||||
$template;
|
|
||||||
$pageData = [];
|
|
||||||
switch ($view) {
|
|
||||||
case "index":
|
|
||||||
case "page":
|
|
||||||
$page;
|
|
||||||
if ($view == 'index') {
|
|
||||||
$template = $currentTheme . '.index';
|
|
||||||
$page = $this->pages->getById(0);
|
|
||||||
} else {
|
|
||||||
$template = $currentTheme . '.page';
|
|
||||||
//if coming from theme page, grabs id of latest page
|
|
||||||
if ($id == null) {
|
|
||||||
$uuid = $this->getPageUUID();
|
|
||||||
} else {
|
|
||||||
//get page by uuid
|
|
||||||
$page = $this->pages->getByUuid($id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$pageData = $this->sort->page($page);
|
|
||||||
break;
|
|
||||||
case "tags":
|
|
||||||
$template = $currentTheme . '.tags';
|
|
||||||
$pageData = $this->sort->tags();
|
|
||||||
break;
|
|
||||||
case "archives":
|
|
||||||
case "archive":
|
|
||||||
$template = $currentTheme . '.archive';
|
|
||||||
$pageData = $this->sort->archive();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$template = $currentTheme . '.index';
|
|
||||||
$page = $this->pages->getBySlug('first');
|
|
||||||
$pageData = $this->sort->page($page);
|
|
||||||
}
|
|
||||||
if ($this->member::status()) {
|
|
||||||
return view($template, $pageData);
|
|
||||||
} else {
|
|
||||||
return redirect('dashboard/start');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getPageUUID()
|
|
||||||
{
|
|
||||||
$book = $this->pages->getAll();
|
|
||||||
$page = $book->where('layout', 'page')->first();
|
|
||||||
return $page['uuid'];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
|
||||||
|
|
||||||
class Kernel extends HttpKernel
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The application's global HTTP middleware stack.
|
|
||||||
*
|
|
||||||
* These middleware are run during every request to your application.
|
|
||||||
*
|
|
||||||
* @var array<int, class-string|string>
|
|
||||||
*/
|
|
||||||
protected $middleware = [
|
|
||||||
// \App\Http\Middleware\TrustHosts::class,
|
|
||||||
\App\Http\Middleware\TrustProxies::class,
|
|
||||||
\Illuminate\Http\Middleware\HandleCors::class,
|
|
||||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
|
||||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
|
||||||
\App\Http\Middleware\TrimStrings::class,
|
|
||||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The application's route middleware groups.
|
|
||||||
*
|
|
||||||
* @var array<string, array<int, class-string|string>>
|
|
||||||
*/
|
|
||||||
protected $middlewareGroups = [
|
|
||||||
'web' => [
|
|
||||||
\App\Http\Middleware\EncryptCookies::class,
|
|
||||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
|
||||||
\Illuminate\Session\Middleware\StartSession::class,
|
|
||||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
|
||||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
|
||||||
],
|
|
||||||
|
|
||||||
'api' => [
|
|
||||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
|
||||||
\Illuminate\Routing\Middleware\ThrottleRequests::class . ':api',
|
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
|
||||||
//added middleware so api has access to session data
|
|
||||||
\App\Http\Middleware\EncryptCookies::class,
|
|
||||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
|
||||||
\Illuminate\Session\Middleware\StartSession::class,
|
|
||||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The application's middleware aliases.
|
|
||||||
*
|
|
||||||
* Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
|
|
||||||
*
|
|
||||||
* @var array<string, class-string|string>
|
|
||||||
*/
|
|
||||||
protected $middlewareAliases = [
|
|
||||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
|
||||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
|
||||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
|
||||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
|
||||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
|
||||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
|
||||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
|
||||||
'precognitive' => \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
|
|
||||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
|
||||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
|
||||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
|
||||||
'member.check' => \App\Http\Middleware\MemberCheck::class,
|
|
||||||
'validate.key' => \App\Http\Middleware\ValidateAPIKey::class,
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class Authenticate extends Middleware
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the path the user should be redirected to when they are not authenticated.
|
|
||||||
*/
|
|
||||||
protected function redirectTo(Request $request): ?string
|
|
||||||
{
|
|
||||||
return $request->expectsJson() ? null : route('login');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
|
||||||
|
|
||||||
class EncryptCookies extends Middleware
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The names of the cookies that should not be encrypted.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $except = [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Services\AuthService;
|
|
||||||
|
|
||||||
class MemberCheck
|
|
||||||
{
|
|
||||||
protected $auth;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
AuthService $authService,
|
|
||||||
) {
|
|
||||||
$this->auth = $authService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle an incoming request.
|
|
||||||
*
|
|
||||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
|
||||||
*/
|
|
||||||
public function handle(Request $request, Closure $next)
|
|
||||||
{
|
|
||||||
if ($this->auth::status()) {
|
|
||||||
return $next($request);
|
|
||||||
} else {
|
|
||||||
return redirect('dashboard');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
|
||||||
|
|
||||||
class PreventRequestsDuringMaintenance extends Middleware
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The URIs that should be reachable while maintenance mode is enabled.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $except = [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use App\Providers\RouteServiceProvider;
|
|
||||||
use Closure;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
|
|
||||||
class RedirectIfAuthenticated
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle an incoming request.
|
|
||||||
*
|
|
||||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
|
||||||
*/
|
|
||||||
public function handle(Request $request, Closure $next, string ...$guards): Response
|
|
||||||
{
|
|
||||||
$guards = empty($guards) ? [null] : $guards;
|
|
||||||
|
|
||||||
foreach ($guards as $guard) {
|
|
||||||
if (Auth::guard($guard)->check()) {
|
|
||||||
return redirect(RouteServiceProvider::HOME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
|
||||||
|
|
||||||
class TrimStrings extends Middleware
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The names of the attributes that should not be trimmed.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $except = [
|
|
||||||
'current_password',
|
|
||||||
'password',
|
|
||||||
'password_confirmation',
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
|
||||||
|
|
||||||
class TrustHosts extends Middleware
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the host patterns that should be trusted.
|
|
||||||
*
|
|
||||||
* @return array<int, string|null>
|
|
||||||
*/
|
|
||||||
public function hosts(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
$this->allSubdomainsOfApplicationUrl(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class TrustProxies extends Middleware
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The trusted proxies for this application.
|
|
||||||
*
|
|
||||||
* @var array<int, string>|string|null
|
|
||||||
*/
|
|
||||||
protected $proxies;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The headers that should be used to detect proxies.
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $headers =
|
|
||||||
Request::HEADER_X_FORWARDED_FOR |
|
|
||||||
Request::HEADER_X_FORWARDED_HOST |
|
|
||||||
Request::HEADER_X_FORWARDED_PORT |
|
|
||||||
Request::HEADER_X_FORWARDED_PROTO |
|
|
||||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use App\Services\Data\SettingsService;
|
|
||||||
|
|
||||||
use function _\find;
|
|
||||||
|
|
||||||
class ValidateAPIKey
|
|
||||||
{
|
|
||||||
protected $member;
|
|
||||||
protected $settings;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
MemberRepositoryInterface $memberRepo,
|
|
||||||
SettingsService $settingsService,
|
|
||||||
) {
|
|
||||||
$this->member = $memberRepo;
|
|
||||||
$this->settings = $settingsService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle an incoming request.
|
|
||||||
*
|
|
||||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
|
||||||
*/
|
|
||||||
public function handle(Request $request, Closure $next): Response
|
|
||||||
{
|
|
||||||
$response = [];
|
|
||||||
//checks to see if request is secure
|
|
||||||
if (isHttps()) {
|
|
||||||
$key = $request->header('fipamo-api-key');
|
|
||||||
$folks = $this->member->getAll();
|
|
||||||
//looks to see if API key exists
|
|
||||||
if (find($folks, ['key' => $key])) {
|
|
||||||
//final check to see if API requests are being accepted
|
|
||||||
$global = $this->settings->getGlobal();
|
|
||||||
if (isset($global['externalAPI']) && $global['externalAPI'] == "true") {
|
|
||||||
return $next($request);
|
|
||||||
} else {
|
|
||||||
$response = [
|
|
||||||
'message' => "API Auth Fail: Not Accepting Requests",
|
|
||||||
'type' => 'postError',
|
|
||||||
];
|
|
||||||
return response()->json($response)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$response = [
|
|
||||||
'message' => "API Auth Fail: API Key Invalid",
|
|
||||||
'type' => 'postError',
|
|
||||||
];
|
|
||||||
return response()->json($response)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$response = [
|
|
||||||
'message' => "API Auth Fail: Request must be secure (HTTPS)",
|
|
||||||
'type' => 'postError',
|
|
||||||
];
|
|
||||||
return response()->json($response)->header('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
|
|
||||||
|
|
||||||
class ValidateSignature extends Middleware
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The names of the query string parameters that should be ignored.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $except = [
|
|
||||||
// 'fbclid',
|
|
||||||
// 'utm_campaign',
|
|
||||||
// 'utm_content',
|
|
||||||
// 'utm_medium',
|
|
||||||
// 'utm_source',
|
|
||||||
// 'utm_term',
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
|
||||||
|
|
||||||
class VerifyCsrfToken extends Middleware
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The URIs that should be excluded from CSRF verification.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $except = [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Interfaces;
|
|
||||||
|
|
||||||
interface MemberRepositoryInterface
|
|
||||||
{
|
|
||||||
public function getAll();
|
|
||||||
|
|
||||||
public function getByID($id);
|
|
||||||
|
|
||||||
public function getByHandle($handle);
|
|
||||||
|
|
||||||
public function delete($id);
|
|
||||||
|
|
||||||
public function create($member);
|
|
||||||
|
|
||||||
public function update($member);
|
|
||||||
|
|
||||||
public function auth($request);
|
|
||||||
|
|
||||||
public static function status();
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Interfaces;
|
|
||||||
|
|
||||||
interface PageRepositoryInterface
|
|
||||||
{
|
|
||||||
public function getAll();
|
|
||||||
|
|
||||||
public function getById($id);
|
|
||||||
|
|
||||||
public function getByUuid($uuid);
|
|
||||||
|
|
||||||
public function getBySlug($slug);
|
|
||||||
|
|
||||||
public function delete($uuid);
|
|
||||||
|
|
||||||
public function create($page);
|
|
||||||
|
|
||||||
public function update($page);
|
|
||||||
|
|
||||||
public function getGroup($num, $limit, $filter);
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Mail;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Mail\Mailable;
|
|
||||||
use Illuminate\Mail\Mailables\Content;
|
|
||||||
use Illuminate\Mail\Mailables\Envelope;
|
|
||||||
use Illuminate\Mail\Mailables\Address;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class SystemEmail extends Mailable
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new message instance.
|
|
||||||
*/
|
|
||||||
public function __construct(public $notifyText)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message envelope.
|
|
||||||
*/
|
|
||||||
public function envelope(): Envelope
|
|
||||||
{
|
|
||||||
return new Envelope(
|
|
||||||
from: new Address(env('MAIL_USERNAME'), 'System Notification'),
|
|
||||||
subject: 'Notification',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message content definition.
|
|
||||||
*/
|
|
||||||
public function content(): Content
|
|
||||||
{
|
|
||||||
return new Content(
|
|
||||||
view: 'mail.notify',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the attachments for the message.
|
|
||||||
*
|
|
||||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
|
||||||
*/
|
|
||||||
public function attachments(): array
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
||||||
use Illuminate\Notifications\Notifiable;
|
|
||||||
use Laravel\Sanctum\HasApiTokens;
|
|
||||||
|
|
||||||
class User extends Authenticatable
|
|
||||||
{
|
|
||||||
use HasApiTokens, HasFactory, Notifiable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'name',
|
|
||||||
'email',
|
|
||||||
'password',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that should be hidden for serialization.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $hidden = [
|
|
||||||
'password',
|
|
||||||
'remember_token',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that should be cast.
|
|
||||||
*
|
|
||||||
* @var array<string, string>
|
|
||||||
*/
|
|
||||||
protected $casts = [
|
|
||||||
'email_verified_at' => 'datetime',
|
|
||||||
'password' => 'hashed',
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Register any application services.
|
|
||||||
*/
|
|
||||||
public function register(): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bootstrap any application services.
|
|
||||||
*/
|
|
||||||
public function boot(): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Providers;
|
|
||||||
|
|
||||||
// use Illuminate\Support\Facades\Gate;
|
|
||||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
|
||||||
|
|
||||||
class AuthServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The model to policy mappings for the application.
|
|
||||||
*
|
|
||||||
* @var array<class-string, class-string>
|
|
||||||
*/
|
|
||||||
protected $policies = [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register any authentication / authorization services.
|
|
||||||
*/
|
|
||||||
public function boot(): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Broadcast;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
|
|
||||||
class BroadcastServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Bootstrap any application services.
|
|
||||||
*/
|
|
||||||
public function boot(): void
|
|
||||||
{
|
|
||||||
Broadcast::routes();
|
|
||||||
|
|
||||||
require base_path('routes/channels.php');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Auth\Events\Registered;
|
|
||||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
|
||||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
|
||||||
use Illuminate\Support\Facades\Event;
|
|
||||||
|
|
||||||
class EventServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The event to listener mappings for the application.
|
|
||||||
*
|
|
||||||
* @var array<class-string, array<int, class-string>>
|
|
||||||
*/
|
|
||||||
protected $listen = [
|
|
||||||
Registered::class => [
|
|
||||||
SendEmailVerificationNotification::class,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register any events for your application.
|
|
||||||
*/
|
|
||||||
public function boot(): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if events and listeners should be automatically discovered.
|
|
||||||
*/
|
|
||||||
public function shouldDiscoverEvents(): bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
|
|
||||||
class FipamoHelperProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Register services.
|
|
||||||
*/
|
|
||||||
public function register(): void
|
|
||||||
{
|
|
||||||
foreach (glob(app_path() . '/Helpers/*.php') as $filename) {
|
|
||||||
require_once $filename;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bootstrap services.
|
|
||||||
*/
|
|
||||||
public function boot(): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,110 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
//Repos
|
|
||||||
use App\Repositories\PageRepository;
|
|
||||||
use App\Interfaces\PageRepositoryInterface;
|
|
||||||
use App\Repositories\MemberRepository;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
//Asset Services
|
|
||||||
use App\Services\Assets\AssetService;
|
|
||||||
use App\Services\Assets\DocService;
|
|
||||||
use App\Services\Assets\FileUploadService;
|
|
||||||
use App\Services\Assets\RenderService;
|
|
||||||
//Data Services
|
|
||||||
use App\Services\Data\SettingsService;
|
|
||||||
use App\Services\Data\ContentService;
|
|
||||||
use App\Services\Data\PaginateService;
|
|
||||||
use App\Services\Data\ThemeService;
|
|
||||||
use App\Services\Data\SortingService;
|
|
||||||
//Upkeep Services
|
|
||||||
use App\Services\Upkeep\MaintenanceService;
|
|
||||||
use App\Services\Upkeep\InitService;
|
|
||||||
use App\Services\Upkeep\ResetService;
|
|
||||||
|
|
||||||
class FipamoServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Register services.
|
|
||||||
*/
|
|
||||||
public function register(): void
|
|
||||||
{
|
|
||||||
//services
|
|
||||||
$this->app->bind(SettingsService::class, function ($app) {
|
|
||||||
return new SettingsService(new DocService(), new ContentService());
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(ContentService::class, function ($app) {
|
|
||||||
return new ContentService();
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(ThemeService::class, function ($app) {
|
|
||||||
return new ThemeService(new SettingsService(new DocService(), new ContentService()));
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(PaginateService::class, function ($app) {
|
|
||||||
return new PaginateService(new ContentService());
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(DocService::class, function ($app) {
|
|
||||||
return new DocService();
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(FileUploadService::class, function ($app) {
|
|
||||||
return new FileUploadService();
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(RenderService::class, function ($app) {
|
|
||||||
return new RenderService(
|
|
||||||
new SortingService(
|
|
||||||
new SettingsService(new DocService(), new ContentService()),
|
|
||||||
new ContentService(),
|
|
||||||
new ThemeService(new SettingsService(new DocService(), new ContentService()))
|
|
||||||
),
|
|
||||||
new SettingsService(new DocService(), new ContentService()),
|
|
||||||
new ContentService(),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(SortingService::class, function ($app) {
|
|
||||||
return new SortingService(
|
|
||||||
new SettingsService(new DocService(), new ContentService()),
|
|
||||||
new ContentService(),
|
|
||||||
new ThemeService(new SettingsService(new DocService(), new ContentService()))
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(AssetService::class, function ($app) {
|
|
||||||
return new AssetService(
|
|
||||||
new ThemeService(
|
|
||||||
new SettingsService(new DocService(), new ContentService())
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(MaintenanceService::class, function ($app) {
|
|
||||||
return new MaintenanceService(
|
|
||||||
new SettingsService(new DocService(), new ContentService())
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(InitService::class, function ($app) {
|
|
||||||
return new InitService(new DocService());
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(ResetService::class, function ($app) {
|
|
||||||
return new ResetService();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bootstrap services.
|
|
||||||
*/
|
|
||||||
public function boot(): void
|
|
||||||
{
|
|
||||||
$this->app->bind(PageRepositoryInterface::class, PageRepository::class);
|
|
||||||
$this->app->bind(MemberRepositoryInterface::class, MemberRepository::class);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Cache\RateLimiting\Limit;
|
|
||||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\RateLimiter;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
|
||||||
|
|
||||||
class RouteServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The path to your application's "home" route.
|
|
||||||
*
|
|
||||||
* Typically, users are redirected here after authentication.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public const HOME = '/home';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define your route model bindings, pattern filters, and other route configuration.
|
|
||||||
*/
|
|
||||||
public function boot(): void
|
|
||||||
{
|
|
||||||
RateLimiter::for('api', function (Request $request) {
|
|
||||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->routes(function () {
|
|
||||||
Route::middleware('api')
|
|
||||||
->prefix('api')
|
|
||||||
->group(base_path('routes/api.php'));
|
|
||||||
|
|
||||||
Route::middleware('web')
|
|
||||||
->group(base_path('routes/web.php'));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,123 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Repositories;
|
|
||||||
|
|
||||||
use App\Services\Assets\DocService;
|
|
||||||
use App\Interfaces\MemberRepositoryInterface;
|
|
||||||
use ReallySimpleJWT\Token;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
use function _\find;
|
|
||||||
use function _\findIndex;
|
|
||||||
|
|
||||||
class MemberRepository implements MemberRepositoryInterface
|
|
||||||
{
|
|
||||||
protected $folks;
|
|
||||||
protected $docs;
|
|
||||||
|
|
||||||
public function __construct(DocService $docService)
|
|
||||||
{
|
|
||||||
$this->docs = $docService;
|
|
||||||
if (file_exists(env('FOLKS_PATH'))) {
|
|
||||||
$this->folks = json_decode(file_get_contents(env('FOLKS_PATH')), true);
|
|
||||||
} else {
|
|
||||||
$this->folks = json_decode(file_get_contents(env('FIPAMO_INIT') . '/folks-template.json'), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAll()
|
|
||||||
{
|
|
||||||
return $this->folks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getById($id)
|
|
||||||
{
|
|
||||||
$member = find($this->folks, ['id' => $id]);
|
|
||||||
return $member;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getByHandle($handle)
|
|
||||||
{
|
|
||||||
$member = find($this->folks, ['handle' => $handle]);
|
|
||||||
return $member;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete($id)
|
|
||||||
{
|
|
||||||
//delete member stuff
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create($member)
|
|
||||||
{
|
|
||||||
//make new member
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update($member)
|
|
||||||
{
|
|
||||||
$index = findIndex($this->folks, ['id' => $member->id]);
|
|
||||||
$this->folks[$index]['handle'] = $member->handle;
|
|
||||||
$this->folks[$index]['email'] = $member->email;
|
|
||||||
if (isset($member->avatar)) {
|
|
||||||
$this->folks[$index]['avatar'] = $member->avatar;
|
|
||||||
}
|
|
||||||
$this->folks[$index]['updated'] = Carbon::now();
|
|
||||||
//save new folks file
|
|
||||||
$this->docs::writeSettings($this->folks, env('FOLKS_PATH'));
|
|
||||||
//update session
|
|
||||||
session()->put('member', $this->folks[$index]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function auth($request)
|
|
||||||
{
|
|
||||||
//suth stuff
|
|
||||||
$folks = $this->folks;
|
|
||||||
$found = $this->getByHandle($request->handle);
|
|
||||||
if ($found) {
|
|
||||||
if (password_verify($request->password, $found['password'])) {
|
|
||||||
$member = [
|
|
||||||
'id' => $found['id'],
|
|
||||||
'handle' => $found['handle'],
|
|
||||||
'email' => $found['email'],
|
|
||||||
'role' => $found['role'],
|
|
||||||
'avatar' => $found['avatar'],
|
|
||||||
'key' => $found['key'],
|
|
||||||
'secret' => $found['secret'],
|
|
||||||
];
|
|
||||||
|
|
||||||
$token = Token::create(
|
|
||||||
$found['key'],
|
|
||||||
$found['secret'],
|
|
||||||
time() + 3600,
|
|
||||||
'localhost'
|
|
||||||
); //expires in an hour
|
|
||||||
$form_token = md5(uniqid(microtime(), true));
|
|
||||||
$request->session()->put('member', $member);
|
|
||||||
$request->session()->put('token', $token);
|
|
||||||
$request->session()->put('form_token', $form_token);
|
|
||||||
return ['status' => true, 'message' => 'HEY WELCOME BACK'];
|
|
||||||
//DO SESSION STUFF
|
|
||||||
} else {
|
|
||||||
return ['status' => false, 'message' => 'CHECK THAT PASSWORD'];
|
|
||||||
//RETURN ERROR
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return ['status' => false, 'message' => 'CHECK THAT HANDLE'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function status()
|
|
||||||
{
|
|
||||||
if (session('member') !== null) {
|
|
||||||
if (
|
|
||||||
Token::validate(session('token'), session('member')['secret']) &&
|
|
||||||
Token::validateExpiration(session('token'), session('member')['secret'])
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,184 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Repositories;
|
|
||||||
|
|
||||||
use App\Interfaces\PageRepositoryInterface;
|
|
||||||
//Asset Services
|
|
||||||
use App\Services\Assets\DocService;
|
|
||||||
use App\Services\Assets\RenderService;
|
|
||||||
//Data Services
|
|
||||||
use App\Services\Data\SettingsService;
|
|
||||||
use App\Services\Data\ContentService;
|
|
||||||
use App\Services\Data\PaginateService;
|
|
||||||
use App\Services\Data\SortingService;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
class PageRepository implements PageRepositoryInterface
|
|
||||||
{
|
|
||||||
protected $content;
|
|
||||||
protected $setttings;
|
|
||||||
protected $paginate;
|
|
||||||
protected $pages;
|
|
||||||
protected $docs;
|
|
||||||
protected $sort;
|
|
||||||
protected $render;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
ContentService $contentService,
|
|
||||||
SettingsService $settingsService,
|
|
||||||
PaginateService $paginateService,
|
|
||||||
DocService $docService,
|
|
||||||
SortingService $sortingService,
|
|
||||||
RenderService $renderService
|
|
||||||
) {
|
|
||||||
$this->content = $contentService;
|
|
||||||
$this->settings = $settingsService;
|
|
||||||
$this->paginate = $paginateService;
|
|
||||||
$this->docs = $docService;
|
|
||||||
$this->sort = $sortingService;
|
|
||||||
$this->render = $renderService;
|
|
||||||
$this->pages = $this->content->loadAllPages();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAll()
|
|
||||||
{
|
|
||||||
return $this->pages;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getById($id)
|
|
||||||
{
|
|
||||||
$page = $this->pages->where('id', $id)->first();
|
|
||||||
//quick check to see if layout is set
|
|
||||||
$page['layout'] == '' ? $page['layout'] = 'page' : $page['layout'] = $page['layout'];
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getByUuid($uuid)
|
|
||||||
{
|
|
||||||
$page = $this->pages->where('uuid', $uuid)->first();
|
|
||||||
//quick check to see if layout is set
|
|
||||||
$page['layout'] == '' ? $page['layout'] = 'page' : $page['layout'] = $page['layout'];
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBySlug($slug)
|
|
||||||
{
|
|
||||||
$page = $this->pages->where('slug', $slug)->first();
|
|
||||||
//quick check to see if layout is set
|
|
||||||
$page['layout'] == '' ? $page['layout'] = 'page' : $page['layout'] = $page['layout'];
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete($page)
|
|
||||||
{
|
|
||||||
return $this->editPage($page, $this->pages->where('uuid', $page->uuid)->first(), 'delete');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create($page)
|
|
||||||
{
|
|
||||||
return $this->editPage($page, null, 'create');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update($page)
|
|
||||||
{
|
|
||||||
return $this->editPage($page, $this->pages->where('uuid', $page->uuid)->first(), 'update');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getGroup($num, $limit, $sort = "all")
|
|
||||||
{
|
|
||||||
return $this->paginate->getPage($num, $limit, $sort);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function editPage($body, $page, $task)
|
|
||||||
{
|
|
||||||
$path;
|
|
||||||
$file;
|
|
||||||
$writePath;
|
|
||||||
$message;
|
|
||||||
$deleted;
|
|
||||||
if ($task != 'create') {
|
|
||||||
$path = date('Y', date($page['rawCreated'])) .
|
|
||||||
'/' .
|
|
||||||
date('m', date($page['rawCreated']));
|
|
||||||
} else {
|
|
||||||
$path = date('Y') . '/' . date('m');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($task == 'delete') {
|
|
||||||
$deleted = 'true';
|
|
||||||
$body->menu = 'false';
|
|
||||||
$body->published = 'false';
|
|
||||||
$body->featured = 'false';
|
|
||||||
//set body object with prexisting data
|
|
||||||
$body->id = $page['id'];
|
|
||||||
$body->layout = $page['layout'];
|
|
||||||
$body->slug = $page['slug'];
|
|
||||||
$body->title = $page['title'];
|
|
||||||
$body->imageList = $page['feature'];
|
|
||||||
$body->fileList = $page['files'];
|
|
||||||
$body->tags = $page['tags'];
|
|
||||||
$body->content = $page['content'];
|
|
||||||
} else {
|
|
||||||
$deleted = isset($page['deleted']) ? $page['deleted'] : 'false';
|
|
||||||
}
|
|
||||||
|
|
||||||
$created = $task != 'create' ? new Carbon($page['rawCreated']) : Carbon::now();
|
|
||||||
$updated = Carbon::now();
|
|
||||||
|
|
||||||
// grab current index from settings and update
|
|
||||||
$id = $task != 'create' ? $body->id : $this->settings->getSettings()['library_stats']['current_index'];
|
|
||||||
$uuid = $task != 'create' ? $body->uuid : createUUID();
|
|
||||||
//set variables post body for saving
|
|
||||||
$body->title = urlencode($body->title);
|
|
||||||
$body->id = $id;
|
|
||||||
$body->uuid = $uuid;
|
|
||||||
$body->path = $path;
|
|
||||||
$body->author = session('member')['handle'];
|
|
||||||
$body->created = $created->format("Y-m-d\TH:i:sP");
|
|
||||||
$body->updated = $updated->format("Y-m-d\TH:i:sP");
|
|
||||||
$body->deleted = $deleted;
|
|
||||||
//set path to save file
|
|
||||||
if ($body->layout == 'index') {
|
|
||||||
$writePath = '../content/pages/start/index.md';
|
|
||||||
} else {
|
|
||||||
$writePath = '../content/pages/' . $path . '/' . $body->slug . '.md';
|
|
||||||
}
|
|
||||||
//write file to path
|
|
||||||
$saved = $this->docs::writePages($task, $path, $writePath, $this->docs::objectToMD($body));
|
|
||||||
//handle post save result
|
|
||||||
if ($saved) {
|
|
||||||
if (
|
|
||||||
$this->settings->getGlobal()['renderOnSave'] == 'true' &&
|
|
||||||
$this->settings->getGlobal()['dynamicRender'] == 'false'
|
|
||||||
) {
|
|
||||||
$this->render->tags();
|
|
||||||
$this->render->archive();
|
|
||||||
$this->render->pages();
|
|
||||||
$message = 'Filed edited and rendered. NOICE.';
|
|
||||||
} else {
|
|
||||||
$message = 'File edited. Nice work';
|
|
||||||
}
|
|
||||||
|
|
||||||
//upadte settings if needed
|
|
||||||
$body->path = $path;
|
|
||||||
$this->settings->updateMenu($body);
|
|
||||||
$this->settings->updateTags($this->sort->tags());
|
|
||||||
// if new page added, update current index in Settings file
|
|
||||||
if ($task == 'create') {
|
|
||||||
$this->settings->updatePageIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'message' => $message,
|
|
||||||
'type' => $task == 'update' ? 'postUpdated' : 'postAdded',
|
|
||||||
'id' => $uuid,
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
return $response = [
|
|
||||||
'message' => "Uh oh. File save problem. Don't panic",
|
|
||||||
'type' => 'postError',
|
|
||||||
'id' => $uuid,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,113 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Assets;
|
|
||||||
|
|
||||||
use App\Services\Data\ThemeService;
|
|
||||||
|
|
||||||
class AssetService
|
|
||||||
{
|
|
||||||
protected $themeTestImagePath;
|
|
||||||
protected $themeTestCSSPath;
|
|
||||||
protected $themeTestScriptsPath;
|
|
||||||
protected $themes;
|
|
||||||
protected $currentTheme;
|
|
||||||
|
|
||||||
public function __construct(ThemeService $themeService)
|
|
||||||
{
|
|
||||||
$this->themeImagePath = '../public/assets/images/global/';
|
|
||||||
$this->themeTestImagePath = '../public/theme/images/global/';
|
|
||||||
$this->themeCSSPath = '../public/assets/css/theme/';
|
|
||||||
$this->themeTestCSSPath = '../public/theme/css/theme/';
|
|
||||||
$this->themeScriptsPath = '../public/assets/scripts/theme/';
|
|
||||||
$this->themeTestScriptsPath = '../public/theme/scripts/theme/';
|
|
||||||
$this->themes = $themeService;
|
|
||||||
$this->currentTheme = $this->themes->getCurrentTheme();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCurrentTheme()
|
|
||||||
{
|
|
||||||
return $this->currentTheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function moveToTheme($live = false)
|
|
||||||
{
|
|
||||||
$imagePath = '';
|
|
||||||
$cssPath = '';
|
|
||||||
$scriptPath = '';
|
|
||||||
($live) ? $imagePath = $this->themeImagePath : $imagePath = $this->themeTestImagePath;
|
|
||||||
($live) ? $cssPath = $this->themeCSSPath : $cssPath = $this->themeTestCSSPath;
|
|
||||||
($live) ? $scriptPath = $this->themeScriptsPath : $scriptPath = $this->themeTestScriptsPath;
|
|
||||||
//get current theme
|
|
||||||
foreach (
|
|
||||||
new \DirectoryIterator('../content/themes/' . $this->currentTheme . '/assets/images/global/') as $file
|
|
||||||
) {
|
|
||||||
if ($file->isDot()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//make theme directory if not present
|
|
||||||
if (!is_dir($imagePath)) {
|
|
||||||
mkdir($imagePath, 0755, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_file($imagePath . $file->getFileName())) {
|
|
||||||
copy(
|
|
||||||
'../content/themes/' .
|
|
||||||
$this->currentTheme .
|
|
||||||
'/assets/images/global/' .
|
|
||||||
$file->getFileName(),
|
|
||||||
$imagePath . $file->getFileName()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
//image is already there, so chill
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//clear test theme css and script directories
|
|
||||||
$styles = glob($cssPath . '*'); // get all file names
|
|
||||||
foreach ($styles as $file) { // iterate files
|
|
||||||
if (is_file($file)) {
|
|
||||||
unlink($file); // delete file
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$scripts = glob($scriptPath . '*'); // get all file names
|
|
||||||
foreach ($scripts as $file) { // iterate files
|
|
||||||
if (is_file($file)) {
|
|
||||||
unlink($file); // delete file
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//copy theme assets to public
|
|
||||||
$newcss = glob('../content/themes/' . $this->currentTheme . '/assets/css/*');
|
|
||||||
if (!is_dir($cssPath)) {
|
|
||||||
mkdir($cssPath, 0755, true);
|
|
||||||
}
|
|
||||||
foreach ($newcss as $file) { // iterate files
|
|
||||||
if (is_file($file)) {
|
|
||||||
$path = explode('/', $file);
|
|
||||||
copy($file, $cssPath . $path[6]);
|
|
||||||
} else {
|
|
||||||
// if there is a type/font folder, move it
|
|
||||||
|
|
||||||
$typePath = explode('/', $file);
|
|
||||||
$src = '../content/themes/' . $this->currentTheme . '/assets/css/' . $typePath[6];
|
|
||||||
$dst = $cssPath . $typePath[6];
|
|
||||||
if (is_dir($dst)) {
|
|
||||||
delete_directory($dst);
|
|
||||||
copy_directory($src, $dst);
|
|
||||||
} else {
|
|
||||||
copy_directory($src, $dst);
|
|
||||||
}
|
|
||||||
//rename($file, $cssPath . $typePath[6]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$newjs = glob('../content/themes/' . $this->currentTheme . '/assets/scripts/*');
|
|
||||||
if (!is_dir($scriptPath)) {
|
|
||||||
mkdir($scriptPath, 0755, true);
|
|
||||||
}
|
|
||||||
foreach ($newjs as $file) { // iterate files
|
|
||||||
if (is_file($file)) {
|
|
||||||
$path = explode('/', $file);
|
|
||||||
copy($file, $scriptPath . $path[6]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Assets;
|
|
||||||
|
|
||||||
class FileUploadService
|
|
||||||
{
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function handleFile($request, $fileMode = true)
|
|
||||||
{
|
|
||||||
//$options = $request->getParsedBody();
|
|
||||||
//front end sends one by one for progress tracking, so grab first
|
|
||||||
|
|
||||||
if ($fileMode) {
|
|
||||||
$file = $request->file('upload_files')[0];
|
|
||||||
} else {
|
|
||||||
$file = $request;
|
|
||||||
}
|
|
||||||
$type = $file->extension();
|
|
||||||
$public_path = '../public';
|
|
||||||
$filesPath = '';
|
|
||||||
$path = date('Y') . '/' . date('m');
|
|
||||||
$response = [];
|
|
||||||
switch ($type) {
|
|
||||||
case 'jpeg':
|
|
||||||
case 'jpg':
|
|
||||||
case 'png':
|
|
||||||
case 'gif':
|
|
||||||
if ($fileMode) {
|
|
||||||
if (isset($request["source"])) {
|
|
||||||
if ($request["source"] == "avatar-upload") {
|
|
||||||
$filesPath = '/assets/images/user/' . $path . '/';
|
|
||||||
//Member::updateData('avi', $filesPath . $file->getClientFileName());
|
|
||||||
} else {
|
|
||||||
$filesPath = '/assets/images/user/' . $path . '/';
|
|
||||||
// Settings::updateGlobalData('background', $filesPath . '/' . $file->getClientFileName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$filesPath = '/assets/images/blog/' . $path . '/';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$filesPath = '/assets/images/blog/' . $path . '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 'mkv':
|
|
||||||
case 'mp4':
|
|
||||||
$filesPath = '/assets/video/blog/' . $path . '/';
|
|
||||||
break;
|
|
||||||
case 'ogg':
|
|
||||||
case 'mp3':
|
|
||||||
$filesPath = '/assets/sound/blog/' . $path . '/';
|
|
||||||
break;
|
|
||||||
case 'pdf':
|
|
||||||
case 'txt':
|
|
||||||
case 'rtf':
|
|
||||||
$filesPath = '/assets/docs/blog/' . $path . '/';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
// if does not exist, so lets create it.
|
|
||||||
if (!is_dir($public_path . $filesPath)) {
|
|
||||||
mkdir($public_path . $filesPath, 0755, true);
|
|
||||||
}
|
|
||||||
$filename = urlencode($file->getClientOriginalName());
|
|
||||||
$file->move($public_path . $filesPath, $filename);
|
|
||||||
} catch (RuntimeException $e) {
|
|
||||||
echo 'ERROR ' . $e->getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = [
|
|
||||||
'message' => "File Uploaded. Great!",
|
|
||||||
"filePath" => $filesPath . urlencode($file->getClientOriginalName()),
|
|
||||||
"fileName" => urlencode($file->getClientOriginalName()),
|
|
||||||
'type' => $type,
|
|
||||||
];
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,132 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Assets;
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\File;
|
|
||||||
use App\Services\Data\SortingService;
|
|
||||||
use App\Services\Data\SettingsService;
|
|
||||||
use App\Services\Data\ContentService;
|
|
||||||
|
|
||||||
class RenderService
|
|
||||||
{
|
|
||||||
private $sort;
|
|
||||||
private $settings;
|
|
||||||
private $contents;
|
|
||||||
private $pageInfo;
|
|
||||||
private $menu;
|
|
||||||
private $background;
|
|
||||||
private $theme;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
SortingService $sortingService,
|
|
||||||
SettingsService $settingsService,
|
|
||||||
ContentService $contentService
|
|
||||||
) {
|
|
||||||
$this->sort = $sortingService;
|
|
||||||
$this->settings = $settingsService;
|
|
||||||
$this->contents = $contentService;
|
|
||||||
$this->theme = $this->settings->getGlobal()['theme'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function publishAll()
|
|
||||||
{
|
|
||||||
$message = [];
|
|
||||||
$dynamicRender = $this->settings->getGlobal()['dynamicRender'];
|
|
||||||
if (isset($dynamicRender) && $dynamicRender === 'true') {
|
|
||||||
$message = [
|
|
||||||
'message' => 'Auto Rendering is already enabled!',
|
|
||||||
'type' => 'RENDER_SUCCESS',
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
$this->archive();
|
|
||||||
$this->tags();
|
|
||||||
$this->pages();
|
|
||||||
$message = [
|
|
||||||
'message' => 'Site Rendered. GOOD EFFORT',
|
|
||||||
'type' => 'RENDER_SUCCESS',
|
|
||||||
];
|
|
||||||
} catch (Error $error) {
|
|
||||||
$message = [
|
|
||||||
'message' => 'Issue With Rendering. DONT PANIC',
|
|
||||||
'type' => 'RENDER_ERROR',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function archive()
|
|
||||||
{
|
|
||||||
$template = $this->theme . '.archive';
|
|
||||||
$pageData = $this->sort->archive(false);
|
|
||||||
$location = '../public/archives.html';
|
|
||||||
File::put(
|
|
||||||
$location,
|
|
||||||
view($template)
|
|
||||||
->with($pageData)
|
|
||||||
->render()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tags()
|
|
||||||
{
|
|
||||||
$data = $this->sort->tags(false);
|
|
||||||
foreach ($data['tags'] as $item) {
|
|
||||||
//$template = 'tags.twig';
|
|
||||||
$template = $this->theme . '.tags';
|
|
||||||
$pageData = [
|
|
||||||
'theme' => $this->theme, // for theme kit
|
|
||||||
'title' => 'Pages Tagged as ' . $item['tag_name'],
|
|
||||||
'dynamicRender' => $data['dynamicRender'],
|
|
||||||
'layout' => 'page',
|
|
||||||
'info' => $data['info'],
|
|
||||||
'menu' => $data['menu'],
|
|
||||||
'pages' => $item['pages'],
|
|
||||||
'media' => $data['media'],
|
|
||||||
];
|
|
||||||
|
|
||||||
$location = '../public/tags/' . $item['slug'] . '.html';
|
|
||||||
|
|
||||||
if (!is_dir('../public/tags')) {
|
|
||||||
mkdir('../public/tags', 0755, true);
|
|
||||||
}
|
|
||||||
File::put(
|
|
||||||
$location,
|
|
||||||
view($template)
|
|
||||||
->with($pageData)
|
|
||||||
->render()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function pages()
|
|
||||||
{
|
|
||||||
$pages = $this->contents->loadAllPages();
|
|
||||||
foreach ($pages as $page) {
|
|
||||||
$template;
|
|
||||||
$page['layout'] == 'index' ?
|
|
||||||
$template = $this->theme . '.index' :
|
|
||||||
$template = $this->theme . '.page';
|
|
||||||
|
|
||||||
$pageData = $this->sort->page($page, false);
|
|
||||||
|
|
||||||
if (str_contains($page['layout'], 'index')) {
|
|
||||||
$location = '../public/index.html';
|
|
||||||
} else {
|
|
||||||
// if page is a menu item, render the page on public root
|
|
||||||
if ($page['menu'] == 'true') {
|
|
||||||
$location = '../public/' . $page['slug'] . '.html';
|
|
||||||
} else {
|
|
||||||
$dir = '../public/' . $page['path'];
|
|
||||||
if (!is_dir($dir)) {
|
|
||||||
mkdir($dir, 0755, true);
|
|
||||||
}
|
|
||||||
$location = '../public/' . $page['path'] . '/' . $page['slug'] . '.html';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File::put($location, view($template)->with($pageData)->render());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Data;
|
|
||||||
|
|
||||||
use function _\filter;
|
|
||||||
|
|
||||||
class PaginateService
|
|
||||||
{
|
|
||||||
protected $content;
|
|
||||||
|
|
||||||
public function __construct(ContentService $contentService)
|
|
||||||
{
|
|
||||||
$this->content = $contentService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPage(int $page, int $limit, string $sort = null)
|
|
||||||
{
|
|
||||||
$content = $this->content->loadAllPages();
|
|
||||||
|
|
||||||
$published = filter($content, function ($item) {
|
|
||||||
return $item['published'] == true && $item['deleted'] == false;
|
|
||||||
});
|
|
||||||
$deleted = filter($content, function ($item) {
|
|
||||||
return $item['deleted'] == true;
|
|
||||||
});
|
|
||||||
|
|
||||||
// $all = $content;
|
|
||||||
$all = filter($content, function ($item) {
|
|
||||||
return $item['deleted'] == false;
|
|
||||||
});
|
|
||||||
$filter = isset($sort) ? $sort : 'all';
|
|
||||||
switch ($filter) {
|
|
||||||
case 'published':
|
|
||||||
$filtered = $published;
|
|
||||||
break;
|
|
||||||
case 'deleted':
|
|
||||||
$filtered = $deleted;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$filtered = $all;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$numOfPages = ceil(count($filtered) / ($limit + 1));
|
|
||||||
$folder = [];
|
|
||||||
|
|
||||||
if (count($filtered) != 0) {
|
|
||||||
if (count($filtered) < $limit) {
|
|
||||||
$limit = count($filtered) - 1;
|
|
||||||
}
|
|
||||||
$range = $page * $limit - $limit;
|
|
||||||
|
|
||||||
if ($range != 0) {
|
|
||||||
$range = $range + 1;
|
|
||||||
}
|
|
||||||
for ($i = 0; $i <= $limit; ++$i) {
|
|
||||||
if (isset($filtered[$i + $range])) {
|
|
||||||
array_push($folder, $filtered[$i + $range]);
|
|
||||||
} else {
|
|
||||||
// chill out
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$prev = $page - 1;
|
|
||||||
if ($prev <= 0) {
|
|
||||||
$prev = $numOfPages;
|
|
||||||
}
|
|
||||||
|
|
||||||
$next = $page + 1;
|
|
||||||
if ($next > $numOfPages) {
|
|
||||||
$next = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'pages' => $folder,
|
|
||||||
'numOfPages' => $numOfPages,
|
|
||||||
'entryCount' => count($filtered),
|
|
||||||
'paginate' => [
|
|
||||||
'sort' => $sort,
|
|
||||||
'nextPage' => $next,
|
|
||||||
'prevPage' => $prev,
|
|
||||||
],
|
|
||||||
'stats' => [
|
|
||||||
'all' => count($all),
|
|
||||||
'published' => count($published),
|
|
||||||
'deleted' => count($deleted),
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,204 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Data;
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use App\Services\Assets\DocService;
|
|
||||||
|
|
||||||
use function _\find;
|
|
||||||
use function _\pull;
|
|
||||||
|
|
||||||
class SettingsService
|
|
||||||
{
|
|
||||||
protected $settings;
|
|
||||||
protected $tags;
|
|
||||||
protected $docs;
|
|
||||||
protected $contents;
|
|
||||||
|
|
||||||
public function __construct(DocService $docService, ContentService $contentService)
|
|
||||||
{
|
|
||||||
if (file_exists(env('TAGS_PATH'))) {
|
|
||||||
$this->tags = json_decode(file_get_contents(env('TAGS_PATH')), true);
|
|
||||||
} else {
|
|
||||||
$this->tags = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->docs = $docService;
|
|
||||||
$this->contents = $contentService;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function loadSettings()
|
|
||||||
{
|
|
||||||
$settings = [];
|
|
||||||
//if config files aren't avaiable, load templates
|
|
||||||
if (file_exists(env('SETTINGS_PATH'))) {
|
|
||||||
$settings = json_decode(file_get_contents(env('SETTINGS_PATH')), true);
|
|
||||||
} else {
|
|
||||||
$settings = json_decode(
|
|
||||||
file_get_contents('../content/init/settings-template.json'),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return $settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSettings()
|
|
||||||
{
|
|
||||||
return $this->loadSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getGlobal()
|
|
||||||
{
|
|
||||||
$this->settings = $this->loadSettings();
|
|
||||||
return $this->settings['global'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getEmail()
|
|
||||||
{
|
|
||||||
$this->settings = $this->loadSettings();
|
|
||||||
return $this->settings['email'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMenu()
|
|
||||||
{
|
|
||||||
$this->settings = $this->loadSettings();
|
|
||||||
return $this->settings['menu'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTags()
|
|
||||||
{
|
|
||||||
return $this->tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updatePageIndex()
|
|
||||||
{
|
|
||||||
$this->settings = $this->loadSettings();
|
|
||||||
++$this->settings['library_stats']['current_index'];
|
|
||||||
$this->docs->writeSettings($this->settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateGlobalData($key, $value)
|
|
||||||
{
|
|
||||||
$this->settings = $this->loadSettings();
|
|
||||||
$this->settings['global'][$key] = $value;
|
|
||||||
$this->docs->writeSettings($this->settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateMenu($body)
|
|
||||||
{
|
|
||||||
$settings = $this->loadSettings();
|
|
||||||
//$menu = $settings["menu"];
|
|
||||||
$item = [
|
|
||||||
'title' => $body->title,
|
|
||||||
'id' => $body->id,
|
|
||||||
'uuid' => $body->uuid,
|
|
||||||
'slug' => $body->slug,
|
|
||||||
'path' => $body->path,
|
|
||||||
];
|
|
||||||
if ($body->menu == 'true') {
|
|
||||||
if (!find($settings['menu'], ['uuid' => $item['uuid']])) {
|
|
||||||
array_push($settings['menu'], $item);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (find($settings['menu'], ['uuid' => $item['uuid']])) {
|
|
||||||
pull($settings['menu'], $item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->docs->writeSettings($settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateTags($update)
|
|
||||||
{
|
|
||||||
$this->docs->writeSettings($update, env('TAGS_PATH'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function sync($data)
|
|
||||||
{
|
|
||||||
$settings = $this->getSettings();
|
|
||||||
$settings['global']['base_url'] = $data->global->base_url;
|
|
||||||
$settings['global']['title'] = $data->global->title;
|
|
||||||
$settings['global']['descriptions'] = $data->global->descriptions;
|
|
||||||
$settings['global']['private'] = $data->global->private;
|
|
||||||
$settings['global']['renderOnSave'] = $data->global->renderOnSave;
|
|
||||||
$settings['global']['theme'] = $data->global->theme;
|
|
||||||
$settings['global']['externalAPI'] = $data->global->externalAPI;
|
|
||||||
$settings['global']['dynamicRender'] = $data->global->dynamicRender;
|
|
||||||
|
|
||||||
//$settings['email']['active'] = $data->email->active;
|
|
||||||
//$settings['email']['smtp'] = $data->email->smtp;
|
|
||||||
//$settings['email']['mailgun'] = $data->email->mailgun;
|
|
||||||
|
|
||||||
return $this->docs::writeSettings($settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function navSync($data)
|
|
||||||
{
|
|
||||||
$settings = $this->loadSettings();
|
|
||||||
$pages = $this->contents->loadAllPages();
|
|
||||||
$remove = $data->remove;
|
|
||||||
$result = [];
|
|
||||||
//if remove contains id, find nav item page and set menu to false
|
|
||||||
if ($remove != null || $remove != '') {
|
|
||||||
$page = $pages->where('uuid', $remove)->first();
|
|
||||||
$page['menu'] = 'false';
|
|
||||||
$page['published']
|
|
||||||
? ($page['published'] = 'true')
|
|
||||||
: ($page['published'] = 'false');
|
|
||||||
$page['featured']
|
|
||||||
? ($page['featured'] = 'true')
|
|
||||||
: ($page['featured'] = 'false');
|
|
||||||
$page['deleted']
|
|
||||||
? ($page['deleted'] = 'true')
|
|
||||||
: ($page['deleted'] = 'false');
|
|
||||||
$updated = Carbon::now();
|
|
||||||
$created = new Carbon($page['rawCreated']);
|
|
||||||
$page['created'] = $created->format("Y-m-d\TH:i:sP");
|
|
||||||
$page['updated'] = $updated->format("Y-m-d\TH:i:sP");
|
|
||||||
|
|
||||||
if ($page['layout'] == 'index') {
|
|
||||||
$writePath = '../content/pages/start/index.md';
|
|
||||||
} else {
|
|
||||||
$writePath = '../content/pages/' . $page['path'] . '/' . $page['slug'] . '.md';
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$object = (object) $page;
|
|
||||||
$object->imageList = $page['feature'];
|
|
||||||
$object->fileList = $page['files'];
|
|
||||||
$this->docs::writePages('write', $page['path'], $writePath, $this->docs::objectToMD($object));
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$result = [
|
|
||||||
'message' => 'Page Was Not Updated. Be cool ',
|
|
||||||
'type' => 'pageUpdateError',
|
|
||||||
'error' => $e->getMessage(),
|
|
||||||
];
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$settings['menu'] = [];
|
|
||||||
$items = $data->menu;
|
|
||||||
foreach ($items as $item) {
|
|
||||||
array_push($settings['menu'], [
|
|
||||||
'title' => $item->title,
|
|
||||||
'id' => $item->id,
|
|
||||||
'uuid' => $item->uuid,
|
|
||||||
'slug' => $item->slug,
|
|
||||||
'path' => $item->path,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$this->docs->writeSettings($settings);
|
|
||||||
$result = [
|
|
||||||
'message' => 'Navigation updated. Very slick!',
|
|
||||||
'type' => 'menuUpdated',
|
|
||||||
];
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$result = [
|
|
||||||
'message' => 'Navigation Update Error. It\'ll be ok!',
|
|
||||||
'type' => 'menuUpdateError',
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,293 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Data;
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
use function _\find;
|
|
||||||
use function _\filter;
|
|
||||||
|
|
||||||
class SortingService
|
|
||||||
{
|
|
||||||
private $p_tags = [];
|
|
||||||
private $p_archive = [];
|
|
||||||
private $settings;
|
|
||||||
private $contents;
|
|
||||||
private $themes;
|
|
||||||
private $info = [];
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
SettingsService $settingsService,
|
|
||||||
ContentService $contentService,
|
|
||||||
ThemeService $themeService,
|
|
||||||
) {
|
|
||||||
$this->settings = $settingsService;
|
|
||||||
$this->contents = $contentService;
|
|
||||||
$this->themes = $themeService;
|
|
||||||
$global = $this->settings->getGlobal();
|
|
||||||
$this->info = [
|
|
||||||
'keywords' => isset($global['keywords'])
|
|
||||||
? $global['keywords']
|
|
||||||
: 'fipamo, blog, jamstack, php, markdown, js',
|
|
||||||
'menu' => $this->settings->getMenu(),
|
|
||||||
'tags' => $this->settings->getTags(),
|
|
||||||
'description' => $global['descriptions'],
|
|
||||||
'image' => $global['base_url'] . $global['background'],
|
|
||||||
'baseURL' => $global['base_url'],
|
|
||||||
'dynamicRender' => $global['dynamicRender'],
|
|
||||||
'theme' => $global['theme'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tags($debug = true)
|
|
||||||
{
|
|
||||||
$pages = $this->contents->loadAllPages();
|
|
||||||
foreach ($pages as $page) {
|
|
||||||
$temp = [];
|
|
||||||
if (isset($page['tags'])) {
|
|
||||||
$temp = explode(',', $page['tags']);
|
|
||||||
foreach ($temp as $tag) {
|
|
||||||
$label = trim($tag);
|
|
||||||
if (!find($this->p_tags, ['tag_name' => $label])) {
|
|
||||||
array_push($this->p_tags, [
|
|
||||||
'tag_name' => $label,
|
|
||||||
'slug' => safeString($label),
|
|
||||||
'pages' => $this->tagPages($label, $pages),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$tagData = [];
|
|
||||||
|
|
||||||
$settingsTags = [];
|
|
||||||
if (isset($this->settings->getTags()['pages'])) {
|
|
||||||
$settingsTags = $this->settings->getTags()['pages'];
|
|
||||||
}
|
|
||||||
$tagData = [
|
|
||||||
'debug' => $debug, // for theme kit
|
|
||||||
'layout' => 'page',
|
|
||||||
'tags' => $this->p_tags,
|
|
||||||
'theme' => $this->info['theme'], // for theme kit
|
|
||||||
'title' => 'Pages Tagged as Tag',
|
|
||||||
'dynamicRender' => $this->info['dynamicRender'],
|
|
||||||
'pages' => $settingsTags,
|
|
||||||
'info' => $this->info,
|
|
||||||
'menu' => $this->settings->getMenu(),
|
|
||||||
'media' => [
|
|
||||||
['file' => $this->info['image'],
|
|
||||||
'type' => trim(pathinfo($this->info['image'], PATHINFO_EXTENSION))]
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
return $tagData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function tagPages($tag, $pages)
|
|
||||||
{
|
|
||||||
$tagged = [];
|
|
||||||
foreach ($pages as $page) {
|
|
||||||
if (isset($page['tags'])) {
|
|
||||||
if (strpos($page['tags'], $tag) !== false) {
|
|
||||||
array_push($tagged, [
|
|
||||||
'title' => urldecode($page['title']),
|
|
||||||
'slug' => $page['slug'],
|
|
||||||
'path' => $page['path'],
|
|
||||||
'feature' => $page['feature'],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $tagged;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function archive($debug = true)
|
|
||||||
{
|
|
||||||
$pages = $this->contents->loadAllPages();
|
|
||||||
$years = [];
|
|
||||||
$archive = [];
|
|
||||||
foreach ($pages as $page) {
|
|
||||||
$date = explode('/', $page['path']);
|
|
||||||
if (!find($years, ['year' => trim($date[0])])) {
|
|
||||||
$findPages = filter($pages, ['createdYear' => trim($date[0])]);
|
|
||||||
array_push(
|
|
||||||
$years,
|
|
||||||
[
|
|
||||||
'year' => trim($date[0]),
|
|
||||||
'count' => count($findPages),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($years as $year) {
|
|
||||||
$sorted = [];
|
|
||||||
$filtered = filter($pages, ['createdYear' => $year['year']]);
|
|
||||||
foreach ($filtered as $obj) {
|
|
||||||
$month = date('m', date($obj['rawCreated']));
|
|
||||||
if (!find($sorted, ['month' => $month])) {
|
|
||||||
$perMonth = filter(
|
|
||||||
$pages,
|
|
||||||
[
|
|
||||||
'path' => $year['year'] . '/' . $month,
|
|
||||||
'deleted' => false,
|
|
||||||
'published' => true,
|
|
||||||
'layout' => 'page',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
array_push($sorted, [
|
|
||||||
'month' => $month,
|
|
||||||
'full_month' => date('F', date($obj['rawCreated'])),
|
|
||||||
'count' => count($perMonth),
|
|
||||||
'pages' => $perMonth,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
array_push($this->p_archive, [
|
|
||||||
'year' => $year['year'],
|
|
||||||
'year_data' => $sorted,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
$archive_data = [];
|
|
||||||
|
|
||||||
$archiveData = [
|
|
||||||
'debug' => $debug, // for theme kit
|
|
||||||
'theme' => $this->info['theme'], // for theme kit
|
|
||||||
'layout' => 'page',
|
|
||||||
'title' => 'Archives',
|
|
||||||
'dynamicRender' => $this->info['dynamicRender'],
|
|
||||||
'archive' => $this->p_archive,
|
|
||||||
'info' => $this->info,
|
|
||||||
'menu' => $this->settings->getMenu(),
|
|
||||||
'media' => [
|
|
||||||
['file' => $this->info['image'],
|
|
||||||
'type' => trim(pathinfo($this->info['image'], PATHINFO_EXTENSION))]
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $archiveData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function page($page, $debug = true)
|
|
||||||
{
|
|
||||||
$pageOptions = [];
|
|
||||||
$tags = [];
|
|
||||||
if (isset($page['tags'])) {
|
|
||||||
$taglist = explode(',', $page['tags']);
|
|
||||||
foreach ($taglist as $tag) {
|
|
||||||
$label = trim($tag);
|
|
||||||
array_push($tags, [
|
|
||||||
'label' => $label . ' ',
|
|
||||||
'slug' => safeString($label),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$meta = [
|
|
||||||
'who' => $page['author'],
|
|
||||||
'when' => $page['created'],
|
|
||||||
'tags' => $tags,
|
|
||||||
];
|
|
||||||
// if page feature isn't empty, find image from list and set it as background image
|
|
||||||
// if it is empty, just use global background
|
|
||||||
if ($page['feature'] != '' || $page['feature'] != null) {
|
|
||||||
$media = explode(',', $page['feature']);
|
|
||||||
$set = false;
|
|
||||||
foreach ($media as $file) {
|
|
||||||
$item = trim($file);
|
|
||||||
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
|
||||||
|
|
||||||
if ($ext != 'mp4' && !$set) {
|
|
||||||
$this->info['image'] = $this->info['baseURL'] . $item;
|
|
||||||
$set = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$recent = [];
|
|
||||||
$featured = [];
|
|
||||||
$limit = 4;
|
|
||||||
$pages = $this->contents->loadAllPages();
|
|
||||||
foreach ($pages as $item) {
|
|
||||||
if (
|
|
||||||
!$item['deleted'] &&
|
|
||||||
$item['published'] &&
|
|
||||||
$item['menu'] != 'true'
|
|
||||||
) {
|
|
||||||
if (count($recent) < $limit) {
|
|
||||||
array_push($recent, [
|
|
||||||
'path' => $item['path'],
|
|
||||||
'slug' => $item['slug'],
|
|
||||||
'title' => urldecode($item['title']),
|
|
||||||
'feature' => $item['feature'],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($item['featured'] == true) {
|
|
||||||
if (count($featured) < $limit) {
|
|
||||||
array_push($featured, [
|
|
||||||
'path' => $item['path'],
|
|
||||||
'slug' => $item['slug'],
|
|
||||||
'title' => urldecode($item['title']),
|
|
||||||
'feature' => $item['feature'],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$pageData = [
|
|
||||||
"debug" => $debug,
|
|
||||||
"theme" => $this->info['theme'],
|
|
||||||
"status" => session('member') != null ? true : false,
|
|
||||||
"title" => urldecode($page['title']),
|
|
||||||
"meta" => $meta,
|
|
||||||
"menu" => $this->settings->getMenu(),
|
|
||||||
"info" => $this->info,
|
|
||||||
"media" => $page['media'],
|
|
||||||
"files" => $page['docs'],
|
|
||||||
"content" => $page['html'],
|
|
||||||
"layout" => $page['layout'],
|
|
||||||
"recent" => $recent,
|
|
||||||
"feature" => $featured,
|
|
||||||
"tags" => $meta['tags'],
|
|
||||||
"dynamicRender" => $this->info['dynamicRender'],
|
|
||||||
];
|
|
||||||
return $pageData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function navigation()
|
|
||||||
{
|
|
||||||
$pageOptions = [
|
|
||||||
'title' => 'Edit Navigation',
|
|
||||||
'status' => session('member') != '' ? true : false,
|
|
||||||
'menu' => $this->settings->getMenu(),
|
|
||||||
];
|
|
||||||
|
|
||||||
return $pageOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function settings()
|
|
||||||
{
|
|
||||||
$global = $this->settings->getGlobal();
|
|
||||||
$updatedContent = new Carbon($global['last_content_backup']);
|
|
||||||
$updatedFiles = new Carbon($global['last_files_backup']);
|
|
||||||
$status = session('member') != '' ? true : false;
|
|
||||||
$pageOptions = [
|
|
||||||
'title' => 'Settings',
|
|
||||||
'private' => $global['private'],
|
|
||||||
'renderOnSave' => $global['renderOnSave'],
|
|
||||||
'background' => $global['background'],
|
|
||||||
'member' => session('member'),
|
|
||||||
'ftoken' => session('form_token'),
|
|
||||||
'siteTitle' => $global['title'],
|
|
||||||
'baseUrl' => $global['base_url'],
|
|
||||||
'desc' => $global['descriptions'],
|
|
||||||
'lastContentBackup' => $updatedContent->format('Y F d H i s'),
|
|
||||||
'lastFilesBackup' => $updatedFiles->format('Y F d H i s'),
|
|
||||||
'currentTheme' => $global['theme'],
|
|
||||||
'themes' => $this->themes->getThemes(),
|
|
||||||
'apiStatus' => isset($global['externalAPI']) ? $global['externalAPI'] : 'false',
|
|
||||||
'dynamicRenderStatus' => isset($global['dynamicRender']) ? $global['dynamicRender'] : 'false',
|
|
||||||
'status' => $status,
|
|
||||||
];
|
|
||||||
return $pageOptions;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,286 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Upkeep;
|
|
||||||
|
|
||||||
use ReallySimpleJWT\Token;
|
|
||||||
use ReallySimpleJWT\Exception\EncodeException;
|
|
||||||
use App\Services\Assets\DocService;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
use function _\find;
|
|
||||||
|
|
||||||
class InitService
|
|
||||||
{
|
|
||||||
protected $docs;
|
|
||||||
protected $filePaths = [];
|
|
||||||
|
|
||||||
public function __construct(DocService $docService)
|
|
||||||
{
|
|
||||||
$this->docs = $docService;
|
|
||||||
$this->filePaths = ['../public/assets/images/blog',
|
|
||||||
'../public/assets/images/user', '../public/assets/video/blog',
|
|
||||||
'../public/assets/docs/blog', '../public/assets/sound/blog'];
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function validSecret($length)
|
|
||||||
{
|
|
||||||
$alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
||||||
$special = '*&!@%^#$';
|
|
||||||
$alphabet = $alphanum . $special;
|
|
||||||
$random = openssl_random_pseudo_bytes($length);
|
|
||||||
$alphabet_length = strlen($alphabet);
|
|
||||||
$string = '';
|
|
||||||
for ($i = 0; $i < $length; ++$i) {
|
|
||||||
$string .= $alphabet[ord($random[$i]) % $alphabet_length];
|
|
||||||
}
|
|
||||||
//secret needs to be a valid token
|
|
||||||
if ($length == 12) {
|
|
||||||
try {
|
|
||||||
$secret = Token::create(12, $string, time() + 3600, 'localhost');
|
|
||||||
return $string;
|
|
||||||
} catch (EncodeException $e) {
|
|
||||||
//bad secret, so try agiain
|
|
||||||
return self::validSecret(12);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Token::validate($key, $string)) {
|
|
||||||
return $string;
|
|
||||||
} else {
|
|
||||||
return self::validSecret(12);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fresh($body)
|
|
||||||
{
|
|
||||||
//grab template files
|
|
||||||
//TODO: Remove hardcoded link and set up init path in settings
|
|
||||||
$newFolks = json_decode(
|
|
||||||
file_get_contents(env('FIPAMO_INIT') . '/folks-template.json'),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
$newSettings = json_decode(
|
|
||||||
file_get_contents(env('FIPAMO_INIT') . '/settings-template.json'),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
//get form values
|
|
||||||
//$body = $request->getParsedBody();
|
|
||||||
$handle = $body->new_member_handle;
|
|
||||||
$email = $body->new_member_email;
|
|
||||||
$pass = $body->new_member_pass;
|
|
||||||
$title = $body->new_member_title;
|
|
||||||
|
|
||||||
$now = Carbon::now();
|
|
||||||
//setup folks config
|
|
||||||
$hash = password_hash($pass, PASSWORD_DEFAULT);
|
|
||||||
$newFolks[0]['id'] = 0;
|
|
||||||
$newFolks[0]['handle'] = $handle;
|
|
||||||
$newFolks[0]['email'] = $email;
|
|
||||||
$newFolks[0]['password'] = $hash;
|
|
||||||
$newFolks[0]['key'] = password_hash($email, PASSWORD_DEFAULT);
|
|
||||||
$newFolks[0]['secret'] = self::validSecret(12);
|
|
||||||
$newFolks[0]['role'] = 'hnic';
|
|
||||||
$newFolks[0]['created'] = $now->format("Y-m-d\TH:i:sP");
|
|
||||||
$newFolks[0]['updated'] = $now->format("Y-m-d\TH:i:sP");
|
|
||||||
//set up settings config
|
|
||||||
$newSettings['global']['title'] = $title;
|
|
||||||
|
|
||||||
//create index file
|
|
||||||
//TODO: upate path attribute to use env variable
|
|
||||||
$index = [
|
|
||||||
'id' => 0,
|
|
||||||
'uuid' => createUUID(),
|
|
||||||
'title' => 'FIRST!',
|
|
||||||
'imageList' => '/assets/images/global/default-bg.jpg',
|
|
||||||
'fileList' => '',
|
|
||||||
'path' => 'content/pages/start',
|
|
||||||
'layout' => 'index',
|
|
||||||
'tags' => 'start, welcome',
|
|
||||||
'author' => $handle,
|
|
||||||
'created' => $now->format("Y-m-d\TH:i:sP"),
|
|
||||||
'updated' => $now->format("Y-m-d\TH:i:sP"),
|
|
||||||
'deleted' => 'false',
|
|
||||||
'slug' => 'first',
|
|
||||||
'menu' => 'false',
|
|
||||||
'featured' => 'false',
|
|
||||||
'published' => 'true',
|
|
||||||
'content' => "# F**k Yes \n\nIf you're seeing this, you're up and running. NICE WORK!\n\nFrom here, feel free to start dropping pages to your heart's content.\n\nFor some tips about using Fipamo, check out the ![docs](https://code.playvicio.us/Are0h/Fipamo/wiki/02-Usage)\n\nAll good? Feel free to edit this page to whatever you want!\n\nYOU'RE THE CAPTAIN NOW.",
|
|
||||||
];
|
|
||||||
|
|
||||||
//once all files created, write down
|
|
||||||
mkdir(env('FIPAMO_CONFIG'), 0755, true);
|
|
||||||
$this->docs->writeSettings($newSettings, env('FIPAMO_CONFIG') . '/settings.json');
|
|
||||||
$this->docs->writeSettings($newFolks, env('FIPAMO_CONFIG') . '/folks.json');
|
|
||||||
$this->docs->writeSettings([], env('FIPAMO_CONFIG') . '/tags.json');
|
|
||||||
$object = (object) $index;
|
|
||||||
|
|
||||||
$this->docs->writePages(
|
|
||||||
'create',
|
|
||||||
'start',
|
|
||||||
env('PAGES_PATH') . '/start/index.md',
|
|
||||||
$this->docs::objectToMD($object)
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = ['type' => 'blogInitGood', 'message' => 'Site Created'];
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function restore($request)
|
|
||||||
{
|
|
||||||
//content required, so check it
|
|
||||||
|
|
||||||
$result = [];
|
|
||||||
$contentArchive = $request->file('backup-content-upload');
|
|
||||||
$fileArchive = $request->file('backup-files-upload');
|
|
||||||
if ($contentArchive == null || $contentArchive == '') {
|
|
||||||
return $result = [
|
|
||||||
'type' => 'requestLame',
|
|
||||||
'message' => 'Content Archive EMPTY',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
$result = $this->restoreContent($contentArchive, $request);
|
|
||||||
|
|
||||||
if ($result['type'] == 'requestLame') {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
//file upload is optional, so if it's present, restore it
|
|
||||||
if ($fileArchive != null || $fileArchive != '') {
|
|
||||||
$result = $this->restoreFiles($fileArchive);
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function restoreContent($contentUpload, $request)
|
|
||||||
{
|
|
||||||
$contentUpload->move(env('FIPAMO_DIR') . '/', $contentUpload->getClientOriginalName());
|
|
||||||
$contentZip = new \ZipArchive();
|
|
||||||
$result = [];
|
|
||||||
$tempDir = env('FIPAMO_DIR') . '/_temp';
|
|
||||||
if ($contentZip->open(env('FIPAMO_DIR') . '/' . $contentUpload->getClientOriginalName()) === true) {
|
|
||||||
$folks = json_decode($contentZip->getFromName('config/folks.json'), true);
|
|
||||||
$found = find($folks, ['handle' => $request->restore_member_handle]);
|
|
||||||
if ($found) {
|
|
||||||
if (password_verify($request->restore_member_pass, $found['password'])) {
|
|
||||||
//restore assets from previous site
|
|
||||||
if ($request->restore_former_url != '' || $request->restore_former_url != null) {
|
|
||||||
$this->moveAssets($contentZip, $request->restore_former_url);
|
|
||||||
}
|
|
||||||
$newFolks = [];
|
|
||||||
if (!isset($found['secret'])) {
|
|
||||||
$found['secret'] = self::validSecret(12);
|
|
||||||
}
|
|
||||||
array_push($newFolks, $found);
|
|
||||||
//make temp folder and dump file in there
|
|
||||||
mkdir($tempDir, 0755, true);
|
|
||||||
$contentZip->extractTo($tempDir);
|
|
||||||
//load up old config file
|
|
||||||
$newConfig = json_decode(
|
|
||||||
file_get_contents($tempDir . '/config/settings.json'),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
//check for key, add if not there
|
|
||||||
if (!isset($newConfig['global']['externalAPI'])) {
|
|
||||||
$newConfig['global']['externalAPI'] = 'false';
|
|
||||||
}
|
|
||||||
//make dir and write new config files
|
|
||||||
if (!is_dir(env('FIPAMO_CONFIG'))) {
|
|
||||||
mkdir(env('FIPAMO_CONFIG'), 0755, true);
|
|
||||||
}
|
|
||||||
$this->docs->writeSettings($newConfig, env('FIPAMO_CONFIG') . '/settings.json');
|
|
||||||
$this->docs->writeSettings($newFolks, env('FIPAMO_CONFIG') . '/folks.json');
|
|
||||||
rename($tempDir . '/config/tags.json', env('FIPAMO_CONFIG') . '/tags.json');
|
|
||||||
//move saved markdown pages
|
|
||||||
rename($tempDir . '/content/pages/', env('PAGES_PATH'));
|
|
||||||
//clean up temp dir and zip file
|
|
||||||
$this->docs::deleteFolder($tempDir);
|
|
||||||
$contentZip->close();
|
|
||||||
unlink(env('FIPAMO_DIR') . '/' . $contentUpload->getClientOriginalName());
|
|
||||||
$result = [
|
|
||||||
'type' => 'requestGood',
|
|
||||||
'message' => 'Content Restored! Redirecting',
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$result = [
|
|
||||||
'type' => 'requestLame',
|
|
||||||
'message' => 'Check that password, champ.',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$result = [
|
|
||||||
'type' => 'requestLame',
|
|
||||||
'message' => 'Uh Oh. Check that handle',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function restoreFiles($filesUpload)
|
|
||||||
{
|
|
||||||
$filesUpload->move(env('FIPAMO_DIR') . '/', $filesUpload->getClientOriginalName());
|
|
||||||
$filesZip = new \ZipArchive();
|
|
||||||
$tempDir = env('FIPAMO_DIR') . '/_file_temp';
|
|
||||||
$result = [];
|
|
||||||
if ($filesZip->open(env('FIPAMO_DIR') . '/' . $filesUpload->getClientOriginalName()) === true) {
|
|
||||||
$filesZip->extractTo($tempDir);
|
|
||||||
//clear and move dir if present
|
|
||||||
foreach ($this->filePaths as $path) {
|
|
||||||
delete_directory($path, false);
|
|
||||||
//non image directories don't exist, so they need to be created
|
|
||||||
$pathing = explode("/", $path);
|
|
||||||
if ($pathing[3] != 'images') {
|
|
||||||
if (!is_dir('../public/assets/' . $pathing[3])) {
|
|
||||||
mkdir('../public/assets/' . $pathing[3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempPath = $tempDir . '/' . substr($path, 3);
|
|
||||||
if (is_dir($tempPath)) {
|
|
||||||
rename($tempPath, $path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$result = [
|
|
||||||
'type' => 'requestGood',
|
|
||||||
'message' => 'Files & Content Restored! Redirecting',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
delete_directory($tempDir);
|
|
||||||
$filesZip->close();
|
|
||||||
unlink(env('FIPAMO_DIR') . '/' . $filesUpload->getClientOriginalName());
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function moveAssets($zip, $url)
|
|
||||||
{
|
|
||||||
$assetFail = 0;
|
|
||||||
$assetList = [];
|
|
||||||
array_push($assetList, json_decode($zip->getFromName('assets/blog_images.json'), true));
|
|
||||||
array_push($assetList, json_decode($zip->getFromName('assets/user_images.json'), true));
|
|
||||||
array_push($assetList, json_decode($zip->getFromName('assets/blog_docs.json'), true));
|
|
||||||
array_push($assetList, json_decode($zip->getFromName('assets/blog_videos.json'), true));
|
|
||||||
foreach ($assetList as $list) {
|
|
||||||
foreach ($list as $asset) {
|
|
||||||
$path = explode('/', $asset['path']);
|
|
||||||
$type = $path[3];
|
|
||||||
$section = $path[4];
|
|
||||||
$year = $path[5];
|
|
||||||
$month = $path[6];
|
|
||||||
$blogDir = '../public/assets/' . $type . '/' . $section . '/' . $year . '/' . $month;
|
|
||||||
if (!is_dir($blogDir)) {
|
|
||||||
mkdir($blogDir, 0755, true);
|
|
||||||
}
|
|
||||||
$externalPath = '/assets/' . $type . '/' . $section . '/' . $year . '/' . $month;
|
|
||||||
$asset_url = $url . $externalPath . '/' . $asset['file'];
|
|
||||||
try {
|
|
||||||
file_put_contents(
|
|
||||||
$asset['path'] . '/' . $asset['file'],
|
|
||||||
file_get_contents($asset_url)
|
|
||||||
);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
$assetFail++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,162 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Upkeep;
|
|
||||||
|
|
||||||
use App\Services\Data\SettingsService;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
class MaintenanceService
|
|
||||||
{
|
|
||||||
protected $settings;
|
|
||||||
protected $filePaths = [];
|
|
||||||
|
|
||||||
public function __construct(SettingsService $settingsService)
|
|
||||||
{
|
|
||||||
$this->settings = $settingsService;
|
|
||||||
$this->filePaths = ['../public/assets/images/blog',
|
|
||||||
'../public/assets/images/user', '../public/assets/docs/blog',
|
|
||||||
'../public/assets/video/blog', '../public/assets/sound/blog'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createContentBackUp()
|
|
||||||
{
|
|
||||||
//make sure back directory is there
|
|
||||||
$stamp = Carbon::now()->format("YmdHis");
|
|
||||||
if (!is_dir(env('FIPAMO_BACKUPS'))) {
|
|
||||||
mkdir(env('FIPAMO_BACKUPS'), 0755, true);
|
|
||||||
}
|
|
||||||
//creat backup zip
|
|
||||||
$zip = new \ZipArchive();
|
|
||||||
|
|
||||||
$zip->open(
|
|
||||||
env('FIPAMO_BACKUPS') . '/backup-content-' . $stamp . '.zip',
|
|
||||||
\ZipArchive::CREATE | \ZipArchive::OVERWRITE
|
|
||||||
);
|
|
||||||
//gather data and path info for md pages
|
|
||||||
$pagePath = env('PAGES_PATH');
|
|
||||||
$yearPaths = glob($pagePath . '/*', GLOB_ONLYDIR);
|
|
||||||
foreach ($yearPaths as $years) {
|
|
||||||
$year = explode('/', $years);
|
|
||||||
//grap the index and save it
|
|
||||||
if (trim($year[3]) == 'start') {
|
|
||||||
$options = [
|
|
||||||
'add_path' => 'content/pages/' . $year[3] . '/',
|
|
||||||
'remove_all_path' => true,
|
|
||||||
];
|
|
||||||
$zip->addGlob($years . '/*.md', GLOB_BRACE, $options);
|
|
||||||
}
|
|
||||||
$monthsPath = glob($pagePath . '/' . $year[3] . '/*', GLOB_ONLYDIR);
|
|
||||||
foreach ($monthsPath as $months) {
|
|
||||||
$month = explode('/', $months);
|
|
||||||
//once info is collected, add md pages to zip
|
|
||||||
$options = [
|
|
||||||
'add_path' => 'content/pages/' . $year[3] . '/' . $month[4] . '/',
|
|
||||||
'remove_all_path' => true,
|
|
||||||
];
|
|
||||||
$zip->addGlob($months . '/*.md', GLOB_BRACE, $options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//gather paths for blog images
|
|
||||||
$blogImages = [];
|
|
||||||
$dir = new \RecursiveDirectoryIterator('../public/assets/images/blog');
|
|
||||||
$flat = new \RecursiveIteratorIterator($dir);
|
|
||||||
$files = new \RegexIterator($flat, '/\.png|jpg|gif$/i');
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$blogImages[] = ['path' => $file->getPath(), 'file' => $file->getFilename()];
|
|
||||||
};
|
|
||||||
|
|
||||||
//gather paths for user images
|
|
||||||
$userImages = [];
|
|
||||||
if (is_dir('../public/assets/images/user')) {
|
|
||||||
$dir = new \RecursiveDirectoryIterator('../public/assets/images/user');
|
|
||||||
$flat = new \RecursiveIteratorIterator($dir);
|
|
||||||
$files = new \RegexIterator($flat, '/\.png|jpg|gif$/i');
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$userImages[] = ['path' => $file->getPath(), 'file' => $file->getFilename()];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//gather paths for blog documents
|
|
||||||
$blogDocs = [];
|
|
||||||
if (is_dir('../public/assets/docs/blog')) {
|
|
||||||
$dir = new \RecursiveDirectoryIterator('../public/assets/docs/blog');
|
|
||||||
$flat = new \RecursiveIteratorIterator($dir);
|
|
||||||
$files = new \RegexIterator($flat, '/\.txt|pdf|rtf$/i');
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$blogDocs[] = ['path' => $file->getPath(), 'file' => $file->getFilename()];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//gather paths for blog videos
|
|
||||||
$blogVids = [];
|
|
||||||
if (is_dir('../public/assets/video/blog')) {
|
|
||||||
$dir = new \RecursiveDirectoryIterator('../public/assets/video/blog');
|
|
||||||
$flat = new \RecursiveIteratorIterator($dir);
|
|
||||||
$files = new \RegexIterator($flat, '/\.mp4$/i');
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$blogVids[] = ['path' => $file->getPath(), 'file' => $file->getFilename()];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//add directory for settings and save them
|
|
||||||
$zip->addEmptyDir('config');
|
|
||||||
$zip->addEmptyDir('assets');
|
|
||||||
$zip->addFile(env('SETTINGS_PATH'), 'config/settings.json');
|
|
||||||
$zip->addFile(env('FOLKS_PATH'), 'config/folks.json');
|
|
||||||
$zip->addFile(env('TAGS_PATH'), 'config/tags.json');
|
|
||||||
// create temp files for image lists
|
|
||||||
file_put_contents(env('FIPAMO_BACKUPS') . '/blog_images_temp.json', json_encode($blogImages));
|
|
||||||
file_put_contents(env('FIPAMO_BACKUPS') . '/user_images_temp.json', json_encode($userImages));
|
|
||||||
file_put_contents(env('FIPAMO_BACKUPS') . '/blog_docs_temp.json', json_encode($blogDocs));
|
|
||||||
file_put_contents(env('FIPAMO_BACKUPS') . '/blog_vids_temp.json', json_encode($blogVids));
|
|
||||||
//add to zip
|
|
||||||
$zip->addFile(env('FIPAMO_BACKUPS') . '/blog_images_temp.json', 'assets/blog_images.json');
|
|
||||||
$zip->addFile(env('FIPAMO_BACKUPS') . '/user_images_temp.json', 'assets/user_images.json');
|
|
||||||
$zip->addFile(env('FIPAMO_BACKUPS') . '/blog_docs_temp.json', 'assets/blog_docs.json');
|
|
||||||
$zip->addFile(env('FIPAMO_BACKUPS') . '/blog_vids_temp.json', 'assets/blog_videos.json');
|
|
||||||
//save zip file
|
|
||||||
$zip->close();
|
|
||||||
//clean up temp files
|
|
||||||
unlink(env('FIPAMO_BACKUPS') . '/blog_images_temp.json');
|
|
||||||
unlink(env('FIPAMO_BACKUPS') . '/user_images_temp.json');
|
|
||||||
unlink(env('FIPAMO_BACKUPS') . '/blog_docs_temp.json');
|
|
||||||
unlink(env('FIPAMO_BACKUPS') . '/blog_vids_temp.json');
|
|
||||||
|
|
||||||
//update settings file with latest back up date
|
|
||||||
$this->settings->updateGlobalData('last_content_backup', $stamp);
|
|
||||||
|
|
||||||
return ['message' => "Content backup created. THIS IS A SAFE SPACE!"];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createFileBackUp()
|
|
||||||
{
|
|
||||||
$stamp = Carbon::now()->format("YmdHis");
|
|
||||||
$zip = new \ZipArchive();
|
|
||||||
$zip->open(
|
|
||||||
env('FIPAMO_BACKUPS') . '/backup-files-' . $stamp . '.zip',
|
|
||||||
\ZipArchive::CREATE | \ZipArchive::OVERWRITE
|
|
||||||
);
|
|
||||||
//gather data and path info for blog images
|
|
||||||
|
|
||||||
foreach ($this->filePaths as $path) {
|
|
||||||
$yearPaths = glob($path . '/*', GLOB_ONLYDIR);
|
|
||||||
foreach ($yearPaths as $years) {
|
|
||||||
$year = explode('/', $years);
|
|
||||||
$monthsPath = glob($path . '/' . $year[5] . '/*', GLOB_ONLYDIR);
|
|
||||||
foreach ($monthsPath as $months) {
|
|
||||||
$month = explode('/', $months);
|
|
||||||
//once info is collected, add images pages to zip
|
|
||||||
$options = [
|
|
||||||
'add_path' => substr($path, 3) . '/' . $year[5] . '/' . $month[6] . '/',
|
|
||||||
'remove_all_path' => true,
|
|
||||||
];
|
|
||||||
$zip->addGlob($months . '/*.*', GLOB_BRACE, $options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$zip->close();
|
|
||||||
$this->settings->updateGlobalData('last_files_backup', $stamp);
|
|
||||||
return ['message' => "Files are backed up. Breath Easy!"];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Upkeep;
|
|
||||||
|
|
||||||
class ResetService
|
|
||||||
{
|
|
||||||
private $protectedItems = ['assets', '.htaccess', 'index.php', 'robots.txt'];
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function site()
|
|
||||||
{
|
|
||||||
$response = [];
|
|
||||||
try {
|
|
||||||
$this->clearPublicAssets();
|
|
||||||
$this->clearPublicRoot();
|
|
||||||
$this->clearContent();
|
|
||||||
session()->flush();
|
|
||||||
$response = [
|
|
||||||
'message' => "PUBLIC CLEARED",
|
|
||||||
'type' => "COOL",
|
|
||||||
];
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
$response = [
|
|
||||||
'message' => "RESET NOT COMPLETED",
|
|
||||||
'error' => $e,
|
|
||||||
'type' => "ERROR",
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function clearContent()
|
|
||||||
{
|
|
||||||
$contentDir = env('FIPAMO_DIR');
|
|
||||||
delete_directory($contentDir . '/pages', false);
|
|
||||||
delete_directory($contentDir . '/config', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function clearPublicAssets()
|
|
||||||
{
|
|
||||||
delete_directory('../public/assets/docs', false);
|
|
||||||
delete_directory('../public/assets/video', false);
|
|
||||||
delete_directory('../public/assets/sound', false);
|
|
||||||
delete_directory('../public/assets/css/theme', false);
|
|
||||||
delete_directory('../public/assets/scripts/theme', false);
|
|
||||||
delete_directory('../public/assets/images/blog', false);
|
|
||||||
delete_directory('../public/assets/images/user', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function clearPublicRoot()
|
|
||||||
{
|
|
||||||
$publicItems = glob('../public/*');
|
|
||||||
$response = [];
|
|
||||||
foreach ($publicItems as $path) {
|
|
||||||
$item = explode('/', $path);
|
|
||||||
if (in_array($item[2], $this->protectedItems)) {
|
|
||||||
//protected item do nothing
|
|
||||||
} else {
|
|
||||||
if (is_file($path)) {
|
|
||||||
unlink($path);
|
|
||||||
} else {
|
|
||||||
delete_directory($path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
53
artisan
53
artisan
|
@ -1,53 +0,0 @@
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
define('LARAVEL_START', microtime(true));
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Register The Auto Loader
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Composer provides a convenient, automatically generated class loader
|
|
||||||
| for our application. We just need to utilize it! We'll require it
|
|
||||||
| into the script here so that we do not have to worry about the
|
|
||||||
| loading of any of our classes manually. It's great to relax.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
require __DIR__.'/vendor/autoload.php';
|
|
||||||
|
|
||||||
$app = require_once __DIR__.'/bootstrap/app.php';
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Run The Artisan Application
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| When we run the console application, the current CLI command will be
|
|
||||||
| executed in this console and the response sent back to a terminal
|
|
||||||
| or another output device for the developers. Here goes nothing!
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
|
||||||
|
|
||||||
$status = $kernel->handle(
|
|
||||||
$input = new Symfony\Component\Console\Input\ArgvInput,
|
|
||||||
new Symfony\Component\Console\Output\ConsoleOutput
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Shutdown The Application
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Once Artisan has finished running, we will fire off the shutdown events
|
|
||||||
| so that any final work may be done by the application before we shut
|
|
||||||
| down the process. This is the last thing to happen to the request.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
$kernel->terminate($input, $status);
|
|
||||||
|
|
||||||
exit($status);
|
|
|
@ -1,55 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Create The Application
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| The first thing we will do is create a new Laravel application instance
|
|
||||||
| which serves as the "glue" for all the components of Laravel, and is
|
|
||||||
| the IoC container for the system binding all of the various parts.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
$app = new Illuminate\Foundation\Application(
|
|
||||||
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Bind Important Interfaces
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Next, we need to bind some important interfaces into the container so
|
|
||||||
| we will be able to resolve them when needed. The kernels serve the
|
|
||||||
| incoming requests to this application from both the web and CLI.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
$app->singleton(
|
|
||||||
Illuminate\Contracts\Http\Kernel::class,
|
|
||||||
App\Http\Kernel::class
|
|
||||||
);
|
|
||||||
|
|
||||||
$app->singleton(
|
|
||||||
Illuminate\Contracts\Console\Kernel::class,
|
|
||||||
App\Console\Kernel::class
|
|
||||||
);
|
|
||||||
|
|
||||||
$app->singleton(
|
|
||||||
Illuminate\Contracts\Debug\ExceptionHandler::class,
|
|
||||||
App\Exceptions\Handler::class
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Return The Application
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| This script returns the application instance. The instance is given to
|
|
||||||
| the calling script so we can separate the building of the instances
|
|
||||||
| from the actual running of the application and sending responses.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
return $app;
|
|
2
bootstrap/cache/.gitignore
vendored
2
bootstrap/cache/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
||||||
*
|
|
||||||
!.gitignore
|
|
10
brain/_loader.php
Normal file
10
brain/_loader.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
spl_autoload_register(function ($className) {
|
||||||
|
$file = dirname(__DIR__) . '\\' . $className . '.php';
|
||||||
|
$file = str_replace('\\', DIRECTORY_SEPARATOR, $file);
|
||||||
|
//echo $file;
|
||||||
|
if (file_exists($file)) {
|
||||||
|
include $file;
|
||||||
|
}
|
||||||
|
});
|
81
brain/api/v1/AuthAPI.php
Normal file
81
brain/api/v1/AuthAPI.php
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\api\v1;
|
||||||
|
|
||||||
|
use brain\data\Auth;
|
||||||
|
use brain\data\Session;
|
||||||
|
|
||||||
|
class AuthAPI
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function status()
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
//internal check for admin action
|
||||||
|
if (Auth::status()) {
|
||||||
|
$result = [
|
||||||
|
'message' => 'Authorized',
|
||||||
|
'type' => 'apiUseAuthorized',
|
||||||
|
'token' => Session::get('token'),
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'Not Authorized',
|
||||||
|
'type' => 'apiUseNotAuthorized',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function login($body)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
switch (Auth::login($body)) {
|
||||||
|
case 'no_name':
|
||||||
|
$result = [
|
||||||
|
'message' => 'Need to see some id, champ',
|
||||||
|
'type' => 'requestLame',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'bad_pass':
|
||||||
|
$result = [
|
||||||
|
'message' => 'Check your password, sport',
|
||||||
|
'type' => 'requestLame',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result = [
|
||||||
|
'message' => 'Welcome back',
|
||||||
|
'type' => 'requestGood',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function logout($body)
|
||||||
|
{
|
||||||
|
Auth::logout($body);
|
||||||
|
$result = [
|
||||||
|
'message' => 'Till next time, g.',
|
||||||
|
'type' => 'TASK_LOGOUT',
|
||||||
|
];
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function requestSecret($body)
|
||||||
|
{
|
||||||
|
$result = Auth::findSecret($body);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function resetPassword($body)
|
||||||
|
{
|
||||||
|
$result = Auth::makeNewPassword($body);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
73
brain/api/v1/FilesAPI.php
Normal file
73
brain/api/v1/FilesAPI.php
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\api\v1;
|
||||||
|
|
||||||
|
use brain\utility\FileUploader;
|
||||||
|
use brain\data\Settings;
|
||||||
|
use brain\data\Member;
|
||||||
|
|
||||||
|
class FilesAPI
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function uploadFiles($request, $type = null)
|
||||||
|
{
|
||||||
|
$upload = $request->getUploadedFiles(); //grab uploaded files
|
||||||
|
$options = $request->getParsedBody();
|
||||||
|
$file = $upload['upload_files'][0]; //front end sends one by one for progress tracking, so grab first
|
||||||
|
$type = $file->getClientMediaType();
|
||||||
|
$filesPath = '';
|
||||||
|
$path = date('Y') . '/' . date('m');
|
||||||
|
$response = [];
|
||||||
|
|
||||||
|
switch ($type) {
|
||||||
|
case 'image/jpeg':
|
||||||
|
case 'image/png':
|
||||||
|
case 'image/gif':
|
||||||
|
case 'image/svg':
|
||||||
|
if (isset($options["source"])) {
|
||||||
|
if ($options["source"] == "avatar-upload") {
|
||||||
|
$filesPath = '/assets/images/user/' . $path . '/';
|
||||||
|
Member::updateData(
|
||||||
|
'avi',
|
||||||
|
$filesPath . $file->getClientFileName()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$filesPath = '/assets/images/user/' . $path . '/';
|
||||||
|
Settings::updateGlobalData(
|
||||||
|
'background',
|
||||||
|
$filesPath . '/' . $file->getClientFileName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$filesPath = '/assets/images/blog/' . $path . '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'video/mp4':
|
||||||
|
$filesPath = '/assets/video/blog/' . $path . '/';
|
||||||
|
break;
|
||||||
|
case 'audio/mpeg':
|
||||||
|
$filesPath = '/assets/sound/blog/' . $path . '/';
|
||||||
|
break;
|
||||||
|
case 'application/pdf':
|
||||||
|
case 'text/plain':
|
||||||
|
case 'text/rtf':
|
||||||
|
$filesPath = '/assets/docs/blog/' . $path . '/';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileUploader::uploadFile('../public' . $filesPath, $file);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'message' => "File Uploaded. Great!",
|
||||||
|
"filePath" => $filesPath . urlencode($file->getClientFileName()),
|
||||||
|
"fileName" => urlencode($file->getClientFileName()),
|
||||||
|
'type' => $type,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
79
brain/api/v1/ImagesAPI.php
Normal file
79
brain/api/v1/ImagesAPI.php
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\api\v1;
|
||||||
|
|
||||||
|
use brain\data\Member;
|
||||||
|
use brain\data\Settings;
|
||||||
|
use brain\utility\FileUploader;
|
||||||
|
|
||||||
|
class ImagesAPI
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function uploadImage($request, $type = null)
|
||||||
|
{
|
||||||
|
$file = $request->getUploadedFiles();
|
||||||
|
$uploadPath = '';
|
||||||
|
$path = date('Y') . '/' . date('m');
|
||||||
|
$response = [];
|
||||||
|
switch ($type) {
|
||||||
|
case 'avatar':
|
||||||
|
$image = $file['avatar_upload'];
|
||||||
|
$uploadPath = '../public/assets/images/user/' . $path;
|
||||||
|
break;
|
||||||
|
case 'background':
|
||||||
|
$image = $file['background_upload'];
|
||||||
|
$uploadPath = '../public/assets/images/user/' . $path;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$image = $file['post_image'];
|
||||||
|
$path = date('Y') . '/' . date('m');
|
||||||
|
$uploadPath = '../public/assets/images/blog/' . $path;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = FileUploader::uploadFile($uploadPath, $image);
|
||||||
|
|
||||||
|
switch ($type) {
|
||||||
|
case 'avatar':
|
||||||
|
$response = [
|
||||||
|
'message' => 'Avatar Added. You look great!',
|
||||||
|
'type' => 'avatarUploaded',
|
||||||
|
'url' => '/assets/images/user/' . $path . '/' . $image->getClientFileName(),
|
||||||
|
];
|
||||||
|
|
||||||
|
//update member data
|
||||||
|
Member::updateData(
|
||||||
|
'avi',
|
||||||
|
'/assets/images/user/' . $path . '/' . $image->getClientFileName()
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'background':
|
||||||
|
$response = [
|
||||||
|
'message' => "Background plugged in. That's nice!",
|
||||||
|
'type' => 'siteBackgroundUploaded',
|
||||||
|
'url' => '/assets/images/user/' . $path . '/' . $image->getClientFileName(),
|
||||||
|
];
|
||||||
|
|
||||||
|
//update settings file
|
||||||
|
Settings::updateGlobalData(
|
||||||
|
'background',
|
||||||
|
'/assets/images/user/' . $path . '/' . $image->getClientFileName()
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$response = [
|
||||||
|
'message' => 'Image Added. Very slick',
|
||||||
|
'type' => 'postImageAdded',
|
||||||
|
'url' => '/assets/images/blog/' . $path . '/' . $image->getClientFileName(),
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
34
brain/api/v1/InitAPI.php
Normal file
34
brain/api/v1/InitAPI.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\api\v1;
|
||||||
|
|
||||||
|
use brain\utility\Setup;
|
||||||
|
|
||||||
|
class InitAPI
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function handleInitTasks($task, $request)
|
||||||
|
{
|
||||||
|
//check if a site config already exists. if it does, deny set up request
|
||||||
|
//restore to previous version of site while a config exists is only accessible
|
||||||
|
//through settings.
|
||||||
|
|
||||||
|
if (Setup::status()) {
|
||||||
|
$result = ['type' => 'blogInitFail', 'message' => 'Site already set up'];
|
||||||
|
} else {
|
||||||
|
switch ($task) {
|
||||||
|
case 'init':
|
||||||
|
$result = Setup::init($request);
|
||||||
|
break;
|
||||||
|
case 'restore':
|
||||||
|
$result = Setup::restore($request);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
32
brain/api/v1/MailerAPI.php
Normal file
32
brain/api/v1/MailerAPI.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\api\v1;
|
||||||
|
|
||||||
|
use brain\data\Session;
|
||||||
|
use brain\utility\Mailer;
|
||||||
|
|
||||||
|
class MailerAPI
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function handleMail($request, $body, $response)
|
||||||
|
{
|
||||||
|
// if testing, verify session is active
|
||||||
|
// add clean method for sending programmtic emails
|
||||||
|
if ($body['mail_task'] == 'TESTING') {
|
||||||
|
if (Session::active()) {
|
||||||
|
$result = Mailer::sendmail($body);
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'You need to be logged in for this, champ.',
|
||||||
|
'type' => 'MAILER_ERROR',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
179
brain/api/v1/PagesAPI.php
Normal file
179
brain/api/v1/PagesAPI.php
Normal file
|
@ -0,0 +1,179 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\api\v1;
|
||||||
|
|
||||||
|
use brain\data\Book;
|
||||||
|
use brain\data\Settings;
|
||||||
|
use brain\data\Session;
|
||||||
|
use brain\utility\StringTools;
|
||||||
|
|
||||||
|
use function _\filter;
|
||||||
|
|
||||||
|
class PagesAPI
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPageContent($request, $args)
|
||||||
|
{
|
||||||
|
$task = $args['fourth'];
|
||||||
|
$pages = (new Book('../content/pages'))->getContents();
|
||||||
|
$content = [];
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
$entry = [
|
||||||
|
'id' => $page['id'],
|
||||||
|
'uuid' => $page['uuid'],
|
||||||
|
'title' => $page['title'],
|
||||||
|
'feature' => $page['feature'],
|
||||||
|
'path' => $page['path'],
|
||||||
|
'layout' => $page['layout'],
|
||||||
|
'tags' => $page['tags'],
|
||||||
|
'author' => $page['author'],
|
||||||
|
'created' => $page['created'],
|
||||||
|
'updated' => $page['updated'],
|
||||||
|
'deleted' => $page['deleted'],
|
||||||
|
'menu' => $page['menu'],
|
||||||
|
'featured' => $page['featured'],
|
||||||
|
'published' => $page['published'],
|
||||||
|
'slug' => $page['slug'],
|
||||||
|
'content' => StringTools::sanitizeContent($page['content']),
|
||||||
|
];
|
||||||
|
|
||||||
|
array_push($content, $entry);
|
||||||
|
}
|
||||||
|
switch ($task) {
|
||||||
|
case 'published':
|
||||||
|
$published = filter($content, function ($item) {
|
||||||
|
return $item['published'] == true && $item['deleted'] == false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$result = ['pages' => $published, 'totalItems' => count($published)];
|
||||||
|
break;
|
||||||
|
case 'featured':
|
||||||
|
$featured = filter($content, function ($item) {
|
||||||
|
return $item['featured'] == true && $item['deleted'] == false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'pages' => $featured,
|
||||||
|
'totalItems' => count($featured),
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'menu':
|
||||||
|
$menu = filter($content, function ($item) {
|
||||||
|
return $item['menu'] == true && $item['deleted'] == false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$result = ['pages' => $menu, 'totalItems' => count($menu)];
|
||||||
|
break;
|
||||||
|
case 'single':
|
||||||
|
$uuid = $args['fifth'];
|
||||||
|
$page = (new Book('../content/pages'))->findPageById($uuid);
|
||||||
|
|
||||||
|
$entry = [
|
||||||
|
'id' => $page['id'],
|
||||||
|
'uuid' => $page['uuid'],
|
||||||
|
'title' => $page['title'],
|
||||||
|
'feature' => $page['feature'],
|
||||||
|
'path' => $page['path'],
|
||||||
|
'layout' => $page['layout'],
|
||||||
|
'tags' => $page['tags'],
|
||||||
|
'author' => $page['author'],
|
||||||
|
'created' => $page['created'],
|
||||||
|
'updated' => $page['updated'],
|
||||||
|
'deleted' => $page['deleted'],
|
||||||
|
'menu' => $page['menu'],
|
||||||
|
'featured' => $page['featured'],
|
||||||
|
'published' => $page['published'],
|
||||||
|
'slug' => $page['slug'],
|
||||||
|
'content' => StringTools::sanitizeContent($page['content']),
|
||||||
|
];
|
||||||
|
$result = $entry;
|
||||||
|
break;
|
||||||
|
case 'tags':
|
||||||
|
$result = Settings::getTags();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result = [
|
||||||
|
'message' => "Hm, no task. That's unfortunate",
|
||||||
|
'type' => 'TASK_NONE',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function handlePageTask($request, $args)
|
||||||
|
{
|
||||||
|
$task = $args['fourth'];
|
||||||
|
switch ($task) {
|
||||||
|
case 'delete':
|
||||||
|
case 'create':
|
||||||
|
case 'write':
|
||||||
|
$body = json_decode(file_get_contents("php://input"), true);
|
||||||
|
$passed = true;
|
||||||
|
if (!isset($body['form_token'])) {
|
||||||
|
$result = [
|
||||||
|
'message' => 'No form token. Not good, sport.',
|
||||||
|
'type' => 'TASK_FORM_AUTH',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
if ($body['form_token'] == Session::get('form_token')) {
|
||||||
|
$keys = [
|
||||||
|
'id',
|
||||||
|
'uuid',
|
||||||
|
'layout',
|
||||||
|
'current_title',
|
||||||
|
'content',
|
||||||
|
'title',
|
||||||
|
'created',
|
||||||
|
'slug',
|
||||||
|
'tags',
|
||||||
|
'menu',
|
||||||
|
'featured',
|
||||||
|
'published',
|
||||||
|
'form_token',
|
||||||
|
'imageList',
|
||||||
|
"fileList",
|
||||||
|
"remote"
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($body as $key => $item) {
|
||||||
|
if (!in_array($key, $keys)) {
|
||||||
|
//found unnecessary key, so reject submission
|
||||||
|
var_dump($key);
|
||||||
|
$passed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($passed) {
|
||||||
|
$result = (new Book())->editPage($task, $request);
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'Unneccessary key found. Post not authorized, slick.',
|
||||||
|
'type' => 'TASK_FORM_AUTH',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'Form token, auth failed. Uh oh.',
|
||||||
|
'type' => 'TASK_FORM_AUTH',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'add-entry-image':
|
||||||
|
$result = ImagesAPI::uploadImage($request);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result = [
|
||||||
|
'message' => "Hm, no task. That's unfortunate",
|
||||||
|
'type' => 'TASK_NONE',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
153
brain/api/v1/SettingsAPI.php
Normal file
153
brain/api/v1/SettingsAPI.php
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\api\v1;
|
||||||
|
|
||||||
|
use brain\data\Render;
|
||||||
|
use brain\data\Settings;
|
||||||
|
use brain\data\Session;
|
||||||
|
use brain\utility\Maintenance;
|
||||||
|
|
||||||
|
class SettingsAPI
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function handleSettingsTask($request, $args, $body = null)
|
||||||
|
{
|
||||||
|
$task = $args['fourth'];
|
||||||
|
switch ($task) {
|
||||||
|
case 'publish':
|
||||||
|
//check settings to see if site is a one pager
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$theme = $settings['global']['theme'];
|
||||||
|
$themeConfig = json_decode(
|
||||||
|
file_get_contents('../content/themes/' . $theme . '/theme.json'),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
//check to see if dynamic rendering is active
|
||||||
|
if (
|
||||||
|
isset($settings['global']['dynamicRender']) &&
|
||||||
|
$settings['global']['dynamicRender'] === 'true'
|
||||||
|
) {
|
||||||
|
$result = [
|
||||||
|
'message' => "Dynamic Render Active! You're good!",
|
||||||
|
'type' => 'RENDER_SUCCESS',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$render = new Render();
|
||||||
|
if (isset($themeConfig['render'])) {
|
||||||
|
//rendering for one page sites
|
||||||
|
if (!$themeConfig['render'] || $themeConfig['render'] === 'false') {
|
||||||
|
$render->renderIndex();
|
||||||
|
$result = [
|
||||||
|
'message' => 'Index Rendered. HAND CLAPS',
|
||||||
|
'type' => 'RENDER_SUCCESS',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$render->renderTags();
|
||||||
|
$render->renderArchive();
|
||||||
|
$render->renderPages();
|
||||||
|
$result = [
|
||||||
|
'message' => 'Site Rendered. GOOD EFFORT',
|
||||||
|
'type' => 'RENDER_SUCCESS',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// just incase the render flag is missing
|
||||||
|
$render->renderTags();
|
||||||
|
$render->renderArchive();
|
||||||
|
$render->renderPages();
|
||||||
|
$result = [
|
||||||
|
'message' => 'Site Rendered. GOOD EFFORT',
|
||||||
|
'type' => 'RENDER_SUCCESS',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if render flag is set and false, just render index page for one page sites
|
||||||
|
//otherwise, render all pages according to theme template files
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'add-avatar':
|
||||||
|
$result = ImagesAPI::uploadImage($request, 'avatar');
|
||||||
|
break;
|
||||||
|
case 'add-feature-background':
|
||||||
|
$result = ImagesAPI::uploadImage($request, 'background');
|
||||||
|
break;
|
||||||
|
case 'sync':
|
||||||
|
Settings::sync($body);
|
||||||
|
$result = [
|
||||||
|
'message' => "Settings Synced. You're doing great!",
|
||||||
|
'type' => 'settingsUpdated',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'nav-sync':
|
||||||
|
Settings::navSync($body);
|
||||||
|
$result = [
|
||||||
|
'message' => 'Navigation updated. Very slick!',
|
||||||
|
'type' => 'menuUpdated',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result = [
|
||||||
|
'message' => "Hm, no task. That's unfortunate",
|
||||||
|
'type' => 'TASK_NONE',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInfo($request, $args)
|
||||||
|
{
|
||||||
|
$task = $args['fourth'];
|
||||||
|
switch ($task) {
|
||||||
|
case 'site':
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$data = [
|
||||||
|
'title' => $settings['global']['title'],
|
||||||
|
'base_url' => $settings['global']['base_url'],
|
||||||
|
'description' => $settings['global']['descriptions'],
|
||||||
|
];
|
||||||
|
$result = [
|
||||||
|
'message' => 'Settings Found',
|
||||||
|
'type' => 'GET_SETTINGS',
|
||||||
|
'data' => $data,
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'member':
|
||||||
|
if (Session::active()) {
|
||||||
|
$member = $member = Session::get('member');
|
||||||
|
$data = ['handle' => $member['handle'], 'email' => $member['email']];
|
||||||
|
$result = [
|
||||||
|
'message' => 'Member Info Found',
|
||||||
|
'type' => 'GET_MEMBER_INFO',
|
||||||
|
'data' => $data,
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => "Not logged in. C'mon, bruh",
|
||||||
|
'type' => 'TASK_NONE',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result = [
|
||||||
|
'message' => 'No Settings found. Frowny Face',
|
||||||
|
'type' => 'TASK_NONE',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function createBackup()
|
||||||
|
{
|
||||||
|
$result = Maintenance::makeBackup();
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
250
brain/controller/APIControl.php
Normal file
250
brain/controller/APIControl.php
Normal file
|
@ -0,0 +1,250 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\controller;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use brain\api\v1\AuthAPI;
|
||||||
|
use brain\api\v1\PagesAPI;
|
||||||
|
use brain\api\v1\FilesAPI;
|
||||||
|
use brain\api\v1\SettingsAPI;
|
||||||
|
use brain\api\v1\InitAPI;
|
||||||
|
use brain\api\v1\MailerAPI;
|
||||||
|
use brain\data\Member;
|
||||||
|
use brain\data\Session;
|
||||||
|
|
||||||
|
class APIControl
|
||||||
|
{
|
||||||
|
public static function get(
|
||||||
|
ServerRequestInterface $request,
|
||||||
|
ResponseInterface $response,
|
||||||
|
array $args
|
||||||
|
): ResponseInterface {
|
||||||
|
$filename = '';
|
||||||
|
switch (isset($args['third']) ? $args['third'] : 'none') {
|
||||||
|
case 'status':
|
||||||
|
$result = AuthAPI::status();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'page':
|
||||||
|
//echo
|
||||||
|
if (Member::verifyKey($_GET['key'])) {
|
||||||
|
$result = PagesAPI::getPageContent($request, $args);
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'API access denied, homie',
|
||||||
|
'type' => 'API_ERROR',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'settings':
|
||||||
|
$token = $request->getHeader('fipamo-access-token');
|
||||||
|
//Verify token to get site info
|
||||||
|
if (isset($token[0])) {
|
||||||
|
if (Session::verifyToken($token[0])) {
|
||||||
|
$result = SettingsAPI::getInfo($request, $args);
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'Invalid token, API access denied, homie',
|
||||||
|
'type' => 'API_ERROR',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'No token, API access denied, homie',
|
||||||
|
'type' => 'API_ERROR',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'files':
|
||||||
|
if (Session::active()) {
|
||||||
|
if ($args['third'] == 'backup') {
|
||||||
|
$filename = '../config/backups/latest_backup.zip';
|
||||||
|
if (file_exists($filename)) {
|
||||||
|
header('Content-Type: application/zip');
|
||||||
|
header(
|
||||||
|
'Content-Disposition: attachment; filename="' .
|
||||||
|
basename($filename) .
|
||||||
|
'"'
|
||||||
|
);
|
||||||
|
header('Content-Length: ' . filesize($filename));
|
||||||
|
|
||||||
|
flush();
|
||||||
|
// return readfile($filename);
|
||||||
|
//readfile($filename);
|
||||||
|
// delete file
|
||||||
|
//unlink($filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'API access denied, homie',
|
||||||
|
'type' => 'API_ERROR',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
// no break
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$freshResponse = $response;
|
||||||
|
|
||||||
|
if ($args['third'] == 'files') {
|
||||||
|
$freshResponse
|
||||||
|
->getBody()
|
||||||
|
->write(file_get_contents('../config/backups/latest_back.zip'));
|
||||||
|
|
||||||
|
$freshResponse->withHeader('Content-Type', 'application/zip');
|
||||||
|
return $freshResponse->withAddedHeader(
|
||||||
|
'Content-Disposition',
|
||||||
|
'attachment; filename=latest_backup.zip'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$response->getBody()->write(json_encode($result));
|
||||||
|
return $response->withHeader('Content-Type', 'application/json');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function post(
|
||||||
|
ServerRequestInterface $request,
|
||||||
|
ResponseInterface $response,
|
||||||
|
array $args
|
||||||
|
): ResponseInterface {
|
||||||
|
$contentType = $request->getHeader('Content-Type');
|
||||||
|
switch ($contentType[0]) {
|
||||||
|
case 'application/json':
|
||||||
|
$body = json_decode(file_get_contents('php://input'), true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (isset($args['third']) ? $args['third'] : 'none') {
|
||||||
|
case 'restore': //move to 'api/auth'
|
||||||
|
case 'init': //move to 'api/auth'
|
||||||
|
$task = $args['third'];
|
||||||
|
$result = InitApi::handleInitTasks(
|
||||||
|
$task,
|
||||||
|
$task == 'init' ? $body : $request
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'backup': //move to 'api/auth'
|
||||||
|
$token = $request->getHeader('fipamo-access-token');
|
||||||
|
//Verify token for admin tasks
|
||||||
|
$result = SettingsAPI::createBackup();
|
||||||
|
/*
|
||||||
|
|
||||||
|
if (Session::verifyToken($token[0])) {
|
||||||
|
$result = SettingsAPI::createBackup();
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
"message" => "API access denied, homie",
|
||||||
|
"type" => "API_ERROR",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
break;
|
||||||
|
case 'login': //move to 'api/auth'
|
||||||
|
//check if request is remote and if so, verify token
|
||||||
|
if ($body['remote'] || $body['remote'] == 'true') {
|
||||||
|
if (Member::verifyKey($body['key'])) {
|
||||||
|
$result = AuthAPI::login($body);
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'API access denied, homie',
|
||||||
|
'type' => 'API_ERROR',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//request is local, so it's cool
|
||||||
|
$result = AuthAPI::login($body);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'logout': //move to 'api/auth'
|
||||||
|
$result = AuthAPI::logout($body);
|
||||||
|
break;
|
||||||
|
case 'get-secret': //move to 'api/auth'
|
||||||
|
$result = AuthAPI::requestSecret($body);
|
||||||
|
break;
|
||||||
|
case 'reset-password': //move to 'api/auth'
|
||||||
|
$result = AuthAPI::resetPassword($body);
|
||||||
|
break;
|
||||||
|
case 'page':
|
||||||
|
$token = $request->getHeader('fipamo-access-token');
|
||||||
|
//Verify token for admin tasks
|
||||||
|
if (isset($token[0])) {
|
||||||
|
if (Session::verifyToken($token[0])) {
|
||||||
|
$result = PagesAPI::handlePageTask($request, $args);
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'Invalid token, API access denied, homie',
|
||||||
|
'type' => 'API_ERROR',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'No token, API access denied, homie',
|
||||||
|
'type' => 'API_ERROR',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "files":
|
||||||
|
$token = $request->getHeader('fipamo-access-token');
|
||||||
|
if (isset($token[0])) {
|
||||||
|
if (Session::verifyToken($token[0])) {
|
||||||
|
$result = FilesAPI::uploadFiles($request, $args);
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'Invalid token, API access denied, homie',
|
||||||
|
'type' => 'API_ERROR',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'No token, API access denied, homie',
|
||||||
|
'type' => 'API_ERROR',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'settings':
|
||||||
|
if (isset($body)) {
|
||||||
|
$postBody = $body;
|
||||||
|
} else {
|
||||||
|
$postBody = null;
|
||||||
|
}
|
||||||
|
$task = $args['fourth'];
|
||||||
|
if ($task == 'add-feature-background' || $task == 'add-avatar') {
|
||||||
|
$result = SettingsAPI::handleSettingsTask($request, $args, $postBody);
|
||||||
|
} else {
|
||||||
|
$token = $request->getHeader('fipamo-access-token');
|
||||||
|
if (Session::verifyToken($token[0])) {
|
||||||
|
$result = SettingsAPI::handleSettingsTask(
|
||||||
|
$request,
|
||||||
|
$args,
|
||||||
|
$postBody
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'API access denied, homie',
|
||||||
|
'type' => 'API_ERROR',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'mailer':
|
||||||
|
$result = MailerAPI::handleMail($request, $body, $response);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result = [
|
||||||
|
'message' => "Oh, nothing to do. That's unfortunate",
|
||||||
|
'type' => 'TASK_NONE',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$response->getBody()->write(json_encode($result));
|
||||||
|
return $response->withHeader('Content-Type', 'application/json');
|
||||||
|
}
|
||||||
|
}
|
226
brain/controller/DashControl.php
Normal file
226
brain/controller/DashControl.php
Normal file
|
@ -0,0 +1,226 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\controller;
|
||||||
|
|
||||||
|
use brain\data\Book;
|
||||||
|
use brain\data\Session;
|
||||||
|
use brain\data\Settings;
|
||||||
|
use brain\data\Themes;
|
||||||
|
use brain\utility\Setup;
|
||||||
|
use brain\utility\Sorting;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Slim\Views\Twig;
|
||||||
|
|
||||||
|
class DashControl
|
||||||
|
{
|
||||||
|
public static function start(
|
||||||
|
ServerRequestInterface $request,
|
||||||
|
ResponseInterface $response,
|
||||||
|
array $args
|
||||||
|
): ResponseInterface {
|
||||||
|
$view = Twig::fromRequest($request);
|
||||||
|
$pageOptions = [];
|
||||||
|
$template = '';
|
||||||
|
if (Setup::status()) {
|
||||||
|
switch (isset($args['second']) ? $args['second'] : 'index') {
|
||||||
|
case 'settings':
|
||||||
|
if (Session::active()) {
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$themes = (new Themes())->getThemes(); // $config->getThemes();
|
||||||
|
$template = 'dash/settings.twig';
|
||||||
|
$member = Session::get('member');
|
||||||
|
$form_token = Session::get('form_token');
|
||||||
|
$updated = new Carbon($settings['global']['last_backup']);
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => 'Settings',
|
||||||
|
'private' => $settings['global']['private'],
|
||||||
|
'renderOnSave' => $settings['global']['renderOnSave'],
|
||||||
|
'background' => $settings['global']['background'],
|
||||||
|
'member' => $member,
|
||||||
|
'ftoken' => $form_token,
|
||||||
|
'siteTitle' => $settings['global']['title'],
|
||||||
|
'baseUrl' => $settings['global']['base_url'],
|
||||||
|
'desc' => $settings['global']['descriptions'],
|
||||||
|
'lastBackup' => $updated->format('Y M D d'),
|
||||||
|
'currentTheme' => $settings['global']['theme'],
|
||||||
|
'themes' => $themes,
|
||||||
|
'apiStatus' => isset($settings['global']['externalAPI'])
|
||||||
|
? $settings['global']['externalAPI']
|
||||||
|
: 'false',
|
||||||
|
'dynamicRenderStatus' => isset(
|
||||||
|
$settings['global']['dynamicRender']
|
||||||
|
)
|
||||||
|
? $settings['global']['dynamicRender']
|
||||||
|
: 'false',
|
||||||
|
'mailOption' => $settings['email']['active'],
|
||||||
|
'mailConfig' => $settings['email'],
|
||||||
|
'status' => Session::active(),
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
header('Location: /dashboard');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'navigation':
|
||||||
|
if (Session::active()) {
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$template = 'dash/navigation.twig';
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => 'Edit Menu',
|
||||||
|
'status' => Session::active(),
|
||||||
|
'menu' => $settings['menu'],
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
header('Location: /dashboard');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'pages':
|
||||||
|
if (Session::active()) {
|
||||||
|
$currentPage = isset($args['fourth']) ? $args['fourth'] : 1;
|
||||||
|
$filter = isset($args['third']) ? $args['third'] : 'all';
|
||||||
|
$data = (new Book())->getPages($currentPage, 4, $filter);
|
||||||
|
$template = 'dash/book.twig';
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => 'Contents',
|
||||||
|
'entryCount' => $data['entryCount'],
|
||||||
|
'numOfPages' => $data['numOfPages'],
|
||||||
|
'currentPage' => $currentPage,
|
||||||
|
'filter' => $data['paginate']['sort'],
|
||||||
|
'stats' => $data['stats'],
|
||||||
|
'pages' => $data['pages'],
|
||||||
|
'paginate' => $data['paginate'],
|
||||||
|
'status' => Session::active(),
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
header('Location: /dashboard');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'page':
|
||||||
|
if (Session::active()) {
|
||||||
|
$template = 'dash/page-edit.twig';
|
||||||
|
$mode = $args['third'];
|
||||||
|
$uuid = $args['fourth'];
|
||||||
|
|
||||||
|
switch ($mode) {
|
||||||
|
case 'edit':
|
||||||
|
$page = (new Book())->findPageById($uuid);
|
||||||
|
$views = [];
|
||||||
|
if (!isset($page['layout'])) {
|
||||||
|
$page['layout'] = "page";
|
||||||
|
}
|
||||||
|
if (str_contains($page['layout'], 'index')) {
|
||||||
|
$views = (new Themes())->getCustomIndex();
|
||||||
|
} else {
|
||||||
|
$views = (new Themes())->getCustomViews();
|
||||||
|
}
|
||||||
|
$imageList = [];
|
||||||
|
$fileList = [];
|
||||||
|
if (isset($page['feature'])) {
|
||||||
|
$imageList = explode(',', $page['feature']);
|
||||||
|
}
|
||||||
|
if (isset($page['files'])) {
|
||||||
|
$fileList = explode(',', $page['files']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$images = [];
|
||||||
|
$files = [];
|
||||||
|
foreach ($imageList as $item) {
|
||||||
|
$image = trim($item);
|
||||||
|
if (!empty($image)) {
|
||||||
|
array_push($images, $image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($fileList as $item) {
|
||||||
|
$file = trim($item);
|
||||||
|
if (!empty($file)) {
|
||||||
|
array_push($files, $file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => $page['title'],
|
||||||
|
'page' => $page,
|
||||||
|
'mode' => $mode,
|
||||||
|
'token' => Session::get('form_token'),
|
||||||
|
'status' => Session::active(),
|
||||||
|
'images' => $images,
|
||||||
|
'files' => $files,
|
||||||
|
'views' => $views,
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'preview':
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$loader = new \Twig\Loader\FilesystemLoader(
|
||||||
|
'../content/themes/' . $settings['global']['theme'] .
|
||||||
|
'/'
|
||||||
|
);
|
||||||
|
$display = new \Twig\Environment($loader, []);
|
||||||
|
|
||||||
|
$book = new Book();
|
||||||
|
$page = $book->findPageById($uuid);
|
||||||
|
$pageOptions = Sorting::page($page);
|
||||||
|
$preview = $page['layout'] .
|
||||||
|
'.twig';
|
||||||
|
$html = $display->render($preview, $pageOptions);
|
||||||
|
$response->getBody()->write($html);
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => 'Fipamo | Create Page',
|
||||||
|
'token' => Session::get('form_token'),
|
||||||
|
'mode' => $mode,
|
||||||
|
'status' => Session::active(),
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
header('Location: /dashboard');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'logout':
|
||||||
|
Session::kill();
|
||||||
|
header('Location: /dashboard');
|
||||||
|
exit();
|
||||||
|
break;
|
||||||
|
case 'reset-password':
|
||||||
|
$template = 'dash/reset-password.twig';
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => 'Reset Password',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$template = 'dash/start.twig';
|
||||||
|
if (Session::active()) {
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => 'Start',
|
||||||
|
'status' => Session::active(),
|
||||||
|
'data' => (new Book())->getPages(1, 4),
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => 'Welcome to Fipamo',
|
||||||
|
'status' => Session::active(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$template = 'dash/init.twig';
|
||||||
|
$pageOptions = ['title' => 'Fipamo Setup'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $view->render($response, $template, $pageOptions);
|
||||||
|
}
|
||||||
|
}
|
110
brain/controller/IndexControl.php
Normal file
110
brain/controller/IndexControl.php
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\controller;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Slim\Views\Twig;
|
||||||
|
use brain\data\Settings;
|
||||||
|
use brain\utility\Sorting;
|
||||||
|
|
||||||
|
use function _\find;
|
||||||
|
|
||||||
|
class IndexControl
|
||||||
|
{
|
||||||
|
public static function start(
|
||||||
|
ServerRequestInterface $request,
|
||||||
|
ResponseInterface $response,
|
||||||
|
array $args
|
||||||
|
): ResponseInterface {
|
||||||
|
//unset($_SESSION);
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$view = Twig::fromRequest($request);
|
||||||
|
//checks dynamic render flag for site render status
|
||||||
|
if ($settings['global']['dynamicRender']) {
|
||||||
|
if ($settings['global']['dynamicRender'] == 'true') {
|
||||||
|
$loader = new \Twig\Loader\FilesystemLoader('../content/themes');
|
||||||
|
$display = new \Twig\Environment($loader, []);
|
||||||
|
$template = '';
|
||||||
|
$pageOptions = [];
|
||||||
|
|
||||||
|
$pageInfo = [
|
||||||
|
'keywords' => isset($settings['global']['keywords'])
|
||||||
|
? $settings['global']['keywords']
|
||||||
|
: 'fipamo, blog, jamstack, php, markdown, js',
|
||||||
|
'description' => $settings['global']['descriptions'],
|
||||||
|
'image' => $settings['global']['base_url'] . $settings['global']['background'],
|
||||||
|
'baseURL' => $settings['global']['base_url'],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isset($args['first'])) {
|
||||||
|
switch ($args['first']) {
|
||||||
|
case 'tags':
|
||||||
|
$template = $settings['global']['theme'] . '/tags.twig';
|
||||||
|
$tag = trim($args['second']);
|
||||||
|
$taglist = Sorting::tags();
|
||||||
|
$item = find($taglist, ['tag_name' => $tag]);
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => 'Pages Tagged as ' . $item['tag_name'],
|
||||||
|
'background' => $pageInfo['image'],
|
||||||
|
'tag_list' => $item['pages'],
|
||||||
|
'info' => $pageInfo,
|
||||||
|
'menu' => $settings['menu'],
|
||||||
|
'dynamicRender' => $settings['global']['dynamicRender'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'archives':
|
||||||
|
$archive = Sorting::archive();
|
||||||
|
$template = $settings['global']['theme'] . '/archive.twig';
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => 'Archive',
|
||||||
|
'background' => $pageInfo['image'],
|
||||||
|
'archives' => $archive,
|
||||||
|
'info' => $pageInfo,
|
||||||
|
'menu' => $settings['menu'],
|
||||||
|
'dynamicRender' => $settings['global']['dynamicRender'],
|
||||||
|
];
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//check if page is a menu item, if not render along path as usual
|
||||||
|
$page = [];
|
||||||
|
$book = new Book();
|
||||||
|
if (is_numeric($args['first'])) {
|
||||||
|
$page = $book->findPageBySlug($args['third']);
|
||||||
|
} else {
|
||||||
|
$page = $book->findPageBySlug($args['first']);
|
||||||
|
}
|
||||||
|
$template = $settings['global']['theme'] . '/' . $page['layout'] . '.twig';
|
||||||
|
$pageOptions = Sorting::page($page);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//index
|
||||||
|
$template = $settings['global']['theme'] . '/' . $page['layout'] . '.twig';
|
||||||
|
$book = new Book('');
|
||||||
|
$page = $book->findPageBySlug();
|
||||||
|
$pageOptions = Sorting::page($page);
|
||||||
|
}
|
||||||
|
|
||||||
|
$html = $display->render($template, $pageOptions);
|
||||||
|
$response->getBody()->write($html);
|
||||||
|
return $response;
|
||||||
|
} else {
|
||||||
|
//if dynamic flag is false, load up html
|
||||||
|
$view = Twig::fromRequest($request);
|
||||||
|
$html = file_get_contents('../public/index.html');
|
||||||
|
$response->getBody()->write($html);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//if flag is not present, default to static html
|
||||||
|
$view = Twig::fromRequest($request);
|
||||||
|
$html = file_get_contents('../public/index.html');
|
||||||
|
$response->getBody()->write($html);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
brain/controller/RouteControl.php
Normal file
47
brain/controller/RouteControl.php
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\controller;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
class RouteControl
|
||||||
|
{
|
||||||
|
//TODO: Add additional HTTP Methods to better organize API control paths
|
||||||
|
public function get(
|
||||||
|
ServerRequestInterface $request,
|
||||||
|
ResponseInterface $response,
|
||||||
|
array $args
|
||||||
|
): ResponseInterface {
|
||||||
|
switch (isset($args['first']) ? $args['first'] : 'index') {
|
||||||
|
case 'dashboard':
|
||||||
|
return DashControl::start($request, $response, $args);
|
||||||
|
break;
|
||||||
|
case 'api':
|
||||||
|
return APIControl::get($request, $response, $args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return IndexControl::start($request, $response, $args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function post(
|
||||||
|
ServerRequestInterface $request,
|
||||||
|
ResponseInterface $response,
|
||||||
|
array $args
|
||||||
|
): ResponseInterface {
|
||||||
|
switch (isset($args['first']) ? $args['first'] : 'index') {
|
||||||
|
case 'api':
|
||||||
|
return APIControl::post($request, $response, $args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result = [
|
||||||
|
'message' => "Nothing matches this route. That's unfortunate",
|
||||||
|
'type' => 'TASK_NONE',
|
||||||
|
];
|
||||||
|
$response->getBody()->write(json_encode($result));
|
||||||
|
return $response->withHeader('Content-Type', 'application/json');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
154
brain/data/Auth.php
Normal file
154
brain/data/Auth.php
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\data;
|
||||||
|
|
||||||
|
use ReallySimpleJWT\Token;
|
||||||
|
|
||||||
|
use function _\find;
|
||||||
|
|
||||||
|
class Auth
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function sessionStatus()
|
||||||
|
{
|
||||||
|
if (isset($_SESSION['member'])) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//return $this->secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function status()
|
||||||
|
{
|
||||||
|
$result = '';
|
||||||
|
if (Session::active()) {
|
||||||
|
$result = true;
|
||||||
|
} else {
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function login($who)
|
||||||
|
{
|
||||||
|
//grab member list
|
||||||
|
$folks = (new Settings())->getFolks();
|
||||||
|
$found = find($folks, ['handle' => $who['handle']]);
|
||||||
|
|
||||||
|
if ($found) {
|
||||||
|
//name is found, verify password
|
||||||
|
if (password_verify($who['password'], $found['password'])) {
|
||||||
|
$member = [
|
||||||
|
'handle' => $found['handle'],
|
||||||
|
'email' => $found['email'],
|
||||||
|
'role' => $found['role'],
|
||||||
|
'avatar' => $found['avi'],
|
||||||
|
'key' => $found['key'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$token = Token::create(
|
||||||
|
$found['key'],
|
||||||
|
$found['secret'],
|
||||||
|
time() + 3600,
|
||||||
|
'localhost'
|
||||||
|
); //expires in an hour
|
||||||
|
|
||||||
|
$form_token = md5(uniqid(microtime(), true));
|
||||||
|
Session::start();
|
||||||
|
Session::set('member', $member);
|
||||||
|
Session::set('token', $token);
|
||||||
|
Session::set('form_token', $form_token);
|
||||||
|
|
||||||
|
$result = 'good_login';
|
||||||
|
} else {
|
||||||
|
$result = 'bad_pass';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//if name is not found
|
||||||
|
$result = 'no_name';
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function findSecret($data)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
$folks = (new Settings())->getFolks();
|
||||||
|
|
||||||
|
if (!empty($data['email']) && filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$found = find($folks, ['email' => $data['email']]);
|
||||||
|
if ($found) {
|
||||||
|
//if email is cool, check mail relay status
|
||||||
|
//if set up, send secret there, if not just return it
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$email = $settings['email']['active'];
|
||||||
|
if ($email != 'option-none') {
|
||||||
|
$data['mail_task'] = 'SEND_SECRET';
|
||||||
|
$data['secret'] = $found['secret'];
|
||||||
|
$result = Mailer::sendmail($data);
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'Valid email, but no email set up!',
|
||||||
|
'type' => 'secretFound',
|
||||||
|
'secret' => $found['secret'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'No valid email, no goodies, pleighboi',
|
||||||
|
'type' => 'secretNotFound',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'Aye, this address is not right, slick.',
|
||||||
|
'type' => 'secretNotFound',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function makeNewPassword($data)
|
||||||
|
{
|
||||||
|
//check if passwordsmatch
|
||||||
|
if ($data['newPass'] == $data['newPassConfirm']) {
|
||||||
|
//verify secret
|
||||||
|
$folks = (new Settings())->getFolks();
|
||||||
|
$found = find($folks, ['secret' => $data['secret']]);
|
||||||
|
if ($found) {
|
||||||
|
//create new pass and secret key, then update file
|
||||||
|
$hash = password_hash($data['newPass'], PASSWORD_DEFAULT);
|
||||||
|
$freshSecret = StringTools::randomString(12);
|
||||||
|
Member::updateData('password', $hash, $data['secret']);
|
||||||
|
Member::updateData('secret', $freshSecret, $data['secret']);
|
||||||
|
$result = [
|
||||||
|
'message' => 'Password Updated. Very nice!',
|
||||||
|
'type' => 'passCreated',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => 'Secret key is invalid. Try to retrieve it again',
|
||||||
|
'type' => 'passNotCreated',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'message' => "Passwords don't match. Try it again.",
|
||||||
|
'type' => 'passNotCreated',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function logout()
|
||||||
|
{
|
||||||
|
Session::kill();
|
||||||
|
}
|
||||||
|
}
|
230
brain/data/Book.php
Normal file
230
brain/data/Book.php
Normal file
|
@ -0,0 +1,230 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\data;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use brain\utility\DocTools;
|
||||||
|
use brain\utility\StringTools;
|
||||||
|
|
||||||
|
use function _\find;
|
||||||
|
use function _\filter;
|
||||||
|
|
||||||
|
class Book
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findPageById(string $uuid)
|
||||||
|
{
|
||||||
|
$content = $this->getContents();
|
||||||
|
$page = find($content, ['uuid' => $uuid]);
|
||||||
|
|
||||||
|
return $page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findPageBySlug(string $slug = null)
|
||||||
|
{
|
||||||
|
$content = $this->getContents();
|
||||||
|
if (isset($slug)) {
|
||||||
|
$page = find($content, ['slug' => $slug]);
|
||||||
|
} else {
|
||||||
|
$page = find($content, ['layout' => 'index']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function editPage($task, $request)
|
||||||
|
{
|
||||||
|
$content = $this->getContents();
|
||||||
|
$body = json_decode(file_get_contents("php://input"), true);
|
||||||
|
//$body = find($content, ["uuid" => $parsed["id"]]);
|
||||||
|
|
||||||
|
$page = find($content, ['uuid' => $body['uuid']]);
|
||||||
|
$files = $request->getUploadedFiles();
|
||||||
|
|
||||||
|
$member = Session::get('member');
|
||||||
|
|
||||||
|
if ($task != 'create') {
|
||||||
|
$path = date('Y', date($page['rawCreated'])) .
|
||||||
|
'/' .
|
||||||
|
date('m', date($page['rawCreated']));
|
||||||
|
} else {
|
||||||
|
$path = date('Y') . '/' . date('m');
|
||||||
|
}
|
||||||
|
|
||||||
|
$page_feature = '';
|
||||||
|
$page_files = '';
|
||||||
|
|
||||||
|
if ($task == 'delete') {
|
||||||
|
$deleted = 'true';
|
||||||
|
$body['menu'] = 'false';
|
||||||
|
$body['published'] = 'false';
|
||||||
|
$body['featured'] = 'false';
|
||||||
|
} else {
|
||||||
|
$deleted = isset($page['deleted']) ? $page['deleted'] : 'false';
|
||||||
|
}
|
||||||
|
|
||||||
|
$created = $task != 'create' ? new Carbon($page['rawCreated']) : Carbon::now();
|
||||||
|
$updated = Carbon::now();
|
||||||
|
|
||||||
|
// grab current index from settings and update
|
||||||
|
$id = $task != 'create' ? $body['id'] : Settings::getCurrentIndex();
|
||||||
|
$uuid = $task != 'create' ? $body['uuid'] : StringTools::createUUID();
|
||||||
|
// now that variables are done, set to body object and then convert to markdown to save
|
||||||
|
|
||||||
|
$body['id'] = $id;
|
||||||
|
$body['uuid'] = $uuid;
|
||||||
|
//$body['feature'] = $page_feature;
|
||||||
|
//$body['files'] = $page_files;
|
||||||
|
$body['path'] = $path;
|
||||||
|
$body['author'] = $member['handle'];
|
||||||
|
$body['created'] = $created->format("Y-m-d\TH:i:sP");
|
||||||
|
$body['updated'] = $updated->format("Y-m-d\TH:i:sP");
|
||||||
|
$body['deleted'] = $deleted;
|
||||||
|
|
||||||
|
$write = DocTools::objectToMD($body);
|
||||||
|
|
||||||
|
// if layout is index, change path to file
|
||||||
|
|
||||||
|
if ($body['layout'] == 'index') {
|
||||||
|
$writePath = '../content/pages/start/index.md';
|
||||||
|
} else {
|
||||||
|
$writePath = '../content/pages/' . $path . '/' . $body['slug'] . '.md';
|
||||||
|
}
|
||||||
|
|
||||||
|
$status = DocTools::writePages($task, $path, $writePath, $write);
|
||||||
|
|
||||||
|
if ($status) {
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$message = '';
|
||||||
|
|
||||||
|
if (
|
||||||
|
$settings['global']['renderOnSave'] == 'true' &&
|
||||||
|
$settings['global']['dynamicRender'] == 'false'
|
||||||
|
) {
|
||||||
|
$render = new Render();
|
||||||
|
$render->renderTags();
|
||||||
|
$render->renderArchive();
|
||||||
|
$render->renderPages();
|
||||||
|
$message = 'Filed edited and rendered. NOICE.';
|
||||||
|
} else {
|
||||||
|
$message = 'File edited. Nice work';
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'message' => $message,
|
||||||
|
'type' => $task == 'write' ? 'postUpdated' : 'postAdded',
|
||||||
|
'id' => $uuid,
|
||||||
|
];
|
||||||
|
|
||||||
|
// TODO: When form submission is successful, make new form token
|
||||||
|
// Session token doesn't reset on the front end, so turning this off for now
|
||||||
|
// $form_token = md5(uniqid(microtime(), true));
|
||||||
|
// Session::set("form_token", $form_token);
|
||||||
|
|
||||||
|
// once saved, update menu
|
||||||
|
$body['path'] = $path;
|
||||||
|
Settings::updateMenu($body);
|
||||||
|
Settings::updateTags();
|
||||||
|
// if new page added, update current index in Settings file
|
||||||
|
if ($task == 'create') {
|
||||||
|
Settings::updateIndex();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response = [
|
||||||
|
'message' => "Uh oh. File save problem. Don't panic",
|
||||||
|
'type' => 'postError',
|
||||||
|
'id' => $uuid,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPages(int $page, int $limit, string $sort = null)
|
||||||
|
{
|
||||||
|
$content = $this->getContents();
|
||||||
|
|
||||||
|
$published = filter($content, function ($item) {
|
||||||
|
return $item['published'] == true && $item['deleted'] == false;
|
||||||
|
});
|
||||||
|
$deleted = filter($content, function ($item) {
|
||||||
|
return $item['deleted'] == true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// $all = $content;
|
||||||
|
$all = filter($content, function ($item) {
|
||||||
|
return $item['deleted'] == false;
|
||||||
|
});
|
||||||
|
$filter = isset($sort) ? $sort : 'all';
|
||||||
|
switch ($filter) {
|
||||||
|
case 'published':
|
||||||
|
$filtered = $published;
|
||||||
|
break;
|
||||||
|
case 'deleted':
|
||||||
|
$filtered = $deleted;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$filtered = $all;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$numOfPages = ceil(count($filtered) / ($limit + 1));
|
||||||
|
$folder = [];
|
||||||
|
|
||||||
|
if (count($filtered) != 0) {
|
||||||
|
if (count($filtered) < $limit) {
|
||||||
|
$limit = count($filtered) - 1;
|
||||||
|
}
|
||||||
|
$range = $page * $limit - $limit;
|
||||||
|
|
||||||
|
if ($range != 0) {
|
||||||
|
$range = $range + 1;
|
||||||
|
}
|
||||||
|
for ($i = 0; $i <= $limit; ++$i) {
|
||||||
|
if (isset($filtered[$i + $range])) {
|
||||||
|
array_push($folder, $filtered[$i + $range]);
|
||||||
|
} else {
|
||||||
|
// chill out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$prev = $page - 1;
|
||||||
|
if ($prev <= 0) {
|
||||||
|
$prev = $numOfPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
$next = $page + 1;
|
||||||
|
if ($next > $numOfPages) {
|
||||||
|
$next = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'pages' => $folder,
|
||||||
|
'numOfPages' => $numOfPages,
|
||||||
|
'entryCount' => count($filtered),
|
||||||
|
'paginate' => [
|
||||||
|
'sort' => $sort,
|
||||||
|
'nextPage' => $next,
|
||||||
|
'prevPage' => $prev,
|
||||||
|
],
|
||||||
|
'stats' => [
|
||||||
|
'all' => count($all),
|
||||||
|
'published' => count($published),
|
||||||
|
'deleted' => count($deleted),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContents()
|
||||||
|
{
|
||||||
|
// test new contents data class
|
||||||
|
// $new = (new Contents("../content/pages"))->getAll();
|
||||||
|
$contents = (new Contents('../content/pages'))->getAll();
|
||||||
|
|
||||||
|
return $contents;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,34 +1,38 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Data;
|
namespace brain\data;
|
||||||
|
|
||||||
|
use HtmlSanitizer\SanitizerBuilder;
|
||||||
use League\CommonMark\MarkdownConverter;
|
use League\CommonMark\MarkdownConverter;
|
||||||
use League\CommonMark\Environment\Environment;
|
use League\CommonMark\Environment\Environment;
|
||||||
|
use HtmlSanitizer\Extension\Basic\BasicExtension;
|
||||||
|
use HtmlSanitizer\Extension\Listing\ListExtension;
|
||||||
|
use HtmlSanitizer\Extension\Iframe\IframeExtension;
|
||||||
use League\CommonMark\Extension\Table\TableExtension;
|
use League\CommonMark\Extension\Table\TableExtension;
|
||||||
use League\CommonMark\Extension\Attributes\AttributesExtension;
|
use League\CommonMark\Extension\Attributes\AttributesExtension;
|
||||||
use League\CommonMark\Extension\FrontMatter\FrontMatterExtension;
|
use League\CommonMark\Extension\FrontMatter\FrontMatterExtension;
|
||||||
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
|
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
|
||||||
use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
|
use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
|
||||||
use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter;
|
use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter;
|
||||||
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
|
|
||||||
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
|
|
||||||
|
|
||||||
class ContentService
|
use function _\orderBy;
|
||||||
{
|
|
||||||
protected $files = [];
|
|
||||||
protected $config = [];
|
|
||||||
|
|
||||||
public function __construct()
|
class Contents
|
||||||
{
|
{
|
||||||
$this->loadPages(env('PAGES_PATH'));
|
public $files = [];
|
||||||
|
public $config = [];
|
||||||
|
|
||||||
|
public function __construct($folder)
|
||||||
|
{
|
||||||
|
$this->read($folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadPages($folder)
|
public function read($folder)
|
||||||
{
|
{
|
||||||
$folders = glob("$folder/*", GLOB_ONLYDIR);
|
$folders = glob("$folder/*", GLOB_ONLYDIR);
|
||||||
foreach ($folders as $folder) {
|
foreach ($folders as $folder) {
|
||||||
//$this->files[] = $folder . "/";
|
//$this->files[] = $folder . "/";
|
||||||
$this->loadPages($folder);
|
$this->read($folder);
|
||||||
}
|
}
|
||||||
$files = array_filter(glob("$folder/*md"), 'is_file');
|
$files = array_filter(glob("$folder/*md"), 'is_file');
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
@ -36,7 +40,7 @@ class ContentService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadAllPages()
|
public function getAll()
|
||||||
{
|
{
|
||||||
$environment = new Environment($this->config);
|
$environment = new Environment($this->config);
|
||||||
$environment->addExtension(new CommonMarkCoreExtension());
|
$environment->addExtension(new CommonMarkCoreExtension());
|
||||||
|
@ -72,21 +76,39 @@ class ContentService
|
||||||
->parse(file_get_contents($file));
|
->parse(file_get_contents($file));
|
||||||
|
|
||||||
//never trust the front end. clean it up
|
//never trust the front end. clean it up
|
||||||
|
//add what sanitizer extensions we need manually
|
||||||
|
$builder = new SanitizerBuilder();
|
||||||
|
$builder->registerExtension(new BasicExtension());
|
||||||
|
$builder->registerExtension(new IframeExtension());
|
||||||
|
$builder->registerExtension(new ListExtension());
|
||||||
|
//just add it straight because classname is already in use
|
||||||
|
$builder->registerExtension(new \HtmlSanitizer\Extension\Table\TableExtension());
|
||||||
|
|
||||||
$soap = (new HtmlSanitizerConfig())
|
//relative-a and relative-image
|
||||||
// Allow "safe" elements and attributes. All scripts will be removed
|
$builder->registerExtension(
|
||||||
// as well as other dangerous behaviors like CSS injection
|
new \HtmlSanitizer\Extension\Relative\A\AExtension()
|
||||||
->allowSafeElements()
|
);
|
||||||
->allowElement('div', ['class', 'title', 'id', 'style'])
|
$builder->registerExtension(
|
||||||
->allowElement('img', ['src', 'alt', 'title', 'class'])
|
new \HtmlSanitizer\Extension\Relative\Image\ImageExtension()
|
||||||
->allowElement('iframe', ['height', 'width', 'title', 'src'])
|
);
|
||||||
->allowElement('table')
|
|
||||||
->allowElement('li')
|
|
||||||
->allowRelativeMedias()
|
|
||||||
->allowRelativeLinks();
|
|
||||||
|
|
||||||
$laundry = new HtmlSanitizer($soap);
|
$detergent = [
|
||||||
$scrubbed = $laundry->sanitize($result->getContent());
|
'extensions' => ['basic', 'list', 'relative-a', 'relative-image', 'iframe', 'table'],
|
||||||
|
'tags' => [
|
||||||
|
'div' => [
|
||||||
|
'allowed_attributes' => ['class', 'title', 'id', 'style'],
|
||||||
|
],
|
||||||
|
'img' => [
|
||||||
|
'allowed_attributes' => ['src', 'alt', 'title', 'class'],
|
||||||
|
],
|
||||||
|
'iframe' => [
|
||||||
|
'allowed_attributes' => ['height', 'width', 'title', 'src'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$sanitizer = $builder->build($detergent);
|
||||||
|
$scrubbed = $sanitizer->sanitize($result->getContent());
|
||||||
if (isset($meta['feature'])) {
|
if (isset($meta['feature'])) {
|
||||||
$featureList = explode(',', $meta['feature']);
|
$featureList = explode(',', $meta['feature']);
|
||||||
} else {
|
} else {
|
||||||
|
@ -165,16 +187,7 @@ class ContentService
|
||||||
array_push($contents, $page);
|
array_push($contents, $page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$collection = collect($contents);
|
$contents = orderBy($contents, ['id'], ['desc']);
|
||||||
$sorted = $collection->sortBy([
|
return $contents;
|
||||||
['id', 'desc'],
|
|
||||||
]);
|
|
||||||
$sorted->values()->all();
|
|
||||||
return $sorted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getAll()
|
|
||||||
{
|
|
||||||
echo("YES");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
61
brain/data/Member.php
Normal file
61
brain/data/Member.php
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\data;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use brain\utility\DocTools;
|
||||||
|
|
||||||
|
use function _\find;
|
||||||
|
|
||||||
|
class Member
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function verifyKey(string $key)
|
||||||
|
{
|
||||||
|
if (isset($key)) {
|
||||||
|
$folks = (new Settings())->getFolks();
|
||||||
|
$found = find($folks, ['key' => $key]);
|
||||||
|
if ($found) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateData(string $key, string $data, $secret = null)
|
||||||
|
{
|
||||||
|
$folks = (new Settings())->getFolks();
|
||||||
|
if (isset($secret)) {
|
||||||
|
$found = find($folks, ['secret' => $secret]);
|
||||||
|
} else {
|
||||||
|
$member = Session::get('member');
|
||||||
|
$found = find($folks, ['handle' => $member['handle']]);
|
||||||
|
}
|
||||||
|
$found[$key] = $data;
|
||||||
|
//record time updated
|
||||||
|
$updated = Carbon::now();
|
||||||
|
$found['updated'] = $updated->format("Y-m-d\TH:i:sP");
|
||||||
|
$newFolks = [];
|
||||||
|
array_push($newFolks, $found);
|
||||||
|
//save updated file
|
||||||
|
DocTools::writeSettings('../config/folks.json', $newFolks);
|
||||||
|
//update member data in session
|
||||||
|
|
||||||
|
if (!isset($secret)) {
|
||||||
|
$member = [
|
||||||
|
'handle' => $found['handle'],
|
||||||
|
'email' => $found['email'],
|
||||||
|
'role' => $found['role'],
|
||||||
|
'avatar' => $found['avi'],
|
||||||
|
'key' => $found['key'],
|
||||||
|
];
|
||||||
|
Session::set('member', $member);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
204
brain/data/Render.php
Normal file
204
brain/data/Render.php
Normal file
|
@ -0,0 +1,204 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\data;
|
||||||
|
|
||||||
|
use brain\utility\Sorting;
|
||||||
|
use brain\utility\DocTools;
|
||||||
|
|
||||||
|
use function _\find;
|
||||||
|
|
||||||
|
class Render
|
||||||
|
{
|
||||||
|
public $loader;
|
||||||
|
public $twig;
|
||||||
|
public $pageInfo;
|
||||||
|
public $menu;
|
||||||
|
public $background;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$config = new Settings();
|
||||||
|
//TODO: Add theme folder to loader
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$this->menu = $settings['menu'];
|
||||||
|
$this->theme = $settings['global']['theme'];
|
||||||
|
$this->loader = new \Twig\Loader\FilesystemLoader('../content/themes/' . $this->theme);
|
||||||
|
$this->twig = new \Twig\Environment($this->loader, []);
|
||||||
|
$this->pageInfo = [
|
||||||
|
'keywords' => isset($settings['global']['keywords'])
|
||||||
|
? $settings['global']['keywords']
|
||||||
|
: 'fipamo, blog, jamstack, php, markdown, js',
|
||||||
|
'description' => $settings['global']['descriptions'],
|
||||||
|
'image' => $settings['global']['base_url'] . $settings['global']['background'],
|
||||||
|
'baseURL' => $settings['global']['base_url'],
|
||||||
|
];
|
||||||
|
//move global theme image assets to public folder
|
||||||
|
foreach (
|
||||||
|
new \DirectoryIterator('../content/themes/' . $this->theme . '/assets/images/global/') as $file
|
||||||
|
) {
|
||||||
|
if ($file->isDot()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!is_file('../public/assets/images/global/' . $file->getFileName())) {
|
||||||
|
copy(
|
||||||
|
'../content/themes/' .
|
||||||
|
$this->theme .
|
||||||
|
'/assets/images/global/' .
|
||||||
|
$file->getFileName(),
|
||||||
|
'../public/assets/images/global/' . $file->getFileName()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
//image is already there, so chill
|
||||||
|
}
|
||||||
|
//print $file->getFilename() . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//copy current theme assets to public
|
||||||
|
|
||||||
|
//clear files in css and scripts folder
|
||||||
|
$styles = glob('../public/assets/css/*'); // get all file names
|
||||||
|
foreach ($styles as $file) { // iterate files
|
||||||
|
if (is_file($file)) {
|
||||||
|
//don't erase dashboard css
|
||||||
|
if (!$file == '../public/assets/css/dash.css') {
|
||||||
|
unlink($file); // delete file
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$scripts = glob('../public/assets/scripts/*'); // get all file names
|
||||||
|
foreach ($scripts as $file) { // iterate files
|
||||||
|
if (is_file($file)) {
|
||||||
|
if (!$file == '../public/assets/scripts/Start.js') {
|
||||||
|
unlink($file); // delete file
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//copy theme assets to public
|
||||||
|
$newcss = glob('../content/themes/' . $this->theme . '/assets/css/*');
|
||||||
|
foreach ($newcss as $file) { // iterate files
|
||||||
|
if (is_file($file)) {
|
||||||
|
$path = explode('/', $file);
|
||||||
|
copy($file, '../public/assets/css/' . $path[6]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$newjs = glob('../content/themes/' . $this->theme . '/assets/scripts/*');
|
||||||
|
foreach ($newjs as $file) { // iterate files
|
||||||
|
if (is_file($file)) {
|
||||||
|
$path = explode('/', $file);
|
||||||
|
copy($file, '../public/assets/scripts/' . $path[6]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderPages()
|
||||||
|
{
|
||||||
|
$pages = (new Book())->getContents();
|
||||||
|
$recent = [];
|
||||||
|
$featured = [];
|
||||||
|
$limit = 4;
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
$pageOptions = Sorting::page($page);
|
||||||
|
|
||||||
|
$layout = $page['layout'];
|
||||||
|
//new pages have no layout, so defautl for now
|
||||||
|
if ($layout == '' || $layout == null) {
|
||||||
|
$layout = 'page';
|
||||||
|
}
|
||||||
|
|
||||||
|
$template = $layout . '.twig';
|
||||||
|
if (str_contains($layout, 'index')) {
|
||||||
|
$location = '../public/index.html';
|
||||||
|
$dir = null;
|
||||||
|
} else {
|
||||||
|
// if page is a menu item, render the page on public root
|
||||||
|
if ($page['menu'] == 'true') {
|
||||||
|
$location = '../public/' . $page['slug'] . '.html';
|
||||||
|
$dir = '../public/';
|
||||||
|
} else {
|
||||||
|
$location = '../public/' . $page['path'] . '/' . $page['slug'] . '.html';
|
||||||
|
$dir = '../public/' . $page['path'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$html = $this->twig->render($template, $pageOptions);
|
||||||
|
DocTools::writeHTML($location, $html, $dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderArchive()
|
||||||
|
{
|
||||||
|
$archive = Sorting::archive();
|
||||||
|
$template = 'archive.twig';
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => 'Archive',
|
||||||
|
'background' => $this->pageInfo['image'],
|
||||||
|
'archives' => $archive,
|
||||||
|
'info' => $this->pageInfo,
|
||||||
|
'menu' => $this->menu,
|
||||||
|
'media' => [['file' => $this->pageInfo['image'], 'type' => trim(pathinfo($this->pageInfo['image'], PATHINFO_EXTENSION))]],
|
||||||
|
];
|
||||||
|
|
||||||
|
$html = $this->twig->render($template, $pageOptions);
|
||||||
|
$location = '../public/archives.html';
|
||||||
|
DocTools::writeHTML($location, $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderTags()
|
||||||
|
{
|
||||||
|
$list = Sorting::tags();
|
||||||
|
foreach ($list as $item) {
|
||||||
|
$template = 'tags.twig';
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => 'Pages Tagged as ' . $item['tag_name'],
|
||||||
|
'background' => $this->pageInfo['image'],
|
||||||
|
'tag_list' => $item['pages'],
|
||||||
|
'info' => $this->pageInfo,
|
||||||
|
'menu' => $this->menu,
|
||||||
|
'media' => [['file' => $this->pageInfo['image'], 'type' => trim(pathinfo($this->pageInfo['image'], PATHINFO_EXTENSION))]],
|
||||||
|
];
|
||||||
|
|
||||||
|
$html = $this->twig->render($template, $pageOptions);
|
||||||
|
|
||||||
|
$location = '../public/tags/' . $item['slug'] . '.html';
|
||||||
|
|
||||||
|
//if tags folder doesn't exist, make it
|
||||||
|
if (!is_dir('../public/tags')) {
|
||||||
|
mkdir('../public/tags', 0755, true);
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_file($location)) {
|
||||||
|
file_put_contents($location, $html);
|
||||||
|
} else {
|
||||||
|
($new = fopen($location, 'w')) or die('Unable to open file!');
|
||||||
|
fwrite($new, $html);
|
||||||
|
fclose($new);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderIndex()
|
||||||
|
{
|
||||||
|
//TODO: Need to fix this to account for new index templating system
|
||||||
|
$pages = (new Book())->getContents();
|
||||||
|
$index = find($pages, ['layout' => 'index']);
|
||||||
|
$template = 'index.twig';
|
||||||
|
$location = '../public/index.html';
|
||||||
|
$dir = null;
|
||||||
|
|
||||||
|
$meta = [
|
||||||
|
'who' => $index['author'],
|
||||||
|
'when' => $index['created'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => $index['title'],
|
||||||
|
'background' => $index['feature'],
|
||||||
|
'meta' => $meta,
|
||||||
|
];
|
||||||
|
|
||||||
|
$html = $this->twig->render($template, $pageOptions);
|
||||||
|
DocTools::writeHTML($location, $html, $dir);
|
||||||
|
}
|
||||||
|
}
|
93
brain/data/Session.php
Normal file
93
brain/data/Session.php
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\data;
|
||||||
|
|
||||||
|
use ReallySimpleJWT\Token;
|
||||||
|
|
||||||
|
class Session
|
||||||
|
{
|
||||||
|
private static $file = '../content/.session';
|
||||||
|
private static $data = [
|
||||||
|
'member' => '',
|
||||||
|
'token' => '',
|
||||||
|
'form_token' => '',
|
||||||
|
];
|
||||||
|
|
||||||
|
public static function start()
|
||||||
|
{
|
||||||
|
if (!is_file(self::$file)) {
|
||||||
|
file_put_contents(self::$file, json_encode(self::$data));
|
||||||
|
} else {
|
||||||
|
($new = fopen(self::$file, 'w')) or die('Unable to open file!');
|
||||||
|
fwrite($new, json_encode(self::$data));
|
||||||
|
fclose($new);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function active()
|
||||||
|
{
|
||||||
|
if (!is_file(self::$file)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
$data = json_decode(file_get_contents(self::$file), true);
|
||||||
|
if ($data['member'] != null) {
|
||||||
|
$secret = (new Settings())->getFolks('secret');
|
||||||
|
if ($secret == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (
|
||||||
|
Token::validate($data['token'], $secret) &&
|
||||||
|
Token::validateExpiration($data['token'], $secret)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function verifyToken($token)
|
||||||
|
{
|
||||||
|
$data = json_decode(file_get_contents(self::$file), true);
|
||||||
|
if ($data['member'] != null) {
|
||||||
|
$secret = (new Settings())->getFolks('secret');
|
||||||
|
if (
|
||||||
|
Token::validate($token, $secret) &&
|
||||||
|
Token::validateExpiration($token, $secret)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function set($key, $value)
|
||||||
|
{
|
||||||
|
$data = json_decode(file_get_contents(self::$file), true);
|
||||||
|
$data[$key] = $value;
|
||||||
|
($fresh = fopen(self::$file, 'w')) or die('Unable to open file!');
|
||||||
|
fwrite($fresh, json_encode($data));
|
||||||
|
fclose($fresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get($key)
|
||||||
|
{
|
||||||
|
$data = json_decode(file_get_contents(self::$file), true);
|
||||||
|
|
||||||
|
return $data[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function kill()
|
||||||
|
{
|
||||||
|
($fresh = fopen(self::$file, 'w')) or die('Unable to open file!');
|
||||||
|
fwrite($fresh, json_encode(self::$data));
|
||||||
|
fclose($fresh);
|
||||||
|
}
|
||||||
|
}
|
175
brain/data/Settings.php
Normal file
175
brain/data/Settings.php
Normal file
|
@ -0,0 +1,175 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\data;
|
||||||
|
|
||||||
|
use brain\utility\DocTools;
|
||||||
|
use brain\utility\Sorting;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
use function _\find;
|
||||||
|
use function _\pull;
|
||||||
|
use function _\remove;
|
||||||
|
|
||||||
|
class Settings
|
||||||
|
{
|
||||||
|
private $folks;
|
||||||
|
private static $tags;
|
||||||
|
private static $settings;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//gets all settings files and converts to php objects
|
||||||
|
$this->folks = json_decode(file_get_contents('../config/folks.json'), true);
|
||||||
|
self::$tags = json_decode(file_get_contents('../config/tags.json'), true);
|
||||||
|
self::$settings = json_decode(
|
||||||
|
file_get_contents('../config/settings.json'),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function sync($data)
|
||||||
|
{
|
||||||
|
$settings = self::$settings;
|
||||||
|
$settings['global']['base_url'] = $data['global']['base_url'];
|
||||||
|
$settings['global']['title'] = $data['global']['title'];
|
||||||
|
$settings['global']['descriptions'] = $data['global']['descriptions'];
|
||||||
|
$settings['global']['base_url'] = $data['global']['base_url'];
|
||||||
|
$settings['global']['private'] = $data['global']['private'];
|
||||||
|
$settings['global']['renderOnSave'] = $data['global']['renderOnSave'];
|
||||||
|
$settings['global']['theme'] = $data['global']['theme'];
|
||||||
|
$settings['global']['externalAPI'] = $data['global']['externalAPI'];
|
||||||
|
$settings['global']['dynamicRender'] = $data['global']['dynamicRender'];
|
||||||
|
|
||||||
|
Member::updateData('handle', $data['member']['handle']);
|
||||||
|
Member::updateData('email', $data['member']['email']);
|
||||||
|
|
||||||
|
$settings['email']['active'] = $data['email']['active'];
|
||||||
|
$settings['email']['smtp'] = $data['email']['smtp'];
|
||||||
|
$settings['email']['mailgun'] = $data['email']['mailgun'];
|
||||||
|
|
||||||
|
DocTools::writeSettings('../config/settings.json', $settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function navSync($data)
|
||||||
|
{
|
||||||
|
$settings = self::$settings;
|
||||||
|
|
||||||
|
$remove = $data['remove'];
|
||||||
|
//if remove contains id, find nav item page and set menu to false
|
||||||
|
if ($remove != null || $remove != '') {
|
||||||
|
$page = (new Book('../content/pages'))->findPageById($remove);
|
||||||
|
$page['menu'] = 'false';
|
||||||
|
$page['published']
|
||||||
|
? ($page['published'] = 'true')
|
||||||
|
: ($page['published'] = 'false');
|
||||||
|
$page['featured']
|
||||||
|
? ($page['featured'] = 'true')
|
||||||
|
: ($page['featured'] = 'false');
|
||||||
|
$page['deleted']
|
||||||
|
? ($page['deleted'] = 'true')
|
||||||
|
: ($page['deleted'] = 'false');
|
||||||
|
$updated = Carbon::now();
|
||||||
|
$created = new Carbon($page['rawCreated']);
|
||||||
|
$page['created'] = $created->format("Y-m-d\TH:i:sP");
|
||||||
|
$page['updated'] = $updated->format("Y-m-d\TH:i:sP");
|
||||||
|
|
||||||
|
$md = DocTools::objectToMD($page);
|
||||||
|
|
||||||
|
if ($page['layout'] == 'index') {
|
||||||
|
$writePath = '../content/pages/start/index.md';
|
||||||
|
} else {
|
||||||
|
$writePath = '../content/pages/' . $page['path'] . '/' . $page['slug'] . '.md';
|
||||||
|
}
|
||||||
|
|
||||||
|
DocTools::writePages('write', $page['path'], $writePath, $md);
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings['menu'] = [];
|
||||||
|
$items = $data['menu'];
|
||||||
|
foreach ($items as $item) {
|
||||||
|
array_push($settings['menu'], [
|
||||||
|
'title' => $item['title'],
|
||||||
|
'id' => $item['id'],
|
||||||
|
'uuid' => $item['uuid'],
|
||||||
|
'slug' => $item['slug'],
|
||||||
|
'path' => $item['path'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DocTools::writeSettings('../config/settings.json', $settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFolks($key = null)
|
||||||
|
{
|
||||||
|
if (isset($key)) {
|
||||||
|
$member = Session::get('member');
|
||||||
|
$found = find($this->folks, ['handle' => $member['handle']]);
|
||||||
|
if ($found) {
|
||||||
|
return $found[$key];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->folks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSettings($key = null)
|
||||||
|
{
|
||||||
|
return self::$settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getTags()
|
||||||
|
{
|
||||||
|
return self::$tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateGlobalData($key, $data)
|
||||||
|
{
|
||||||
|
$settings = self::$settings;
|
||||||
|
$settings['global'][$key] = $data;
|
||||||
|
DocTools::writeSettings('../config/settings.json', $settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCurrentIndex()
|
||||||
|
{
|
||||||
|
$settings = self::$settings;
|
||||||
|
return $settings['library_stats']['current_index'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateIndex()
|
||||||
|
{
|
||||||
|
$settings = self::$settings;
|
||||||
|
|
||||||
|
$settings['library_stats']['current_index'] = $settings['library_stats']['current_index'] + 1;
|
||||||
|
|
||||||
|
DocTools::writeSettings('../config/settings.json', $settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateMenu($body)
|
||||||
|
{
|
||||||
|
$settings = self::$settings;
|
||||||
|
//$menu = $settings["menu"];
|
||||||
|
$item = [
|
||||||
|
'title' => $body['title'],
|
||||||
|
'id' => $body['id'],
|
||||||
|
'uuid' => $body['uuid'],
|
||||||
|
'slug' => $body['slug'],
|
||||||
|
'path' => $body['path'],
|
||||||
|
];
|
||||||
|
if ($body['menu'] == 'true') {
|
||||||
|
if (!find($settings['menu'], ['uuid' => $item['uuid']])) {
|
||||||
|
array_push($settings['menu'], $item);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (find($settings['menu'], ['uuid' => $item['uuid']])) {
|
||||||
|
pull($settings['menu'], $item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DocTools::writeSettings('../config/settings.json', $settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateTags()
|
||||||
|
{
|
||||||
|
$tags = Sorting::tags();
|
||||||
|
DocTools::writeSettings('../config/tags.json', $tags);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,16 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Data;
|
namespace brain\data;
|
||||||
|
|
||||||
class ThemeService
|
class Themes
|
||||||
{
|
{
|
||||||
protected $themes = [];
|
private $themes = [];
|
||||||
protected $settings;
|
|
||||||
|
|
||||||
public function __construct(SettingsService $settingsService)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->settings = $settingsService;
|
$_themes = glob('../content/themes/*', GLOB_ONLYDIR);
|
||||||
$_themes = glob(env('THEMES_PATH') . '/*', GLOB_ONLYDIR);
|
|
||||||
foreach ($_themes as $theme) {
|
foreach ($_themes as $theme) {
|
||||||
array_push(
|
array_push(
|
||||||
$this->themes,
|
$this->themes,
|
||||||
|
@ -19,32 +17,17 @@ class ThemeService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCurrentTheme()
|
|
||||||
{
|
|
||||||
return $this->settings->getGlobal()['theme'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getThemes()
|
public function getThemes()
|
||||||
{
|
{
|
||||||
return $this->themes;
|
return $this->themes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCustomViews($layout)
|
public function getCustomIndex()
|
||||||
{
|
{
|
||||||
$views = [];
|
$settings = (new Settings())->getSettings();
|
||||||
if (str_contains($layout, 'index')) {
|
$currentTheme = $settings['global']['theme'];
|
||||||
$views = $this->findCustomIndex();
|
|
||||||
} else {
|
|
||||||
$views = $this->findCustomViews();
|
|
||||||
}
|
|
||||||
return $views;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findCustomIndex()
|
|
||||||
{
|
|
||||||
$currentTheme = $this->settings->getGlobal()['theme'];
|
|
||||||
$folder = '../content/themes/' . $currentTheme;
|
$folder = '../content/themes/' . $currentTheme;
|
||||||
$files = array_filter(glob("$folder/*blade.php"), 'is_file');
|
$files = array_filter(glob("$folder/*twig"), 'is_file');
|
||||||
$views = [];
|
$views = [];
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
@ -58,11 +41,12 @@ class ThemeService
|
||||||
return $views;
|
return $views;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findCustomViews()
|
public function getCustomViews()
|
||||||
{
|
{
|
||||||
$currentTheme = $this->settings->getGlobal()['theme'];
|
$settings = (new Settings())->getSettings();
|
||||||
|
$currentTheme = $settings['global']['theme'];
|
||||||
$folder = '../content/themes/' . $currentTheme;
|
$folder = '../content/themes/' . $currentTheme;
|
||||||
$files = array_filter(glob("$folder/*blade.php"), 'is_file');
|
$files = array_filter(glob("$folder/*twig"), 'is_file');
|
||||||
$views = [];
|
$views = [];
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
33
brain/init/App.php
Normal file
33
brain/init/App.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\init;
|
||||||
|
|
||||||
|
use brain\utility\HandleCors;
|
||||||
|
use Slim\Factory\AppFactory;
|
||||||
|
use Slim\Views\Twig;
|
||||||
|
use Slim\Views\TwigMiddleware;
|
||||||
|
|
||||||
|
class App
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// when a new class is made, run composer dump-autoload
|
||||||
|
// set up cors
|
||||||
|
new HandleCors();
|
||||||
|
$app = AppFactory::create();
|
||||||
|
$twig = Twig::create('../brain/views/');
|
||||||
|
$app->add(TwigMiddleware::create($app, $twig));
|
||||||
|
// set up routing
|
||||||
|
$app->get(
|
||||||
|
'/[{first}[/{second}[/{third}[/{fourth}[/{fifth}]]]]]',
|
||||||
|
"brain\controller\RouteControl:get"
|
||||||
|
);
|
||||||
|
$app->post(
|
||||||
|
'/[{first}[/{second}[/{third}[/{fourth}]]]]',
|
||||||
|
"brain\controller\RouteControl:post"
|
||||||
|
);
|
||||||
|
// start the app
|
||||||
|
|
||||||
|
$app->run();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Assets;
|
namespace brain\utility;
|
||||||
|
|
||||||
class DocService
|
class DocTools
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -22,63 +22,22 @@ class DocService
|
||||||
fwrite($new, $fileContents);
|
fwrite($new, $fileContents);
|
||||||
fclose($new);
|
fclose($new);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Error $error) {
|
} catch (Error $error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function updateMenu($body)
|
public static function writeSettings($fileLocation, $fileContents)
|
||||||
{
|
{
|
||||||
$settings = self::$settings;
|
|
||||||
//$menu = $settings["menu"];
|
|
||||||
$item = [
|
|
||||||
'title' => $body['title'],
|
|
||||||
'id' => $body['id'],
|
|
||||||
'uuid' => $body['uuid'],
|
|
||||||
'slug' => $body['slug'],
|
|
||||||
'path' => $body['path'],
|
|
||||||
];
|
|
||||||
if ($body['menu'] == 'true') {
|
|
||||||
if (!find($settings['menu'], ['uuid' => $item['uuid']])) {
|
|
||||||
array_push($settings['menu'], $item);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (find($settings['menu'], ['uuid' => $item['uuid']])) {
|
|
||||||
pull($settings['menu'], $item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DocTools::writeSettings('../config/settings.json', $settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function writeSettings($fileContents, $location = null)
|
|
||||||
{
|
|
||||||
if (is_null($location)) {
|
|
||||||
$fileLocation = env('SETTINGS_PATH');
|
|
||||||
} else {
|
|
||||||
$fileLocation = $location;
|
|
||||||
}
|
|
||||||
|
|
||||||
$message = [];
|
|
||||||
try {
|
|
||||||
if (!is_file($fileLocation)) {
|
if (!is_file($fileLocation)) {
|
||||||
file_put_contents($fileLocation, json_encode($fileContents));
|
file_put_contents($fileLocation, json_encode($fileContents));
|
||||||
} else {
|
} else {
|
||||||
($new = fopen($fileLocation, 'w')) or die('Unable to open file!');
|
($new = fopen($fileLocation, 'w')) or die('Unable to open file!');
|
||||||
fwrite($new, json_encode($fileContents));
|
fwrite($new, json_encode($fileContents));
|
||||||
fclose($new);
|
fclose($new);
|
||||||
}$message = [
|
|
||||||
'message' => "Settings Synced. You're doing great!",
|
|
||||||
'type' => 'settingsUpdated',
|
|
||||||
];
|
|
||||||
} catch (Error $error) {
|
|
||||||
$message = [
|
|
||||||
'message' => "Settings Not Synced. We'll figure it out",
|
|
||||||
'type' => 'settingsUpdated',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function writeHTML($location, $html, $path = null)
|
public static function writeHTML($location, $html, $path = null)
|
||||||
|
@ -129,56 +88,56 @@ class DocService
|
||||||
{
|
{
|
||||||
$markdown = "---\n" .
|
$markdown = "---\n" .
|
||||||
'id: ' .
|
'id: ' .
|
||||||
$object->id .
|
$object['id'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'uuid: ' .
|
'uuid: ' .
|
||||||
$object->uuid .
|
$object['uuid'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'title: ' .
|
'title: ' .
|
||||||
"'" .
|
"'" .
|
||||||
$object->title .
|
$object['title'] .
|
||||||
"'" .
|
"'" .
|
||||||
"\n" .
|
"\n" .
|
||||||
'feature: ' .
|
'feature: ' .
|
||||||
$object->imageList .
|
$object['imageList'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'files: ' .
|
'files: ' .
|
||||||
$object->fileList .
|
$object['fileList'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'path: ' .
|
'path: ' .
|
||||||
$object->path .
|
$object['path'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'layout: ' .
|
'layout: ' .
|
||||||
$object->layout .
|
$object['layout'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'tags: ' .
|
'tags: ' .
|
||||||
$object->tags .
|
$object['tags'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'author: ' .
|
'author: ' .
|
||||||
$object->author .
|
$object['author'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'created: ' .
|
'created: ' .
|
||||||
$object->created .
|
$object['created'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'updated: ' .
|
'updated: ' .
|
||||||
$object->updated .
|
$object['updated'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'deleted: ' .
|
'deleted: ' .
|
||||||
$object->deleted .
|
$object['deleted'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'slug: ' .
|
'slug: ' .
|
||||||
$object->slug .
|
$object['slug'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'menu: ' .
|
'menu: ' .
|
||||||
$object->menu .
|
$object['menu'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'published: ' .
|
'published: ' .
|
||||||
$object->published .
|
$object['published'] .
|
||||||
"\n" .
|
"\n" .
|
||||||
'featured: ' .
|
'featured: ' .
|
||||||
$object->featured .
|
$object['featured'] .
|
||||||
"\n---\n" .
|
"\n---\n" .
|
||||||
$object->content;
|
$object['content'];
|
||||||
|
|
||||||
return $markdown;
|
return $markdown;
|
||||||
}
|
}
|
32
brain/utility/FileUploader.php
Normal file
32
brain/utility/FileUploader.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\utility;
|
||||||
|
|
||||||
|
class FileUploader
|
||||||
|
{
|
||||||
|
public static function uploadFile(string $directory, $file)
|
||||||
|
{
|
||||||
|
$response = [];
|
||||||
|
try {
|
||||||
|
if (!is_dir($directory)) {
|
||||||
|
// Directory does not exist, so lets create it.
|
||||||
|
mkdir($directory, 0755, true);
|
||||||
|
}
|
||||||
|
// $upload = move_uploaded_file($file->getClientFileName(), $directory);
|
||||||
|
// $extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
|
||||||
|
|
||||||
|
// see http://php.net/manual/en/function.random-bytes.php
|
||||||
|
// $basename = bin2hex(random_bytes(8));
|
||||||
|
// $filename = sprintf("%s.%0.8s", $basename, $extension);
|
||||||
|
|
||||||
|
// echo "**FILE** " . $file->getClientFileName();
|
||||||
|
|
||||||
|
$file->moveTo($directory . '/' . urlencode($file->getClientFileName()));
|
||||||
|
} catch (RuntimeException $e) {
|
||||||
|
echo 'ERROR ' . $e->getMessage();
|
||||||
|
|
||||||
|
// echo "failed to upload image: " . $e->getMessage();
|
||||||
|
// throw new Error("Failed to upload image file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
61
brain/utility/HandleCors.php
Normal file
61
brain/utility/HandleCors.php
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\utility;
|
||||||
|
|
||||||
|
use brain\data\Settings;
|
||||||
|
|
||||||
|
class HandleCors
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//look to see if settings file exists. kinda important
|
||||||
|
if (file_exists('../config/settings.json')) {
|
||||||
|
//check settings to see if external api access is allowed
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
if ($settings['global']['externalAPI']) {
|
||||||
|
//echo "API STATUS: " . $settings["global"]["externalAPI"];
|
||||||
|
if ($settings['global']['externalAPI'] == 'true') {
|
||||||
|
//echo "API ACCESS ACTIVE";
|
||||||
|
// checks to see if origin is set
|
||||||
|
if (isset($_SERVER['HTTP_ORIGIN'])) {
|
||||||
|
// You can decide if the origin in $_SERVER['HTTP_ORIGIN']
|
||||||
|
//is something you want to allow, or as we do here, just allow all
|
||||||
|
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
|
||||||
|
} else {
|
||||||
|
//No HTTP_ORIGIN set, so we allow any. You can disallow if needed here
|
||||||
|
//never allow just any domain, so turn CORS off if no No HTTP_ORIGIN is set
|
||||||
|
//header("Access-Control-Allow-Origin: *");
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Access-Control-Allow-Credentials: true');
|
||||||
|
header('Access-Control-Max-Age: 600'); // cache for 10 minutes
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||||
|
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
|
||||||
|
header(
|
||||||
|
'Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT'
|
||||||
|
);
|
||||||
|
} //Make sure you remove those you do not want to support
|
||||||
|
|
||||||
|
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
|
||||||
|
header(
|
||||||
|
"Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Just exit with 200 OK with the above headers for OPTIONS method
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//echo "API ACCESS ACTIVE";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//value doesn't exist, so whatevs
|
||||||
|
//echo "API ACCESS VALUE NOT PRESENT";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//init state, so chill
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
95
brain/utility/Mailer.php
Normal file
95
brain/utility/Mailer.php
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\utility;
|
||||||
|
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
use brain\data\Settings;
|
||||||
|
use brain\data\Session;
|
||||||
|
|
||||||
|
class Mailer
|
||||||
|
{
|
||||||
|
public static function sendMail($body)
|
||||||
|
{
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$mailConfig = $settings['email'];
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
|
||||||
|
switch ($body['mail_task']) {
|
||||||
|
case 'TESTING':
|
||||||
|
$html = "<h1>Hi! It's Fipamo!</h1><br>" .
|
||||||
|
"<strong>It's just a test</strong><br>" .
|
||||||
|
$body['content'];
|
||||||
|
$member = Session::get('member');
|
||||||
|
$mail->addAddress($member['email'], ''); //pull email address from current user
|
||||||
|
$mail->Subject = 'A test email';
|
||||||
|
break;
|
||||||
|
case 'SEND_SECRET':
|
||||||
|
$html = "<h1>Hi! It's Fipamo!</h1><br>" .
|
||||||
|
'<strong>This is your secret key.</strong><br><br>' .
|
||||||
|
'<h3>' .
|
||||||
|
$body['secret'] .
|
||||||
|
'</h3>' .
|
||||||
|
'<br> Use this key to reset your password.';
|
||||||
|
$mail->addAddress($body['email'], ''); //pull email address from current user
|
||||||
|
$mail->Subject = "Shhhh! It's a secret!";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return $result = [
|
||||||
|
'type' => 'noMailService',
|
||||||
|
'message' => 'Mail task is undefined. What are you doing??',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//set values based on current active protocol
|
||||||
|
switch ($mailConfig['active']) {
|
||||||
|
case 'option-smtp':
|
||||||
|
$mail->setFrom($mailConfig['smtp']['email'], 'System Email');
|
||||||
|
$mail->Host = 'playvicio.us';
|
||||||
|
$mail->Username = $mailConfig['smtp']['email'];
|
||||||
|
$mail->Password = $mailConfig['smtp']['password'];
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'option-mg':
|
||||||
|
$mail->setFrom($mailConfig['mailgun']['domain'], 'No Reply');
|
||||||
|
$mail->Host = 'smtp.mailgun.org';
|
||||||
|
$mail->Username = $mailConfig['mailgun']['domain'];
|
||||||
|
$mail->Password = $mailConfig['mailgun']['key'];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//no mail service
|
||||||
|
return $result = [
|
||||||
|
'type' => 'noMailService',
|
||||||
|
'message' => 'Mail is not configured. Handle that.',
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail->Body = $html;
|
||||||
|
$mail->IsHTML(true);
|
||||||
|
$mail->isSMTP();
|
||||||
|
$mail->SMTPAuth = true;
|
||||||
|
$mail->SMTPSecure = 'ssl';
|
||||||
|
$mail->Port = 465;
|
||||||
|
|
||||||
|
// Uncomment for debug info
|
||||||
|
//$mail->SMTPDebug = 4;
|
||||||
|
|
||||||
|
/* Finally send the mail. */
|
||||||
|
try {
|
||||||
|
$mail->send();
|
||||||
|
$result = ['type' => 'mailSent', 'message' => 'Message Away!'];
|
||||||
|
} catch (Exception $e) {
|
||||||
|
//echo $e->errorMessage();
|
||||||
|
$result = [
|
||||||
|
'type' => 'mailNotSent',
|
||||||
|
'message' => 'Message Not Away!',
|
||||||
|
'error' => $e->errorMessage(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
103
brain/utility/Maintenance.php
Normal file
103
brain/utility/Maintenance.php
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\utility;
|
||||||
|
|
||||||
|
use brain\data\Settings;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class Maintenance
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function makeBackup()
|
||||||
|
{
|
||||||
|
//make sure back directory is there
|
||||||
|
if (!is_dir('../config/backups')) {
|
||||||
|
mkdir('../config/backups', 0755, true);
|
||||||
|
}
|
||||||
|
//creat backup zip
|
||||||
|
$zip = new \ZipArchive();
|
||||||
|
$zip->open(
|
||||||
|
'../config/backups/latest_back.zip',
|
||||||
|
\ZipArchive::CREATE | \ZipArchive::OVERWRITE
|
||||||
|
);
|
||||||
|
//gather data and path info for md pages
|
||||||
|
$pagePath = '../content/pages';
|
||||||
|
$yearPaths = glob($pagePath . '/*', GLOB_ONLYDIR);
|
||||||
|
foreach ($yearPaths as $years) {
|
||||||
|
$year = explode('/', $years);
|
||||||
|
//grap the index and save it
|
||||||
|
if (trim($year[3]) == 'start') {
|
||||||
|
$options = [
|
||||||
|
'add_path' => 'content/pages/' . $year[3] . '/',
|
||||||
|
'remove_all_path' => true,
|
||||||
|
];
|
||||||
|
$zip->addGlob($years . '/*.md', GLOB_BRACE, $options);
|
||||||
|
}
|
||||||
|
$monthsPath = glob($pagePath . '/' . $year[3] . '/*', GLOB_ONLYDIR);
|
||||||
|
foreach ($monthsPath as $months) {
|
||||||
|
$month = explode('/', $months);
|
||||||
|
//once info is collected, add md pages to zip
|
||||||
|
$options = [
|
||||||
|
'add_path' => 'content/pages/' . $year[3] . '/' . $month[4] . '/',
|
||||||
|
'remove_all_path' => true,
|
||||||
|
];
|
||||||
|
$zip->addGlob($months . '/*.md', GLOB_BRACE, $options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//gather data and path info for blog images
|
||||||
|
$blogImagesPath = '../public/assets/images/blog';
|
||||||
|
$yearPaths = glob($blogImagesPath . '/*', GLOB_ONLYDIR);
|
||||||
|
foreach ($yearPaths as $years) {
|
||||||
|
$year = explode('/', $years);
|
||||||
|
$monthsPath = glob($blogImagesPath . '/' . $year[5] . '/*', GLOB_ONLYDIR);
|
||||||
|
foreach ($monthsPath as $months) {
|
||||||
|
$month = explode('/', $months);
|
||||||
|
//once info is collected, add images pages to zip
|
||||||
|
$options = [
|
||||||
|
'add_path' => 'public/assets/images/blog/' . $year[5] . '/' . $month[6] . '/',
|
||||||
|
'remove_all_path' => true,
|
||||||
|
];
|
||||||
|
$zip->addGlob($months . '/*.*', GLOB_BRACE, $options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//gather data and path info for user images
|
||||||
|
$userImagesPath = '../public/assets/images/user';
|
||||||
|
$yearPaths = glob($userImagesPath . '/*', GLOB_ONLYDIR);
|
||||||
|
foreach ($yearPaths as $years) {
|
||||||
|
$year = explode('/', $years);
|
||||||
|
$monthsPath = glob($userImagesPath . '/' . $year[5] . '/*', GLOB_ONLYDIR);
|
||||||
|
foreach ($monthsPath as $months) {
|
||||||
|
$month = explode('/', $months);
|
||||||
|
//once info is collected, add images pages to zip
|
||||||
|
$options = [
|
||||||
|
'add_path' => 'public/assets/images/user/' . $year[5] . '/' . $month[6] . '/',
|
||||||
|
'remove_all_path' => true,
|
||||||
|
];
|
||||||
|
$zip->addGlob($months . '/*.*', GLOB_BRACE, $options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//add directory for settings and save them
|
||||||
|
$zip->addEmptyDir('settings');
|
||||||
|
$zip->addFile('../config/settings.json', 'settings/settings.json');
|
||||||
|
$zip->addFile('../config/folks.json', 'settings/folks.json');
|
||||||
|
$zip->addFile('../config/tags.json', 'settings/tags.json');
|
||||||
|
//save zip file
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
//update settings file with latest back up date
|
||||||
|
$updated = Carbon::now();
|
||||||
|
Settings::updateGlobalData(
|
||||||
|
'last_backup',
|
||||||
|
$updated->format("Y-m-d\TH:i:sP")
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = ['message' => 'Backup created. THIS IS A SAFE SPACE!'];
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
230
brain/utility/Setup.php
Normal file
230
brain/utility/Setup.php
Normal file
|
@ -0,0 +1,230 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\utility;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
use function _\find;
|
||||||
|
|
||||||
|
class SetUp
|
||||||
|
{
|
||||||
|
public static function status()
|
||||||
|
{
|
||||||
|
if (file_exists('../config/settings.json')) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function init($body)
|
||||||
|
{
|
||||||
|
//grab template files
|
||||||
|
$newFolks = json_decode(
|
||||||
|
file_get_contents('../config/init/folks-template.json'),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$newSettings = json_decode(
|
||||||
|
file_get_contents('../config/init/settings-template.json'),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
//get form values
|
||||||
|
//$body = $request->getParsedBody();
|
||||||
|
$handle = $body['new_member_handle'];
|
||||||
|
$email = $body['new_member_email'];
|
||||||
|
$pass = $body['new_member_pass'];
|
||||||
|
$title = $body['new_member_title'];
|
||||||
|
|
||||||
|
$now = Carbon::now();
|
||||||
|
//setup folks config
|
||||||
|
$hash = password_hash($pass, PASSWORD_DEFAULT);
|
||||||
|
$newFolks[0]['id'] = 0;
|
||||||
|
$newFolks[0]['handle'] = $handle;
|
||||||
|
$newFolks[0]['email'] = $email;
|
||||||
|
$newFolks[0]['password'] = $hash;
|
||||||
|
$newFolks[0]['key'] = password_hash($email, PASSWORD_DEFAULT);
|
||||||
|
$newFolks[0]['secret'] = StringTools::randomString(12);
|
||||||
|
$newFolks[0]['role'] = 'hnic';
|
||||||
|
$newFolks[0]['created'] = $now->format("Y-m-d\TH:i:sP");
|
||||||
|
$newFolks[0]['updated'] = $now->format("Y-m-d\TH:i:sP");
|
||||||
|
//set up settings config
|
||||||
|
$newSettings['global']['title'] = $title;
|
||||||
|
|
||||||
|
//create index file
|
||||||
|
//$rightNow = $now->format("Y-m-d\TH:i:sP");
|
||||||
|
//var_dump($now->format("Y-m-d\TH:i:sP"));
|
||||||
|
$index = [
|
||||||
|
'id' => 1,
|
||||||
|
'uuid' => StringTools::createUUID(),
|
||||||
|
'title' => 'FIRST!',
|
||||||
|
'imageList' => '/assets/images/global/default-bg.jpg',
|
||||||
|
'fileList' => '',
|
||||||
|
'path' => 'content/pages/start',
|
||||||
|
'layout' => 'index',
|
||||||
|
'tags' => 'start, welcome',
|
||||||
|
'author' => $handle,
|
||||||
|
'created' => $now->format("Y-m-d\TH:i:sP"),
|
||||||
|
'updated' => $now->format("Y-m-d\TH:i:sP"),
|
||||||
|
'deleted' => 'false',
|
||||||
|
'slug' => 'first',
|
||||||
|
'menu' => 'false',
|
||||||
|
'featured' => 'false',
|
||||||
|
'published' => 'true',
|
||||||
|
'content' => "# F**k Yes \n\nIf you're seeing this, you're up and running. NICE WORK!\n\nFrom here, feel free to start dropping pages to your heart's content.\n\nFor some tips about using Fipamo, check out the ![docs](https://code.playvicio.us/Are0h/Fipamo/wiki/02-Usage)\n\nAll good? Feel free to edit this page to whatever you want!\n\nYOU'RE THE CAPTAIN NOW.",
|
||||||
|
];
|
||||||
|
|
||||||
|
$freshIndex = DocTools::objectToMD($index);
|
||||||
|
|
||||||
|
//once all files created, write down
|
||||||
|
|
||||||
|
DocTools::writeSettings('../config/settings.json', $newSettings);
|
||||||
|
DocTools::writeSettings('../config/folks.json', $newFolks);
|
||||||
|
DocTools::writeSettings('../config/tags.json', []);
|
||||||
|
DocTools::writePages(
|
||||||
|
'create',
|
||||||
|
'start',
|
||||||
|
'../content/pages/start/index.md',
|
||||||
|
$freshIndex
|
||||||
|
);
|
||||||
|
|
||||||
|
//if there is an older session file, get rid of it
|
||||||
|
if (is_file('../content/.session')) {
|
||||||
|
unlink('../content/.session');
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = ['type' => 'blogInitGood', 'message' => 'Site Created'];
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function restore($request)
|
||||||
|
{
|
||||||
|
$result = [
|
||||||
|
'type' => 'requestLame',
|
||||||
|
'message' => 'Still working on it.',
|
||||||
|
];
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
|
||||||
|
$backup = $request->getUploadedFiles();
|
||||||
|
$file = $backup['backup-upload'];
|
||||||
|
//NOTE: If this fails check 'post_max_size' in php.ini
|
||||||
|
$size = $file->getSize();
|
||||||
|
$name = $file->getClientFileName();
|
||||||
|
|
||||||
|
//park it so it can be read
|
||||||
|
$file->moveTo('../content' . '/' . $name);
|
||||||
|
|
||||||
|
//open it and get files to verify user
|
||||||
|
$zip = new \ZipArchive();
|
||||||
|
if ($zip->open('../content' . '/' . $name) === true) {
|
||||||
|
$folks = json_decode($zip->getFromName('settings/folks.json'), true);
|
||||||
|
$found = find($folks, ['handle' => $body['restore_member_handle']]);
|
||||||
|
|
||||||
|
//if member is found in back up, check pass
|
||||||
|
if ($found) {
|
||||||
|
if (password_verify($body['restore_member_pass'], $found['password'])) {
|
||||||
|
//backup verified, restore site
|
||||||
|
|
||||||
|
//set new secret key for older folks configs
|
||||||
|
$newFolks = [];
|
||||||
|
if (!isset($found['secret'])) {
|
||||||
|
$found['secret'] = StringTools::randomString(12);
|
||||||
|
}
|
||||||
|
array_push($newFolks, $found);
|
||||||
|
//dump files in folder
|
||||||
|
$zip->extractTo('../content');
|
||||||
|
|
||||||
|
//move to appropriate spots
|
||||||
|
/*
|
||||||
|
rename(
|
||||||
|
"../content/settings/settings.json",
|
||||||
|
"../config/settings.json"
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
//load up old config file
|
||||||
|
$newConfig = json_decode(
|
||||||
|
file_get_contents('../content/settings/settings.json'),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
//check for key, add if not there
|
||||||
|
if (!isset($newConfig['global']['externalAPI'])) {
|
||||||
|
$newConfig['global']['externalAPI'] = 'false';
|
||||||
|
}
|
||||||
|
//write new config file
|
||||||
|
DocTools::writeSettings('../config/settings.json', $newConfig);
|
||||||
|
|
||||||
|
//rename("../content/settings/folks.json", "../config/folks.json");
|
||||||
|
DocTools::writeSettings('../config/folks.json', $newFolks);
|
||||||
|
|
||||||
|
rename('../content/settings/tags.json', '../config/tags.json');
|
||||||
|
|
||||||
|
//images path for blog and user
|
||||||
|
$blogImagePath = '../public/assets/images/blog';
|
||||||
|
$userImagePath = '../public/assets/images/user';
|
||||||
|
|
||||||
|
//check to see if image dirs are empty, if not chill
|
||||||
|
if ($globs = glob($blogImagePath . '/*')) {
|
||||||
|
//directory not empty, relax
|
||||||
|
} else {
|
||||||
|
rename('../content/public/assets/images/blog', $blogImagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($globs = glob($userImagePath . '/*')) {
|
||||||
|
//directory not empty, relax
|
||||||
|
} else {
|
||||||
|
rename('../content/public/assets/images/user', $userImagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
rename('../content/content/pages/', '../content/pages');
|
||||||
|
|
||||||
|
//legacy check for old file structure
|
||||||
|
if (is_file('../content/pages/index.md')) {
|
||||||
|
if (!is_dir('../content/pages/start')) {
|
||||||
|
//Directory does not exist, so lets create it.
|
||||||
|
mkdir('../content/pages/start', 0755, true);
|
||||||
|
//move start page to appropriate spot
|
||||||
|
rename(
|
||||||
|
'../content/pages/index.md',
|
||||||
|
'../content/pages/start/index.md'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//chill
|
||||||
|
}
|
||||||
|
|
||||||
|
//clean up
|
||||||
|
|
||||||
|
DocTools::deleteFolder('../content/settings');
|
||||||
|
DocTools::deleteFolder('../content/public');
|
||||||
|
DocTools::deleteFolder('../content/content');
|
||||||
|
$result = [
|
||||||
|
'type' => 'requestGood',
|
||||||
|
'message' => 'Site Restored! Redirecting',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'type' => 'requestLame',
|
||||||
|
'message' => 'Check that password, champ.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'type' => 'requestLame',
|
||||||
|
'message' => 'No member found by that name, hoss',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$zip->close();
|
||||||
|
$zipPath = '../content/' . $name;
|
||||||
|
//trash zip when done
|
||||||
|
unlink($zipPath);
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'type' => 'requestLame',
|
||||||
|
'message' => 'Could not open backup. RATS!',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
269
brain/utility/Sorting.php
Normal file
269
brain/utility/Sorting.php
Normal file
|
@ -0,0 +1,269 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\utility;
|
||||||
|
|
||||||
|
use brain\data\Book;
|
||||||
|
use brain\data\Settings;
|
||||||
|
use Mni\FrontYAML\Parser;
|
||||||
|
|
||||||
|
use function _\filter;
|
||||||
|
use function _\find;
|
||||||
|
|
||||||
|
class Sorting
|
||||||
|
{
|
||||||
|
private static $p_tags = [];
|
||||||
|
private static $p_archive = [];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tags()
|
||||||
|
{
|
||||||
|
$pages = (new Book('../content/pages'))->getContents();
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
$temp = [];
|
||||||
|
if (isset($page['tags'])) {
|
||||||
|
$temp = explode(',', $page['tags']);
|
||||||
|
foreach ($temp as $tag) {
|
||||||
|
$label = trim($tag);
|
||||||
|
if (!find(self::$p_tags, ['tag_name' => $label])) {
|
||||||
|
array_push(self::$p_tags, [
|
||||||
|
'tag_name' => $label,
|
||||||
|
'slug' => StringTools::safeString($label),
|
||||||
|
'pages' => self::tagPages($label, $pages),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$p_tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function tagPages($tag, $pages)
|
||||||
|
{
|
||||||
|
$tagged = [];
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
if (isset($page['tags'])) {
|
||||||
|
if (strpos($page['tags'], $tag) !== false) {
|
||||||
|
array_push($tagged, [
|
||||||
|
'title' => $page['title'],
|
||||||
|
'slug' => $page['slug'],
|
||||||
|
'path' => $page['path'],
|
||||||
|
'feature' => $page['feature'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tagged;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function archive()
|
||||||
|
{
|
||||||
|
$pages = (new Book('../content/pages'))->getContents();
|
||||||
|
$years = [];
|
||||||
|
$archive = [];
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
// $year = date("Y", date($page["rawCreated"]));
|
||||||
|
$date = explode('/', $page['path']);
|
||||||
|
// echo $page["title"] . " : " . $year . "\n";
|
||||||
|
if (!find($years, ['year' => trim($date[0])])) {
|
||||||
|
$findPages = filter($pages, ['createdYear' => trim($date[0])]);
|
||||||
|
// var_dump($findPages);
|
||||||
|
array_push(
|
||||||
|
$years,
|
||||||
|
[
|
||||||
|
'year' => trim($date[0]),
|
||||||
|
'count' => count($findPages),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($years as $year) {
|
||||||
|
$sorted = [];
|
||||||
|
$filtered = filter($pages, ['createdYear' => $year['year']]);
|
||||||
|
|
||||||
|
foreach ($filtered as $obj) {
|
||||||
|
$month = date('m', date($obj['rawCreated']));
|
||||||
|
if (!find($sorted, ['month' => $month])) {
|
||||||
|
$perMonth = filter(
|
||||||
|
$pages,
|
||||||
|
[
|
||||||
|
'path' => $year['year'] . '/' . $month,
|
||||||
|
'deleted' => false,
|
||||||
|
'published' => true,
|
||||||
|
'layout' => 'page',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
array_push($sorted, [
|
||||||
|
'month' => $month,
|
||||||
|
'full_month' => date('F', date($obj['rawCreated'])),
|
||||||
|
'count' => count($perMonth),
|
||||||
|
'pages' => $perMonth,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array_push(self::$p_archive, [
|
||||||
|
'year' => $year['year'],
|
||||||
|
'year_data' => $sorted,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$p_archive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function page($page)
|
||||||
|
{
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$pageOption = [];
|
||||||
|
|
||||||
|
$pageInfo = [
|
||||||
|
'keywords' => isset($settings['global']['keywords'])
|
||||||
|
? $settings['global']['keywords']
|
||||||
|
: 'fipamo, blog, jamstack, php, markdown, js',
|
||||||
|
'description' => $settings['global']['descriptions'],
|
||||||
|
'image' => $settings['global']['base_url'] . $settings['global']['background'],
|
||||||
|
'baseURL' => $settings['global']['base_url'],
|
||||||
|
];
|
||||||
|
$tags = [];
|
||||||
|
if (isset($page['tags'])) {
|
||||||
|
$taglist = explode(',', $page['tags']);
|
||||||
|
foreach ($taglist as $tag) {
|
||||||
|
$label = trim($tag);
|
||||||
|
array_push($tags, [
|
||||||
|
'label' => $label . ' ',
|
||||||
|
'slug' => StringTools::safeString($label),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$meta = [
|
||||||
|
'who' => $page['author'],
|
||||||
|
'when' => $page['created'],
|
||||||
|
'tags' => $tags,
|
||||||
|
];
|
||||||
|
|
||||||
|
// render markdown content and clean it
|
||||||
|
$parser = new Parser();
|
||||||
|
$rendered = $parser->parse($page['content']);
|
||||||
|
$sanitizer = \HtmlSanitizer\Sanitizer::create([
|
||||||
|
'extensions' => ['basic', 'image', 'list', 'code'],
|
||||||
|
'tags' => [
|
||||||
|
'img' => [
|
||||||
|
'allowed_attributes' => ['src', 'alt', 'title', 'class'],
|
||||||
|
'allowed_hosts' => null,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$preclean = $sanitizer->sanitize($rendered->getContent());
|
||||||
|
|
||||||
|
// just clean renderd string for now, Sanitize doesn't like relative img urls
|
||||||
|
// so another option is needed
|
||||||
|
$cleaned = strip_tags($rendered->getContent(), [
|
||||||
|
'a',
|
||||||
|
'br',
|
||||||
|
'p',
|
||||||
|
'strong',
|
||||||
|
'br',
|
||||||
|
'img',
|
||||||
|
'iframe',
|
||||||
|
'ul',
|
||||||
|
'li',
|
||||||
|
'i',
|
||||||
|
'em',
|
||||||
|
'h1',
|
||||||
|
'h2',
|
||||||
|
'h3',
|
||||||
|
'pre',
|
||||||
|
'code',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// if page feature isn't empty, find image from list and set it as background image
|
||||||
|
// if it is empty, just use global background
|
||||||
|
if ($page['feature'] != '' || $page['feature'] != null) {
|
||||||
|
$media = explode(',', $page['feature']);
|
||||||
|
$set = false;
|
||||||
|
foreach ($media as $file) {
|
||||||
|
$item = trim($file);
|
||||||
|
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
||||||
|
|
||||||
|
if ($ext != 'mp4' && !$set) {
|
||||||
|
$pageInfo['image'] = $pageInfo['baseURL'] . $item;
|
||||||
|
$set = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($page['layout'] == 'index') {
|
||||||
|
// $template = $this->theme . "/index.twig";
|
||||||
|
// $location = "../public/index.html";
|
||||||
|
// $dir = null;
|
||||||
|
|
||||||
|
$recent = [];
|
||||||
|
$featured = [];
|
||||||
|
$limit = 4;
|
||||||
|
$pages = (new Book())->getContents();
|
||||||
|
foreach ($pages as $item) {
|
||||||
|
if (!$item['deleted'] &&
|
||||||
|
$item['published'] &&
|
||||||
|
$item['menu'] != 'true'
|
||||||
|
) {
|
||||||
|
if (count($recent) < $limit) {
|
||||||
|
array_push($recent, [
|
||||||
|
'path' => $item['path'],
|
||||||
|
'slug' => $item['slug'],
|
||||||
|
'title' => $item['title'],
|
||||||
|
'feature' => $item['feature'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($item['featured'] == true) {
|
||||||
|
if (count($featured) < $limit) {
|
||||||
|
array_push($featured, [
|
||||||
|
'path' => $item['path'],
|
||||||
|
'slug' => $item['slug'],
|
||||||
|
'title' => $item['title'],
|
||||||
|
'feature' => $item['feature'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => $page['title'],
|
||||||
|
'background' => $page['feature'],
|
||||||
|
'content' => $page['html'], // $cleaned,
|
||||||
|
'meta' => $meta,
|
||||||
|
'recent' => $recent,
|
||||||
|
'featured' => $featured,
|
||||||
|
'info' => $pageInfo,
|
||||||
|
'menu' => $settings['menu'],
|
||||||
|
'dynamicRender' => $settings['global']['dynamicRender'],
|
||||||
|
'media' => $page['media'],
|
||||||
|
'files' => $page['docs'],
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
// $template = $this->theme . "/page.twig";
|
||||||
|
// $location = "../public/" . $page["path"] . "/" . $page["slug"] . ".html";
|
||||||
|
// $dir = "../public/" . $page["path"];
|
||||||
|
$pageOptions = [
|
||||||
|
'title' => $page['title'],
|
||||||
|
'background' => $page['feature'],
|
||||||
|
'content' => $page['html'], // $cleaned,
|
||||||
|
'meta' => $meta,
|
||||||
|
'info' => $pageInfo,
|
||||||
|
'menu' => $settings['menu'],
|
||||||
|
'dynamicRender' => $settings['global']['dynamicRender'],
|
||||||
|
'media' => $page['media'],
|
||||||
|
'files' => $page['docs'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pageOptions;
|
||||||
|
}
|
||||||
|
}
|
131
brain/utility/StringTools.php
Normal file
131
brain/utility/StringTools.php
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace brain\utility;
|
||||||
|
|
||||||
|
use ReallySimpleJWT\Token;
|
||||||
|
use ReallySimpleJWT\Exception\BuildException;
|
||||||
|
use Mni\FrontYAML\Parser;
|
||||||
|
|
||||||
|
class StringTools
|
||||||
|
{
|
||||||
|
public static function createUUID()
|
||||||
|
{
|
||||||
|
if (function_exists('com_create_guid') === true) {
|
||||||
|
return trim(com_create_guid(), '{}');
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
'%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
|
||||||
|
mt_rand(0, 65535),
|
||||||
|
mt_rand(0, 65535),
|
||||||
|
mt_rand(0, 65535),
|
||||||
|
mt_rand(16384, 20479),
|
||||||
|
mt_rand(32768, 49151),
|
||||||
|
mt_rand(0, 65535),
|
||||||
|
mt_rand(0, 65535),
|
||||||
|
mt_rand(0, 65535)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function sanitizeContent($entry)
|
||||||
|
{
|
||||||
|
$parser = new Parser();
|
||||||
|
$rendered = $parser->parse($entry);
|
||||||
|
$sanitizer = HtmlSanitizer\Sanitizer::create([
|
||||||
|
'extensions' => ['basic', 'image', 'list', 'code'],
|
||||||
|
'tags' => [
|
||||||
|
'img' => [
|
||||||
|
'allowed_attributes' => ['src', 'alt', 'title', 'class'],
|
||||||
|
'allowed_hosts' => null,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$preclean = $sanitizer->sanitize($rendered->getContent());
|
||||||
|
|
||||||
|
$cleaned = strip_tags($rendered->getContent(), [
|
||||||
|
'a',
|
||||||
|
'br',
|
||||||
|
'p',
|
||||||
|
'strong',
|
||||||
|
'br',
|
||||||
|
'img',
|
||||||
|
'iframe',
|
||||||
|
'ul',
|
||||||
|
'li',
|
||||||
|
'i',
|
||||||
|
'h1',
|
||||||
|
'h2',
|
||||||
|
'h3',
|
||||||
|
'pre',
|
||||||
|
'code',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $cleaned;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function safeString($string)
|
||||||
|
{
|
||||||
|
return strtolower(
|
||||||
|
trim(
|
||||||
|
preg_replace(
|
||||||
|
'~[^0-9a-z]+~i',
|
||||||
|
'_',
|
||||||
|
html_entity_decode(
|
||||||
|
preg_replace(
|
||||||
|
'~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i',
|
||||||
|
'$1',
|
||||||
|
htmlentities($string, ENT_QUOTES, 'UTF-8')
|
||||||
|
),
|
||||||
|
ENT_QUOTES,
|
||||||
|
'UTF-8'
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'-'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function randomString(int $length)
|
||||||
|
{
|
||||||
|
$alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
$special = '*&!@%^#$';
|
||||||
|
$alphabet = $alphanum . $special;
|
||||||
|
$random = openssl_random_pseudo_bytes($length);
|
||||||
|
$alphabet_length = strlen($alphabet);
|
||||||
|
$string = '';
|
||||||
|
for ($i = 0; $i < $length; ++$i) {
|
||||||
|
$string .= $alphabet[ord($random[$i]) % $alphabet_length];
|
||||||
|
}
|
||||||
|
|
||||||
|
//secret needs to be a valid token
|
||||||
|
if ($length == 12) {
|
||||||
|
try {
|
||||||
|
$secret = Token::create(12, $string, time() + 3600, 'localhost');
|
||||||
|
return $string;
|
||||||
|
} catch (BuildException $e) {
|
||||||
|
//bad secret, so try agiain
|
||||||
|
//echo "BAD STRING";
|
||||||
|
return self::randomString(12);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Token::validate($key, $string)) {
|
||||||
|
return $string;
|
||||||
|
} else {
|
||||||
|
return self::randomString(12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function checkSpecial($string)
|
||||||
|
{
|
||||||
|
$specials = ['*', '&', '!', '@', '%', '^', '#', '$'];
|
||||||
|
$valid = false;
|
||||||
|
foreach ($specials as $item) {
|
||||||
|
if (strpos($string, $item)) {
|
||||||
|
return $valid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
}
|
49
brain/views/dash/_frame.twig
Normal file
49
brain/views/dash/_frame.twig
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="theme-color" content="#FFFFFF"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>
|
||||||
|
{% block title %}
|
||||||
|
{{ title }}
|
||||||
|
{% endblock %}
|
||||||
|
</title>
|
||||||
|
{% block stylesheets %}{% endblock %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% if status %}
|
||||||
|
<header>
|
||||||
|
{% apply spaceless %}
|
||||||
|
<nav role="top-nav">
|
||||||
|
<div role="nav-left">
|
||||||
|
<a href="/dashboard"><img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/></a>
|
||||||
|
</div>
|
||||||
|
<div role="title">
|
||||||
|
<h1>{{ title }}</h1>
|
||||||
|
</div>
|
||||||
|
<div role="nav-right">
|
||||||
|
{% if status %}
|
||||||
|
{% apply spaceless %}
|
||||||
|
{{ include("dash/partials/navigation.twig") }}
|
||||||
|
{% endapply %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<div role="notify">
|
||||||
|
{% apply spaceless %}
|
||||||
|
{{ include("dash/partials/notifications.twig") }}
|
||||||
|
{% endapply %}
|
||||||
|
</div>
|
||||||
|
{% endapply %}
|
||||||
|
{% endif %}
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
{% apply spaceless %}
|
||||||
|
{% block mainContent %}{% endblock %}
|
||||||
|
{% endapply %}
|
||||||
|
</main>
|
||||||
|
<footer></footer>
|
||||||
|
<script type="module" src="/assets/scripts/dash.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
80
brain/views/dash/book.twig
Normal file
80
brain/views/dash/book.twig
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
{% extends "dash/_frame.twig" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{{ title }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block stylesheets %}
|
||||||
|
<link rel="stylesheet" type="text/css" href="/assets/css/dash/start.css?=vdthg">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block mainContent %}
|
||||||
|
<section role="book-index-header">
|
||||||
|
<div role="book-index-header-left">
|
||||||
|
{{ filter }}
|
||||||
|
Pages
|
||||||
|
</div>
|
||||||
|
<div role="book-index-header-right">
|
||||||
|
<a href="/dashboard/pages/all" title="view all pages">
|
||||||
|
<button>
|
||||||
|
<i class="ti ti-clipboard-list"></i>
|
||||||
|
{{ stats['all'] }}
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
|
<a href="/dashboard/pages/published" title="view publised pages">
|
||||||
|
<button>
|
||||||
|
<i class="ti ti-clipboard-check"></i>
|
||||||
|
{{ stats['published'] }}
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
|
<a href="/dashboard/pages/deleted" title="view deleted pages">
|
||||||
|
<button>
|
||||||
|
<i class="ti ti-clipboard-off"></i>
|
||||||
|
{{ stats['deleted'] }}
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
|
</section>
|
||||||
|
<section role="book-index-pages">
|
||||||
|
{% for page in pages %}
|
||||||
|
{% if page.media[0].type == 'mp4' %}
|
||||||
|
<a href="/dashboard/page/edit/{{ page.uuid }}" id="{{ page.uuid }}" class="page-link">
|
||||||
|
<div class="page-video">
|
||||||
|
<video class="post-video" loop muted autoplay>
|
||||||
|
<source src="{{ page.media[0].file }}" type="video/mp4">
|
||||||
|
|
||||||
|
Sorry, your browser doesn't support embedded videos.
|
||||||
|
</video>
|
||||||
|
<div id="meta">
|
||||||
|
{{ include("dash/partials/recent-meta.twig") }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="page-link" href="/dashboard/page/edit/{{ page.uuid }}">
|
||||||
|
<div class="page-bg" style="background: url({{ page.media[0].file }}) no-repeat center center / cover #fc6399">
|
||||||
|
<div id="meta">
|
||||||
|
{{ include("dash/partials/recent-meta.twig") }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% if numOfPages > 1 %}
|
||||||
|
<div role="paginate">
|
||||||
|
<a class="page-btns" href="/dashboard/pages/{{ paginate['sort'] }}/{{ paginate['prevPage'] }}">
|
||||||
|
<i class="ti ti-square-arrow-left"></i>
|
||||||
|
</a>
|
||||||
|
<span class="count">
|
||||||
|
{{ currentPage }}
|
||||||
|
of
|
||||||
|
{{ numOfPages }}
|
||||||
|
</span>
|
||||||
|
<a class="page-btns" href="/dashboard/pages/{{ paginate['sort'] }}/{{ paginate['nextPage'] }}">
|
||||||
|
<i class="ti ti-square-arrow-right"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
120
brain/views/dash/email.twig
Normal file
120
brain/views/dash/email.twig
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
|
||||||
|
<meta name='viewport' content='width=device-width, initial-scale=1.0' />
|
||||||
|
<title>
|
||||||
|
{{title}}
|
||||||
|
</title>
|
||||||
|
<style type="text/css">
|
||||||
|
/* reset */
|
||||||
|
#outlook a {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
/* Force Outlook to provide a "view in browser" menu link. */
|
||||||
|
.ExternalClass {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
/* Force Hotmail to display emails at full width */
|
||||||
|
.ExternalClass,
|
||||||
|
.ExternalClass p,
|
||||||
|
.ExternalClass span,
|
||||||
|
.ExternalClass font,
|
||||||
|
.ExternalClass td,
|
||||||
|
.ExternalClass div {
|
||||||
|
line-height: 100%;
|
||||||
|
}
|
||||||
|
/* Forces Hotmail to display normal line spacing. More on that: http://www.emailonacid.com/forum/viewthread/43/ */
|
||||||
|
p {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-size: 0px;
|
||||||
|
line-height: 0px;
|
||||||
|
}
|
||||||
|
/* squash Exact Target injected paragraphs */
|
||||||
|
table td {
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
/* Outlook 07, 10 padding issue fix */
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
mso-table-lspace: 0pt;
|
||||||
|
mso-table-rspace: 0pt;
|
||||||
|
}
|
||||||
|
/* remove spacing around Outlook 07, 10 tables */
|
||||||
|
/* bring inline */
|
||||||
|
img {
|
||||||
|
display: block;
|
||||||
|
outline: none;
|
||||||
|
text-decoration: none;
|
||||||
|
-ms-interpolation-mode: bicubic;
|
||||||
|
}
|
||||||
|
a img {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #000001;
|
||||||
|
}
|
||||||
|
/* text link */
|
||||||
|
a.phone {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #000001 !important;
|
||||||
|
pointer-events: auto;
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
/* phone link, use as wrapper on phone numbers */
|
||||||
|
span {
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 17px;
|
||||||
|
font-family: monospace;
|
||||||
|
color: #000001;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table cellpadding='0' cellspacing='0' border='0' style="margin:0; padding:0; width:100%; line-height: 100% !important;">
|
||||||
|
<tr>
|
||||||
|
<td valign='top'>
|
||||||
|
{# edge wrapper #}
|
||||||
|
<table cellpadding='0' cellspacing='0' border='0' align='center' width='600' style='background: #374857;'>
|
||||||
|
<tr>
|
||||||
|
<td valign='top' style='vertical-align: top;')>
|
||||||
|
{# info table start #}
|
||||||
|
<table cellpadding='0' cellspacing='0' border='0' align='center' style='width:100%'>
|
||||||
|
<tr>
|
||||||
|
<td valign='top' style='vertical-align: top;text-align: center; padding: 10px'>
|
||||||
|
<span style='font-family: Arial,Helvetica Neue,Helvetica,sans-serif; color:#f5ab35; font-size:20px; font-weight: bold;'>
|
||||||
|
{{ header }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td valign='top' style='vertical-align: top; background: #161d23; padding:10px;'>
|
||||||
|
<span style='font-family: Arial,Helvetica Neue,Helvetica,sans-serif; color:#cecece; font-size:16px;'>
|
||||||
|
{{ content }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td valign='top' style='vertical-align: top; padding: 10px;'>
|
||||||
|
<span style='font-family: Arial,Helvetica Neue,Helvetica,sans-serif; color:#b2cce5; font-size:12px;'>
|
||||||
|
{{ footer }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
{# info table end #}
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
16
brain/views/dash/forms/init-backup.twig
Normal file
16
brain/views/dash/forms/init-backup.twig
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<div>
|
||||||
|
<a href="/dashboard">
|
||||||
|
<img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<form id="init-restore" method="POST">
|
||||||
|
<input type="text" name="restore_member_handle" id="restore_member_handle" placeholder="handle"/><input type="password" name="restore_member_pass" id="restore_member_pass" placeholder="password"/>
|
||||||
|
<div>
|
||||||
|
<label>Grab your backup zip</label>
|
||||||
|
<input id="backup-upload" type="file" name="backup-upload" placeholder="Backup Zip"/>
|
||||||
|
</div>
|
||||||
|
<br/><br/>
|
||||||
|
<button id="blog-restore" data-action='blog-restore' type='submit'>RESTORE</button>
|
||||||
|
<br/><br/>
|
||||||
|
<button class="init-option" id="init-switch-fresh">OR INSTALL FROM SCRATCH</button>
|
||||||
|
</form>
|
15
brain/views/dash/forms/init-fresh.twig
Normal file
15
brain/views/dash/forms/init-fresh.twig
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<div>
|
||||||
|
<a href="/dashboard">
|
||||||
|
<img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<form id="init-form" method="POST" onsubmit="return false;">
|
||||||
|
<input type="text" name="new_member_handle" id="new_member_handle" placeholder="handle"/>
|
||||||
|
<input type="text" name="new_member_email" id="new_member_email" placeholder="email"/>
|
||||||
|
<input type="text" name="new_member_pass" id="new_member_pass" placeholder="password"/>
|
||||||
|
<input type="text" name="new_member_pass2" id="new_member_pass2" placeholder="password confirm"/>
|
||||||
|
<input type="text" name="new_member_title" id="new_member_title" placeholder="title"/>
|
||||||
|
<button id="init-blog" data-action='blog-init' type='submit'>SET UP YOUR SITE</button>
|
||||||
|
<br/><br/>
|
||||||
|
<button class="init-option" id="init-switch-restore">RESTORE FROM BACKUP</button>
|
||||||
|
</form>
|
13
brain/views/dash/forms/login.twig
Normal file
13
brain/views/dash/forms/login.twig
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<section role="login">
|
||||||
|
<div>
|
||||||
|
<img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/>
|
||||||
|
</div>
|
||||||
|
<form id="login" class='login' name="login" method="POST" onsubmit="return false;">
|
||||||
|
<input type="text" name="handle" class="form-control" placeholder="Handle" required/>
|
||||||
|
<input type="password" name="password" class="form-control" placeholder="Password" required/>
|
||||||
|
<button id="login-btn" class='login-btn'>
|
||||||
|
ID, PLEASE
|
||||||
|
</button>
|
||||||
|
<a href="/dashboard/reset-password">?</a>
|
||||||
|
</form>
|
||||||
|
</section>
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue