Compare commits
62 Commits
89ae41d9ec
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 21c1d22859 | |||
| 68b328dabc | |||
| 817bd17959 | |||
| 77dd99ee2b | |||
| 857f33be54 | |||
| 320a98893a | |||
| e07fb3a72a | |||
| 1bb588d1d2 | |||
| aa1cb7411c | |||
| 5fe8c015f1 | |||
| 6f9538053c | |||
| 5e503cf3a5 | |||
| ce860cfef9 | |||
| 989755d33c | |||
| 9ddf52c635 | |||
| 9b62f79301 | |||
| 64aa9ec023 | |||
| 9bfd96af2c | |||
| 000af6934f | |||
| c94e36a861 | |||
| 2c831628b2 | |||
| 02fc666661 | |||
| c3cb224402 | |||
| 2b8ea1963b | |||
| f94880e758 | |||
| b6142cee44 | |||
| 53bfe5955d | |||
| 9f503c011d | |||
| 415d95ed47 | |||
| e787544a2b | |||
| 9f94164c61 | |||
| 608ccfdecd | |||
| 933652fd57 | |||
| fdaed1033a | |||
| bc77baca2e | |||
| 7c9a55224a | |||
| 85ba3747b1 | |||
| 71f8629d18 | |||
| b1492918d5 | |||
| 95ea38d250 | |||
| 81be69f08d | |||
| 71eaa3e788 | |||
| 5c75f1416f | |||
| 3379e50503 | |||
| 30c8937566 | |||
| 770a96b099 | |||
| 604ba00c70 | |||
| b6c9d0b2ac | |||
| 51ab99b839 | |||
| 2f733e5ffc | |||
| d7e3162f55 | |||
| 8e127e7e3a | |||
| e853cb543a | |||
| e29953ab90 | |||
| 366974475f | |||
| fa29888578 | |||
| 31f3c6fb2f | |||
| 936662e35c | |||
| a440583691 | |||
| 6486d377b2 | |||
| 6c842ebe7f | |||
| 89c9771a84 |
@@ -1,5 +1,9 @@
|
||||
/plugins/
|
||||
!/plugins/
|
||||
/plugins/*
|
||||
!/plugins/.gitkeep
|
||||
!/plugins/cache-on-save/
|
||||
!/plugins/story-blocks/
|
||||
/data/
|
||||
/pages/01.trips/italy-2026-demo/
|
||||
/pages/02.post/*ui-test*/
|
||||
/config/plugins/git-sync.yaml
|
||||
/config/security.yaml
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
login: mischa
|
||||
state: enabled
|
||||
title: Mischa
|
||||
title: ''
|
||||
email: mischa@gorinskat.nl
|
||||
fullname: Mischa
|
||||
hashed_password: $2y$10$gAhnWvgzquwC0Vg5vwSJee22eO5kLxphS4RiqMZv9nf61kX.96XW6
|
||||
hashed_password: $2y$10$xyV7bAUWEo75K6LbatUuYe/6x2Tj9nT6YnIjaDvESAhU2hJ7tjG2.
|
||||
language: en
|
||||
modified: 1781874349
|
||||
modified: 1782051328
|
||||
admin_next:
|
||||
preferences:
|
||||
pluginsViewMode: cards
|
||||
@@ -13,6 +13,9 @@ admin_next:
|
||||
accentHue: 271
|
||||
accentSaturation: 91
|
||||
fontFamily: inter
|
||||
pagesViewMode: tree
|
||||
content_editor: ''
|
||||
groups: { }
|
||||
access:
|
||||
admin:
|
||||
login: true
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
salt: HlC0NrX9QsYq1S
|
||||
@@ -1,10 +1,9 @@
|
||||
title: 'Into the East'
|
||||
description: 'A travel blog by Mischa'
|
||||
author:
|
||||
name: Mischa
|
||||
email: mischa@gorinskat.nl
|
||||
taxonomies: [category, tag]
|
||||
metadata:
|
||||
description: 'Into the East — travel journal'
|
||||
active_trip: /trips/italy-2026-demo
|
||||
travelling: true
|
||||
description: 'A travel blog by Mischa'
|
||||
active_trip: /trips/us-canada-mex-2024
|
||||
travelling: false
|
||||
|
||||
@@ -4,12 +4,12 @@ date: '2023-08-28 07:49'
|
||||
template: entry
|
||||
published: true
|
||||
hero_image: 'photo-1.png'
|
||||
lat: ''
|
||||
lng: ''
|
||||
lat: '52.5200'
|
||||
lng: '13.4050'
|
||||
location_city: 'Berlin'
|
||||
location_country: 'Germany'
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
weather_temp_c: '24'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
Welcome to my picture diary of my 2023 adventure through Central Asia! Get ready for a visual journey through breathtaking landscapes and unforgettable moments! Join me as I explore the winding roads of Kazakhstan, Kyrgyzstan, Tajikistan, and Uzbekistan. Follow along as I share one picture per day, capturing unique experiences and adding stories to bring them to life. Get inspired and come along on this exciting adventure with me!
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'Last Beer Before the Foreign Land'
|
||||
date: '2023-08-29 10:29'
|
||||
template: entry
|
||||
transport_mode: train
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
lat: '52.36402'
|
||||
lng: '13.50745'
|
||||
location_city: 'Berlin'
|
||||
location_country: 'Germany'
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
weather_temp_c: '24'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
Today the trip has become a reality, passed through security and waiting at the gate... A strange feeling, the months of anticipation are changing into a reality that so far only has lived in fantasy and bank statements... A last German beer to sooth that anxious feeling of knowing that for the next few months everything will be different!
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'The UAZ Buchanka Counter Begins'
|
||||
date: '2023-08-30 18:06'
|
||||
template: entry
|
||||
transport_mode: plane
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '51.140108'
|
||||
lng: '71.429747'
|
||||
location_city: 'Astana'
|
||||
location_country: 'Kazakhstan'
|
||||
weather_temp_c: '15'
|
||||
weather_desc: 'rainy'
|
||||
---
|
||||
|
||||
A simple van, quite boring even if I'd say to myself after all I've seen today. Though this is not just some van, it's a UAZ "Buchanka". I do have a special and weird relationship with these cars, the little UAZ 469 brother as well. Within first 50 meters of my Hostel i saw this one and i couldn't resist capturing it on my camera... so far this is Number 2 i spotted during my trip! I'll keep the counter running...
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'Baiterek: Bird of Happiness in Astana'
|
||||
date: '2023-08-31 16:45'
|
||||
template: entry
|
||||
transport_mode: walking
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
lat: '51.128246'
|
||||
lng: '71.430466'
|
||||
location_city: 'Astana'
|
||||
location_country: 'Kazakhstan'
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
weather_temp_c: '15'
|
||||
weather_desc: 'cloudy'
|
||||
---
|
||||
|
||||
After finishing my Beshbarmak I was thinking it would be today's picture. Even though it's Kazakhstans main dish, it doesn't represent my day which was about Kazakhstans history and culture ... So.... Бәйтерек (Baïterek) a monument built to support the moving of the capital from Almaty to Astana. It symbolizes the mythical tree of live in which Samruk, the bird of happiness, has laid it's egg. A new beginning for Kazakhstan after its independence.
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'Doshirak and Politics on the Night Train'
|
||||
date: '2023-09-02 15:47'
|
||||
template: entry
|
||||
transport_mode: train
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
lat: '43.2220'
|
||||
lng: '76.8512'
|
||||
location_city: 'Almaty'
|
||||
location_country: 'Kazakhstan'
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
weather_temp_c: '25'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
Last night I took a 15 hour train ride from Astana to Almaty. A modern train with a bar and self prepared Doshirak noodles.
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'Plov and Street Art in Almaty'
|
||||
date: '2023-09-03 16:38'
|
||||
template: entry
|
||||
transport_mode: train
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
lat: '43.2220'
|
||||
lng: '76.8512'
|
||||
location_city: 'Almaty'
|
||||
location_country: 'Kazakhstan'
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
weather_temp_c: '24'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
Almaty, a wonderful city in which I realise will not be able to spend enough time. Its more modern (it has so many bikelanes), has more character than Astana, but also is on the border with beautiful nature...
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
title: 'Rain in Charyn Canyon, Manti for Dinner'
|
||||
date: '2023-09-04 15:50'
|
||||
template: entry
|
||||
transport_mode: car
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
hero_image: photo-1.jpg
|
||||
lat: '43.35102'
|
||||
lng: '79.08010'
|
||||
location_city: 'Charyn Canyon'
|
||||
location_country: Kazakhstan
|
||||
weather_temp_c: '18'
|
||||
weather_desc: 'cloudy with showers'
|
||||
featured: true
|
||||
---
|
||||
|
||||
The adventure started, a big jeep, few adventurous tourists and our guide Aybek.
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'Kurt, Kumis and a UAZ Dream Ride'
|
||||
date: '2023-09-05 15:50'
|
||||
template: entry
|
||||
transport_mode: car
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '43.068370'
|
||||
lng: '78.412857'
|
||||
location_city: 'Kaindy / Kolsai'
|
||||
location_country: 'Kazakhstan'
|
||||
weather_temp_c: '20'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
The planned focus of today was nature! Seeing Kaindy and Kolsai lakes. They are amazingly beautiful.
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'First Hike Up Toward Ala Kol'
|
||||
date: '2023-09-07 17:00'
|
||||
template: entry
|
||||
transport_mode: car
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
lat: '42.4900'
|
||||
lng: '78.3936'
|
||||
location_city: 'Karakol'
|
||||
location_country: 'Kyrgyzstan'
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
weather_temp_c: '0'
|
||||
weather_desc: 'partly cloudy'
|
||||
---
|
||||
|
||||
Via the border at Kegen, I made it to Karakol. Ala Kol is the most beautiful of all Kyrgyz lakes! In a good mood I set out and after taking a drive with a UAZ 469B 😎 I started going up. 500 meters upward and 15km further I found a camp to spend the night. Next I planned to go to the lake and take the same route back. This track is not for inexperienced hikers. After a 300 meter incline I decided to go back and not get stuck with 0 energy. Im proud of my achievement as a first time hiker!
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'Tea Trails and No Seatbelts in Kyrgyzstan'
|
||||
date: '2023-09-10 06:16'
|
||||
template: entry
|
||||
transport_mode: bus
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '42.876640'
|
||||
lng: '74.603745'
|
||||
location_city: 'Bishkek'
|
||||
location_country: 'Kyrgyzstan'
|
||||
weather_temp_c: '16'
|
||||
weather_desc: 'partly cloudy'
|
||||
---
|
||||
|
||||
Kyrgyzstan is a beautiful country with many mountains, beautiful lakes, friendly people and no seatbelts. I definitely did not get a full grasp of it all... Just a brief morning in Karakol half a day in Bishkek, room with a view, and a quick flight to OSU for just half an evening... I did however start to explore the many different teas they serve here. Now the adventure continuous toward the Pamir mountains in Tajikistan!
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: "Stuck in No Man's Land at 4655m"
|
||||
date: '2023-09-18 03:20'
|
||||
template: entry
|
||||
transport_mode: car
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '39.384414'
|
||||
lng: '73.322529'
|
||||
location_city: 'Akbaital Pass'
|
||||
location_country: 'Tajikistan'
|
||||
weather_temp_c: '16'
|
||||
weather_desc: 'partly cloudy'
|
||||
---
|
||||
|
||||
10-09 - The day marks an end to being a guest in Kyrgyzstan and a beginning of being welcomed by Tajik hospitality. We drive from Osh to Karakul (TJ) and climb from about 1000 meters to nearly 4000 meters altitude. We cross the Akbaital Pass (4655m) and try to leave Kyrgyzstan.
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'Black Water Lake on the Pamir Highway'
|
||||
date: '2023-09-19 05:50'
|
||||
template: entry
|
||||
transport_mode: car
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '39.01250'
|
||||
lng: '73.55978'
|
||||
location_city: 'Karakul'
|
||||
location_country: 'Tajikistan'
|
||||
weather_temp_c: '15'
|
||||
weather_desc: 'windy'
|
||||
---
|
||||
|
||||
10-09 - In the middle of no mans land, right on the actual border, our new driver was waiting and we started our tour through Tajikistan. The epic and harsh nature of the Pamirs is spectacular and makes it unimaginable how people can survive here, especially In winter. We ended in Karakul, not Karakol where I was before. Kara means black, kul means lake. The lake has beautiful.colours depending on the sunlight, but its name comes from the fact thats its fed with ground (black) water.
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'Warm Soup in a Village of Hundreds'
|
||||
date: '2023-09-19 06:04'
|
||||
template: entry
|
||||
transport_mode: car
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '37.755579'
|
||||
lng: '73.271513'
|
||||
location_city: 'Alichur'
|
||||
location_country: 'Tajikistan'
|
||||
weather_temp_c: '15'
|
||||
weather_desc: 'windy'
|
||||
---
|
||||
|
||||
11-09 - In this village live just a few hundred people and there is a small military base. There is a school and a mosque, a very hard to find shop (we did not succeed) and some water wells. People drive old, rugged, Soviet UAZs, its the only affordable machine that can survive the rocky roads.
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'Afghanistan Just Across the Wakhan River'
|
||||
date: '2023-09-23 08:41'
|
||||
template: entry
|
||||
transport_mode: car
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '37.032071'
|
||||
lng: '72.630602'
|
||||
location_city: 'Zong'
|
||||
location_country: 'Tajikistan'
|
||||
weather_temp_c: '28'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
PMU14-9 - Zong (what a name, huh). We descended from the harsh Pamir Plateau into the greener Wakhan valley. Epic views and epic roads (our driver is a hero) we past in our study Toyota Landcruiser. To finally meet another mysterious land, that became an obsession in our group...
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'The Night the Beer Finally Arrived'
|
||||
date: '2023-09-23 08:29'
|
||||
template: entry
|
||||
transport_mode: car
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '37.755660'
|
||||
lng: '73.271591'
|
||||
location_city: 'Alichur'
|
||||
location_country: 'Tajikistan'
|
||||
weather_temp_c: '15'
|
||||
weather_desc: 'windy'
|
||||
---
|
||||
|
||||
PMU13-9 - Alichur, slightly less harsh than Karakul, there is grass for yaks and sheep.
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
---
|
||||
title: "Farewell Vodka Under the World's Tallest Flag"
|
||||
date: '2023-09-20 16:19'
|
||||
date: '2023-10-01 18:00'
|
||||
template: entry
|
||||
transport_mode: car
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
lat: '38.5598'
|
||||
lng: '68.7870'
|
||||
location_city: 'Dushanbe'
|
||||
location_country: 'Tajikistan'
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
weather_temp_c: '28'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
Dushanbe, a warm welcome back into civilization after the Pamirs. Another kind of weird modern city, the central park is beautiful and they have a huge flag. The pole was the largest in the world, till recently. Its over 150 meters and the flag weighs more than 700 kgs.
|
||||
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 250 KiB After Width: | Height: | Size: 250 KiB |
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 99 KiB |
@@ -2,14 +2,15 @@
|
||||
title: 'Hot Springs and a Pamiri Homestay'
|
||||
date: '2023-10-01 10:40'
|
||||
template: entry
|
||||
transport_mode: car
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '36.983527'
|
||||
lng: '72.264250'
|
||||
location_city: 'Ishkashim / Bibi Fatima'
|
||||
location_country: 'Tajikistan'
|
||||
weather_temp_c: '18'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
PMU15-9 - Along the way we visited a traditional Pamiri house. We've slept in quite a few with a similar design. The guide gave us insights in how people lived. Usually three/four generations shared a single house with usually two rooms. They were multipurpose rooms for cooking, living and sleeping.
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'What Is Normal? Reflections from Khorog'
|
||||
date: '2023-10-01 10:51'
|
||||
template: entry
|
||||
transport_mode: car
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '37.49046'
|
||||
lng: '71.53921'
|
||||
location_city: 'Khorog'
|
||||
location_country: 'Tajikistan'
|
||||
weather_temp_c: '25'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
Recap - When travelling to new places, I always wonder what is their "normal" and how much do i perceive this as "weird".
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
---
|
||||
title: 'Millionaires and Minarets in Bukhara'
|
||||
date: '2023-09-23 08:14'
|
||||
date: '2023-10-02 00:00'
|
||||
template: entry
|
||||
transport_mode: train
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '39.775957'
|
||||
lng: '64.416693'
|
||||
location_city: 'Bukhara'
|
||||
location_country: 'Uzbekistan'
|
||||
weather_temp_c: '25'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
In Uzbekistan everyone can be a millionaire, it only costs about €80. A handmade magnet costs 25k and a beer 30k. Definitely the hardest currency to convert in my mind this trip.
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'Four Weeks in Central Asia, Barely Enough'
|
||||
date: '2023-10-03 07:58'
|
||||
template: entry
|
||||
transport_mode: train
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: 'Tbilisi'
|
||||
location_country: 'Georgia'
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '40.37660'
|
||||
lng: '49.84752'
|
||||
location_city: 'Baku'
|
||||
location_country: 'Azerbaijan'
|
||||
weather_temp_c: '24'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
The holiday adventure is over. 4 weeks of central Asia was just enough to scratch the surface on most countries and I definitely went to go back!
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: "Timur's Samarkand and a Badly Parked Truck"
|
||||
date: '2023-10-03 07:38'
|
||||
template: entry
|
||||
transport_mode: train
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '39.65841'
|
||||
lng: '66.98542'
|
||||
location_city: 'Samarkand'
|
||||
location_country: 'Uzbekistan'
|
||||
weather_temp_c: '25'
|
||||
weather_desc: 'sunny'
|
||||
---
|
||||
|
||||
Samarkand, Amir Timur made this city great again as the capital of his vast empire. It sparked a wave of Islamic art inspired by the styles in Persia. The buildings are beautifully restored, sometimes with a little imagination. It gives however a great feeling of how these buildings must have looked like, simply beautiful!
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
title: 'Hunting the Mother of Georgia from Above'
|
||||
date: '2023-10-18 07:38'
|
||||
template: entry
|
||||
transport_mode: plane
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
lat: '41.6938'
|
||||
lng: '44.8015'
|
||||
location_city: 'Tbilisi'
|
||||
location_country: 'Georgia'
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
weather_temp_c: '20'
|
||||
weather_desc: 'partly cloudy'
|
||||
---
|
||||
|
||||
Past weekend. I was fit enougto exploe more of Tbilisi. A hike in the nearby mountains gave great views of the city and the backside of the Mother of Georgia statue. So I went on a mission to capture her majestic front.... not so easy in a hily city, but I managed.
|
||||
|
||||
@@ -6,3 +6,4 @@ date_start: '2025-10-11'
|
||||
date_end: '2025-10-16'
|
||||
cover_image: ''
|
||||
---
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@ date: '2024-05-28 07:03'
|
||||
template: entry
|
||||
published: true
|
||||
hero_image: 'photo-1.jpg'
|
||||
lat: ''
|
||||
lng: ''
|
||||
location_city: ''
|
||||
location_country: ''
|
||||
weather_temp_c: ''
|
||||
weather_desc: ''
|
||||
lat: '45.5285'
|
||||
lng: '13.5680'
|
||||
location_city: Piran
|
||||
location_country: Slovenia
|
||||
weather_temp_c: '21'
|
||||
weather_desc: sunny
|
||||
---
|
||||
|
||||
A sunny day in Piran. We drove from Ljubljana through the beautiful Slovenian countryside. The more west we went, the more Mediterranean the landscape felt. Piran is a cute, Mediterranean harbor town, with little streets, squares and no cars. The view from the old fortification walls was great and the climb in the warm weather gave us a sense of accomplishment which we rewarded with a well deserved ice cream.
|
||||
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 202 KiB After Width: | Height: | Size: 202 KiB |
|
Before Width: | Height: | Size: 237 KiB After Width: | Height: | Size: 237 KiB |
|
Before Width: | Height: | Size: 302 KiB After Width: | Height: | Size: 302 KiB |
@@ -0,0 +1,11 @@
|
||||
---
|
||||
title: 'The Journey'
|
||||
template: dailies
|
||||
content:
|
||||
items: '@self.children'
|
||||
order:
|
||||
by: date
|
||||
dir: desc
|
||||
filter:
|
||||
published: true
|
||||
---
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
title: 'Trip Map'
|
||||
template: map
|
||||
---
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
title: 'Trip Stats'
|
||||
template: stats
|
||||
---
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
title: Stories
|
||||
template: stories
|
||||
published: true
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
title: 'Slovenia 2024'
|
||||
template: trip
|
||||
date: '2024-05-28'
|
||||
date_start: '2024-05-28'
|
||||
date_end: '2024-05-28'
|
||||
cover_image: ''
|
||||
---
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: 'Northern America 2024'
|
||||
template: trip
|
||||
date: '2024-05-28'
|
||||
date_start: '2024-05-28'
|
||||
date: '2024-07-21'
|
||||
date_start: '2024-07-21'
|
||||
date_end: '2024-08-07'
|
||||
cover_image: ''
|
||||
---
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
title: 'Into the East'
|
||||
visible: false
|
||||
routable: true
|
||||
routes:
|
||||
default: /
|
||||
---
|
||||
|
||||
Dispatches from foreign lands and places closer by. A few moments worth remembering, collected here while I'm between trips.
|
||||
|
||||
-- Mischa
|
||||
@@ -1,237 +0,0 @@
|
||||
# v3.3.0
|
||||
## 09/14/2023
|
||||
|
||||
1. [](#improved)
|
||||
- Added support multiple slug_fields to form unique slug, either as comma separated list or as array. Many thanks to walkload for the [pull request](https://github.com/bleutzinn/grav-plugin-add-page-by-form/pull/65)
|
||||
|
||||
# v3.2.0
|
||||
## 02/17/2023
|
||||
|
||||
1. [](#bugfix)
|
||||
- Fixed a problem when `pagefrontmatter.content` was set (issue [#63](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/63))
|
||||
1. [](#bugfix)
|
||||
- Fixed incorrect handling of using `pageconfig.parent: /` (issue [#59](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/59))
|
||||
1. [](#improved)
|
||||
- Added composer
|
||||
|
||||
# v3.1.0
|
||||
## 12/13/2022
|
||||
|
||||
1. [](#improved)
|
||||
- Tested with PHP version 8 (8.1.10)
|
||||
- Fixed some incorrect variable types in PHPDoc Comments
|
||||
1. [](#bugfix)
|
||||
- Changed the declaration of the function `sanitize` to "static". [#62](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/62)). Thanks to masetto for raising this issue.
|
||||
|
||||
# v3.0.4
|
||||
## 03/28/2022
|
||||
|
||||
1. [](#bugfix)
|
||||
- A title containing diacritic characters prevented a form submit (issues [#56](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/56) and [#60](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/60)). Thanks goes to davay for the pull request.
|
||||
|
||||
# v3.0.3
|
||||
## 05/29/2020
|
||||
|
||||
1. [](#bugfix)
|
||||
- Fixed not handling overwrite_mode setting properly, issue [#54](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/54), thanks to mooomooo for reporting and testing
|
||||
|
||||
# v3.0.2
|
||||
## 05/17/2020
|
||||
|
||||
1. [](#improved)
|
||||
- Yet another release. This time just to synchronize the versioning number in 'bleuprints.yaml' and this Changelog. For interesting changes see v3.0.0.
|
||||
|
||||
# v3.0.1
|
||||
## 05/17/2020
|
||||
|
||||
1. [](#improved)
|
||||
- Removed a newline between the version number and the date in this Changelog file in an attempt to restore the correct display of this file in the Grav repository
|
||||
|
||||
# v3.0.0
|
||||
## 05/03/2020
|
||||
|
||||
1. [](#new)
|
||||
- New 'overwrite_mode' option 'edit' allows for editing a page. Note: yet undocumented.
|
||||
- Removing upload files is now handled
|
||||
1. [](#bugfix)
|
||||
- Switched to Laravel str_slug function to remedy problems with hyphens on some Windows systems
|
||||
1. [](#improved)
|
||||
* (Possibly breaking change:) Changed uploaded files data structure from numeric array to associative array
|
||||
* (Possibly breaking change:) Changed default setting of 'physical_template_name' to 'true'
|
||||
* Minimum Grav version is set to 1.6
|
||||
|
||||
# v2.4.1
|
||||
## 04/12/2020
|
||||
|
||||
1. [](#bugfix)
|
||||
* Fixed a bug ([issue #52](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/52)) where an empty value for the 'slug' variable would delete folder(s). Thanks to [anton-mellit](https://github.com/anton-mellit) for reporting this.
|
||||
|
||||
# v2.4.0
|
||||
## 01/28/2020
|
||||
|
||||
1. [](#new)
|
||||
* Added a new config variable 'physical_template_name' to make using the new page template name as the new page's file name optional.
|
||||
1. [](#improved)
|
||||
* Removed the Changelog entry that was included in [https://github.com/bleutzinn/grav-plugin-add-page-by-form/pull/47](PR #47) from this file as it was not in the Grav Changelog format and prevented changes showing up correctly in the Grav Plugins download section.
|
||||
|
||||
# v2.3.5
|
||||
## 01/25/2020
|
||||
|
||||
1. [](#new)
|
||||
* Add option to suppress loading of simpleMDE assets (reduces overhead if its known it will not be used)
|
||||
|
||||
# v2.3.4
|
||||
## 01/20/2020
|
||||
|
||||
1. [](#bugfix)
|
||||
* Prepared a new release to mainly consolidate the fix "Use moveTo method not native copy to move uploaded files to final destination" and to bring this changelog format back in line with Grav requirements. Thanks to Dave Nichols (pd-giz-dave).
|
||||
1. [](#improved)
|
||||
* Also included the ability to use the new page template name as the new page's folder name. Thanks to Dave Nichols (pd-giz-dave).
|
||||
|
||||
# v2.3.3
|
||||
## 12/05/2019
|
||||
|
||||
1. [](#bugfix)
|
||||
* Fixed inconsistancies in version numbering which prevented the addition of the latest updates in the Grav Plugin repository.
|
||||
|
||||
# v2.3.2
|
||||
## 11/24/2019
|
||||
|
||||
1. [](#bugfix)
|
||||
* Prepared a new release to fix a bug in version numbering. The letter "v" appears to be case sensitive. The versions 2.3.0 and 2.3.1 were tagged with a capital "V" as V2.3.0 and V2.3.1 respectively. Previous versions were tagged using a lowercase "v". This difference causes the Grav Repository to think these are two different plugins.
|
||||
|
||||
# v2.3.1
|
||||
## 10/10/2019
|
||||
|
||||
1. [](#bugfix)
|
||||
* Fixed a subsequent failure to save file uploads to new page folder (form field File with `destination: @self`) introduced with Grav version 1.6.11 ([issue #44](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/44)). Thanks goes to mahagr for tips and to tranduyhung for the fix itself.
|
||||
|
||||
# v2.3.0
|
||||
## 06/06/2019
|
||||
|
||||
1. [](#bugfix)
|
||||
* Fixed the failure to save file uploads to new page folder (form field File with `destination: @self`) introduced with Grav version 1.6 ([issue #40](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/40))
|
||||
|
||||
# v2.2.0
|
||||
## 04/15/2018
|
||||
|
||||
1. [](#new)
|
||||
* Added support for `process.redirect: @self-admin` ([issue #13](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/31))
|
||||
1. [](#improved)
|
||||
* Fixed a problem with uploading files
|
||||
|
||||
# v2.1.0
|
||||
## 09/18/2017
|
||||
|
||||
1. [](#new)
|
||||
* Added support for taxonomy types and tags
|
||||
|
||||
# v2.0.0
|
||||
## 06/18/2017
|
||||
|
||||
1. [](#new)
|
||||
* Added support for multiple textarea editors ([issue #21](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/21))
|
||||
* Added support for `process.redirect: @self` ([issue #23](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/23))
|
||||
* Added the `overwrite_mode` configuration frontmatter variable
|
||||
* Added the `subroute` configuration frontmatter variable
|
||||
* Added the `slug_field` configuration frontmatter variable
|
||||
* Added filename sanitizing of uploaded files
|
||||
1. [](#improved)
|
||||
* In the form page frontmatter configuration variables are separated from variables which main purpose it is to get passed on to the new page
|
||||
* Uploaded file properties are now included in the new page frontmatter
|
||||
* Improved safe slug generator
|
||||
* Removed "use editor" option from `blueprints.yaml` (to allow [issue #21](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/21))
|
||||
* Extended `blueprints.yaml` to set "fallback" configuration values
|
||||
1. [](#bugfix)
|
||||
* Fixed an issue with form pages outside the web root ([issue #20](https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues/20))
|
||||
* Fixed a problem that prevented having different destinations for file uploads
|
||||
|
||||
# v1.4.2
|
||||
## 03/22/2017
|
||||
|
||||
1. [](#new)
|
||||
* Cleaned up code for release.
|
||||
|
||||
# v1.4.1
|
||||
## 02/16/2017
|
||||
|
||||
1. [](#improved)
|
||||
* Simplified YAML frontmatter formatting as suggested in
|
||||
https://github.com/getgrav/grav/issues/1287#issuecomment-279965492
|
||||
|
||||
# v1.4.0
|
||||
## 02/12/2017
|
||||
|
||||
1. [](#new)
|
||||
* Added the ability to include the File field in the form. When `destination` is `@self` uploaded files are stored in the new page folder.
|
||||
|
||||
# v1.3.2
|
||||
## 01/31/2017
|
||||
|
||||
1. [](#improved)
|
||||
* Removed the spyc.php class dependency; the page creation and YAML frontmatter handling is now done "the Grav way".
|
||||
|
||||
# v1.3.1
|
||||
## 01/15/2017
|
||||
|
||||
1. [](#improved)
|
||||
* Added jQuery as an asset.
|
||||
|
||||
# v1.3.0
|
||||
## 12/31/2016
|
||||
|
||||
1. [](#new)
|
||||
* Added the SimpleMDE Markdown Editor.
|
||||
|
||||
# v1.2.2
|
||||
## 12/29/2016
|
||||
|
||||
1. [](#improved)
|
||||
* Removed note about the (previous) test release in the ReadMe.
|
||||
|
||||
# v1.2.1
|
||||
## 12/29/2016
|
||||
|
||||
1. [](#improved)
|
||||
* Improved the usage explanation in the ReadMe.
|
||||
* Removed debug messages.
|
||||
|
||||
# v1.2.0
|
||||
## 12/23/2016
|
||||
|
||||
1. [](#improved)
|
||||
* Improved new page route handling.
|
||||
|
||||
# v1.1.1
|
||||
## 11/17/2016
|
||||
|
||||
1. [](#improved)
|
||||
* Removed dependency of PECL YAML function yaml_emit() in favor of using vendor/spyc.php class.
|
||||
|
||||
# v1.1.0
|
||||
## 11/16/2016
|
||||
|
||||
1. [](#new)
|
||||
* Settings in the pagefrontmatter block in the form page frontmatter now are merged with values from form fields. Form field values ovverride the pagefrontmatter settings.
|
||||
|
||||
# v1.0.0
|
||||
## 11/15/2016
|
||||
|
||||
1. [](#new)
|
||||
* Added an extra form field: 'author'
|
||||
* Added copying an (optional) frontmatter block from the form page frontmatter to the newly added page's frontmatter
|
||||
|
||||
# v0.2.0
|
||||
## 11/13/2016
|
||||
|
||||
1. [](#new)
|
||||
* Plugin name changed to Add Page By Form (add-page-by-form)
|
||||
* Added timestamp as date in page header (date format is taken from plugin config)
|
||||
* Pages with identical titles are saved by adding a incremental number to the page slug (e.g. 'my-page\_2', 'my-page\_2', etc.)
|
||||
* Added error handling
|
||||
|
||||
# v0.1.0
|
||||
## 11/08/2016
|
||||
|
||||
1. [](#new)
|
||||
* ChangeLog started...
|
||||
@@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Ron Wardenier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,444 +0,0 @@
|
||||
# Add Page By Form Plugin
|
||||
|
||||
The **Add Page By Form** Plugin is for [Grav CMS](http://github.com/getgrav/grav). It allows users to add a new page by filling in a form.
|
||||
|
||||
This plugin uses the possibilities of [custom frontmatter](https://learn.getgrav.org/content/headers#custom-page-headers). By setting your own variables in the form page frontmatter a priori and optionally letting users override these variable values by filling in corresponding form fields you can transport these data into the new page frontmatter.
|
||||
|
||||
The passing on of both the default settings and form field values entered by the end user to the new page frontmatter makes for an extremely configurable solution.
|
||||
By mixing default settings and configuring the page form you can to a large extent control the appearence and behaviour of the newly added page by using the frontmatter variables present in the new page in a Twig template.
|
||||
|
||||
For example, a new page can act as a new blog post simply by setting the appropriate template variable in the form page definition (with the AntiMatter theme, this is `template: item`). That template value is inserted in the new page frontmatter and, so, will be used by Grav to display the new page.
|
||||
|
||||
|
||||
## Security Warning
|
||||
|
||||
Allowing anonymous visitors to create pages is a potential website security risk. It is **strongly advised** to use the [Grav Login Plugin](https://github.com/getgrav/grav-plugin-login) or the [Private Grav Plugin](https://github.com/Diyzzuf/grav-plugin-private) **to restrict the page creation to logged in users only**.
|
||||
|
||||
This plugin itself does not provide any security measures. Please take this in consideration before using this plugin.
|
||||
|
||||
|
||||
## Installation and Configuration
|
||||
|
||||
Typically the plugin should be installed via [GPM](http://learn.getgrav.org/advanced/grav-gpm) (Grav Package Manager):
|
||||
|
||||
```
|
||||
$ bin/gpm install add-page-by-form
|
||||
```
|
||||
|
||||
Alternatively it can be installed via the [Admin Plugin](http://learn.getgrav.org/admin-panel/plugins).
|
||||
|
||||
Another option is to manualy install the plugin by [downloading](https://github.com/bleutzinn/grav-plugin-add-page-by-form/archive/master.zip) the plugin as a zip file. Copy the zip file to your `/user/plugins` directory, unzip it there and rename the folder to `add-page-by-form`.
|
||||
|
||||
### Configuration Defaults
|
||||
|
||||
Here is the default configuration in the configuration file `add-page-by-form.yaml` plus an explanation of the settings:
|
||||
|
||||
```yaml
|
||||
enabled: true
|
||||
date_display_format: 'd-m-Y g:ia'
|
||||
default_title: 'My New Page'
|
||||
default_content: 'No content.'
|
||||
overwrite_mode: false
|
||||
include_username: false
|
||||
auto_taxonomy_types: false
|
||||
use_editor_class: true
|
||||
physical_template_name: true
|
||||
```
|
||||
- `enabled` determines whether the plugin is active or not;
|
||||
- `date_display_format` sets a default date and time format;
|
||||
- `default_title` will be used as a fallback for the new page title when no other value is set;
|
||||
|
||||
- `default_content` will be used as the page content for the new page when no other value is set;
|
||||
- `include_username` sets whether or not the username of the currently logged in frontend user is included in the new page frontmatter;
|
||||
- `overwrite_mode` determines how to act when a page with the same name or slug already exists;
|
||||
- `auto_taxonomy_types` saves any new taxonomy types that were input by the user to the site configuration file `site.yaml`;
|
||||
- `use_editor_class` determines whether or not to change a textarea field into a Markdown editor when the texture field includes the class "editor" (`classes: editor`);
|
||||
- `physical_template_name` should normally not be used. For more information see the description in the section 'pageconfig' block variables.
|
||||
|
||||
|
||||
### Customizing the default configuration
|
||||
|
||||
To keep your custom configuration when updating the plugin you need to use a configuration file which is stored in the `user/config/plugins` folder.
|
||||
|
||||
Simply edit the plugin options in the Admin panel and the changes will be saved to the configuration file in that location. If you don't use the Admin panel, copy the `add-page-by-form.yaml` default file to your `user/config/plugins` folder and use that copy to change configuration settings.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Using this plugin requires:
|
||||
|
||||
- a normal page containing a Grav Form with a unique name that starts with "add_page";
|
||||
- optionally, but required for usefulness, one or two blocks of extra page frontmatter variables in that page being:
|
||||
- a 'pageconfig' block with variables that are used in the new page creation process;
|
||||
- a 'pagefrontmatter' block with variables that are passed on to the new page frontmatter and can be processed by Twig along the way.
|
||||
|
||||
### Modifying frontmatter variables
|
||||
|
||||
Every frontmatter variable value can be changed by the user when an input field with the same name as the variable is included in the form.
|
||||
|
||||
The basic method of modifying is overriding or replacing an initial value. An extreme case of overriding a variable which is quite uncommon but illustrates the process well:
|
||||
|
||||
1. `overwrite_mode` is set in `add-page-by-form.yaml`
|
||||
2. and can be changed in the Plugin configuration in the Admin Panel
|
||||
3. can be set in the `pageconfig` block
|
||||
4. and finally may be changed again by the end user when the form contains an `overwrite_mode` field.
|
||||
|
||||
### Page Headers / Frontmatter
|
||||
This plugin makes extensive use of [Custom Page Headers](https://learn.getgrav.org/content/headers#custom-page-headers). Unfortunately the Grav documentation mixes the terms "frontmatter", "page headers" and simply "headers". This may be confusing at first. They [all](https://learn.getgrav.org/content/headers) refer to the optional top part of a Grav page which contains data in [YAML syntax](https://learn.getgrav.org/advanced/yaml).
|
||||
|
||||
|
||||
## Form page Frontmatter
|
||||
|
||||
The frontmatter in the form page and the way it is handled by the plugin is where the flexibility of this plugin originates.
|
||||
|
||||
The form page frontmatter is divided into three sections or blocks:
|
||||
|
||||
1. So called 'root level' variables are intended to act upon the form page itself. They are not passed on to the new page;
|
||||
2. the `pageconfig` block contains variables that are used by the plugin in the new page creation process and do get passed on to the new page frontmatter;
|
||||
3. the `pagefrontmatter` block holds all other variables that must be passed on to the new page frontmatter.
|
||||
|
||||
### Root level variables
|
||||
|
||||
In the examples above the root level configuration options are:
|
||||
|
||||
- `title` sets the title of the page containing the form;
|
||||
- `template: form` activates the form on this page (not required when the form page is named `form.md`);
|
||||
- `form` defines the form.
|
||||
|
||||
From version 2, the use of `parent` in the, what is now called, root level block is deprecated. It is however still supported for backwards compatibility.
|
||||
|
||||
### 'pageconfig' block variables
|
||||
|
||||
In the optional pageconfig block you can set these, and only these, variables (other variables will be ignored):
|
||||
|
||||
- `parent` sets the parent page for the new page. This variable may be an absolute route (for example `parent: /user_contributions`) or a relative route (e.g. `parent: articles`. In case of an absolute route this route starts from the pages root. A relative route is regarded to start from the form page, so the new page will be a child page of the form page. The form page is also used as the parent page when the set parent page does not exist;
|
||||
- `subroute` defines a route from the (initial) parent value. If one or more folders in the route do not exist they will be created;
|
||||
- `slug_field` tells the plugin what field or fields to use as the new page's slug or folder name. Multiple form field names may be specified either using a comma separated string or as an array. When `slug_field` is missing the plugin tries to use the value of `title`;
|
||||
- `overwrite_mode: true|false|edit` (default `false`) tells the plugin what to do when a page with the same name already exists. With `overwrite_mode: true` the existing page is overwritten. Any additional (media) files besides the page itself which are stored in the existing page folder are deleted as well. With `overwite_mode: false` the new page slug gets a sequential number attached at the end (for example "my-new-page-1" in case "my-new-page" exists).
|
||||
Using `overwite_mode: edit` allows for the page being saved to it's existing folder respecting any already present uploaded files;
|
||||
- `include_username: true|false` (default `false`) determines whether or not to include the username of a logged in frontend user in the new page frontmatter;
|
||||
- `physical_template_name: true|false` (default `true`) does or does not cause the plugin to use the template name of the new page as that new page's filesystem filename. Defaults to "default" when no template is set in the 'pagefrontmatter' block. When set to `true` to avoid future confusion the frontmatter variable `template` is removed from the new page frontmatter.
|
||||
|
||||
#### A note on parent and subroute
|
||||
|
||||
Together the variables `parent` and `subroute` define the new page's destination. Or, in other words, together they set the path or route of the new page filesystem folder in the page structure.
|
||||
|
||||
The difference between parent and subroute worded in another way:
|
||||
|
||||
- Parent: works on a page level; when there is no page at the parent route, the form page is used as the parent;
|
||||
- Subroute: works on a folder level; a subroute may consist of empty folders and if a folder in the subroute does not exist it gets created.
|
||||
|
||||
### 'pagefrontmatter' block variables
|
||||
|
||||
The content of the optional `pagefrontmatter` block will be included in the new page frontmatter.
|
||||
|
||||
|
||||
## Form usage
|
||||
|
||||
The form page needs to use a [simple single form](https://learn.getgrav.org/forms/forms#create-a-simple-single-form).
|
||||
|
||||
Two examples are included at the end of this ReadMe file.
|
||||
|
||||
### Mandatory fields and values
|
||||
|
||||
#### Form Name
|
||||
It is always a good thing to give each form a unique name, especially when multiple forms are used.
|
||||
|
||||
To pre fill form fields with default values the Form name must include the string "add_page". Valid names are for example `add_page.blogpost`, `add_page_profile`.
|
||||
|
||||
###Form Actions
|
||||
|
||||
**Custom Form processing** ( Important ! )
|
||||
|
||||
To let the plugin process the form after a Submit a custom process action must be set like so:
|
||||
|
||||
```
|
||||
process:
|
||||
-
|
||||
add_page: true
|
||||
```
|
||||
|
||||
**Redirect to the new page**
|
||||
|
||||
|
||||
To show the new page to the user set the `redirect` action to the custom value `@self` or `@self-admin`.
|
||||
|
||||
When using `redirect: '@self'` the page will be shown as a regular web page, for example:
|
||||
|
||||
```
|
||||
process:
|
||||
-
|
||||
add_page: true
|
||||
-
|
||||
redirect: '@self'
|
||||
```
|
||||
|
||||
To open the new page in the Admin panel use `redirect: '@self-admin'`.
|
||||
Note that this plugin does not handle the admin user authentication. If the Admin plugin is not installed or is inactive redirection occurs as if `@self` was used.
|
||||
|
||||
> Tip: using `@self-admin` is a very convenient way to learn how to use this plugin as it is easy to view and examine the source of the resulting new page including it's frontmatter in the Admin panel.
|
||||
|
||||
### Using a Markdown editor in textarea fields
|
||||
When a `textarea` field is given the class `editor` it will use the [SimpleMDE Markdown Editor](https://simplemde.com).
|
||||
|
||||
|
||||
## Value overrides
|
||||
|
||||
The variables which are defined and given a value in the `pageconfig` and `pagefrontmatter` blocks may be 'overridden' or in other words replaced by form input fields. In that respect these variables can be seen to hold a set of default values.
|
||||
|
||||
There is only one exception to the default variable override behaviour and that is the handling of `taxonomy` types. Extra taxonomy types and values (for example tags) which are entered via form fields are added to the new page taxonomy.
|
||||
|
||||
To override a default value by user input is simply a matter of including a form field by the same name in the page form.
|
||||
For example in the example 2 - _create a new blog post_, the default title is set to "My new Blog post". The form contains a form field of type text with `name: title`. Thus the user is prompted to enter a title for the new page in the form but does not need to do so because filling in the title field is not mandatory. If the user enters a title that value is used as the title for the new page. If he or she does not, the default title "My new Blog post" will be used.
|
||||
|
||||
|
||||
## Setting taxonomy categories and tags
|
||||
|
||||
The Add Blog Post example shows how to let the user add extra tags via the form.
|
||||
Extra categories may be added in the same way.
|
||||
|
||||
|
||||
## Handling extra taxonomy types
|
||||
|
||||
By default Grav 'knows' two taxonomy types, `category` and `tag`. Extra taxonomy types may be defined and added just like with any other variables you can include a form field. The new type is then added to the list of taxonomy types instead of replacing the existing types.
|
||||
|
||||
This can be done in the `pagefrontmatter` block. For example, to define a new taxonomy type named 'department':
|
||||
|
||||
```
|
||||
pagefrontmatter:
|
||||
taxonomy:
|
||||
- department
|
||||
```
|
||||
And/or in the form:
|
||||
|
||||
```
|
||||
form:
|
||||
name: my_form
|
||||
fields:
|
||||
-
|
||||
name: taxonomy
|
||||
label: Taxonomy type
|
||||
type: text
|
||||
```
|
||||
|
||||
This is a feature which calls for a solid look-before-you-leap approach because of it's side effects. Using a new taxonomy type requires it to be included in the list of known taxonomy types. This list is in the site configuration file `site.yaml`.
|
||||
|
||||
By setting the plugin configuration option `auto_taxonomy_types: true` new types get automatically saved and can then be used in a collection.
|
||||
|
||||
The side effect and possibly downside is that every modification of the site configuration file causes Grav to rebuild the cache, so this may not be desirable with larger sites.
|
||||
Use with caution!
|
||||
|
||||
## Examples
|
||||
|
||||
The least error prone way to test and play with the examples is to set up a fresh Grav site and using it's default theme Antimatter.
|
||||
|
||||
### Form page example 1: create a normal page
|
||||
|
||||
The goal of this example is to show how to let a user create a new page where uploaded images and files are saved along the page (in the same folder). After the user clicked Submit he or she will be shown the new page.
|
||||
|
||||
Suppose this minimal Grav website structure in `user/pages/`:
|
||||
|
||||
```
|
||||
03.submit-assignment/
|
||||
default.md
|
||||
04.assignments/
|
||||
cmpt363-e100/
|
||||
default.md
|
||||
drafts/
|
||||
modular.md
|
||||
reviewed/
|
||||
modular.md
|
||||
```
|
||||
|
||||
BTW both modular pages are not required but are mentioned as they could be used to display a collection of draft and reviewed assignments.
|
||||
|
||||
Then the 'Submit assignment for review' page (with slug `submit-assignment`) full content (both frontmatter and content) could look like:
|
||||
|
||||
```
|
||||
---
|
||||
routable: true
|
||||
title: 'Submit assignment for review'
|
||||
template: form
|
||||
visible: true
|
||||
pageconfig:
|
||||
parent: /submitted-assignments/cmpt363-e100/drafts
|
||||
pagefrontmatter:
|
||||
visible: true
|
||||
status: draft
|
||||
template: default
|
||||
course:
|
||||
assignment: 'CMPT363 E100'
|
||||
instructor:
|
||||
name: 'Jane Doe'
|
||||
form:
|
||||
name: addpage-assignment-cmpt363-e100
|
||||
fields:
|
||||
-
|
||||
name: name
|
||||
label: Name
|
||||
type: text
|
||||
validate:
|
||||
required: true
|
||||
-
|
||||
name: title
|
||||
label: Title
|
||||
type: text
|
||||
validate:
|
||||
required: true
|
||||
-
|
||||
name: content
|
||||
label: 'Assignment text'
|
||||
type: textarea
|
||||
size: long
|
||||
classes: editor
|
||||
validate:
|
||||
required: true
|
||||
-
|
||||
name: attachments
|
||||
label: 'Attachment (PDF only)'
|
||||
type: file
|
||||
multiple: true
|
||||
accept:
|
||||
- application/pdf
|
||||
validate:
|
||||
required: false
|
||||
-
|
||||
name: honeypot
|
||||
type: honeypot
|
||||
buttons:
|
||||
-
|
||||
type: submit
|
||||
value: Submit
|
||||
process:
|
||||
-
|
||||
addpage: null
|
||||
-
|
||||
redirect: '@self'
|
||||
---
|
||||
|
||||
Please write your assignment and attach any images and/or files.
|
||||
```
|
||||
|
||||
Supposing the user has not changed the pre filled title field, has entered his name "Paul Walker", has entered a simple "q.e.d." as the assignment content and uploaded one PDF document, then the full new page will be:
|
||||
|
||||
```
|
||||
---
|
||||
visible: true
|
||||
status: draft
|
||||
course:
|
||||
assignment: 'CMPT363 E100'
|
||||
instructor:
|
||||
name: 'Jane Doe'
|
||||
name: 'Paul Walker'
|
||||
title: 'CMPT363 E100'
|
||||
attachments:
|
||||
/Users/rwgc/devroot/repos/grav-test/htdocs/user/pages/assignments/cmpt363-e100/drafts/cmpt363-e100-1/scrum-guide-sept-2013.pdf
|
||||
name: scrum-guide-sept-2013.pdf
|
||||
type: application/pdf
|
||||
size: 273 KB
|
||||
path: /Users/rwgc/devroot/repos/grav-test/htdocs/user/pages/assignments/cmpt363-e100/drafts/cmpt363-e100-1/scrum-guide-sept-2013.pdf
|
||||
---
|
||||
|
||||
q.e.d.
|
||||
```
|
||||
|
||||
On the file system level the file structure will be:
|
||||
|
||||
```
|
||||
01.home/
|
||||
default.md
|
||||
02.add-new-article/
|
||||
default.md
|
||||
03.assignments/
|
||||
cmpt363-e100/
|
||||
default.md
|
||||
drafts/
|
||||
cmpt363-e100-1/
|
||||
default.md
|
||||
scrum-guide-sept-2013.pdf
|
||||
modular.md
|
||||
reviewed/
|
||||
modular.md
|
||||
```
|
||||
|
||||
|
||||
### Form page example 2: create a blog post
|
||||
|
||||
In this example the user can add a blog post. To ensure the new page will be treated as a blog post simply set the `template` variable to be used by the new page to `item`. BTW the active theme must include the corresponding template `item.html.twig`. This is why it is best to start with Grav's default theme Antimatter.
|
||||
|
||||
```
|
||||
---
|
||||
title: 'Add Blog Post'
|
||||
template: form
|
||||
pageconfig:
|
||||
parent: '/blog'
|
||||
include_username: true
|
||||
overwrite_mode: true
|
||||
pagefrontmatter:
|
||||
template: item
|
||||
title: My new Blog post
|
||||
taxonomy:
|
||||
category: blog
|
||||
tag: [journal, guest]
|
||||
form:
|
||||
name: add_page.blogpost
|
||||
fields:
|
||||
-
|
||||
name: author
|
||||
label: 'Author'
|
||||
type: text
|
||||
-
|
||||
name: title
|
||||
label: 'Post Title'
|
||||
type: text
|
||||
-
|
||||
name: taxonomy.tag
|
||||
label: 'Tags (comma separated)'
|
||||
type: text
|
||||
-
|
||||
name: content
|
||||
label: 'Post Content'
|
||||
type: textarea
|
||||
size: long
|
||||
classes: editor
|
||||
-
|
||||
name: images
|
||||
label: 'Images to upload'
|
||||
type: file
|
||||
multiple: true
|
||||
accept:
|
||||
- 'image/*'
|
||||
-
|
||||
name: honeypot
|
||||
type: honeypot
|
||||
buttons:
|
||||
-
|
||||
type: submit
|
||||
value: Submit
|
||||
process:
|
||||
-
|
||||
add_page: true
|
||||
-
|
||||
redirect: '/blog'
|
||||
---
|
||||
|
||||
## New Blog Post
|
||||
|
||||
Write your blog post:
|
||||
```
|
||||
After the form has been submitted the user is taken to the blog main page where the new post should show up.
|
||||
|
||||
|
||||
## Issues
|
||||
|
||||
|
||||
### Grav Form issue
|
||||
|
||||
The form on the form page is a standard Grav form. Please note that the Grav Form Plugin currently (latest test using version 4.0.1) has an issue which prevents the form to be submitted when a form field of type `file` is set to `required: true`(see issue [#106](https://github.com/getgrav/grav-plugin-form/issues/106)).
|
||||
|
||||
|
||||
## Credits
|
||||
|
||||
- Team Grav and everyone who contributes to Grav;
|
||||
- Wes Cossick for [SimpleMDE Markdown Editor](https://simplemde.com);
|
||||
- All [contributors](https://github.com/bleutzinn/grav-plugin-add-page-by-form/graphs/contributors) who've helped me out on things.
|
||||
@@ -1,9 +0,0 @@
|
||||
enabled: true
|
||||
date_display_format: 'd-m-Y H:i'
|
||||
default_title: 'My New Page'
|
||||
default_content: 'No content.'
|
||||
overwrite_mode: false
|
||||
include_username: false
|
||||
auto_taxonomy_types: false
|
||||
use_editor_class: true
|
||||
physical_template_name: true
|
||||
@@ -1,8 +0,0 @@
|
||||
|
||||
.editor-toolbar a.active, .editor-toolbar a:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.CodeMirror, .CodeMirror-scroll {
|
||||
min-height: 70px;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
$(function () {
|
||||
$(".editor").each(function(){
|
||||
var simplemde = new SimpleMDE({
|
||||
element: this,
|
||||
forceSync: true,
|
||||
hideIcons: ["side-by-side", "fullscreen"],
|
||||
spellChecker: false,
|
||||
toolbar: ["bold", "italic", "heading", "|",
|
||||
"quote", "unordered-list", "ordered-list", "|",
|
||||
"link", "table", "|",
|
||||
"undo", "redo", "|",
|
||||
"preview", "guide"
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,109 +0,0 @@
|
||||
name: Add Page By Form
|
||||
version: 3.3.0
|
||||
description: Adds a page by means of a form
|
||||
icon: plus-square-o
|
||||
author:
|
||||
name: Ron Wardenier
|
||||
email: ron@wardenier.com
|
||||
homepage: https://github.com/bleutzinn/grav-plugin-add-page-by-form
|
||||
keywords: grav, plugin, page, form, frontmatter
|
||||
bugs: https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues
|
||||
docs: https://github.com/bleutzinn/grav-plugin-add-page-by-form/blob/master/README.md
|
||||
license: MIT
|
||||
|
||||
dependencies:
|
||||
- { name: grav, version: '>=1.6.0' }
|
||||
|
||||
form:
|
||||
validation: strict
|
||||
fields:
|
||||
enabled:
|
||||
type: toggle
|
||||
label: Plugin status
|
||||
highlight: 1
|
||||
default: 0
|
||||
options:
|
||||
1: Enabled
|
||||
0: Disabled
|
||||
validate:
|
||||
type: bool
|
||||
default_title:
|
||||
type: text
|
||||
size: large
|
||||
label: Default Page Title
|
||||
help: Will be used for the new page folder name when no other value is set
|
||||
default_content:
|
||||
type: text
|
||||
size: large
|
||||
label: Default Page Content
|
||||
help: Will be used as the page content for the new page when no other value is set
|
||||
include_username:
|
||||
type: toggle
|
||||
label: Include username
|
||||
help: Include the logged in user username in the new page frontmatter
|
||||
highlight: 0
|
||||
default: 0
|
||||
options:
|
||||
1: Enabled
|
||||
0: Disabled
|
||||
validate:
|
||||
type: bool
|
||||
overwrite_mode:
|
||||
type: select
|
||||
label: Overwrite mode
|
||||
help: Overwrite existing page
|
||||
highlight: 0
|
||||
default: false
|
||||
options:
|
||||
0: Disabled
|
||||
1: Enabled
|
||||
edit: Edit
|
||||
auto_taxonomy_types:
|
||||
type: toggle
|
||||
label: Add new taxonomy types
|
||||
help: Automatically add new taxonomy types to site configuration. May have performance impact on large sites.
|
||||
highlight: 0
|
||||
default: 0
|
||||
options:
|
||||
1: Enabled
|
||||
0: Disabled
|
||||
validate:
|
||||
type: bool
|
||||
use_editor_class:
|
||||
type: toggle
|
||||
label: Use the editor class
|
||||
help: When set, adding class=editor to a textarea provides the simpleMDE editor on that area
|
||||
highlight: 1
|
||||
default: 1
|
||||
options:
|
||||
1: Enabled
|
||||
0: Disabled
|
||||
validate:
|
||||
type: bool
|
||||
date_display_format:
|
||||
type: select
|
||||
size: medium
|
||||
classes: fancy
|
||||
label: Date Format
|
||||
default: 'd-m-Y H:i'
|
||||
options:
|
||||
'F jS Y': "February 1st 2014"
|
||||
'l jS of F': "Saturday 1st of February"
|
||||
'D, m M Y': "Sat, 01 Feb 2014"
|
||||
'd-m-y': "01-02-14"
|
||||
'd-m-Y': "01-02-2014"
|
||||
'jS M Y': "1st Feb 2014"
|
||||
'F Y': "Feb 2014"
|
||||
'Y-m-d': "2014-02-01"
|
||||
'd-m-Y H:i': "01-02-2014 09:30"
|
||||
physical_template_name:
|
||||
type: toggle
|
||||
label: Physical template name
|
||||
help: Use the template name in the filename of the new page
|
||||
highlight: 1
|
||||
default: 1
|
||||
options:
|
||||
1: Enabled
|
||||
0: Disabled
|
||||
validate:
|
||||
type: bool
|
||||
@@ -1,35 +0,0 @@
|
||||
{
|
||||
"name": "bleutzinn/grav-plugin-add-page-by-form",
|
||||
"type": "grav-plugin",
|
||||
"description": "Adds a page by means of a form",
|
||||
"keywords": ["grav", "plugin", "page", "form", "frontmatter"],
|
||||
"homepage": "https://github.com/bleutzinn/grav-plugin-add-page-by-form",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ron Wardenier",
|
||||
"email": "bleutzinn@rwgc.nl",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/bleutzinn/grav-plugin-add-page-by-form/issues",
|
||||
"docs": "https://github.com/bleutzinn/grav-plugin-add-page-by-form/blob/master/README.md"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Grav\\Plugin\\AddPageByFormPlugin\\": "classes/"
|
||||
},
|
||||
"classmap": [
|
||||
"add-page-by-form.php"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"platform": {
|
||||
"php": "7.1.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "3d1383f8c010e20d78cbeeba97140c36",
|
||||
"packages": [],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": ">=7.1.3"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"platform-overrides": {
|
||||
"php": "7.1.3"
|
||||
},
|
||||
"plugin-api-version": "2.2.0"
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload.php @generated by Composer
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit0206cd2f5513395c6d5551a767d5c39f::getLoader();
|
||||
@@ -1,572 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
/**
|
||||
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
|
||||
*
|
||||
* $loader = new \Composer\Autoload\ClassLoader();
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
* // activate the autoloader
|
||||
* $loader->register();
|
||||
*
|
||||
* // to enable searching the include path (eg. for PEAR packages)
|
||||
* $loader->setUseIncludePath(true);
|
||||
*
|
||||
* In this example, if you try to use a class in the Symfony\Component
|
||||
* namespace or one of its children (Symfony\Component\Console for instance),
|
||||
* the autoloader will first look for the class under the component/
|
||||
* directory, and it will then fallback to the framework/ directory if not
|
||||
* found before giving up.
|
||||
*
|
||||
* This class is loosely based on the Symfony UniversalClassLoader.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @see https://www.php-fig.org/psr/psr-0/
|
||||
* @see https://www.php-fig.org/psr/psr-4/
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
/** @var ?string */
|
||||
private $vendorDir;
|
||||
|
||||
// PSR-4
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, array<string, int>>
|
||||
*/
|
||||
private $prefixLengthsPsr4 = array();
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, array<int, string>>
|
||||
*/
|
||||
private $prefixDirsPsr4 = array();
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, string>
|
||||
*/
|
||||
private $fallbackDirsPsr4 = array();
|
||||
|
||||
// PSR-0
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, array<string, string[]>>
|
||||
*/
|
||||
private $prefixesPsr0 = array();
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, string>
|
||||
*/
|
||||
private $fallbackDirsPsr0 = array();
|
||||
|
||||
/** @var bool */
|
||||
private $useIncludePath = false;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
* @psalm-var array<string, string>
|
||||
*/
|
||||
private $classMap = array();
|
||||
|
||||
/** @var bool */
|
||||
private $classMapAuthoritative = false;
|
||||
|
||||
/**
|
||||
* @var bool[]
|
||||
* @psalm-var array<string, bool>
|
||||
*/
|
||||
private $missingClasses = array();
|
||||
|
||||
/** @var ?string */
|
||||
private $apcuPrefix;
|
||||
|
||||
/**
|
||||
* @var self[]
|
||||
*/
|
||||
private static $registeredLoaders = array();
|
||||
|
||||
/**
|
||||
* @param ?string $vendorDir
|
||||
*/
|
||||
public function __construct($vendorDir = null)
|
||||
{
|
||||
$this->vendorDir = $vendorDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPrefixes()
|
||||
{
|
||||
if (!empty($this->prefixesPsr0)) {
|
||||
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return array<string, array<int, string>>
|
||||
*/
|
||||
public function getPrefixesPsr4()
|
||||
{
|
||||
return $this->prefixDirsPsr4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return array<string, string>
|
||||
*/
|
||||
public function getFallbackDirs()
|
||||
{
|
||||
return $this->fallbackDirsPsr0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return array<string, string>
|
||||
*/
|
||||
public function getFallbackDirsPsr4()
|
||||
{
|
||||
return $this->fallbackDirsPsr4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] Array of classname => path
|
||||
* @psalm-return array<string, string>
|
||||
*/
|
||||
public function getClassMap()
|
||||
{
|
||||
return $this->classMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $classMap Class to filename map
|
||||
* @psalm-param array<string, string> $classMap
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addClassMap(array $classMap)
|
||||
{
|
||||
if ($this->classMap) {
|
||||
$this->classMap = array_merge($this->classMap, $classMap);
|
||||
} else {
|
||||
$this->classMap = $classMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix, either
|
||||
* appending or prepending to the ones previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param string[]|string $paths The PSR-0 root directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr0
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$this->fallbackDirsPsr0,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$first = $prefix[0];
|
||||
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($prepend) {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixesPsr0[$first][$prefix]
|
||||
);
|
||||
} else {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$this->prefixesPsr0[$first][$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace, either
|
||||
* appending or prepending to the ones previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param string[]|string $paths The PSR-4 base directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addPsr4($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
// Register directories for the root namespace.
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr4
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$this->fallbackDirsPsr4,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||
// Register directories for a new namespace.
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
} elseif ($prepend) {
|
||||
// Prepend directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixDirsPsr4[$prefix]
|
||||
);
|
||||
} else {
|
||||
// Append directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$this->prefixDirsPsr4[$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix,
|
||||
* replacing any others previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param string[]|string $paths The PSR-0 base directories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr0 = (array) $paths;
|
||||
} else {
|
||||
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace,
|
||||
* replacing any others previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param string[]|string $paths The PSR-4 base directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPsr4($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr4 = (array) $paths;
|
||||
} else {
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on searching the include path for class files.
|
||||
*
|
||||
* @param bool $useIncludePath
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUseIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
return $this->useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off searching the prefix and fallback directories for classes
|
||||
* that have not been registered with the class map.
|
||||
*
|
||||
* @param bool $classMapAuthoritative
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setClassMapAuthoritative($classMapAuthoritative)
|
||||
{
|
||||
$this->classMapAuthoritative = $classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should class lookup fail if not found in the current class map?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isClassMapAuthoritative()
|
||||
{
|
||||
return $this->classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
|
||||
*
|
||||
* @param string|null $apcuPrefix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setApcuPrefix($apcuPrefix)
|
||||
{
|
||||
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The APCu prefix in use, or null if APCu caching is not enabled.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getApcuPrefix()
|
||||
{
|
||||
return $this->apcuPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
|
||||
if (null === $this->vendorDir) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($prepend) {
|
||||
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
|
||||
} else {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
self::$registeredLoaders[$this->vendorDir] = $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters this instance as an autoloader.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
|
||||
if (null !== $this->vendorDir) {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
* @return true|null True if loaded, null otherwise
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
if ($file = $this->findFile($class)) {
|
||||
includeFile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the path to the file where the class is defined.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return string|false The path if found, false otherwise
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
// class map lookup
|
||||
if (isset($this->classMap[$class])) {
|
||||
return $this->classMap[$class];
|
||||
}
|
||||
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
|
||||
return false;
|
||||
}
|
||||
if (null !== $this->apcuPrefix) {
|
||||
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
|
||||
if ($hit) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
$file = $this->findFileWithExtension($class, '.php');
|
||||
|
||||
// Search for Hack files if we are running on HHVM
|
||||
if (false === $file && defined('HHVM_VERSION')) {
|
||||
$file = $this->findFileWithExtension($class, '.hh');
|
||||
}
|
||||
|
||||
if (null !== $this->apcuPrefix) {
|
||||
apcu_add($this->apcuPrefix.$class, $file);
|
||||
}
|
||||
|
||||
if (false === $file) {
|
||||
// Remember that this class does not exist.
|
||||
$this->missingClasses[$class] = true;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently registered loaders indexed by their corresponding vendor directories.
|
||||
*
|
||||
* @return self[]
|
||||
*/
|
||||
public static function getRegisteredLoaders()
|
||||
{
|
||||
return self::$registeredLoaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $ext
|
||||
* @return string|false
|
||||
*/
|
||||
private function findFileWithExtension($class, $ext)
|
||||
{
|
||||
// PSR-4 lookup
|
||||
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
|
||||
|
||||
$first = $class[0];
|
||||
if (isset($this->prefixLengthsPsr4[$first])) {
|
||||
$subPath = $class;
|
||||
while (false !== $lastPos = strrpos($subPath, '\\')) {
|
||||
$subPath = substr($subPath, 0, $lastPos);
|
||||
$search = $subPath . '\\';
|
||||
if (isset($this->prefixDirsPsr4[$search])) {
|
||||
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
|
||||
foreach ($this->prefixDirsPsr4[$search] as $dir) {
|
||||
if (file_exists($file = $dir . $pathEnd)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-4 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr4 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 lookup
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
|
||||
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
|
||||
}
|
||||
|
||||
if (isset($this->prefixesPsr0[$first])) {
|
||||
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr0 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 include paths.
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope isolated include.
|
||||
*
|
||||
* Prevents access to $this/self from included files.
|
||||
*
|
||||
* @param string $file
|
||||
* @return void
|
||||
* @private
|
||||
*/
|
||||
function includeFile($file)
|
||||
{
|
||||
include $file;
|
||||
}
|
||||
@@ -1,350 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer;
|
||||
|
||||
use Composer\Autoload\ClassLoader;
|
||||
use Composer\Semver\VersionParser;
|
||||
|
||||
/**
|
||||
* This class is copied in every Composer installed project and available to all
|
||||
*
|
||||
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
|
||||
*
|
||||
* To require its presence, you can require `composer-runtime-api ^2.0`
|
||||
*/
|
||||
class InstalledVersions
|
||||
{
|
||||
/**
|
||||
* @var mixed[]|null
|
||||
* @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null
|
||||
*/
|
||||
private static $installed;
|
||||
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
private static $canGetVendors;
|
||||
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
|
||||
*/
|
||||
private static $installedByVendor = array();
|
||||
|
||||
/**
|
||||
* Returns a list of all package names which are present, either by being installed, replaced or provided
|
||||
*
|
||||
* @return string[]
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
public static function getInstalledPackages()
|
||||
{
|
||||
$packages = array();
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
$packages[] = array_keys($installed['versions']);
|
||||
}
|
||||
|
||||
if (1 === \count($packages)) {
|
||||
return $packages[0];
|
||||
}
|
||||
|
||||
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all package names with a specific type e.g. 'library'
|
||||
*
|
||||
* @param string $type
|
||||
* @return string[]
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
public static function getInstalledPackagesByType($type)
|
||||
{
|
||||
$packagesByType = array();
|
||||
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
foreach ($installed['versions'] as $name => $package) {
|
||||
if (isset($package['type']) && $package['type'] === $type) {
|
||||
$packagesByType[] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $packagesByType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given package is installed
|
||||
*
|
||||
* This also returns true if the package name is provided or replaced by another package
|
||||
*
|
||||
* @param string $packageName
|
||||
* @param bool $includeDevRequirements
|
||||
* @return bool
|
||||
*/
|
||||
public static function isInstalled($packageName, $includeDevRequirements = true)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (isset($installed['versions'][$packageName])) {
|
||||
return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given package satisfies a version constraint
|
||||
*
|
||||
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
|
||||
*
|
||||
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
|
||||
*
|
||||
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
|
||||
* @param string $packageName
|
||||
* @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
|
||||
* @return bool
|
||||
*/
|
||||
public static function satisfies(VersionParser $parser, $packageName, $constraint)
|
||||
{
|
||||
$constraint = $parser->parseConstraints($constraint);
|
||||
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
|
||||
|
||||
return $provided->matches($constraint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a version constraint representing all the range(s) which are installed for a given package
|
||||
*
|
||||
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
|
||||
* whether a given version of a package is installed, and not just whether it exists
|
||||
*
|
||||
* @param string $packageName
|
||||
* @return string Version constraint usable with composer/semver
|
||||
*/
|
||||
public static function getVersionRanges($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ranges = array();
|
||||
if (isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
|
||||
}
|
||||
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
|
||||
}
|
||||
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
|
||||
}
|
||||
if (array_key_exists('provided', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
|
||||
}
|
||||
|
||||
return implode(' || ', $ranges);
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||
*/
|
||||
public static function getVersion($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['version'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['version'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||
*/
|
||||
public static function getPrettyVersion($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['pretty_version'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
|
||||
*/
|
||||
public static function getReference($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['reference'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['reference'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
|
||||
*/
|
||||
public static function getInstallPath($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
|
||||
*/
|
||||
public static function getRootPackage()
|
||||
{
|
||||
$installed = self::getInstalled();
|
||||
|
||||
return $installed[0]['root'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw installed.php data for custom implementations
|
||||
*
|
||||
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
|
||||
* @return array[]
|
||||
* @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}
|
||||
*/
|
||||
public static function getRawData()
|
||||
{
|
||||
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
|
||||
|
||||
if (null === self::$installed) {
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
self::$installed = include __DIR__ . '/installed.php';
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
|
||||
return self::$installed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw data of all installed.php which are currently loaded for custom implementations
|
||||
*
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
|
||||
*/
|
||||
public static function getAllRawData()
|
||||
{
|
||||
return self::getInstalled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you reload the static array from another file
|
||||
*
|
||||
* This is only useful for complex integrations in which a project needs to use
|
||||
* this class but then also needs to execute another project's autoloader in process,
|
||||
* and wants to ensure both projects have access to their version of installed.php.
|
||||
*
|
||||
* A typical case would be PHPUnit, where it would need to make sure it reads all
|
||||
* the data it needs from this class, then call reload() with
|
||||
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
|
||||
* the project in which it runs can then also use this class safely, without
|
||||
* interference between PHPUnit's dependencies and the project's dependencies.
|
||||
*
|
||||
* @param array[] $data A vendor/composer/installed.php data set
|
||||
* @return void
|
||||
*
|
||||
* @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data
|
||||
*/
|
||||
public static function reload($data)
|
||||
{
|
||||
self::$installed = $data;
|
||||
self::$installedByVendor = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
|
||||
*/
|
||||
private static function getInstalled()
|
||||
{
|
||||
if (null === self::$canGetVendors) {
|
||||
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
|
||||
}
|
||||
|
||||
$installed = array();
|
||||
|
||||
if (self::$canGetVendors) {
|
||||
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
|
||||
if (isset(self::$installedByVendor[$vendorDir])) {
|
||||
$installed[] = self::$installedByVendor[$vendorDir];
|
||||
} elseif (is_file($vendorDir.'/composer/installed.php')) {
|
||||
$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
|
||||
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
|
||||
self::$installed = $installed[count($installed) - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null === self::$installed) {
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
self::$installed = require __DIR__ . '/installed.php';
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
$installed[] = self::$installed;
|
||||
|
||||
return $installed;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
|
||||
Copyright (c) Nils Adermann, Jordi Boggiano
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||
'Grav\\Plugin\\AddPageByFormPlugin' => $baseDir . '/add-page-by-form.php',
|
||||
);
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload_namespaces.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload_psr4.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Grav\\Plugin\\AddPageByFormPlugin\\' => array($baseDir . '/classes'),
|
||||
);
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit0206cd2f5513395c6d5551a767d5c39f
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
public static function loadClassLoader($class)
|
||||
{
|
||||
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||
require __DIR__ . '/ClassLoader.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Composer\Autoload\ClassLoader
|
||||
*/
|
||||
public static function getLoader()
|
||||
{
|
||||
if (null !== self::$loader) {
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
require __DIR__ . '/platform_check.php';
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit0206cd2f5513395c6d5551a767d5c39f', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit0206cd2f5513395c6d5551a767d5c39f', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit0206cd2f5513395c6d5551a767d5c39f::getInitializer($loader));
|
||||
} else {
|
||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->set($namespace, $path);
|
||||
}
|
||||
|
||||
$map = require __DIR__ . '/autoload_psr4.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->setPsr4($namespace, $path);
|
||||
}
|
||||
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
$loader->addClassMap($classMap);
|
||||
}
|
||||
}
|
||||
|
||||
$loader->register(true);
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
// autoload_static.php @generated by Composer
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit0206cd2f5513395c6d5551a767d5c39f
|
||||
{
|
||||
public static $prefixLengthsPsr4 = array (
|
||||
'G' =>
|
||||
array (
|
||||
'Grav\\Plugin\\AddPageByFormPlugin\\' => 32,
|
||||
),
|
||||
);
|
||||
|
||||
public static $prefixDirsPsr4 = array (
|
||||
'Grav\\Plugin\\AddPageByFormPlugin\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/../..' . '/classes',
|
||||
),
|
||||
);
|
||||
|
||||
public static $classMap = array (
|
||||
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||
'Grav\\Plugin\\AddPageByFormPlugin' => __DIR__ . '/../..' . '/add-page-by-form.php',
|
||||
);
|
||||
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit0206cd2f5513395c6d5551a767d5c39f::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit0206cd2f5513395c6d5551a767d5c39f::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit0206cd2f5513395c6d5551a767d5c39f::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"packages": [],
|
||||
"dev": false,
|
||||
"dev-package-names": []
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php return array(
|
||||
'root' => array(
|
||||
'pretty_version' => '1.0.0+no-version-set',
|
||||
'version' => '1.0.0.0',
|
||||
'type' => 'grav-plugin',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => NULL,
|
||||
'name' => 'bleutzinn/grav-plugin-add-page-by-form',
|
||||
'dev' => false,
|
||||
),
|
||||
'versions' => array(
|
||||
'bleutzinn/grav-plugin-add-page-by-form' => array(
|
||||
'pretty_version' => '1.0.0+no-version-set',
|
||||
'version' => '1.0.0.0',
|
||||
'type' => 'grav-plugin',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => NULL,
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
// platform_check.php @generated by Composer
|
||||
|
||||
$issues = array();
|
||||
|
||||
if (!(PHP_VERSION_ID >= 70103)) {
|
||||
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.1.3". You are running ' . PHP_VERSION . '.';
|
||||
}
|
||||
|
||||
if ($issues) {
|
||||
if (!headers_sent()) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
if (!ini_get('display_errors')) {
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
|
||||
} elseif (!headers_sent()) {
|
||||
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
|
||||
}
|
||||
}
|
||||
trigger_error(
|
||||
'Composer detected issues in your platform: ' . implode(' ', $issues),
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
# Linguist Normalizer
|
||||
*.yaml linguistic-language=PHP
|
||||
*.twig linguistic-language=PHP
|
||||
**/gulpfile.babel.js linguist-vendored
|
||||
**/webpack.conf.js linguist-vendored
|
||||
**/js/*.js linguist-vendored
|
||||
**/js/*.json linguist-vendored
|
||||
**/css-compiled/*.css linguist-vendored
|
||||
@@ -1,8 +0,0 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: grav
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
custom: # Replace with a single custom sponsorship URL
|
||||
@@ -1,6 +0,0 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
@@ -1 +0,0 @@
|
||||
Please read the <a href="https://github.com/getgrav/grav/blob/develop/CONTRIBUTING.md" target="_blank">Contributing Guidelines of the Grav Project</a>
|
||||
@@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Grav
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,152 +0,0 @@
|
||||
# Grav Standard Administration Panel Plugin
|
||||
|
||||
This **admin plugin** for [Grav](https://github.com/getgrav/grav) is an HTML user interface that provides a convenient way to configure Grav and easily create and modify pages. This will remain a totally optional plugin, and is not in any way required or needed to use Grav effectively. In fact, the admin provides an intentionally limited view to ensure it remains easy to use and not overwhelming. I'm sure power users will still prefer to work with the configuration files directly.
|
||||
|
||||

|
||||
|
||||
# Features
|
||||
|
||||
* User login with automatic password encryption
|
||||
* Forgot password functionality
|
||||
* Logged-in-user management
|
||||
* One click Grav core updates
|
||||
* Dashboard with maintenance status, site activity and latest page updates
|
||||
* Notifications system for latest news, blogs, and announcements
|
||||
* Ajax-powered backup capability
|
||||
* Ajax-powered clear-cache capability
|
||||
* System configuration management
|
||||
* Site configuration management
|
||||
* Normal and Expert modes which allow editing via forms or YAML
|
||||
* Page listing with filtering and search
|
||||
* Page creation, editing, moving, copying, and deleting
|
||||
* Powerful syntax highlighting code editor with instant Grav-powered preview
|
||||
* Editor features, hot keys, toolbar, and distraction-free fullscreen mode
|
||||
* Drag-n-drop upload of page media files including drag-n-drop placement in the editor
|
||||
* One click theme and plugin updates
|
||||
* Plugin manager that allows listing and configuration of installed plugins
|
||||
* Theme manager that allows listing and configuration of installed themes
|
||||
* GPM-powered installation of new plugins and themes
|
||||
|
||||
# Support
|
||||
|
||||
#### Support
|
||||
|
||||
We have tested internally, but we hope to use this public beta phase to identify, isolate, and fix issues related to the plugin to ensure it is as solid and reliable as possible.
|
||||
|
||||
For **live chatting**, please use the dedicated [Discord Chat Room](https://getgrav.org/discord) for discussions directly related to Grav.
|
||||
|
||||
For **bugs, features, improvements**, please ensure you [create issues in the admin plugin GitHub repository](https://github.com/getgrav/grav-plugin-admin).
|
||||
|
||||
# Installation
|
||||
|
||||
First ensure you are running the latest **Grav 1.6.7 or later**. This is required for the admin plugin to run properly (`-f` forces a refresh of the GPM index).
|
||||
|
||||
```
|
||||
$ bin/gpm selfupgrade -f
|
||||
```
|
||||
|
||||
The admin plugin actually requires the help of 3 other plugins, so to get the admin plugin to work you first need to install **admin**, **login**, **forms**, and **email** plugins. These are available via GPM, and because the plugin has dependencies you just need to proceed and install the admin plugin, and agree when prompted to install the others:
|
||||
|
||||
```
|
||||
$ bin/gpm install admin
|
||||
```
|
||||
|
||||
### Manual Installation
|
||||
|
||||
Manual installation is not the recommended method of installation, however, it is still possible to install the admin plugin manually. Basically, you need to download each of the following plugins individually:
|
||||
|
||||
* [admin](https://github.com/getgrav/grav-plugin-admin/archive/develop.zip)
|
||||
* [login](https://github.com/getgrav/grav-plugin-login/archive/develop.zip)
|
||||
* [form](https://github.com/getgrav/grav-plugin-form/archive/develop.zip)
|
||||
* [email](https://github.com/getgrav/grav-plugin-email/archive/develop.zip)
|
||||
|
||||
Extract each archive file into your `user/plugins` folder, then ensure the folders are renamed to just `admin/`, `login/`, `form/`, and `email/`. Then proceed with the **Usage instructions below**.
|
||||
|
||||
# Usage
|
||||
|
||||
### Create User with CLI
|
||||
|
||||
After this you need to create a user account with admin privileges:
|
||||
|
||||
```
|
||||
$ bin/plugin login new-user
|
||||
```
|
||||
|
||||
### Create User Manually
|
||||
|
||||
Alternatively, you can create a user account manually, in a file called `user/accounts/admin.yaml`. This **filename** is actually the **username** that you will use to login. The contents will contain the other information for the user.
|
||||
|
||||
```
|
||||
password: 'password'
|
||||
email: 'youremail@mail.com'
|
||||
fullname: 'Johnny Appleseed'
|
||||
title: 'Site Administrator'
|
||||
access:
|
||||
admin:
|
||||
login: true
|
||||
super: true
|
||||
```
|
||||
|
||||
Of course you should edit your `email`, `password`, `fullname`, and `title` to suit your needs.
|
||||
|
||||
> You can use any password when you manually put it in this `.yaml` file. However, when you change your password in the admin, it must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters.
|
||||
|
||||
# Accessing the Admin
|
||||
|
||||
By default, you can access the admin by pointing your browser to `http://yoursite.com/admin`. You can simply log in with the `username` and `password` set in the YAML file you configured earlier.
|
||||
|
||||
> After logging in, your **plaintext password** will be removed and replaced by an **encrypted** one.
|
||||
|
||||
# Standard Free & Paid Pro Versions
|
||||
|
||||
If you have been following the [blog](https://getgrav.org/blog), [Twitter](https://twitter.com/getgrav), [Discord chat](https://getgrav.org/discord), etc., you probably already know now that our intention is to provide two versions of this plugin.
|
||||
|
||||
The **standard free version**, is very powerful, and has more functionality than most commercial flat-file CMS systems.
|
||||
|
||||
We also intend to release in the near future a more feature-rich **pro version** that will include enhanced functionality, as well as some additional nice-to-have capabilities. This pro version will be a **paid** plugin the price of which is not yet 100% finalized.
|
||||
|
||||
# Admin Events
|
||||
|
||||
## General events
|
||||
|
||||
- onAdminRegisterPermissions - (admin)
|
||||
- onAdminThemeInitialized
|
||||
- onAdminPage - (page)
|
||||
- onAdminMenu
|
||||
- onAdminTwigTemplatePaths - (paths)
|
||||
|
||||
## Page specific events
|
||||
|
||||
- onAdminDashboard
|
||||
- onAdminTools - (tools)
|
||||
- onAdminLogFiles - (logs)
|
||||
- onAdminGenerateReports - (reports)
|
||||
|
||||
## Tasks
|
||||
|
||||
- onAdminControllerInit - (controller)
|
||||
- onAdminTaskExecute - (controller, method)
|
||||
|
||||
## Editing
|
||||
|
||||
- onAdminData
|
||||
- onAdminSave - (object)
|
||||
- onAdminAfterSave - (object)
|
||||
|
||||
## Pages
|
||||
|
||||
- onAdminPageTypes - (types)
|
||||
- onAdminModularPageTypes
|
||||
- onAdminSave - (page)
|
||||
- onAdminAfterSaveAs - (path)
|
||||
- onAdminAfterSave - (page)
|
||||
- onAdminAfterDelete - (page)
|
||||
- onAdminAfterAddMedia - (page)
|
||||
- onAdminAfterDelMedia - (page)
|
||||
- onAdminCreatePageFrontmatter - (header, data)
|
||||
|
||||
|
||||
# Running Tests
|
||||
|
||||
First install the dev dependencies by running `composer update` from the Grav root.
|
||||
Then `composer test` will run the Unit Tests, which should be always executed successfully on any site.
|
||||
@@ -1,6 +0,0 @@
|
||||
# Upgrading to Admin 1.10
|
||||
|
||||
Twig:
|
||||
|
||||
* **Admin link**: When linking to another admin page, use `{{ admin_route('/config/site') }}` instead of any other method, such as `{{ base_url_relative }}/config/site` (fixes multi-language issues)
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
enabled: false
|
||||
route: '/admin'
|
||||
cache_enabled: true
|
||||
theme: grav
|
||||
logo_text: ''
|
||||
body_classes: ''
|
||||
content_padding: true
|
||||
twofa_enabled: true
|
||||
sidebar:
|
||||
activate: tab
|
||||
hover_delay: 100
|
||||
size: auto
|
||||
dashboard:
|
||||
days_of_stats: 7
|
||||
widgets_display:
|
||||
dashboard-maintenance: true
|
||||
dashboard-statistics: true
|
||||
dashboard-notifications: true
|
||||
dashboard-feed: true
|
||||
dashboard-pages: true
|
||||
pages:
|
||||
show_parents: both
|
||||
show_modular: true
|
||||
session:
|
||||
timeout: 1800
|
||||
keep_alive: true
|
||||
edit_mode: normal
|
||||
frontend_preview_target: inline
|
||||
show_github_msg: true
|
||||
admin_icons: line-awesome
|
||||
enable_auto_updates_check: true
|
||||
notifications:
|
||||
feed: true
|
||||
dashboard: true
|
||||
plugins: true
|
||||
themes: true
|
||||
popularity:
|
||||
enabled: true
|
||||
ignore: ['/test*','/modular']
|
||||
history:
|
||||
daily: 30
|
||||
monthly: 12
|
||||
visitors: 20
|
||||
whitelabel:
|
||||
quicktray_recompile: false
|
||||
codemirror_theme: paper
|
||||
codemirror_fontsize: md
|
||||
codemirror_md_font: sans
|
||||
logo_custom:
|
||||
logo_login:
|
||||
color_scheme:
|
||||
accents:
|
||||
primary-accent: button
|
||||
secondary-accent: notice
|
||||
tertiary-accent: critical
|
||||
colors:
|
||||
logo-bg: '#323640'
|
||||
logo-link: '#FFFFFF'
|
||||
nav-bg: '#3D424E'
|
||||
nav-text: '#B7B9BD'
|
||||
nav-link: '#ffffff'
|
||||
nav-selected-bg: '#323640'
|
||||
nav-selected-link: '#ffffff'
|
||||
nav-hover-bg: '#434753'
|
||||
nav-hover-link: '#ffffff'
|
||||
toolbar-bg: '#ffffff'
|
||||
toolbar-text: '#3D424E'
|
||||
page-bg: '#F6F6F6'
|
||||
page-text: '#6f7b8a'
|
||||
page-link: '#0090D9'
|
||||
content-bg: '#ffffff'
|
||||
content-text: '#6f7b8a'
|
||||
content-link: '#0090D9'
|
||||
content-link2: '#da4b46'
|
||||
content-header: '#414147'
|
||||
content-tabs-bg: '#e6e6e6'
|
||||
content-tabs-text: '#808080'
|
||||
button-bg: '#0090D9'
|
||||
button-text: '#ffffff'
|
||||
notice-bg: '#06A599'
|
||||
notice-text: '#ffffff'
|
||||
update-bg: '#77559D'
|
||||
update-text: '#ffffff'
|
||||
critical-bg: '#F45857'
|
||||
critical-text: '#ffffff'
|
||||
|
Before Width: | Height: | Size: 236 KiB |
@@ -1,792 +0,0 @@
|
||||
name: Admin Panel
|
||||
slug: admin
|
||||
type: plugin
|
||||
testing: true
|
||||
version: 1.11.0-beta.5
|
||||
description: Adds an advanced administration panel to manage your site
|
||||
icon: empire
|
||||
author:
|
||||
name: Team Grav
|
||||
email: devs@getgrav.org
|
||||
url: https://getgrav.org
|
||||
homepage: https://github.com/getgrav/grav-plugin-admin
|
||||
keywords: admin, plugin, manager, panel
|
||||
bugs: https://github.com/getgrav/grav-plugin-admin/issues
|
||||
docs: https://github.com/getgrav/grav-plugin-admin/blob/develop/README.md
|
||||
license: MIT
|
||||
|
||||
dependencies:
|
||||
- { name: grav, version: '>=1.8.0-beta.1' }
|
||||
- { name: form, version: '>=6.0.1' }
|
||||
- { name: login, version: '>=3.7.8' }
|
||||
- { name: email, version: '>=3.1.6' }
|
||||
- { name: flex-objects, version: '>=1.4.0-beta.1' }
|
||||
|
||||
form:
|
||||
validation: loose
|
||||
fields:
|
||||
admin_tabs:
|
||||
type: tabs
|
||||
fields:
|
||||
config_tab:
|
||||
type: tab
|
||||
title: PLUGIN_ADMIN.CONFIGURATION
|
||||
|
||||
fields:
|
||||
|
||||
Basics:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.BASICS
|
||||
underline: false
|
||||
|
||||
enabled:
|
||||
type: hidden
|
||||
label: PLUGIN_ADMIN.PLUGIN_STATUS
|
||||
highlight: 1
|
||||
default: 0
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
cache_enabled:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.ADMIN_CACHING
|
||||
help: PLUGIN_ADMIN.ADMIN_CACHING_HELP
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
twofa_enabled:
|
||||
type: toggle
|
||||
label: PLUGIN_LOGIN.2FA_TITLE
|
||||
help: PLUGIN_LOGIN.2FA_ENABLED_HELP
|
||||
default: 1
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
route:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.ADMIN_PATH
|
||||
size: medium
|
||||
placeholder: ADMIN_PATH_PLACEHOLDER
|
||||
help: ADMIN_PATH_HELP
|
||||
|
||||
logo_text:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.LOGO_TEXT
|
||||
size: medium
|
||||
placeholder: "Grav"
|
||||
help: PLUGIN_ADMIN.LOGO_TEXT_HELP
|
||||
|
||||
content_padding:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.CONTENT_PADDING
|
||||
help: PLUGIN_ADMIN.CONTENT_PADDING_HELP
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
body_classes:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.BODY_CLASSES
|
||||
size: medium
|
||||
help: PLUGIN_ADMIN.BODY_CLASSES_HELP
|
||||
|
||||
sidebar.activate:
|
||||
type: select
|
||||
label: PLUGIN_ADMIN.SIDEBAR_ACTIVATION
|
||||
help: PLUGIN_ADMIN.SIDEBAR_ACTIVATION_HELP
|
||||
size: small
|
||||
default: tab
|
||||
options:
|
||||
tab: PLUGIN_ADMIN.SIDEBAR_ACTIVATION_TAB
|
||||
hover: PLUGIN_ADMIN.SIDEBAR_ACTIVATION_HOVER
|
||||
|
||||
sidebar.hover_delay:
|
||||
type: text
|
||||
size: x-small
|
||||
append: PLUGIN_ADMIN.SIDEBAR_HOVER_DELAY_APPEND
|
||||
label: PLUGIN_ADMIN.SIDEBAR_HOVER_DELAY
|
||||
default: 500
|
||||
validate:
|
||||
type: number
|
||||
min: 1
|
||||
|
||||
|
||||
sidebar.size:
|
||||
type: select
|
||||
label: PLUGIN_ADMIN.SIDEBAR_SIZE
|
||||
help: PLUGIN_ADMIN.SIDEBAR_SIZE_HELP
|
||||
size: medium
|
||||
default: auto
|
||||
options:
|
||||
auto: PLUGIN_ADMIN.SIDEBAR_SIZE_AUTO
|
||||
small: PLUGIN_ADMIN.SIDEBAR_SIZE_SMALL
|
||||
|
||||
theme:
|
||||
type: hidden
|
||||
label: PLUGIN_ADMIN.THEME
|
||||
default: grav
|
||||
|
||||
edit_mode:
|
||||
type: select
|
||||
label: PLUGIN_ADMIN.EDIT_MODE
|
||||
size: small
|
||||
default: normal
|
||||
options:
|
||||
normal: PLUGIN_ADMIN.NORMAL
|
||||
expert: PLUGIN_ADMIN.EXPERT
|
||||
help: PLUGIN_ADMIN.EDIT_MODE_HELP
|
||||
|
||||
frontend_preview_target:
|
||||
type: select
|
||||
label: PLUGIN_ADMIN.FRONTEND_PREVIEW_TARGET
|
||||
size: medium
|
||||
default: inline
|
||||
options:
|
||||
inline: PLUGIN_ADMIN.FRONTEND_PREVIEW_TARGET_INLINE
|
||||
_blank: PLUGIN_ADMIN.FRONTEND_PREVIEW_TARGET_NEW
|
||||
_self: PLUGIN_ADMIN.FRONTEND_PREVIEW_TARGET_CURRENT
|
||||
|
||||
pages.show_parents:
|
||||
type: select
|
||||
size: medium
|
||||
label: PLUGIN_ADMIN.PARENT_DROPDOWN
|
||||
highlight: 1
|
||||
options:
|
||||
both: PLUGIN_ADMIN.PARENT_DROPDOWN_BOTH
|
||||
folder: PLUGIN_ADMIN.PARENT_DROPDOWN_FOLDER
|
||||
fullpath: PLUGIN_ADMIN.PARENT_DROPDOWN_FULLPATH
|
||||
|
||||
pages.parents_levels:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.PARENTS_LEVELS
|
||||
size: small
|
||||
help: PLUGIN_ADMIN.PARENTS_LEVELS_HELP
|
||||
|
||||
pages.show_modular:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.MODULAR_PARENTS
|
||||
highlight: 1
|
||||
default: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
help: PLUGIN_ADMIN.MODULAR_PARENTS_HELP
|
||||
|
||||
show_beta_msg:
|
||||
type: hidden
|
||||
|
||||
show_github_msg:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.SHOW_GITHUB_LINK
|
||||
highlight: 1
|
||||
default: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
help: PLUGIN_ADMIN.SHOW_GITHUB_LINK_HELP
|
||||
|
||||
enable_auto_updates_check:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.AUTO_UPDATES
|
||||
highlight: 1
|
||||
default: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
help: PLUGIN_ADMIN.AUTO_UPDATES_HELP
|
||||
|
||||
session.timeout:
|
||||
type: text
|
||||
size: small
|
||||
label: PLUGIN_ADMIN.TIMEOUT
|
||||
append: GRAV.NICETIME.SECOND_PLURAL
|
||||
help: PLUGIN_ADMIN.TIMEOUT_HELP
|
||||
validate:
|
||||
type: number
|
||||
min: 1
|
||||
|
||||
session.keep_alive:
|
||||
type: toggle
|
||||
label: Keep Alive Ping
|
||||
help: "Periodically pings to keep your admin session alive. Turn OFF to allow the session to expire while idle (useful for testing timeouts)."
|
||||
highlight: 1
|
||||
default: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
hide_page_types:
|
||||
type: select
|
||||
size: large
|
||||
label: PLUGIN_ADMIN.HIDE_PAGE_TYPES
|
||||
classes: fancy
|
||||
multiple: true
|
||||
array: true
|
||||
selectize:
|
||||
create: true
|
||||
data-options@: ['\Grav\Plugin\AdminPlugin::pagesTypes', true]
|
||||
|
||||
hide_modular_page_types:
|
||||
type: select
|
||||
size: large
|
||||
label: PLUGIN_ADMIN.HIDE_MODULAR_PAGE_TYPES
|
||||
classes: fancy
|
||||
multiple: true
|
||||
array: true
|
||||
selectize:
|
||||
create: true
|
||||
data-options@: ['\Grav\Plugin\AdminPlugin::pagesModularTypes', true]
|
||||
|
||||
Dashboard:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.DASHBOARD
|
||||
underline: true
|
||||
|
||||
widgets_display:
|
||||
type: widgets
|
||||
label: PLUGIN_ADMIN.WIDGETS_DISPLAY
|
||||
validate:
|
||||
type: array
|
||||
|
||||
Notifications:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.NOTIFICATIONS
|
||||
underline: true
|
||||
|
||||
notifications.feed:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.FEED_NOTIFICATIONS
|
||||
highlight: 1
|
||||
default: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
help: PLUGIN_ADMIN.FEED_NOTIFICATIONS_HELP
|
||||
|
||||
notifications.dashboard:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.DASHBOARD_NOTIFICATIONS
|
||||
highlight: 1
|
||||
default: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
help: PLUGIN_ADMIN.DASHBOARD_NOTIFICATIONS_HELP
|
||||
|
||||
notifications.plugins:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.PLUGINS_NOTIFICATIONS
|
||||
highlight: 1
|
||||
default: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
help: PLUGIN_ADMIN.PLUGINS_NOTIFICATIONS_HELP
|
||||
|
||||
notifications.themes:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.THEMES_NOTIFICATIONS
|
||||
highlight: 1
|
||||
default: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
help: PLUGIN_ADMIN.THEMES_NOTIFICATIONS_HELP
|
||||
|
||||
customization_tab:
|
||||
type: tab
|
||||
title: PLUGIN_ADMIN.CUSTOMIZATION
|
||||
|
||||
fields:
|
||||
whitelabel.logos:
|
||||
type: section
|
||||
underline: true
|
||||
title: PLUGIN_ADMIN.LOGOS
|
||||
|
||||
whitelabel.logo_login:
|
||||
type: file
|
||||
label: PLUGIN_ADMIN.LOGIN_SCREEN_CUSTOM_LOGO_LABEL
|
||||
destination: 'user://assets'
|
||||
accept:
|
||||
- image/*
|
||||
|
||||
whitelabel.logo_custom:
|
||||
type: file
|
||||
label: PLUGIN_ADMIN.TOP_LEFT_CUSTOM_LOGO_LABEL
|
||||
destination: 'user://assets'
|
||||
accept:
|
||||
- image/*
|
||||
|
||||
codemirror_section:
|
||||
type: section
|
||||
underline: true
|
||||
title: PLUGIN_ADMIN.CODEMIRROR
|
||||
|
||||
whitelabel.codemirror_theme:
|
||||
type: select
|
||||
label: PLUGIN_ADMIN.CODEMIRROR_THEME
|
||||
default: paper
|
||||
markdown: true
|
||||
data-options@: '\Grav\Plugin\AdminPlugin::themeOptions'
|
||||
description: PLUGIN_ADMIN.CODEMIRROR_THEME_DESC
|
||||
|
||||
whitelabel.codemirror_fontsize:
|
||||
type: select
|
||||
label: PLUGIN_ADMIN.CODEMIRROR_FONTSIZE
|
||||
default: md
|
||||
options:
|
||||
sm: PLUGIN_ADMIN.CODEMIRROR_FONTSIZE_SM
|
||||
md: PLUGIN_ADMIN.CODEMIRROR_FONTSIZE_MD
|
||||
lg: PLUGIN_ADMIN.CODEMIRROR_FONTSIZE_LG
|
||||
|
||||
whitelabel.codemirror_md_font:
|
||||
type: select
|
||||
label: PLUGIN_ADMIN.CODEMIRROR_MD_FONT
|
||||
default: sans
|
||||
options:
|
||||
sans: PLUGIN_ADMIN.CODEMIRROR_MD_FONT_SANS
|
||||
mono: PLUGIN_ADMIN.CODEMIRROR_MD_FONT_MONO
|
||||
|
||||
customization_section:
|
||||
type: section
|
||||
underline: true
|
||||
title: PLUGIN_ADMIN.CUSTOMIZATION
|
||||
|
||||
whitelabel.quicktray_recompile:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.QUICKTRAY_RECOMPILE
|
||||
help: PLUGIN_ADMIN.QUICKTRAY_RECOMPILE_HELP
|
||||
highlight: 0
|
||||
default: 0
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
|
||||
|
||||
whitelabel.color_scheme.name:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.COLOR_SCHEME_NAME
|
||||
help: PLUGIN_ADMIN.COLOR_SCHEME_NAME_HELP
|
||||
placeholder: PLUGIN_ADMIN.COLOR_SCHEME_NAME_PLACEHOLDER
|
||||
|
||||
themes-preview:
|
||||
type: themepreview
|
||||
ignore: true;
|
||||
label: PLUGIN_ADMIN.PRESETS
|
||||
style: vertical
|
||||
|
||||
colorschemes:
|
||||
type: colorscheme
|
||||
label: PLUGIN_ADMIN.COLOR_SCHEME_LABEL
|
||||
style: vertical
|
||||
help: PLUGIN_ADMIN.COLOR_SCHEME_HELP
|
||||
|
||||
fields:
|
||||
whitelabel.color_scheme.colors.logo-bg:
|
||||
type: colorscheme.color
|
||||
default: '#1e333e'
|
||||
help: PLUGIN_ADMIN.LOGO_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.logo-link:
|
||||
type: colorscheme.color
|
||||
default: '#ffffff'
|
||||
help: PLUGIN_ADMIN.LOGO_LINK_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.nav-bg:
|
||||
type: colorscheme.color
|
||||
default: '#253a47'
|
||||
help: PLUGIN_ADMIN.NAV_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.nav-text:
|
||||
type: colorscheme.color
|
||||
default: '#afc7d5'
|
||||
help: PLUGIN_ADMIN.NAV_TEXT_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.nav-link:
|
||||
type: colorscheme.color
|
||||
default: '#d1dee7'
|
||||
help: PLUGIN_ADMIN.NAV_LINK_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.nav-selected-bg:
|
||||
type: colorscheme.color
|
||||
default: '#2d4d5b'
|
||||
help: PLUGIN_ADMIN.NAV_SELECTED_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.nav-selected-link:
|
||||
type: colorscheme.color
|
||||
default: '#ffffff'
|
||||
help: PLUGIN_ADMIN.NAV_SELECTED_LINK_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.nav-hover-bg:
|
||||
type: colorscheme.color
|
||||
default: '#1e333e'
|
||||
help: PLUGIN_ADMIN.NAV_HOVER_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.nav-hover-link:
|
||||
type: colorscheme.color
|
||||
default: '#ffffff'
|
||||
help: PLUGIN_ADMIN.NAV_HOVER_LINK_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.toolbar-bg:
|
||||
type: colorscheme.color
|
||||
default: '#349886'
|
||||
help: PLUGIN_ADMIN.TOOLBAR_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.toolbar-text:
|
||||
type: colorscheme.color
|
||||
default: '#ffffff'
|
||||
help: PLUGIN_ADMIN.TOOLBAR_TEXT_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.page-bg:
|
||||
type: colorscheme.color
|
||||
default: '#314d5b'
|
||||
help: PLUGIN_ADMIN.PAGE_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.page-text:
|
||||
type: colorscheme.color
|
||||
default: '#81a5b5'
|
||||
help: PLUGIN_ADMIN.PAGE_TEXT_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.page-link:
|
||||
type: colorscheme.color
|
||||
default: '#aad9ed'
|
||||
help: PLUGIN_ADMIN.PAGE_LINK_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.content-bg:
|
||||
type: colorscheme.color
|
||||
default: '#eeeeee'
|
||||
help: PLUGIN_ADMIN.CONTENT_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.content-text:
|
||||
type: colorscheme.color
|
||||
default: '#737c81'
|
||||
help: PLUGIN_ADMIN.CONTENT_TEXT_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.content-link:
|
||||
type: colorscheme.color
|
||||
default: '#0082ba'
|
||||
help: PLUGIN_ADMIN.CONTENT_LINK_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.content-link2:
|
||||
type: colorscheme.color
|
||||
default: '#da4b46'
|
||||
help: PLUGIN_ADMIN.CONTENT_LINK2_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.content-header:
|
||||
type: colorscheme.color
|
||||
default: '#314d5b'
|
||||
help: PLUGIN_ADMIN.CONTENT_HEADER_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.content-tabs-bg:
|
||||
type: colorscheme.color
|
||||
default: '#223a47'
|
||||
help: PLUGIN_ADMIN.CONTENT_TABS_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.content-tabs-text:
|
||||
type: colorscheme.color
|
||||
default: '#d1dee7'
|
||||
help: PLUGIN_ADMIN.CONTENT_TABS_TEXT_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.content-highlight:
|
||||
type: colorscheme.color
|
||||
default: '#ffffd7'
|
||||
help: PLUGIN_ADMIN.CONTENT_HIGHLIGHT_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.button-bg:
|
||||
type: colorscheme.color
|
||||
default: '#41bea8'
|
||||
help: PLUGIN_ADMIN.BUTTON_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.button-text:
|
||||
type: colorscheme.color
|
||||
default: '#ffffff'
|
||||
help: PLUGIN_ADMIN.BUTTON_TEXT_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.notice-bg:
|
||||
type: colorscheme.color
|
||||
default: '#00a6cf'
|
||||
help: PLUGIN_ADMIN.NOTICE_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.notice-text:
|
||||
type: colorscheme.color
|
||||
default: '#ffffff'
|
||||
help: PLUGIN_ADMIN.NOTICE_TEXT_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.update-bg:
|
||||
type: colorscheme.color
|
||||
default: '#8f5aad'
|
||||
help: PLUGIN_ADMIN.UPDATES_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.update-text:
|
||||
type: colorscheme.color
|
||||
default: '#ffffff'
|
||||
help: PLUGIN_ADMIN.UPDATES_TEXT_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.critical-bg:
|
||||
type: colorscheme.color
|
||||
default: '#da4b46'
|
||||
help: PLUGIN_ADMIN.CRITICAL_BG_HELP
|
||||
|
||||
whitelabel.color_scheme.colors.critical-text:
|
||||
type: colorscheme.color
|
||||
default: '#ffffff'
|
||||
help: PLUGIN_ADMIN.CRITICAL_TEXT_HELP
|
||||
|
||||
whitelabel.color_scheme.accents.primary-accent:
|
||||
type: select
|
||||
size: medium
|
||||
classes: fancy
|
||||
label: PLUGIN_ADMIN.PRIMARY_ACCENT_LABEL
|
||||
help: PLUGIN_ADMIN.PRIMARY_ACCENT_HELP
|
||||
options:
|
||||
button: PLUGIN_ADMIN.BUTTON_COLORS
|
||||
content: PLUGIN_ADMIN.CONTENT_COLORS
|
||||
tabs: PLUGIN_ADMIN.TABS_COLORS
|
||||
critical: PLUGIN_ADMIN.CRITICAL_COLORS
|
||||
logo: PLUGIN_ADMIN.LOGO_COLORS
|
||||
nav: PLUGIN_ADMIN.NAV_COLORS
|
||||
notice: PLUGIN_ADMIN.NOTICE_COLORS
|
||||
page: PLUGIN_ADMIN.PAGE_COLORS
|
||||
toolbar: PLUGIN_ADMIN.TOOLBAR_COLORS
|
||||
update: PLUGIN_ADMIN.UPDATE_COLORS
|
||||
|
||||
whitelabel.color_scheme.accents.secondary-accent:
|
||||
type: select
|
||||
size: medium
|
||||
classes: fancy
|
||||
label: PLUGIN_ADMIN.SECONDARY_ACCENT_LABEL
|
||||
help: PLUGIN_ADMIN.SECONDARY_ACCENT_HELP
|
||||
options:
|
||||
button: PLUGIN_ADMIN.BUTTON_COLORS
|
||||
content: PLUGIN_ADMIN.CONTENT_COLORS
|
||||
tabs: PLUGIN_ADMIN.TABS_COLORS
|
||||
critical: PLUGIN_ADMIN.CRITICAL_COLORS
|
||||
logo: PLUGIN_ADMIN.LOGO_COLORS
|
||||
nav: PLUGIN_ADMIN.NAV_COLORS
|
||||
notice: PLUGIN_ADMIN.NOTICE_COLORS
|
||||
page: PLUGIN_ADMIN.PAGE_COLORS
|
||||
toolbar: PLUGIN_ADMIN.TOOLBAR_COLORS
|
||||
update: PLUGIN_ADMIN.UPDATE_COLORS
|
||||
|
||||
whitelabel.color_scheme.accents.tertiary-accent:
|
||||
type: select
|
||||
size: medium
|
||||
classes: fancy
|
||||
label: PLUGIN_ADMIN.TERTIARY_ACCENT_LABEL
|
||||
help: PLUGIN_ADMIN.TERTIARY_ACCENT_HELP
|
||||
options:
|
||||
button: PLUGIN_ADMIN.BUTTON_COLORS
|
||||
content: PLUGIN_ADMIN.CONTENT_COLORS
|
||||
tabs: PLUGIN_ADMIN.TABS_COLORS
|
||||
critical: PLUGIN_ADMIN.CRITICAL_COLORS
|
||||
logo: PLUGIN_ADMIN.LOGO_COLORS
|
||||
nav: PLUGIN_ADMIN.NAV_COLORS
|
||||
notice: PLUGIN_ADMIN.NOTICE_COLORS
|
||||
page: PLUGIN_ADMIN.PAGE_COLORS
|
||||
toolbar: PLUGIN_ADMIN.TOOLBAR_COLORS
|
||||
update: PLUGIN_ADMIN.UPDATE_COLORS
|
||||
|
||||
whitelabel.custom_footer:
|
||||
type: textarea
|
||||
rows: 2
|
||||
label: PLUGIN_ADMIN.CUSTOM_FOOTER
|
||||
help: PLUGIN_ADMIN.CUSTOM_FOOTER_HELP
|
||||
placeholder: PLUGIN_ADMIN.CUSTOM_FOOTER_PLACEHOLDER
|
||||
|
||||
|
||||
whitelabel.custom_css:
|
||||
label: PLUGIN_ADMIN.CUSTOM_CSS_LABEL
|
||||
placeholder: PLUGIN_ADMIN.CUSTOM_CSS_PLACEHOLDER
|
||||
help: PLUGIN_ADMIN.CUSTOM_CSS_HELP
|
||||
type: editor
|
||||
codemirror:
|
||||
mode: 'css'
|
||||
indentUnit: 2
|
||||
indentWithTabs: true
|
||||
lineNumbers: true
|
||||
styleActiveLine: true
|
||||
|
||||
whitelabel.custom_presets:
|
||||
label: PLUGIN_ADMIN.CUSTOM_PRESETS
|
||||
help: PLUGIN_ADMIN.CUSTOM_PRESETS_HELP
|
||||
placeholder: PLUGIN_ADMIN.CUSTOM_PRESETS_PLACEHOLDER
|
||||
type: editor
|
||||
codemirror:
|
||||
mode: 'yaml'
|
||||
indentUnit: 2
|
||||
indentWithTabs: false
|
||||
lineNumbers: true
|
||||
styleActiveLine: true
|
||||
gutters: ['CodeMirror-lint-markers']
|
||||
lint: true
|
||||
|
||||
extras_tab:
|
||||
type: tab
|
||||
title: PLUGIN_ADMIN.EXTRAS
|
||||
|
||||
fields:
|
||||
|
||||
Popularity:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.POPULARITY
|
||||
underline: true
|
||||
|
||||
popularity.enabled:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.VISITOR_TRACKING
|
||||
highlight: 1
|
||||
default: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
help: PLUGIN_ADMIN.VISITOR_TRACKING_HELP
|
||||
|
||||
dashboard.days_of_stats:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.DAYS_OF_STATS
|
||||
append: days
|
||||
size: x-small
|
||||
default: 7
|
||||
help: PLUGIN_ADMIN.DAYS_OF_STATS_HELP
|
||||
validate:
|
||||
type: int
|
||||
|
||||
popularity.ignore:
|
||||
type: array
|
||||
label: PLUGIN_ADMIN.IGNORE_URLS
|
||||
size: large
|
||||
help: PLUGIN_ADMIN.IGNORE_URLS_HELP
|
||||
default: ['/test*','/modular']
|
||||
value_only: true
|
||||
placeholder_value: /ignore-this-route
|
||||
|
||||
popularity.history.daily:
|
||||
type: hidden
|
||||
label: PLUGIN_ADMIN.DAILY_HISTORY
|
||||
default: 30
|
||||
|
||||
popularity.history.monthly:
|
||||
type: hidden
|
||||
label: PLUGIN_ADMIN.MONTHLY_HISTORY
|
||||
default: 12
|
||||
|
||||
popularity.history.visitors:
|
||||
type: hidden
|
||||
label: PLUGIN_ADMIN.VISITORS_HISTORY
|
||||
default: 20
|
||||
|
||||
MediaResize:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.MEDIA_RESIZE
|
||||
underline: true
|
||||
|
||||
MediaResizeNote:
|
||||
type: spacer
|
||||
text: PLUGIN_ADMIN.PAGEMEDIA_RESIZER
|
||||
markdown: true
|
||||
|
||||
pagemedia.resize_width:
|
||||
type: number
|
||||
size: x-small
|
||||
append: PLUGIN_ADMIN.PIXELS
|
||||
label: PLUGIN_ADMIN.RESIZE_WIDTH
|
||||
default: 0
|
||||
validate:
|
||||
type: number
|
||||
help: PLUGIN_ADMIN.RESIZE_WIDTH_HELP
|
||||
|
||||
pagemedia.resize_height:
|
||||
type: number
|
||||
size: x-small
|
||||
append: PLUGIN_ADMIN.PIXELS
|
||||
label: PLUGIN_ADMIN.RESIZE_HEIGHT
|
||||
default: 0
|
||||
validate:
|
||||
type: number
|
||||
help: PLUGIN_ADMIN.RESIZE_HEIGHT_HELP
|
||||
|
||||
pagemedia.res_min_width:
|
||||
type: number
|
||||
size: x-small
|
||||
append: PLUGIN_ADMIN.PIXELS
|
||||
label: PLUGIN_ADMIN.RES_MIN_WIDTH
|
||||
default: 0
|
||||
validate:
|
||||
type: number
|
||||
help: PLUGIN_ADMIN.RES_MIN_WIDTH_HELP
|
||||
|
||||
pagemedia.res_min_height:
|
||||
type: number
|
||||
size: x-small
|
||||
append: PLUGIN_ADMIN.PIXELS
|
||||
label: PLUGIN_ADMIN.RES_MIN_HEIGHT
|
||||
default: 0
|
||||
validate:
|
||||
type: number
|
||||
help: PLUGIN_ADMIN.RES_MIN_HEIGHT_HELP
|
||||
|
||||
pagemedia.res_max_width:
|
||||
type: number
|
||||
size: x-small
|
||||
append: PLUGIN_ADMIN.PIXELS
|
||||
label: PLUGIN_ADMIN.RES_MAX_WIDTH
|
||||
default: 0
|
||||
validate:
|
||||
type: number
|
||||
help: PLUGIN_ADMIN.RES_MAX_WIDTH_HELP
|
||||
|
||||
pagemedia.res_max_height:
|
||||
type: number
|
||||
size: x-small
|
||||
append: PLUGIN_ADMIN.PIXELS
|
||||
label: PLUGIN_ADMIN.RES_MAX_HEIGHT
|
||||
default: 0
|
||||
validate:
|
||||
type: number
|
||||
help: PLUGIN_ADMIN.RES_MAX_HEIGHT_HELP
|
||||
|
||||
pagemedia.resize_quality:
|
||||
type: number
|
||||
size: x-small
|
||||
append: 0...1
|
||||
label: PLUGIN_ADMIN.RESIZE_QUALITY
|
||||
default: 0.8
|
||||
validate:
|
||||
type: number
|
||||
step: 0.01
|
||||
help: PLUGIN_ADMIN.RESIZE_QUALITY_HELP
|
||||
@@ -1,43 +0,0 @@
|
||||
rules:
|
||||
slug:
|
||||
pattern: '[a-zA-Zа-яA-Я0-9_\-]+'
|
||||
min: 1
|
||||
max: 200
|
||||
|
||||
form:
|
||||
validation: loose
|
||||
fields:
|
||||
|
||||
section:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.COPY_PAGE
|
||||
|
||||
title:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.PAGE_TITLE
|
||||
help: PLUGIN_ADMIN.PAGE_TITLE_HELP
|
||||
validate:
|
||||
required: true
|
||||
|
||||
folder:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.FOLDER_NAME
|
||||
help: PLUGIN_ADMIN.FOLDER_NAME_HELP
|
||||
validate:
|
||||
rule: slug
|
||||
required: true
|
||||
|
||||
header.published:
|
||||
id: move-header-published
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.PUBLISHED
|
||||
help: PLUGIN_ADMIN.PUBLISHED_HELP
|
||||
highlight: ''
|
||||
default: ''
|
||||
size: medium
|
||||
options:
|
||||
'': PLUGIN_ADMIN.AUTO
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
validate:
|
||||
type: bool
|
||||
@@ -1,52 +0,0 @@
|
||||
rules:
|
||||
slug:
|
||||
pattern: '[a-zA-Zа-яA-Я0-9_\-]+'
|
||||
min: 1
|
||||
max: 200
|
||||
|
||||
form:
|
||||
validation: loose
|
||||
fields:
|
||||
|
||||
section:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.ADD_MODULE_CONTENT
|
||||
|
||||
title:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.PAGE_TITLE
|
||||
validate:
|
||||
required: true
|
||||
|
||||
folder:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.FOLDER_NAME
|
||||
validate:
|
||||
rule: slug
|
||||
required: true
|
||||
|
||||
route:
|
||||
type: parents
|
||||
label: PLUGIN_ADMIN.PAGE
|
||||
classes: fancy
|
||||
validate:
|
||||
required: true
|
||||
|
||||
name:
|
||||
type: select
|
||||
classes: fancy
|
||||
label: PLUGIN_ADMIN.MODULE_TEMPLATE
|
||||
help: PLUGIN_ADMIN.PAGE_FILE_HELP
|
||||
default: default
|
||||
data-options@: '\Grav\Plugin\AdminPlugin::pagesModularTypes'
|
||||
validate:
|
||||
required: true
|
||||
|
||||
modular:
|
||||
type: hidden
|
||||
default: 1
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
blueprint:
|
||||
type: blueprint
|
||||
@@ -1,104 +0,0 @@
|
||||
rules:
|
||||
slug:
|
||||
pattern: '[a-zA-Zа-яA-Я0-9_\-]+'
|
||||
min: 1
|
||||
max: 200
|
||||
|
||||
form:
|
||||
validation: loose
|
||||
fields:
|
||||
|
||||
tabs:
|
||||
type: tabs
|
||||
active: 1
|
||||
|
||||
fields:
|
||||
content:
|
||||
type: tab
|
||||
title: PLUGIN_ADMIN.CONTENT
|
||||
|
||||
fields:
|
||||
xss_check:
|
||||
type: xss
|
||||
|
||||
frontmatter:
|
||||
classes: frontmatter
|
||||
type: editor
|
||||
label: PLUGIN_ADMIN.FRONTMATTER
|
||||
autofocus: true
|
||||
codemirror:
|
||||
mode: 'yaml'
|
||||
indentUnit: 4
|
||||
autofocus: true
|
||||
indentWithTabs: false
|
||||
lineNumbers: true
|
||||
styleActiveLine: true
|
||||
gutters: ['CodeMirror-lint-markers']
|
||||
lint: true
|
||||
|
||||
content:
|
||||
type: markdown
|
||||
|
||||
header.media_order:
|
||||
type: pagemedia
|
||||
label: PLUGIN_ADMIN.PAGE_MEDIA
|
||||
|
||||
options:
|
||||
type: tab
|
||||
title: PLUGIN_ADMIN.OPTIONS
|
||||
|
||||
fields:
|
||||
|
||||
columns:
|
||||
type: columns
|
||||
|
||||
fields:
|
||||
column1:
|
||||
type: column
|
||||
|
||||
fields:
|
||||
|
||||
ordering:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.FOLDER_NUMERIC_PREFIX
|
||||
help: PLUGIN_ADMIN.FOLDER_NUMERIC_PREFIX_HELP
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
folder:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.FILENAME
|
||||
validate:
|
||||
rule: slug
|
||||
required: true
|
||||
|
||||
route:
|
||||
type: parents
|
||||
label: PLUGIN_ADMIN.PARENT
|
||||
classes: fancy
|
||||
validate:
|
||||
required: true
|
||||
|
||||
name:
|
||||
type: select
|
||||
classes: fancy
|
||||
label: PLUGIN_ADMIN.MODULE_TEMPLATE
|
||||
default: default
|
||||
data-options@: '\Grav\Plugin\AdminPlugin::pagesModularTypes'
|
||||
validate:
|
||||
required: true
|
||||
|
||||
column2:
|
||||
type: column
|
||||
|
||||
fields:
|
||||
order:
|
||||
type: order
|
||||
label: PLUGIN_ADMIN.ORDERING
|
||||
|
||||
blueprint:
|
||||
type: blueprint
|
||||
@@ -1,5 +0,0 @@
|
||||
form:
|
||||
validation: loose
|
||||
fields:
|
||||
route:
|
||||
type: hidden
|
||||
@@ -1,62 +0,0 @@
|
||||
rules:
|
||||
slug:
|
||||
pattern: '[a-zA-Zа-яA-Я0-9_\-]+'
|
||||
min: 1
|
||||
max: 200
|
||||
|
||||
form:
|
||||
validation: loose
|
||||
fields:
|
||||
|
||||
section:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.ADD_PAGE
|
||||
|
||||
title:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.PAGE_TITLE
|
||||
help: PLUGIN_ADMIN.PAGE_TITLE_HELP
|
||||
validate:
|
||||
required: true
|
||||
|
||||
folder:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.FOLDER_NAME
|
||||
help: PLUGIN_ADMIN.FOLDER_NAME_HELP
|
||||
validate:
|
||||
rule: slug
|
||||
required: true
|
||||
|
||||
route:
|
||||
type: parents
|
||||
label: PLUGIN_ADMIN.PARENT_PAGE
|
||||
classes: fancy
|
||||
validate:
|
||||
required: true
|
||||
|
||||
name:
|
||||
type: select
|
||||
classes: fancy
|
||||
label: PLUGIN_ADMIN.PAGE_FILE
|
||||
help: PLUGIN_ADMIN.PAGE_FILE_HELP
|
||||
data-options@: '\Grav\Plugin\AdminPlugin::pagesTypes'
|
||||
data-default@: '\Grav\Plugin\Admin\Admin::getLastPageName'
|
||||
validate:
|
||||
required: true
|
||||
|
||||
visible:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.VISIBLE
|
||||
help: PLUGIN_ADMIN.VISIBLE_HELP
|
||||
highlight: ''
|
||||
default: ''
|
||||
options:
|
||||
'': PLUGIN_ADMIN.AUTO
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
validate:
|
||||
type: bool
|
||||
required: true
|
||||
|
||||
blueprint:
|
||||
type: blueprint
|
||||
@@ -1,31 +0,0 @@
|
||||
rules:
|
||||
slug:
|
||||
pattern: '[a-zA-Zа-яA-Я0-9_\-]+'
|
||||
min: 1
|
||||
max: 200
|
||||
|
||||
form:
|
||||
validation: loose
|
||||
fields:
|
||||
|
||||
section:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.ADD_FOLDER
|
||||
|
||||
folder:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.FOLDER_NAME
|
||||
help: PLUGIN_ADMIN.FOLDER_NAME_HELP
|
||||
validate:
|
||||
rule: slug
|
||||
required: true
|
||||
|
||||
route:
|
||||
type: parents
|
||||
label: PLUGIN_ADMIN.PARENT_PAGE
|
||||
classes: fancy
|
||||
validate:
|
||||
required: true
|
||||
|
||||
blueprint:
|
||||
type: blueprint
|
||||
@@ -1,104 +0,0 @@
|
||||
rules:
|
||||
slug:
|
||||
pattern: '[a-zA-Zа-яA-Я0-9_\-]+'
|
||||
min: 1
|
||||
max: 200
|
||||
|
||||
form:
|
||||
validation: loose
|
||||
fields:
|
||||
|
||||
tabs:
|
||||
type: tabs
|
||||
active: 1
|
||||
|
||||
fields:
|
||||
content:
|
||||
type: tab
|
||||
title: PLUGIN_ADMIN.CONTENT
|
||||
|
||||
fields:
|
||||
xss_check:
|
||||
type: xss
|
||||
|
||||
frontmatter:
|
||||
classes: frontmatter
|
||||
type: editor
|
||||
label: PLUGIN_ADMIN.FRONTMATTER
|
||||
autofocus: true
|
||||
codemirror:
|
||||
mode: 'yaml'
|
||||
indentUnit: 4
|
||||
autofocus: true
|
||||
indentWithTabs: false
|
||||
lineNumbers: true
|
||||
styleActiveLine: true
|
||||
gutters: ['CodeMirror-lint-markers']
|
||||
lint: true
|
||||
|
||||
content:
|
||||
type: codemirror
|
||||
|
||||
header.media_order:
|
||||
type: pagemedia
|
||||
label: PLUGIN_ADMIN.PAGE_MEDIA
|
||||
|
||||
options:
|
||||
type: tab
|
||||
title: PLUGIN_ADMIN.OPTIONS
|
||||
|
||||
fields:
|
||||
|
||||
columns:
|
||||
type: columns
|
||||
|
||||
fields:
|
||||
column1:
|
||||
type: column
|
||||
|
||||
fields:
|
||||
|
||||
ordering:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.FOLDER_NUMERIC_PREFIX
|
||||
help: PLUGIN_ADMIN.FOLDER_NUMERIC_PREFIX_HELP
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
folder:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.FOLDER_NAME
|
||||
help: PLUGIN_ADMIN.FOLDER_NAME_HELP
|
||||
validate:
|
||||
rule: slug
|
||||
required: true
|
||||
|
||||
route:
|
||||
type: parents
|
||||
label: PLUGIN_ADMIN.PARENT
|
||||
classes: fancy
|
||||
|
||||
name:
|
||||
type: select
|
||||
classes: fancy
|
||||
label: PLUGIN_ADMIN.DISPLAY_TEMPLATE
|
||||
help: PLUGIN_ADMIN.DISPLAY_TEMPLATE_HELP
|
||||
default: default
|
||||
data-options@: '\Grav\Plugin\AdminPlugin::pagesTypes'
|
||||
validate:
|
||||
required: true
|
||||
|
||||
column2:
|
||||
type: column
|
||||
|
||||
fields:
|
||||
order:
|
||||
type: order
|
||||
label: PLUGIN_ADMIN.ORDERING
|
||||
|
||||
blueprint:
|
||||
type: blueprint
|
||||
@@ -1,34 +0,0 @@
|
||||
rules:
|
||||
slug:
|
||||
pattern: '[a-zA-Zа-яA-Я0-9_\-]+'
|
||||
min: 1
|
||||
max: 200
|
||||
|
||||
form:
|
||||
validation: loose
|
||||
fields:
|
||||
|
||||
tabs:
|
||||
type: tabs
|
||||
active: 1
|
||||
|
||||
fields:
|
||||
content:
|
||||
type: tab
|
||||
title: PLUGIN_ADMIN.CONTENT
|
||||
|
||||
fields:
|
||||
frontmatter:
|
||||
classes: frontmatter
|
||||
type: editor
|
||||
label: PLUGIN_ADMIN.FRONTMATTER
|
||||
autofocus: true
|
||||
codemirror:
|
||||
mode: 'yaml'
|
||||
indentUnit: 4
|
||||
autofocus: true
|
||||
indentWithTabs: false
|
||||
lineNumbers: true
|
||||
styleActiveLine: true
|
||||
gutters: ['CodeMirror-lint-markers']
|
||||
lint: true
|
||||
@@ -1,36 +0,0 @@
|
||||
title: PLUGIN_ADMIN.MEDIA
|
||||
form:
|
||||
validation: loose
|
||||
fields:
|
||||
'types':
|
||||
name: medias
|
||||
type: list
|
||||
label: PLUGIN_ADMIN.MEDIA_TYPES
|
||||
style: vertical
|
||||
key: extension
|
||||
controls: both
|
||||
collapsed: true
|
||||
|
||||
fields:
|
||||
.extension:
|
||||
type: key
|
||||
label: PLUGIN_ADMIN.FILE_EXTENSION
|
||||
.type:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.TYPE
|
||||
.thumb:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.THUMB
|
||||
.mime:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.MIME_TYPE
|
||||
validate:
|
||||
type: lower
|
||||
.image:
|
||||
type: textarea
|
||||
yaml: true
|
||||
label: PLUGIN_ADMIN.IMAGE_OPTIONS
|
||||
validate:
|
||||
type: yaml
|
||||
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Plugin\Admin
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Plugin\Admin;
|
||||
|
||||
use ArrayAccess;
|
||||
use Exception;
|
||||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Framework\Form\Interfaces\FormFlashInterface;
|
||||
use Grav\Framework\Form\Interfaces\FormInterface;
|
||||
use Grav\Framework\Form\Traits\FormTrait;
|
||||
use InvalidArgumentException;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* Class AdminForm
|
||||
* @package Grav\Plugin\Admin
|
||||
*/
|
||||
class AdminForm implements FormInterface, JsonSerializable
|
||||
{
|
||||
use FormTrait;
|
||||
|
||||
/** @var string */
|
||||
protected $nonce_name;
|
||||
/** @var string */
|
||||
protected $nonce_action;
|
||||
/** @var callable */
|
||||
protected $submitMethod;
|
||||
|
||||
/**
|
||||
* AdminForm constructor.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(string $name, array $options)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->nonce_name = $options['nonce_name'] ?? 'admin-nonce';
|
||||
$this->nonce_action = $options['nonce_action'] ?? 'admin-form';
|
||||
|
||||
$this->setId($options['id'] ?? $this->getName());
|
||||
$this->setUniqueId($options['unique_id'] ?? $this->getName());
|
||||
$this->setBlueprint($options['blueprint']);
|
||||
$this->setSubmitMethod($options['submit_method'] ?? null);
|
||||
$this->setFlashLookupFolder('tmp://admin/forms/[SESSIONID]');
|
||||
|
||||
if (!empty($options['reset'])) {
|
||||
$this->getFlash()->delete();
|
||||
}
|
||||
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function initialize(): AdminForm
|
||||
{
|
||||
$this->messages = [];
|
||||
$this->submitted = false;
|
||||
$this->unsetFlash();
|
||||
|
||||
/** @var FormFlashInterface $flash */
|
||||
$flash = $this->getFlash();
|
||||
if ($flash->exists()) {
|
||||
$data = $flash->getData();
|
||||
if (null !== $data) {
|
||||
$data = new Data($data, $this->getBlueprint());
|
||||
$data->setKeepEmptyValues(true);
|
||||
$data->setMissingValuesAsNull(true);
|
||||
}
|
||||
|
||||
$this->data = $data;
|
||||
$this->files = $flash->getFilesByFields(false);
|
||||
} else {
|
||||
$this->data = new Data([], $this->getBlueprint());
|
||||
$this->files = [];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNonceName(): string
|
||||
{
|
||||
return $this->nonce_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNonceAction(): string
|
||||
{
|
||||
return $this->nonce_action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getScope(): string
|
||||
{
|
||||
return 'data.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Blueprint $blueprint
|
||||
*/
|
||||
public function setBlueprint(Blueprint $blueprint): void
|
||||
{
|
||||
if (null === $blueprint) {
|
||||
throw new InvalidArgumentException('Blueprint is required');
|
||||
}
|
||||
|
||||
$this->blueprint = $blueprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setData(string $field, $value): void
|
||||
{
|
||||
$this->getData()->set($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Blueprint
|
||||
*/
|
||||
public function getBlueprint(): Blueprint
|
||||
{
|
||||
return $this->blueprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable|null $submitMethod
|
||||
*/
|
||||
public function setSubmitMethod(?callable $submitMethod): void
|
||||
{
|
||||
if (null === $submitMethod) {
|
||||
throw new InvalidArgumentException('Submit method is required');
|
||||
}
|
||||
|
||||
$this->submitMethod = $submitMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $files
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function doSubmit(array $data, array $files): void
|
||||
{
|
||||
$method = $this->submitMethod;
|
||||
$method($data, $files);
|
||||
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter validated data.
|
||||
*
|
||||
* @param ArrayAccess|Data|null $data
|
||||
* @return void
|
||||
*/
|
||||
protected function filterData($data = null): void
|
||||
{
|
||||
if ($data instanceof Data) {
|
||||
$data->filter(true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Plugin\Admin
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Grav\Plugin\Admin;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Page\Interfaces\PageInterface;
|
||||
use Grav\Common\Page\Page;
|
||||
use Grav\Framework\Form\Interfaces\FormFactoryInterface;
|
||||
use Grav\Framework\Form\Interfaces\FormInterface;
|
||||
|
||||
/**
|
||||
* Class FlexFormFactory
|
||||
* @package Grav\Plugin\FlexObjects
|
||||
*/
|
||||
class AdminFormFactory implements FormFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @param Page $page
|
||||
* @param string $name
|
||||
* @param array $form
|
||||
* @return FormInterface|null
|
||||
*/
|
||||
public function createPageForm(Page $page, string $name, array $form): ?FormInterface
|
||||
{
|
||||
return $this->createFormForPage($page, $name, $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PageInterface $page
|
||||
* @param string $name
|
||||
* @param array $form
|
||||
* @return FormInterface|null
|
||||
*/
|
||||
public function createFormForPage(PageInterface $page, string $name, array $form): ?FormInterface
|
||||
{
|
||||
/** @var Admin|null $admin */
|
||||
$admin = Grav::instance()['admin'] ?? null;
|
||||
$object = $admin->form ?? null;
|
||||
|
||||
return $object && $object->getName() === $name ? $object : null;
|
||||
}
|
||||
}
|
||||
@@ -1,414 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Plugin\Admin
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Grav\Plugin\Admin\Controllers;
|
||||
|
||||
use Grav\Common\Debugger;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Inflector;
|
||||
use Grav\Common\Language\Language;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
|
||||
use Grav\Framework\Form\Interfaces\FormInterface;
|
||||
use Grav\Framework\Psr7\Response;
|
||||
use Grav\Framework\RequestHandler\Exception\NotFoundException;
|
||||
use Grav\Framework\RequestHandler\Exception\PageExpiredException;
|
||||
use Grav\Framework\RequestHandler\Exception\RequestException;
|
||||
use Grav\Framework\Route\Route;
|
||||
use Grav\Framework\Session\SessionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\Session\Message;
|
||||
|
||||
abstract class AbstractController implements RequestHandlerInterface
|
||||
{
|
||||
/** @var string */
|
||||
protected $nonce_action = 'admin-form';
|
||||
|
||||
/** @var string */
|
||||
protected $nonce_name = 'admin-nonce';
|
||||
|
||||
/** @var ServerRequestInterface */
|
||||
protected $request;
|
||||
|
||||
/** @var Grav */
|
||||
protected $grav;
|
||||
|
||||
/** @var string */
|
||||
protected $type;
|
||||
|
||||
/** @var string */
|
||||
protected $key;
|
||||
|
||||
/**
|
||||
* Handle request.
|
||||
*
|
||||
* Fires event: admin.[directory].[task|action].[command]
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return Response
|
||||
*/
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$attributes = $request->getAttributes();
|
||||
$this->request = $request;
|
||||
$this->grav = $attributes['grav'] ?? Grav::instance();
|
||||
$this->type = $attributes['type'] ?? null;
|
||||
$this->key = $attributes['key'] ?? null;
|
||||
|
||||
/** @var Route $route */
|
||||
$route = $attributes['route'];
|
||||
$post = $this->getPost();
|
||||
|
||||
if ($this->isFormSubmit()) {
|
||||
$form = $this->getForm();
|
||||
$this->nonce_name = $attributes['nonce_name'] ?? $form->getNonceName();
|
||||
$this->nonce_action = $attributes['nonce_action'] ?? $form->getNonceAction();
|
||||
}
|
||||
|
||||
try {
|
||||
$task = $request->getAttribute('task') ?? $post['task'] ?? $route->getParam('task');
|
||||
if ($task) {
|
||||
if (empty($attributes['forwarded'])) {
|
||||
$this->checkNonce($task);
|
||||
}
|
||||
$type = 'task';
|
||||
$command = $task;
|
||||
} else {
|
||||
$type = 'action';
|
||||
$command = $request->getAttribute('action') ?? $post['action'] ?? $route->getParam('action') ?? 'display';
|
||||
}
|
||||
$command = strtolower($command);
|
||||
|
||||
$event = new Event(
|
||||
[
|
||||
'controller' => $this,
|
||||
'response' => null
|
||||
]
|
||||
);
|
||||
|
||||
$this->grav->fireEvent("admin.{$this->type}.{$type}.{$command}", $event);
|
||||
|
||||
$response = $event['response'];
|
||||
if (!$response) {
|
||||
/** @var Inflector $inflector */
|
||||
$inflector = $this->grav['inflector'];
|
||||
$method = $type . $inflector::camelize($command);
|
||||
if ($method && method_exists($this, $method)) {
|
||||
$response = $this->{$method}($request);
|
||||
} else {
|
||||
throw new NotFoundException($request);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
/** @var Debugger $debugger */
|
||||
$debugger = $this->grav['debugger'];
|
||||
$debugger->addException($e);
|
||||
|
||||
$response = $this->createErrorResponse($e);
|
||||
}
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $this->createJsonResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request.
|
||||
*
|
||||
* @return ServerRequestInterface
|
||||
*/
|
||||
public function getRequest(): ServerRequestInterface
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $name
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPost(?string $name = null, $default = null)
|
||||
{
|
||||
$body = $this->request->getParsedBody();
|
||||
|
||||
if ($name) {
|
||||
return $body[$name] ?? $default;
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a form has been submitted.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFormSubmit(): bool
|
||||
{
|
||||
return (bool)$this->getPost('__form-name__');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get form.
|
||||
*
|
||||
* @param string|null $type
|
||||
* @return FormInterface
|
||||
*/
|
||||
public function getForm(?string $type = null): FormInterface
|
||||
{
|
||||
$object = $this->getObject();
|
||||
if (!$object) {
|
||||
throw new \RuntimeException('Not Found', 404);
|
||||
}
|
||||
|
||||
$formName = $this->getPost('__form-name__');
|
||||
$uniqueId = $this->getPost('__unique_form_id__') ?: $formName;
|
||||
|
||||
$form = $object->getForm($type ?? 'edit');
|
||||
if ($uniqueId) {
|
||||
$form->setUniqueId($uniqueId);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FlexObjectInterface
|
||||
*/
|
||||
abstract public function getObject();
|
||||
|
||||
/**
|
||||
* Get Grav instance.
|
||||
*
|
||||
* @return Grav
|
||||
*/
|
||||
public function getGrav(): Grav
|
||||
{
|
||||
return $this->grav;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session.
|
||||
*
|
||||
* @return SessionInterface
|
||||
*/
|
||||
public function getSession(): SessionInterface
|
||||
{
|
||||
return $this->getGrav()['session'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the current admin page.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function createDisplayResponse(): ResponseInterface
|
||||
{
|
||||
return new Response(418);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create custom HTML response.
|
||||
*
|
||||
* @param string $content
|
||||
* @param int $code
|
||||
* @return Response
|
||||
*/
|
||||
public function createHtmlResponse(string $content, ?int $code = null): ResponseInterface
|
||||
{
|
||||
return new Response($code ?: 200, [], $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create JSON response.
|
||||
*
|
||||
* @param array $content
|
||||
* @return Response
|
||||
*/
|
||||
public function createJsonResponse(array $content): ResponseInterface
|
||||
{
|
||||
$code = $content['code'] ?? 200;
|
||||
if ($code >= 301 && $code <= 307) {
|
||||
$code = 200;
|
||||
}
|
||||
|
||||
return new Response($code, ['Content-Type' => 'application/json'], json_encode($content));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create redirect response.
|
||||
*
|
||||
* @param string $url
|
||||
* @param int $code
|
||||
* @return Response
|
||||
*/
|
||||
public function createRedirectResponse(string $url, ?int $code = null): ResponseInterface
|
||||
{
|
||||
if (null === $code || $code < 301 || $code > 307) {
|
||||
$code = $this->grav['config']->get('system.pages.redirect_default_code', 302);
|
||||
}
|
||||
|
||||
$accept = $this->getAccept(['application/json', 'text/html']);
|
||||
|
||||
if ($accept === 'application/json') {
|
||||
return $this->createJsonResponse(['code' => $code, 'status' => 'redirect', 'redirect' => $url]);
|
||||
}
|
||||
|
||||
return new Response($code, ['Location' => $url]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create error response.
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @return Response
|
||||
*/
|
||||
public function createErrorResponse(\Exception $exception): ResponseInterface
|
||||
{
|
||||
$validCodes = [
|
||||
400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418,
|
||||
422, 423, 424, 425, 426, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 506, 507, 508, 511
|
||||
];
|
||||
|
||||
if ($exception instanceof RequestException) {
|
||||
$code = $exception->getHttpCode();
|
||||
$reason = $exception->getHttpReason();
|
||||
} else {
|
||||
$code = $exception->getCode();
|
||||
$reason = null;
|
||||
}
|
||||
|
||||
if (!in_array($code, $validCodes, true)) {
|
||||
$code = 500;
|
||||
}
|
||||
|
||||
$message = $exception->getMessage();
|
||||
$response = [
|
||||
'code' => $code,
|
||||
'status' => 'error',
|
||||
'message' => htmlspecialchars($message, ENT_QUOTES | ENT_HTML5, 'UTF-8')
|
||||
];
|
||||
|
||||
$accept = $this->getAccept(['application/json', 'text/html']);
|
||||
|
||||
if ($accept === 'text/html') {
|
||||
$method = $this->getRequest()->getMethod();
|
||||
|
||||
// On POST etc, redirect back to the previous page.
|
||||
if ($method !== 'GET' && $method !== 'HEAD') {
|
||||
$this->setMessage($message, 'error');
|
||||
$referer = $this->request->getHeaderLine('Referer');
|
||||
return $this->createRedirectResponse($referer, 303);
|
||||
}
|
||||
|
||||
// TODO: improve error page
|
||||
return $this->createHtmlResponse($response['message']);
|
||||
}
|
||||
|
||||
return new Response($code, ['Content-Type' => 'application/json'], json_encode($response), '1.1', $reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a string.
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public function translate(string $string): string
|
||||
{
|
||||
/** @var Language $language */
|
||||
$language = $this->grav['language'];
|
||||
|
||||
return $language->translate($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set message to be shown in the admin.
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $type
|
||||
* @return $this
|
||||
*/
|
||||
public function setMessage($message, $type = 'info')
|
||||
{
|
||||
/** @var Message $messages */
|
||||
$messages = $this->grav['messages'];
|
||||
$messages->add($message, $type);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if request nonce is valid.
|
||||
*
|
||||
* @param string $task
|
||||
* @throws PageExpiredException If nonce is not valid.
|
||||
*/
|
||||
protected function checkNonce(string $task): void
|
||||
{
|
||||
$nonce = null;
|
||||
|
||||
if (\in_array(strtoupper($this->request->getMethod()), ['POST', 'PUT', 'PATCH', 'DELETE'])) {
|
||||
$nonce = $this->getPost($this->nonce_name);
|
||||
}
|
||||
|
||||
if (!$nonce) {
|
||||
$nonce = $this->grav['uri']->param($this->nonce_name);
|
||||
}
|
||||
|
||||
if (!$nonce) {
|
||||
$nonce = $this->grav['uri']->query($this->nonce_name);
|
||||
}
|
||||
|
||||
if (!$nonce || !Utils::verifyNonce($nonce, $this->nonce_action)) {
|
||||
throw new PageExpiredException($this->request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the best matching mime type for the request.
|
||||
*
|
||||
* @param string[] $compare
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getAccept(array $compare): ?string
|
||||
{
|
||||
$accepted = [];
|
||||
foreach ($this->request->getHeader('Accept') as $accept) {
|
||||
foreach (explode(',', $accept) as $item) {
|
||||
if (!$item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$split = explode(';q=', $item);
|
||||
$mime = array_shift($split);
|
||||
$priority = array_shift($split) ?? 1.0;
|
||||
|
||||
$accepted[$mime] = $priority;
|
||||
}
|
||||
}
|
||||
|
||||
arsort($accepted);
|
||||
|
||||
// TODO: add support for image/* etc
|
||||
$list = array_intersect($compare, array_keys($accepted));
|
||||
if (!$list && (isset($accepted['*/*']) || isset($accepted['*']))) {
|
||||
return reset($compare) ?: null;
|
||||
}
|
||||
|
||||
return reset($list) ?: null;
|
||||
}
|
||||
}
|
||||
@@ -1,359 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Plugin\Admin
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Grav\Plugin\Admin\Controllers;
|
||||
|
||||
use Grav\Common\Config\Config;
|
||||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Language\Language;
|
||||
use Grav\Common\Page\Interfaces\PageInterface;
|
||||
use Grav\Common\Page\Page;
|
||||
use Grav\Common\Page\Pages;
|
||||
use Grav\Common\Uri;
|
||||
use Grav\Common\User\Interfaces\UserInterface;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Framework\Controller\Traits\ControllerResponseTrait;
|
||||
use Grav\Framework\RequestHandler\Exception\PageExpiredException;
|
||||
use Grav\Framework\Session\SessionInterface;
|
||||
use Grav\Plugin\Admin\Admin;
|
||||
use Grav\Plugin\Admin\AdminForm;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use RocketTheme\Toolbox\Session\Message;
|
||||
|
||||
abstract class AdminController
|
||||
{
|
||||
use ControllerResponseTrait {
|
||||
createRedirectResponse as traitCreateRedirectResponse;
|
||||
getErrorJson as traitGetErrorJson;
|
||||
}
|
||||
|
||||
/** @var string */
|
||||
protected $nonce_action = 'admin-form';
|
||||
/** @var string */
|
||||
protected $nonce_name = 'admin-nonce';
|
||||
/** @var Grav */
|
||||
protected $grav;
|
||||
/** @var PageInterface */
|
||||
protected $page;
|
||||
/** @var AdminForm|null */
|
||||
protected $form;
|
||||
|
||||
public function __construct(Grav $grav)
|
||||
{
|
||||
$this->grav = $grav;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PageInterface|null
|
||||
*/
|
||||
public function getPage(): ?PageInterface
|
||||
{
|
||||
return $this->page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currently active form.
|
||||
*
|
||||
* @return AdminForm|null
|
||||
*/
|
||||
public function getActiveForm(): ?AdminForm
|
||||
{
|
||||
if (null === $this->form) {
|
||||
$post = $this->getPost();
|
||||
|
||||
$active = $post['__form-name__'] ?? null;
|
||||
|
||||
$this->form = $active ? $this->getForm($active) : null;
|
||||
}
|
||||
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a form.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $options
|
||||
* @return AdminForm|null
|
||||
*/
|
||||
public function getForm(string $name, array $options = []): ?AdminForm
|
||||
{
|
||||
$post = $this->getPost();
|
||||
$page = $this->getPage();
|
||||
$forms = $page ? $page->forms() : [];
|
||||
$blueprint = $forms[$name] ?? null;
|
||||
if (null === $blueprint) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$active = $post['__form-name__'] ?? null;
|
||||
$unique_id = $active && $active === $name ? ($post['__unique_form_id__'] ?? null) : null;
|
||||
|
||||
$options += [
|
||||
'unique_id' => $unique_id,
|
||||
'blueprint' => new Blueprint(null, ['form' => $blueprint]),
|
||||
'submit_method' => $this->getFormSubmitMethod($name),
|
||||
'nonce_name' => $this->nonce_name,
|
||||
'nonce_action' => $this->nonce_action,
|
||||
];
|
||||
|
||||
return new AdminForm($name, $options);
|
||||
}
|
||||
|
||||
abstract protected function getFormSubmitMethod(string $name): callable;
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param string|null $lang
|
||||
* @return string
|
||||
*/
|
||||
public function getAdminUrl(string $route, ?string $lang = null): string
|
||||
{
|
||||
/** @var Pages $pages */
|
||||
$pages = $this->grav['pages'];
|
||||
$admin = $this->getAdmin();
|
||||
|
||||
return $pages->baseUrl($lang) . $admin->base . $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param string|null $lang
|
||||
* @return string
|
||||
*/
|
||||
public function getAbsoluteAdminUrl(string $route, ?string $lang = null): string
|
||||
{
|
||||
/** @var Pages $pages */
|
||||
$pages = $this->grav['pages'];
|
||||
$admin = $this->getAdmin();
|
||||
|
||||
return $pages->baseUrl($lang, true) . $admin->base . $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session.
|
||||
*
|
||||
* @return SessionInterface
|
||||
*/
|
||||
public function getSession(): SessionInterface
|
||||
{
|
||||
return $this->grav['session'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Admin
|
||||
*/
|
||||
protected function getAdmin(): Admin
|
||||
{
|
||||
return $this->grav['admin'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UserInterface
|
||||
*/
|
||||
protected function getUser(): UserInterface
|
||||
{
|
||||
return $this->getAdmin()->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ServerRequestInterface
|
||||
*/
|
||||
public function getRequest(): ServerRequestInterface
|
||||
{
|
||||
return $this->getAdmin()->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getPost(): array
|
||||
{
|
||||
return (array)($this->getRequest()->getParsedBody() ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a string.
|
||||
*
|
||||
* @param string $string
|
||||
* @param mixed ...$args
|
||||
* @return string
|
||||
*/
|
||||
public function translate(string $string, ...$args): string
|
||||
{
|
||||
/** @var Language $language */
|
||||
$language = $this->grav['language'];
|
||||
|
||||
array_unshift($args, $string);
|
||||
|
||||
return $language->translate($args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set message to be shown in the admin.
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $type
|
||||
* @return $this
|
||||
*/
|
||||
public function setMessage(string $message, string $type = 'info'): AdminController
|
||||
{
|
||||
/** @var Message $messages */
|
||||
$messages = $this->grav['messages'];
|
||||
$messages->add($message, $type);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
protected function getConfig(): Config
|
||||
{
|
||||
return $this->grav['config'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if request nonce is valid.
|
||||
*
|
||||
* @return void
|
||||
* @throws PageExpiredException If nonce is not valid.
|
||||
*/
|
||||
protected function checkNonce(): void
|
||||
{
|
||||
$nonce = null;
|
||||
|
||||
$nonce_name = $this->form ? $this->form->getNonceName() : $this->nonce_name;
|
||||
$nonce_action = $this->form ? $this->form->getNonceAction() : $this->nonce_action;
|
||||
|
||||
if (\in_array(strtoupper($this->getRequest()->getMethod()), ['POST', 'PUT', 'PATCH', 'DELETE'])) {
|
||||
$post = $this->getPost();
|
||||
$nonce = $post[$nonce_name] ?? null;
|
||||
}
|
||||
|
||||
/** @var Uri $uri */
|
||||
$uri = $this->grav['uri'];
|
||||
if (!$nonce) {
|
||||
$nonce = $uri->param($nonce_name);
|
||||
}
|
||||
|
||||
if (!$nonce) {
|
||||
$nonce = $uri->query($nonce_name);
|
||||
}
|
||||
|
||||
if (!$nonce || !Utils::verifyNonce($nonce, $nonce_action)) {
|
||||
throw new PageExpiredException($this->getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the best matching mime type for the request.
|
||||
*
|
||||
* @param string[] $compare
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getAccept(array $compare): ?string
|
||||
{
|
||||
$accepted = [];
|
||||
foreach ($this->getRequest()->getHeader('Accept') as $accept) {
|
||||
foreach (explode(',', $accept) as $item) {
|
||||
if (!$item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$split = explode(';q=', $item);
|
||||
$mime = array_shift($split);
|
||||
$priority = array_shift($split) ?? 1.0;
|
||||
|
||||
$accepted[$mime] = $priority;
|
||||
}
|
||||
}
|
||||
|
||||
arsort($accepted);
|
||||
|
||||
// TODO: add support for image/* etc
|
||||
$list = array_intersect($compare, array_keys($accepted));
|
||||
if (!$list && (isset($accepted['*/*']) || isset($accepted['*']))) {
|
||||
return reset($compare) ?: null;
|
||||
}
|
||||
|
||||
return reset($list) ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $template
|
||||
* @return PageInterface
|
||||
*/
|
||||
protected function createPage(string $template): PageInterface
|
||||
{
|
||||
$page = new Page();
|
||||
|
||||
// Plugins may not have the correct Cache-Control header set, force no-store for the proxies.
|
||||
$page->expires(0);
|
||||
|
||||
$filename = "plugin://admin/pages/admin/{$template}.md";
|
||||
if (!file_exists($filename)) {
|
||||
throw new \RuntimeException(sprintf('Creating admin page %s failed: not found', $template));
|
||||
}
|
||||
|
||||
Admin::DEBUG && Admin::addDebugMessage("Admin page: {$template}");
|
||||
|
||||
$page->init(new \SplFileInfo($filename));
|
||||
$page->slug($template);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $url
|
||||
* @param int|null $code
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
protected function createRedirectResponse(?string $url = null, ?int $code = null): ResponseInterface
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
if (null === $url || '' === $url) {
|
||||
$url = (string)$request->getUri();
|
||||
} elseif (mb_strpos($url, '/') === 0) {
|
||||
$url = $this->getAbsoluteAdminUrl($url);
|
||||
}
|
||||
|
||||
if (null === $code) {
|
||||
if (in_array($request->getMethod(), ['GET', 'HEAD'])) {
|
||||
$code = 302;
|
||||
} else {
|
||||
$code = 303;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->traitCreateRedirectResponse($url, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable $e
|
||||
* @return array
|
||||
*/
|
||||
protected function getErrorJson(\Throwable $e): array
|
||||
{
|
||||
$json = $this->traitGetErrorJson($e);
|
||||
$code = $e->getCode();
|
||||
if ($code === 401) {
|
||||
$json['redirect'] = $this->getAbsoluteAdminUrl('/');
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,673 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Plugin\Admin
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Plugin\Admin\Controllers\Login;
|
||||
|
||||
use Grav\Common\Debugger;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Page\Pages;
|
||||
use Grav\Common\Uri;
|
||||
use Grav\Common\User\Interfaces\UserCollectionInterface;
|
||||
use Grav\Common\User\Interfaces\UserInterface;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Framework\RequestHandler\Exception\PageExpiredException;
|
||||
use Grav\Framework\RequestHandler\Exception\RequestException;
|
||||
use Grav\Plugin\Admin\Admin;
|
||||
use Grav\Plugin\Admin\Controllers\AdminController;
|
||||
use Grav\Plugin\Email\Email;
|
||||
use Grav\Plugin\Login\Login;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use RobThree\Auth\TwoFactorAuthException;
|
||||
|
||||
/**
|
||||
* Class LoginController
|
||||
* @package Grav\Plugin\Admin\Controllers\Login
|
||||
*/
|
||||
class LoginController extends AdminController
|
||||
{
|
||||
/** @var string */
|
||||
protected $nonce_action = 'admin-login';
|
||||
/** @var string */
|
||||
protected $nonce_name = 'login-nonce';
|
||||
|
||||
/**
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function displayLogin(): ResponseInterface
|
||||
{
|
||||
$this->page = $this->createPage('login');
|
||||
|
||||
$user = $this->getUser();
|
||||
if ($this->is2FA($user)) {
|
||||
$this->form = $this->getForm('login-twofa', ['reset' => true]);
|
||||
} else {
|
||||
$this->form = $this->getForm('login', ['reset' => true]);
|
||||
}
|
||||
|
||||
return $this->createDisplayResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function displayForgot(): ResponseInterface
|
||||
{
|
||||
$this->page = $this->createPage('forgot');
|
||||
$this->form = $this->getForm('admin-login-forgot', ['reset' => true]);
|
||||
|
||||
return $this->createDisplayResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the reset password action.
|
||||
*
|
||||
* @param string|null $username
|
||||
* @param string|null $token
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function displayReset(?string $username = null, ?string $token = null): ResponseInterface
|
||||
{
|
||||
if ('' === (string)$username || '' === (string)$token) {
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.RESET_INVALID_LINK'), 'error');
|
||||
|
||||
return $this->createRedirectResponse('/forgot');
|
||||
}
|
||||
|
||||
$this->page = $this->createPage('reset');
|
||||
$this->form = $this->getForm('admin-login-reset', ['reset' => true]);
|
||||
$this->form->setData('username', $username);
|
||||
$this->form->setData('token', $token);
|
||||
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.RESET_NEW_PASSWORD'));
|
||||
|
||||
return $this->createDisplayResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function displayRegister(): ResponseInterface
|
||||
{
|
||||
$route = $this->getRequest()->getAttribute('admin')['route'] ?? '';
|
||||
if ('' !== $route) {
|
||||
return $this->createRedirectResponse('/');
|
||||
}
|
||||
|
||||
$this->page = $this->createPage('register');
|
||||
$this->form = $this->getForm('admin-login-register');
|
||||
|
||||
return $this->createDisplayResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function displayUnauthorized(): ResponseInterface
|
||||
{
|
||||
$uri = (string)$this->getRequest()->getUri();
|
||||
|
||||
$ext = Utils::pathinfo($uri, PATHINFO_EXTENSION);
|
||||
$accept = $this->getAccept(['application/json', 'text/html']);
|
||||
if ($ext === 'json' || $accept === 'application/json') {
|
||||
return $this->createErrorResponse(new RequestException($this->getRequest(), $this->translate('PLUGIN_ADMIN.LOGGED_OUT'), 401));
|
||||
}
|
||||
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.LOGGED_OUT'), 'warning');
|
||||
|
||||
return $this->createRedirectResponse('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle login.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function taskLogin(): ResponseInterface
|
||||
{
|
||||
$this->page = $this->createPage('login');
|
||||
$this->form = $this->getActiveForm() ?? $this->getForm('login');
|
||||
try {
|
||||
$this->checkNonce();
|
||||
} catch (PageExpiredException $e) {
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'), 'error');
|
||||
|
||||
return $this->createDisplayResponse();
|
||||
}
|
||||
|
||||
$post = $this->getPost();
|
||||
$credentials = (array)($post['data'] ?? []);
|
||||
$login = $this->getLogin();
|
||||
$config = $this->getConfig();
|
||||
|
||||
$userKey = (string)($credentials['username'] ?? '');
|
||||
// Pseudonymization of the IP.
|
||||
$ipKey = sha1(Uri::ip() . $config->get('security.salt'));
|
||||
|
||||
$rateLimiter = $login->getRateLimiter('login_attempts');
|
||||
|
||||
// Check if the current IP has been used in failed login attempts.
|
||||
$attempts = count($rateLimiter->getAttempts($ipKey, 'ip'));
|
||||
|
||||
$rateLimiter->registerRateLimitedAction($ipKey, 'ip')->registerRateLimitedAction($userKey);
|
||||
|
||||
// Check rate limit for both IP and user, but allow each IP a single try even if user is already rate limited.
|
||||
if ($rateLimiter->isRateLimited($ipKey, 'ip') || ($attempts && $rateLimiter->isRateLimited($userKey))) {
|
||||
Admin::DEBUG && Admin::addDebugMessage('Admin login: rate limit, redirecting', $credentials);
|
||||
|
||||
$this->setMessage($this->translate('PLUGIN_LOGIN.TOO_MANY_LOGIN_ATTEMPTS', $rateLimiter->getInterval()), 'error');
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
/** @var Pages $pages */
|
||||
$pages = $this->grav['pages'];
|
||||
|
||||
// Redirect to the home page of the site.
|
||||
return $this->createRedirectResponse($pages->homeUrl(null, true));
|
||||
}
|
||||
|
||||
Admin::DEBUG && Admin::addDebugMessage('Admin login', $credentials);
|
||||
|
||||
// Fire Login process.
|
||||
$event = $login->login(
|
||||
$credentials,
|
||||
['admin' => true, 'twofa' => $config->get('plugins.admin.twofa_enabled', false)],
|
||||
['authorize' => 'admin.login', 'return_event' => true]
|
||||
);
|
||||
$user = $event->getUser();
|
||||
|
||||
Admin::DEBUG && Admin::addDebugMessage('Admin login: user', $user);
|
||||
|
||||
$redirect = (string)$this->getRequest()->getUri();
|
||||
|
||||
if ($user->authenticated) {
|
||||
$rateLimiter->resetRateLimit($ipKey, 'ip')->resetRateLimit($userKey);
|
||||
if ($user->authorized) {
|
||||
$event->defMessage('PLUGIN_ADMIN.LOGIN_LOGGED_IN', 'info');
|
||||
}
|
||||
|
||||
$event->defRedirect($redirect);
|
||||
} elseif ($user->authorized) {
|
||||
$event->defMessage('PLUGIN_LOGIN.ACCESS_DENIED', 'error');
|
||||
} else {
|
||||
$event->defMessage('PLUGIN_LOGIN.LOGIN_FAILED', 'error');
|
||||
}
|
||||
|
||||
$event->defRedirect($redirect);
|
||||
|
||||
$message = $event->getMessage();
|
||||
if ($message) {
|
||||
$this->setMessage($this->translate($message), $event->getMessageType());
|
||||
}
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
return $this->createRedirectResponse($event->getRedirect());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle logout when user isn't fully logged in or clicks logout after the session has been expired.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function taskLogout(): ResponseInterface
|
||||
{
|
||||
// We do not need to check the nonce here as user session has been expired or user hasn't fully logged in (2FA).
|
||||
// Just be sure we terminate the current session.
|
||||
$login = $this->getLogin();
|
||||
$event = $login->logout(['admin' => true], ['return_event' => true]);
|
||||
|
||||
$event->defMessage('PLUGIN_ADMIN.LOGGED_OUT', 'info');
|
||||
$message = $event->getMessage();
|
||||
if ($message) {
|
||||
$this->getSession()->setFlashCookieObject(Admin::TMP_COOKIE_NAME, ['message' => $this->translate($message), 'status' => $event->getMessageType()]);
|
||||
}
|
||||
|
||||
return $this->createRedirectResponse('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a fresh login nonce and keep anonymous session alive while on the login screen.
|
||||
*
|
||||
* Route: GET /login.json/task:nonce
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function taskNonce(): ResponseInterface
|
||||
{
|
||||
// Touch the anonymous session to prevent immediate expiry on the login page.
|
||||
$session = $this->getSession();
|
||||
if (!$session->isStarted()) {
|
||||
$session->start();
|
||||
}
|
||||
$session->__set('admin_login_keepalive', time());
|
||||
|
||||
// Generate a fresh nonce for the login form.
|
||||
$nonce = Admin::getNonce($this->nonce_action);
|
||||
|
||||
return $this->createJsonResponse([
|
||||
'status' => 'success',
|
||||
'message' => null,
|
||||
'nonce_name' => $this->nonce_name,
|
||||
'nonce_action' => $this->nonce_action,
|
||||
'nonce' => $nonce
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle 2FA verification.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function taskTwofa(): ResponseInterface
|
||||
{
|
||||
$user = $this->getUser();
|
||||
if (!$this->is2FA($user)) {
|
||||
Admin::DEBUG && Admin::addDebugMessage('Admin login: user is not logged in or does not have 2FA enabled', $user);
|
||||
|
||||
// Task is visible only for users who have enabled 2FA.
|
||||
return $this->createRedirectResponse('/');
|
||||
}
|
||||
|
||||
$login = $this->getLogin();
|
||||
|
||||
$this->page = $this->createPage('login');
|
||||
$this->form = $this->getForm('login-twofa');
|
||||
try {
|
||||
$this->checkNonce();
|
||||
} catch (PageExpiredException $e) {
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'), 'error');
|
||||
|
||||
// Failed 2FA nonce check, logout and redirect.
|
||||
$login->logout(['admin' => true]);
|
||||
$this->form->reset();
|
||||
|
||||
return $this->createRedirectResponse('/');
|
||||
}
|
||||
|
||||
|
||||
$post = $this->getPost();
|
||||
$data = $post['data'] ?? [];
|
||||
|
||||
try {
|
||||
$twoFa = $login->twoFactorAuth();
|
||||
} catch (TwoFactorAuthException $e) {
|
||||
/** @var Debugger $debugger */
|
||||
$debugger = $this->grav['debugger'];
|
||||
$debugger->addException($e);
|
||||
|
||||
$twoFa = null;
|
||||
}
|
||||
|
||||
$code = $data['2fa_code'] ?? '';
|
||||
$secret = $user->twofa_secret ?? '';
|
||||
// Strip any whitespace from secret (fixes corrupted secrets)
|
||||
$secret = preg_replace('/\s+/', '', $secret);
|
||||
$twofa_valid = $twoFa->verifyCode($secret, $code);
|
||||
|
||||
$yubikey_otp = $data['yubikey_otp'] ?? '';
|
||||
$yubikey_id = $user->yubikey_id ?? '';
|
||||
$yubikey_valid = $twoFa->verifyYubikeyOTP($yubikey_id, $yubikey_otp);
|
||||
|
||||
$redirect = (string)$this->getRequest()->getUri();
|
||||
|
||||
if (null === $twoFa || !$user->authenticated || (!$twofa_valid && !$yubikey_valid) ) {
|
||||
Admin::DEBUG && Admin::addDebugMessage('Admin login: 2FA check failed, log out!');
|
||||
|
||||
// Failed 2FA auth, logout and redirect to the current page.
|
||||
$login->logout(['admin' => true]);
|
||||
|
||||
$this->grav['session']->setFlashCookieObject(Admin::TMP_COOKIE_NAME, ['message' => $this->translate('PLUGIN_ADMIN.2FA_FAILED'), 'status' => 'error']);
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
return $this->createRedirectResponse($redirect);
|
||||
}
|
||||
|
||||
// Successful 2FA, authorize user and redirect.
|
||||
Grav::instance()['user']->authorized = true;
|
||||
|
||||
Admin::DEBUG && Admin::addDebugMessage('Admin login: 2FA check succeeded, authorize user and redirect');
|
||||
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.LOGIN_LOGGED_IN'));
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
return $this->createRedirectResponse($redirect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the reset password action.
|
||||
*
|
||||
* @param string|null $username
|
||||
* @param string|null $token
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function taskReset(?string $username = null, ?string $token = null): ResponseInterface
|
||||
{
|
||||
$this->page = $this->createPage('reset');
|
||||
$this->form = $this->getForm('admin-login-reset');
|
||||
try {
|
||||
$this->checkNonce();
|
||||
} catch (PageExpiredException $e) {
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'), 'error');
|
||||
|
||||
return $this->createDisplayResponse();
|
||||
}
|
||||
|
||||
|
||||
$post = $this->getPost();
|
||||
$data = $post['data'] ?? [];
|
||||
$users = $this->getAccounts();
|
||||
|
||||
$username = $username ?? $data['username'] ?? null;
|
||||
$token = $token ?? $data['token'] ?? null;
|
||||
|
||||
$user = $username ? $users->load($username) : null;
|
||||
$password = $data['password'];
|
||||
|
||||
if ($user && $user->exists() && !empty($user->get('reset'))) {
|
||||
[$good_token, $expire] = explode('::', $user->get('reset'));
|
||||
|
||||
if ($good_token === $token) {
|
||||
if (time() > $expire) {
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.RESET_LINK_EXPIRED'), 'error');
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
return $this->createRedirectResponse('/forgot');
|
||||
}
|
||||
|
||||
// Set new password.
|
||||
$login = $this->getLogin();
|
||||
try {
|
||||
$login->validateField('password1', $password);
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->setMessage($this->translate($e->getMessage()), 'error');
|
||||
|
||||
return $this->createRedirectResponse("/reset/u/{$username}/{$token}");
|
||||
}
|
||||
|
||||
$user->undef('hashed_password');
|
||||
$user->undef('reset');
|
||||
$user->update(['password' => $password]);
|
||||
$user->save();
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.RESET_PASSWORD_RESET'));
|
||||
|
||||
return $this->createRedirectResponse('/login');
|
||||
}
|
||||
|
||||
Admin::DEBUG && Admin::addDebugMessage(sprintf('Failed to reset password: Token %s is not good', $token));
|
||||
} else {
|
||||
Admin::DEBUG && Admin::addDebugMessage(sprintf('Failed to reset password: User %s does not exist or has not requested reset', $username));
|
||||
}
|
||||
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.RESET_INVALID_LINK'), 'error');
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
return $this->createRedirectResponse('/forgot');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the email password recovery procedure.
|
||||
*
|
||||
* Sends email to the user.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function taskForgot(): ResponseInterface
|
||||
{
|
||||
$this->page = $this->createPage('forgot');
|
||||
$this->form = $this->getForm('admin-login-forgot');
|
||||
try {
|
||||
$this->checkNonce();
|
||||
} catch (PageExpiredException $e) {
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'), 'error');
|
||||
|
||||
return $this->createDisplayResponse();
|
||||
}
|
||||
|
||||
|
||||
$post = $this->getPost();
|
||||
$data = $post['data'] ?? [];
|
||||
$login = $this->getLogin();
|
||||
$users = $this->getAccounts();
|
||||
$email = $this->getEmail();
|
||||
|
||||
$current = (string)$this->getRequest()->getUri();
|
||||
|
||||
$search = isset($data['username']) ? strip_tags($data['username']) : '';
|
||||
$user = !empty($search) ? $users->load($search) : null;
|
||||
$username = $user->username ?? null;
|
||||
$to = $user->email ?? null;
|
||||
|
||||
// Only send email to users which are enabled and have an email address.
|
||||
if (null === $user || $user->state !== 'enabled' || !$to) {
|
||||
Admin::DEBUG && Admin::addDebugMessage(sprintf('Failed sending email: %s <%s> was not found or is blocked', $search, $to ?? 'N/A'));
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL'));
|
||||
|
||||
return $this->createRedirectResponse($current);
|
||||
}
|
||||
|
||||
$config = $this->getConfig();
|
||||
|
||||
// Check rate limit for the user.
|
||||
$rateLimiter = $login->getRateLimiter('pw_resets');
|
||||
$rateLimiter->registerRateLimitedAction($username);
|
||||
if ($rateLimiter->isRateLimited($username)) {
|
||||
Admin::DEBUG && Admin::addDebugMessage(sprintf('Failed sending email: user %s <%s> is rate limited', $search, $to));
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
$interval = $config->get('plugins.login.max_pw_resets_interval', 2);
|
||||
|
||||
// Security: Use generic message to prevent email enumeration (GHSA-q3qx-cp62-f6m7)
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.FORGOT_CANNOT_RESET_RATE_LIMITED', $interval), 'error');
|
||||
|
||||
return $this->createRedirectResponse($current);
|
||||
}
|
||||
|
||||
$token = md5(uniqid(mt_rand(), true));
|
||||
$expire = time() + 3600; // 1 hour
|
||||
|
||||
$user->set('reset', $token . '::' . $expire);
|
||||
$user->save();
|
||||
|
||||
$from = $config->get('plugins.email.from');
|
||||
if (empty($from)) {
|
||||
Admin::DEBUG && Admin::addDebugMessage('Failed sending email: from address is not configured in email plugin');
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.FORGOT_EMAIL_NOT_CONFIGURED'), 'error');
|
||||
|
||||
return $this->createRedirectResponse($current);
|
||||
}
|
||||
|
||||
// Do not trust username from the request.
|
||||
$fullname = $user->fullname ?: $username;
|
||||
$author = $config->get('site.author.name', '');
|
||||
$sitename = $config->get('site.title', 'Website');
|
||||
$reset_route = "/reset/u/{$username}/{$token}";
|
||||
|
||||
$site_host = $config->get('plugins.login.site_host');
|
||||
if (!empty($site_host)) {
|
||||
$admin = $this->getAdmin();
|
||||
$reset_link = rtrim($site_host, '/') . '/' . trim($admin->base, '/') . '/' . ltrim($reset_route, '/');
|
||||
} else {
|
||||
$reset_link = $this->getAbsoluteAdminUrl($reset_route);
|
||||
}
|
||||
|
||||
// For testing only!
|
||||
//Admin::DEBUG && Admin::addDebugMessage(sprintf('Reset link: %s', $reset_link));
|
||||
|
||||
$subject = $this->translate('PLUGIN_ADMIN.FORGOT_EMAIL_SUBJECT', $sitename);
|
||||
$content = $this->translate('PLUGIN_ADMIN.FORGOT_EMAIL_BODY', $fullname, $reset_link, $author, $sitename);
|
||||
|
||||
$this->grav['twig']->init();
|
||||
$body = $this->grav['twig']->processTemplate('email/base.html.twig', ['content' => $content]);
|
||||
|
||||
try {
|
||||
$message = $email->message($subject, $body, 'text/html')->setFrom($from)->setTo($to);
|
||||
$sent = $email->send($message);
|
||||
if ($sent < 1) {
|
||||
throw new \RuntimeException('Sending email failed');
|
||||
}
|
||||
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL'));
|
||||
} catch (\Exception $e) {
|
||||
$rateLimiter->resetRateLimit($username);
|
||||
|
||||
/** @var Debugger $debugger */
|
||||
$debugger = $this->grav['debugger'];
|
||||
$debugger->addException($e);
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.FORGOT_FAILED_TO_EMAIL'), 'error');
|
||||
|
||||
return $this->createRedirectResponse('/forgot');
|
||||
}
|
||||
|
||||
$this->form->reset();
|
||||
|
||||
return $this->createRedirectResponse('/login');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function taskRegister(): ResponseInterface
|
||||
{
|
||||
$this->page = $this->createPage('register');
|
||||
$this->form = $form = $this->getForm('admin-login-register');
|
||||
try {
|
||||
$this->checkNonce();
|
||||
} catch (PageExpiredException $e) {
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'), 'error');
|
||||
|
||||
return $this->createDisplayResponse();
|
||||
}
|
||||
|
||||
// Note: Calls $this->doRegistration() to perform the user registration.
|
||||
$form->handleRequest($this->getRequest());
|
||||
$error = $form->getError();
|
||||
$errors = $form->getErrors();
|
||||
if ($error || $errors) {
|
||||
foreach ($errors as $field => $list) {
|
||||
foreach ((array)$list as $message) {
|
||||
if ($message !== $error) {
|
||||
$this->setMessage($message, 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->createDisplayResponse();
|
||||
}
|
||||
|
||||
$this->setMessage($this->translate('PLUGIN_ADMIN.LOGIN_LOGGED_IN'));
|
||||
|
||||
return $this->createRedirectResponse('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserInterface $user
|
||||
* @return bool
|
||||
*/
|
||||
protected function is2FA(UserInterface $user): bool
|
||||
{
|
||||
return $user && $user->authenticated && !$user->authorized && $user->get('twofa_enabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return callable
|
||||
*/
|
||||
protected function getFormSubmitMethod(string $name): callable
|
||||
{
|
||||
switch ($name) {
|
||||
case 'login':
|
||||
case 'login-twofa':
|
||||
case 'admin-login-forgot':
|
||||
case 'admin-login-reset':
|
||||
return static function(array $data, array $files) {};
|
||||
case 'admin-login-register':
|
||||
return function(array $data, array $files) {
|
||||
$this->doRegistration($data, $files);
|
||||
};
|
||||
}
|
||||
|
||||
throw new \RuntimeException('Unknown form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by registration form when calling handleRequest().
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $files
|
||||
*/
|
||||
private function doRegistration(array $data, array $files): void
|
||||
{
|
||||
if (Admin::doAnyUsersExist()) {
|
||||
throw new \RuntimeException('A user account already exists, please create an admin account manually.', 400);
|
||||
}
|
||||
|
||||
$login = $this->getLogin();
|
||||
if (!$login) {
|
||||
throw new \RuntimeException($this->grav['language']->translate('PLUGIN_LOGIN.PLUGIN_LOGIN_DISABLED', 500));
|
||||
}
|
||||
|
||||
$data['title'] = $data['title'] ?? 'Administrator';
|
||||
|
||||
// Do not allow form to set the following fields (make super user):
|
||||
$data['state'] = 'enabled';
|
||||
$data['access'] = ['admin' => ['login' => true, 'super' => true], 'site' => ['login' => true]];
|
||||
unset($data['groups']);
|
||||
|
||||
// Create user.
|
||||
$user = $login->register($data, $files);
|
||||
|
||||
// Log in the new super admin user.
|
||||
unset($this->grav['user']);
|
||||
$this->grav['user'] = $user;
|
||||
$this->grav['session']->user = $user;
|
||||
$user->authenticated = true;
|
||||
$user->authorized = $user->authorize('admin.login') ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Login
|
||||
*/
|
||||
private function getLogin(): Login
|
||||
{
|
||||
return $this->grav['login'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Email
|
||||
*/
|
||||
private function getEmail(): Email
|
||||
{
|
||||
return $this->grav['Email'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UserCollectionInterface
|
||||
*/
|
||||
private function getAccounts(): UserCollectionInterface
|
||||
{
|
||||
return $this->grav['accounts'];
|
||||
}
|
||||
}
|
||||
@@ -1,442 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Plugin\Admin
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Plugin\Admin;
|
||||
|
||||
use Grav\Common\Cache;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\GPM\GPM as GravGPM;
|
||||
use Grav\Common\GPM\Licenses;
|
||||
use Grav\Common\GPM\Installer;
|
||||
use Grav\Common\GPM\Upgrader;
|
||||
use Grav\Common\HTTP\Response;
|
||||
use Grav\Common\Filesystem\Folder;
|
||||
use Grav\Common\GPM\Common\Package;
|
||||
|
||||
/**
|
||||
* Class Gpm
|
||||
*
|
||||
* @package Grav\Plugin\Admin
|
||||
*/
|
||||
class Gpm
|
||||
{
|
||||
// Probably should move this to Grav DI container?
|
||||
/** @var GravGPM */
|
||||
protected static $GPM;
|
||||
|
||||
public static function GPM()
|
||||
{
|
||||
if (!static::$GPM) {
|
||||
static::$GPM = new GravGPM();
|
||||
}
|
||||
|
||||
return static::$GPM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default options for the install
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $options = [
|
||||
'destination' => GRAV_ROOT,
|
||||
'overwrite' => true,
|
||||
'ignore_symlinks' => true,
|
||||
'skip_invalid' => true,
|
||||
'install_deps' => true,
|
||||
'theme' => false
|
||||
];
|
||||
|
||||
/**
|
||||
* @param Package[]|string[]|string $packages
|
||||
* @param array $options
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function install($packages, array $options)
|
||||
{
|
||||
$options = array_merge(self::$options, $options);
|
||||
|
||||
if (!Installer::isGravInstance($options['destination']) || !Installer::isValidDestination($options['destination'],
|
||||
[Installer::EXISTS, Installer::IS_LINK])
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$packages = is_array($packages) ? $packages : [$packages];
|
||||
$count = count($packages);
|
||||
|
||||
$packages = array_filter(array_map(function ($p) {
|
||||
return !is_string($p) ? $p instanceof Package ? $p : false : self::GPM()->findPackage($p);
|
||||
}, $packages));
|
||||
|
||||
if (!$options['skip_invalid'] && $count !== count($packages)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$messages = '';
|
||||
|
||||
foreach ($packages as $package) {
|
||||
if (isset($package->dependencies) && $options['install_deps']) {
|
||||
$result = static::install($package->dependencies, $options);
|
||||
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check destination
|
||||
Installer::isValidDestination($options['destination'] . DS . $package->install_path);
|
||||
|
||||
if (!$options['overwrite'] && Installer::lastErrorCode() === Installer::EXISTS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$options['ignore_symlinks'] && Installer::lastErrorCode() === Installer::IS_LINK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$license = Licenses::get($package->slug);
|
||||
$local = static::download($package, $license);
|
||||
|
||||
Installer::install($local, $options['destination'],
|
||||
['install_path' => $package->install_path, 'theme' => $options['theme']]);
|
||||
Folder::delete(dirname($local));
|
||||
|
||||
$errorCode = Installer::lastErrorCode();
|
||||
if ($errorCode) {
|
||||
$msg = Installer::lastErrorMsg();
|
||||
throw new \RuntimeException($msg);
|
||||
}
|
||||
|
||||
if (count($packages) === 1) {
|
||||
$message = Installer::getMessage();
|
||||
if ($message) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
$messages .= $message;
|
||||
}
|
||||
}
|
||||
|
||||
Cache::clearCache();
|
||||
|
||||
return $messages ?: true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Package[]|string[]|string $packages
|
||||
* @param array $options
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function update($packages, array $options)
|
||||
{
|
||||
$options['overwrite'] = true;
|
||||
|
||||
return static::install($packages, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Package[]|string[]|string $packages
|
||||
* @param array $options
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function uninstall($packages, array $options)
|
||||
{
|
||||
$options = array_merge(self::$options, $options);
|
||||
|
||||
$packages = (array)$packages;
|
||||
$count = count($packages);
|
||||
|
||||
$packages = array_filter(array_map(function ($p) {
|
||||
|
||||
if (is_string($p)) {
|
||||
$p = strtolower($p);
|
||||
$plugin = static::GPM()->getInstalledPlugin($p);
|
||||
$p = $plugin ?: static::GPM()->getInstalledTheme($p);
|
||||
}
|
||||
|
||||
return $p instanceof Package ? $p : false;
|
||||
|
||||
}, $packages));
|
||||
|
||||
if (!$options['skip_invalid'] && $count !== count($packages)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($packages as $package) {
|
||||
|
||||
$location = Grav::instance()['locator']->findResource($package->package_type . '://' . $package->slug);
|
||||
|
||||
// Check destination
|
||||
Installer::isValidDestination($location);
|
||||
|
||||
if (!$options['ignore_symlinks'] && Installer::lastErrorCode() === Installer::IS_LINK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Installer::uninstall($location);
|
||||
|
||||
$errorCode = Installer::lastErrorCode();
|
||||
if ($errorCode && $errorCode !== Installer::IS_LINK && $errorCode !== Installer::EXISTS) {
|
||||
$msg = Installer::lastErrorMsg();
|
||||
throw new \RuntimeException($msg);
|
||||
}
|
||||
|
||||
if (count($packages) === 1) {
|
||||
$message = Installer::getMessage();
|
||||
if ($message) {
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Cache::clearCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Direct install a file
|
||||
*
|
||||
* @param string $package_file
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function directInstall($package_file)
|
||||
{
|
||||
if (!$package_file) {
|
||||
return Admin::translate('PLUGIN_ADMIN.NO_PACKAGE_NAME');
|
||||
}
|
||||
|
||||
$tmp_dir = Grav::instance()['locator']->findResource('tmp://', true, true);
|
||||
$tmp_zip = $tmp_dir . '/Grav-' . uniqid('', false);
|
||||
|
||||
if (Response::isRemote($package_file)) {
|
||||
$zip = GravGPM::downloadPackage($package_file, $tmp_zip);
|
||||
} else {
|
||||
$zip = GravGPM::copyPackage($package_file, $tmp_zip);
|
||||
}
|
||||
|
||||
if (file_exists($zip)) {
|
||||
$tmp_source = $tmp_dir . '/Grav-' . uniqid('', false);
|
||||
$extracted = Installer::unZip($zip, $tmp_source);
|
||||
|
||||
if (!$extracted) {
|
||||
Folder::delete($tmp_source);
|
||||
Folder::delete($tmp_zip);
|
||||
return Admin::translate('PLUGIN_ADMIN.PACKAGE_EXTRACTION_FAILED');
|
||||
}
|
||||
|
||||
$type = GravGPM::getPackageType($extracted);
|
||||
|
||||
if (!$type) {
|
||||
Folder::delete($tmp_source);
|
||||
Folder::delete($tmp_zip);
|
||||
return Admin::translate('PLUGIN_ADMIN.NOT_VALID_GRAV_PACKAGE');
|
||||
}
|
||||
|
||||
if ($type === 'grav') {
|
||||
Installer::isValidDestination(GRAV_ROOT . '/system');
|
||||
if (Installer::IS_LINK === Installer::lastErrorCode()) {
|
||||
Folder::delete($tmp_source);
|
||||
Folder::delete($tmp_zip);
|
||||
return Admin::translate('PLUGIN_ADMIN.CANNOT_OVERWRITE_SYMLINKS');
|
||||
}
|
||||
|
||||
static::upgradeGrav($zip, $extracted);
|
||||
} else {
|
||||
$name = GravGPM::getPackageName($extracted);
|
||||
|
||||
if (!$name) {
|
||||
Folder::delete($tmp_source);
|
||||
Folder::delete($tmp_zip);
|
||||
return Admin::translate('PLUGIN_ADMIN.NAME_COULD_NOT_BE_DETERMINED');
|
||||
}
|
||||
|
||||
$install_path = GravGPM::getInstallPath($type, $name);
|
||||
$is_update = file_exists($install_path);
|
||||
|
||||
Installer::isValidDestination(GRAV_ROOT . DS . $install_path);
|
||||
if (Installer::lastErrorCode() === Installer::IS_LINK) {
|
||||
Folder::delete($tmp_source);
|
||||
Folder::delete($tmp_zip);
|
||||
return Admin::translate('PLUGIN_ADMIN.CANNOT_OVERWRITE_SYMLINKS');
|
||||
}
|
||||
|
||||
Installer::install($zip, GRAV_ROOT,
|
||||
['install_path' => $install_path, 'theme' => $type === 'theme', 'is_update' => $is_update],
|
||||
$extracted);
|
||||
}
|
||||
|
||||
Folder::delete($tmp_source);
|
||||
|
||||
if (Installer::lastErrorCode()) {
|
||||
return Installer::lastErrorMsg();
|
||||
}
|
||||
|
||||
} else {
|
||||
return Admin::translate('PLUGIN_ADMIN.ZIP_PACKAGE_NOT_FOUND');
|
||||
}
|
||||
|
||||
Folder::delete($tmp_zip);
|
||||
Cache::clearCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Package $package
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function download(Package $package, $license = null)
|
||||
{
|
||||
$query = '';
|
||||
|
||||
if ($package->premium) {
|
||||
$query = \json_encode(array_merge($package->premium, [
|
||||
'slug' => $package->slug,
|
||||
'license_key' => $license,
|
||||
'sid' => md5(GRAV_ROOT)
|
||||
]));
|
||||
|
||||
$query = '?d=' . base64_encode($query);
|
||||
}
|
||||
|
||||
try {
|
||||
$contents = Response::get($package->zipball_url . $query, []);
|
||||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException($e->getMessage());
|
||||
}
|
||||
|
||||
$tmp_dir = Admin::getTempDir() . '/Grav-' . uniqid('', false);
|
||||
Folder::mkdir($tmp_dir);
|
||||
|
||||
$bad_chars = array_merge(array_map('chr', range(0, 31)), ['<', '>', ':', '"', '/', '\\', '|', '?', '*']);
|
||||
|
||||
$filename = $package->slug . str_replace($bad_chars, '', \Grav\Common\Utils::basename($package->zipball_url));
|
||||
$filename = preg_replace('/[\\\\\/:"*?&<>|]+/m', '-', $filename);
|
||||
|
||||
file_put_contents($tmp_dir . DS . $filename . '.zip', $contents);
|
||||
|
||||
return $tmp_dir . DS . $filename . '.zip';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $package
|
||||
* @param string $tmp
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function _downloadSelfupgrade(array $package, $tmp)
|
||||
{
|
||||
$output = Response::get($package['download'], []);
|
||||
Folder::mkdir($tmp);
|
||||
file_put_contents($tmp . DS . $package['name'], $output);
|
||||
|
||||
return $tmp . DS . $package['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function selfupgrade()
|
||||
{
|
||||
$upgrader = new Upgrader();
|
||||
|
||||
if (!Installer::isGravInstance(GRAV_ROOT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_link(GRAV_ROOT . DS . 'index.php')) {
|
||||
Installer::setError(Installer::IS_LINK);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (method_exists($upgrader, 'meetsRequirements') &&
|
||||
method_exists($upgrader, 'minPHPVersion') &&
|
||||
!$upgrader->meetsRequirements()) {
|
||||
$error = [];
|
||||
$error[] = '<p>Grav has increased the minimum PHP requirement.<br />';
|
||||
$error[] = 'You are currently running PHP <strong>' . phpversion() . '</strong>';
|
||||
$error[] = ', but PHP <strong>' . $upgrader->minPHPVersion() . '</strong> is required.</p>';
|
||||
$error[] = '<p><a href="https://getgrav.org/blog/changing-php-requirements-to-5.5" class="button button-small secondary">Additional information</a></p>';
|
||||
|
||||
Installer::setError(implode("\n", $error));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$update = $upgrader->getAssets()['grav-update'];
|
||||
$tmp = Admin::getTempDir() . '/Grav-' . uniqid('', false);
|
||||
if ($tmp) {
|
||||
$file = self::_downloadSelfupgrade($update, $tmp);
|
||||
$folder = Installer::unZip($file, $tmp . '/zip');
|
||||
$keepFolder = false;
|
||||
} else {
|
||||
// If you make $tmp empty, you can install your local copy of Grav (for testing purposes only).
|
||||
$file = 'grav.zip';
|
||||
$folder = '~/phpstorm/grav-clones/grav';
|
||||
//$folder = '/home/matias/phpstorm/rockettheme/grav-devtools/grav-clones/grav';
|
||||
$keepFolder = true;
|
||||
}
|
||||
|
||||
static::upgradeGrav($file, $folder, $keepFolder);
|
||||
|
||||
$errorCode = Installer::lastErrorCode();
|
||||
|
||||
if ($tmp) {
|
||||
Folder::delete($tmp);
|
||||
}
|
||||
|
||||
return !(is_string($errorCode) || ($errorCode & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)));
|
||||
}
|
||||
|
||||
private static function upgradeGrav($zip, $folder, $keepFolder = false)
|
||||
{
|
||||
static $ignores = [
|
||||
'backup',
|
||||
'cache',
|
||||
'images',
|
||||
'logs',
|
||||
'tmp',
|
||||
'user',
|
||||
'.htaccess',
|
||||
'robots.txt'
|
||||
];
|
||||
|
||||
if (!is_dir($folder)) {
|
||||
Installer::setError('Invalid source folder');
|
||||
}
|
||||
|
||||
try {
|
||||
$script = $folder . '/system/install.php';
|
||||
/** Install $installer */
|
||||
if ((file_exists($script) && $install = include $script) && is_callable($install)) {
|
||||
$install($zip);
|
||||
} else {
|
||||
Installer::install(
|
||||
$zip,
|
||||
GRAV_ROOT,
|
||||
['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true, 'ignores' => $ignores],
|
||||
$folder,
|
||||
$keepFolder
|
||||
);
|
||||
|
||||
Cache::clearCache();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Installer::setError($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,310 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Plugin\Admin
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Plugin\Admin;
|
||||
|
||||
use Grav\Common\Config\Config;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Page\Interfaces\PageInterface;
|
||||
|
||||
/**
|
||||
* Class Popularity
|
||||
* @package Grav\Plugin
|
||||
*/
|
||||
class Popularity
|
||||
{
|
||||
/** @var Config */
|
||||
protected $config;
|
||||
protected $data_path;
|
||||
|
||||
protected $daily_file;
|
||||
protected $monthly_file;
|
||||
protected $totals_file;
|
||||
protected $visitors_file;
|
||||
|
||||
protected $daily_data;
|
||||
protected $monthly_data;
|
||||
protected $totals_data;
|
||||
protected $visitors_data;
|
||||
|
||||
const DAILY_FORMAT = 'd-m-Y';
|
||||
const MONTHLY_FORMAT = 'm-Y';
|
||||
const DAILY_FILE = 'daily.json';
|
||||
const MONTHLY_FILE = 'monthly.json';
|
||||
const TOTALS_FILE = 'totals.json';
|
||||
const VISITORS_FILE = 'visitors.json';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = Grav::instance()['config'];
|
||||
|
||||
$this->data_path = Grav::instance()['locator']->findResource('log://popularity', true, true);
|
||||
$this->daily_file = $this->data_path . '/' . self::DAILY_FILE;
|
||||
$this->monthly_file = $this->data_path . '/' . self::MONTHLY_FILE;
|
||||
$this->totals_file = $this->data_path . '/' . self::TOTALS_FILE;
|
||||
$this->visitors_file = $this->data_path . '/' . self::VISITORS_FILE;
|
||||
|
||||
}
|
||||
|
||||
public function trackHit()
|
||||
{
|
||||
// Don't track bot or crawler requests
|
||||
if (!Grav::instance()['browser']->isHuman()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Respect visitors "do not track" setting
|
||||
if (!Grav::instance()['browser']->isTrackable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var PageInterface $page */
|
||||
$page = Grav::instance()['page'];
|
||||
$relative_url = str_replace(Grav::instance()['base_url_relative'], '', $page->url());
|
||||
|
||||
// Don't track error pages or pages that have no route
|
||||
if ($page->template() === 'error' || !$page->route()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure no 'widcard-style' ignore matches this url
|
||||
foreach ((array)$this->config->get('plugins.admin.popularity.ignore') as $ignore) {
|
||||
if (fnmatch($ignore, $relative_url)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// initial creation if it doesn't exist
|
||||
if (!file_exists($this->data_path)) {
|
||||
mkdir($this->data_path);
|
||||
$this->flushPopularity();
|
||||
}
|
||||
|
||||
// Update the data we want to track
|
||||
$this->updateDaily();
|
||||
$this->updateMonthly();
|
||||
$this->updateTotals($page->route());
|
||||
$this->updateVisitors(Grav::instance()['uri']->ip());
|
||||
|
||||
}
|
||||
|
||||
protected function updateDaily()
|
||||
{
|
||||
|
||||
if (!$this->daily_data) {
|
||||
$this->daily_data = $this->getData($this->daily_file);
|
||||
}
|
||||
|
||||
$day_month_year = date(self::DAILY_FORMAT);
|
||||
|
||||
// get the daily access count
|
||||
if (array_key_exists($day_month_year, $this->daily_data)) {
|
||||
$this->daily_data[$day_month_year] = (int)$this->daily_data[$day_month_year] + 1;
|
||||
} else {
|
||||
$this->daily_data[$day_month_year] = 1;
|
||||
}
|
||||
|
||||
// keep correct number as set by history
|
||||
$count = (int)$this->config->get('plugins.admin.popularity.history.daily', 30);
|
||||
$total = count($this->daily_data);
|
||||
|
||||
if ($total > $count) {
|
||||
$this->daily_data = array_slice($this->daily_data, -$count, $count, true);
|
||||
}
|
||||
|
||||
file_put_contents($this->daily_file, json_encode($this->daily_data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDailyChartData()
|
||||
{
|
||||
if (!$this->daily_data) {
|
||||
$this->daily_data = $this->getData($this->daily_file);
|
||||
}
|
||||
|
||||
$limit = (int)$this->config->get('plugins.admin.popularity.dashboard.days_of_stats', 7);
|
||||
$chart_data = array_slice($this->daily_data, -$limit, $limit);
|
||||
|
||||
$labels = [];
|
||||
$data = [];
|
||||
|
||||
/** @var Admin $admin */
|
||||
$admin = Grav::instance()['admin'];
|
||||
foreach ($chart_data as $date => $count) {
|
||||
$labels[] = $admin::translate([
|
||||
'PLUGIN_ADMIN.' . strtoupper(date('D', strtotime($date)))]) .
|
||||
'<br>' . date('M d', strtotime($date));
|
||||
$data[] = $count;
|
||||
}
|
||||
|
||||
return ['labels' => $labels, 'data' => $data];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getDailyTotal()
|
||||
{
|
||||
if (!$this->daily_data) {
|
||||
$this->daily_data = $this->getData($this->daily_file);
|
||||
}
|
||||
|
||||
if (isset($this->daily_data[date(self::DAILY_FORMAT)])) {
|
||||
return $this->daily_data[date(self::DAILY_FORMAT)];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWeeklyTotal()
|
||||
{
|
||||
if (!$this->daily_data) {
|
||||
$this->daily_data = $this->getData($this->daily_file);
|
||||
}
|
||||
|
||||
$day = 0;
|
||||
$total = 0;
|
||||
foreach (array_reverse($this->daily_data) as $daily) {
|
||||
$total += $daily;
|
||||
$day++;
|
||||
if ($day === 7) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMonthlyTotal()
|
||||
{
|
||||
if (!$this->monthly_data) {
|
||||
$this->monthly_data = $this->getData($this->monthly_file);
|
||||
}
|
||||
if (isset($this->monthly_data[date(self::MONTHLY_FORMAT)])) {
|
||||
return $this->monthly_data[date(self::MONTHLY_FORMAT)];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function updateMonthly()
|
||||
{
|
||||
|
||||
if (!$this->monthly_data) {
|
||||
$this->monthly_data = $this->getData($this->monthly_file);
|
||||
}
|
||||
|
||||
$month_year = date(self::MONTHLY_FORMAT);
|
||||
|
||||
// get the monthly access count
|
||||
if (array_key_exists($month_year, $this->monthly_data)) {
|
||||
$this->monthly_data[$month_year] = (int)$this->monthly_data[$month_year] + 1;
|
||||
} else {
|
||||
$this->monthly_data[$month_year] = 1;
|
||||
}
|
||||
|
||||
// keep correct number as set by history
|
||||
$count = (int)$this->config->get('plugins.admin.popularity.history.monthly', 12);
|
||||
$total = count($this->monthly_data);
|
||||
$this->monthly_data = array_slice($this->monthly_data, $total - $count, $count);
|
||||
|
||||
|
||||
file_put_contents($this->monthly_file, json_encode($this->monthly_data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getMonthyChartData()
|
||||
{
|
||||
if (!$this->monthly_data) {
|
||||
$this->monthly_data = $this->getData($this->monthly_file);
|
||||
}
|
||||
|
||||
$labels = [];
|
||||
$data = [];
|
||||
|
||||
foreach ($this->monthly_data as $date => $count) {
|
||||
$labels[] = date('M', strtotime($date));
|
||||
$data[] = $count;
|
||||
}
|
||||
|
||||
return ['labels' => $labels, 'data' => $data];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*/
|
||||
protected function updateTotals($url)
|
||||
{
|
||||
if (!$this->totals_data) {
|
||||
$this->totals_data = $this->getData($this->totals_file);
|
||||
}
|
||||
|
||||
// get the totals for this url
|
||||
if (array_key_exists($url, $this->totals_data)) {
|
||||
$this->totals_data[$url] = (int)$this->totals_data[$url] + 1;
|
||||
} else {
|
||||
$this->totals_data[$url] = 1;
|
||||
}
|
||||
|
||||
file_put_contents($this->totals_file, json_encode($this->totals_data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $ip
|
||||
*/
|
||||
protected function updateVisitors($ip)
|
||||
{
|
||||
if (!$this->visitors_data) {
|
||||
$this->visitors_data = $this->getData($this->visitors_file);
|
||||
}
|
||||
|
||||
// update with current timestamp
|
||||
$this->visitors_data[hash('sha1', $ip)] = time();
|
||||
$visitors = $this->visitors_data;
|
||||
arsort($visitors);
|
||||
|
||||
$count = (int)$this->config->get('plugins.admin.popularity.history.visitors', 20);
|
||||
$this->visitors_data = array_slice($visitors, 0, $count, true);
|
||||
|
||||
file_put_contents($this->visitors_file, json_encode($this->visitors_data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($path)
|
||||
{
|
||||
if (file_exists($path)) {
|
||||
return (array)json_decode(file_get_contents($path), true);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
public function flushPopularity()
|
||||
{
|
||||
file_put_contents($this->daily_file, []);
|
||||
file_put_contents($this->monthly_file, []);
|
||||
file_put_contents($this->totals_file, []);
|
||||
file_put_contents($this->visitors_file, []);
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Plugin\Admin
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Plugin\Admin;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Processors\ProcessorBase;
|
||||
use Grav\Framework\Route\Route;
|
||||
use Grav\Plugin\Admin\Routers\LoginRouter;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
class Router extends ProcessorBase
|
||||
{
|
||||
public $id = 'admin_router';
|
||||
public $title = 'Admin Panel';
|
||||
|
||||
/** @var Admin */
|
||||
protected $admin;
|
||||
|
||||
public function __construct(Grav $container, Admin $admin)
|
||||
{
|
||||
parent::__construct($container);
|
||||
|
||||
$this->admin = $admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle routing to the dashboard, group and build objects.
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param RequestHandlerInterface $handler
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
|
||||
{
|
||||
$this->startTimer();
|
||||
|
||||
$context = $request->getAttributes();
|
||||
$query = $request->getQueryParams();
|
||||
|
||||
/** @var Route $route */
|
||||
$route = $context['route'];
|
||||
$normalized = mb_strtolower(trim($route->getRoute(), '/'));
|
||||
$parts = explode('/', $normalized);
|
||||
array_shift($parts); // Admin path
|
||||
$routeStr = implode('/', $parts);
|
||||
$view = array_shift($parts);
|
||||
$path = implode('/', $parts);
|
||||
$task = $this->container['task'] ?? $query['task'] ?? null;
|
||||
$action = $this->container['action'] ?? $query['action'] ?? null;
|
||||
|
||||
$params = ['view' => $view, 'route' => $routeStr, 'path' => $path, 'parts' => $parts, 'task' => $task, 'action' => $action];
|
||||
$request = $request->withAttribute('admin', $params);
|
||||
|
||||
// Run login controller if user isn't fully logged in or asks to logout.
|
||||
$user = $this->admin->user;
|
||||
if (!$user->authorized || !$user->authorize('admin.login')) {
|
||||
$params = (new LoginRouter())->matchServerRequest($request);
|
||||
$request = $request->withAttribute('admin', $params + $request->getAttribute('admin'));
|
||||
}
|
||||
|
||||
$this->admin->request = $request;
|
||||
|
||||
$response = $handler->handle($request);
|
||||
|
||||
$this->stopTimer();
|
||||
|
||||
// Never allow admin pages to be rendered in <frame>, <iframe>, <embed> or <object> for improved security.
|
||||
return $response->withHeader('X-Frame-Options', 'DENY');
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Plugin\Admin
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Plugin\Admin\Routers;
|
||||
|
||||
use Grav\Plugin\Admin\Admin;
|
||||
use Grav\Plugin\Admin\Controllers\Login\LoginController;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class LoginRouter
|
||||
{
|
||||
/** @var string[] */
|
||||
private $taskTemplates = [
|
||||
'logout' => 'login',
|
||||
'twofa' => 'login',
|
||||
'forgot' => 'forgot',
|
||||
'reset' => 'reset'
|
||||
];
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return array
|
||||
*/
|
||||
public function matchServerRequest(ServerRequestInterface $request): array
|
||||
{
|
||||
$adminInfo = $request->getAttribute('admin');
|
||||
$task = $adminInfo['task'];
|
||||
$class = LoginController::class;
|
||||
|
||||
// Special controller for the new sites.
|
||||
if (!Admin::doAnyUsersExist()) {
|
||||
$method = $task === 'register' ? 'taskRegister' : 'displayRegister';
|
||||
|
||||
return [
|
||||
'controller' => [
|
||||
'class' => $class,
|
||||
'method' => $method,
|
||||
'params' => []
|
||||
],
|
||||
'template' => 'register',
|
||||
];
|
||||
}
|
||||
|
||||
$httpMethod = $request->getMethod() ?? '';
|
||||
$template = $this->taskTemplates[$task ?? ''] ?? $adminInfo['view'];
|
||||
|
||||
$params = [];
|
||||
|
||||
switch ($template) {
|
||||
case 'forgot':
|
||||
break;
|
||||
case 'reset':
|
||||
$path = $adminInfo['path'];
|
||||
if (str_starts_with($path, 'u/')) {
|
||||
// Path is 'u/username/token'
|
||||
$parts = explode('/', $path, 4);
|
||||
$user = $parts[1] ?? null;
|
||||
$token = $parts[2] ?? null;
|
||||
} else {
|
||||
// Old path used to be 'task:reset/user:username/token:token'
|
||||
if ($httpMethod === 'GET' || $httpMethod === 'HEAD') {
|
||||
$task = null;
|
||||
}
|
||||
$route = $request->getAttribute('route');
|
||||
$user = $route->getGravParam('user');
|
||||
$token = $route->getGravParam('token');
|
||||
}
|
||||
$params = [$user, $token];
|
||||
break;
|
||||
default:
|
||||
$template = 'login';
|
||||
}
|
||||
|
||||
$method = ($task ? 'task' : 'display') . ucfirst($task ?? $template);
|
||||
if (!method_exists($class, $method)) {
|
||||
$method = 'displayUnauthorized';
|
||||
}
|
||||
|
||||
return [
|
||||
'controller' => [
|
||||
'class' => $class,
|
||||
'method' => $method,
|
||||
'params' => $params
|
||||
],
|
||||
'template' => $template,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Plugin\Admin
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Plugin\Admin;
|
||||
|
||||
use ScssPhp\ScssPhp\Compiler;
|
||||
use ScssPhp\ScssPhp\ValueConverter;
|
||||
|
||||
class ScssCompiler
|
||||
{
|
||||
protected $compiler;
|
||||
|
||||
public function compiler()
|
||||
{
|
||||
if ($this->compiler === null) {
|
||||
$this->reset();
|
||||
}
|
||||
return $this->compiler;
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->compiler = new Compiler();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setVariables(array $variables)
|
||||
{
|
||||
// $parsed = ValueConverter::fromPhp($variables);
|
||||
$parsed = [];
|
||||
foreach ($variables as $key => $value) {
|
||||
$parsed[$key] = ValueConverter::parseValue($value);
|
||||
}
|
||||
|
||||
$this->compiler()->addVariables($parsed);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setImportPaths(array $paths)
|
||||
{
|
||||
$this->compiler()->setImportPaths($paths);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function compile(string $input_file, string $output_file)
|
||||
{
|
||||
$input = file_get_contents($input_file);
|
||||
$output = $this->compiler()->compileString($input)->getCss();
|
||||
file_put_contents($output_file, $output);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function compileAll(array $input_paths, string $output_file)
|
||||
{
|
||||
$input = '';
|
||||
foreach ($input_paths as $input_file) {
|
||||
$input .= trim(file_get_contents($input_file)) . "\n\n";
|
||||
}
|
||||
$output = $this->compiler()->compileString($input)->getCss();
|
||||
file_put_contents($output_file, $output);
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Plugin\Admin
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Plugin\Admin;
|
||||
|
||||
class ScssList
|
||||
{
|
||||
/** @var string[] */
|
||||
protected $list = [];
|
||||
|
||||
/**
|
||||
* ScssList constructor.
|
||||
* @param string|null $item
|
||||
*/
|
||||
public function __construct($item = null)
|
||||
{
|
||||
if ($item) {
|
||||
$this->add($item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function all(): array
|
||||
{
|
||||
return $this->list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $item
|
||||
* @return void
|
||||
*/
|
||||
public function add($item): void
|
||||
{
|
||||
if ($item) {
|
||||
$this->list[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $item
|
||||
* @return void
|
||||
*/
|
||||
public function remove($item): void
|
||||
{
|
||||
$pos = array_search($item, $this->list, true);
|
||||
if ($pos) {
|
||||
unset($this->list[$pos]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||