Compare commits
628 Commits
shift-9188
...
feature/re
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d5ee292a9 | |||
| 6f53c7ea6f | |||
| 7d9b6793d3 | |||
|
|
c432b32d08 | ||
|
|
8cf628153c | ||
|
|
ab0bd9e7d9 | ||
|
|
51cd70f2ec | ||
| 235d4e3784 | |||
|
|
dd0bbad18f | ||
| f32059c3e7 | |||
|
|
92578ef738 | ||
| 367205f955 | |||
| 1fdf36669f | |||
|
|
dfa06b148f | ||
|
|
139b437118 | ||
| 4dca636359 | |||
| 4f1d2a179b | |||
|
|
ede28f375a | ||
|
|
06dfb8d7f6 | ||
| 2d4090922f | |||
| 3d58a09c21 | |||
| 05da5f016c | |||
|
|
256eead944 | ||
|
|
dcb8ffaa0d | ||
|
|
def671dd47 | ||
| 717f360952 | |||
|
|
1c0b91f52c | ||
| c733d39d30 | |||
| 87bdea3bba | |||
| efe80694f9 | |||
| be7e6ee400 | |||
| 319a7b27c5 | |||
| dbe20ac724 | |||
|
|
dc6ed3f43a | ||
| ecddb5c6d3 | |||
| 34e5a37e24 | |||
| eaca6bcc72 | |||
|
|
bad588d4b2 | ||
|
|
d5daf20351 | ||
|
|
f512ab96fc | ||
|
|
0cfa9a5483 | ||
|
|
979f934f22 | ||
|
|
1fa5820550 | ||
| 8233afa825 | |||
| ba6f67798d | |||
| daabbaa3e4 | |||
| caa68b24d6 | |||
| 114db744b4 | |||
| 8c910ed5f3 | |||
| 1ef4332df6 | |||
| 6e98269a0b | |||
|
|
c918b91438 | ||
| 2a1e634b34 | |||
|
|
d45165d759 | ||
| a0a885e004 | |||
| 52f7070311 | |||
| e0650da5e9 | |||
| bf5cf3bce4 | |||
| 07d1dc4955 | |||
| 11db41b900 | |||
| 3bca959d49 | |||
| 3fee673314 | |||
| 3121d12f3a | |||
| b8731c3f37 | |||
| b445a42896 | |||
| dbab224a9d | |||
| 03f9659243 | |||
| 0fb56133ff | |||
| afa7ca629c | |||
| 9a9c382d7f | |||
| 518b8d67bc | |||
| ff0f8194e0 | |||
| f84f982c29 | |||
| 420d81866c | |||
| 1cd78ce93a | |||
| 7cae8af89a | |||
| 5088cea413 | |||
| d670d52083 | |||
| 004aa116fb | |||
| 32a08e1e10 | |||
| 30d39c5326 | |||
| 8affea3360 | |||
| 3b6b4dc388 | |||
| 9a9e75d96d | |||
| ad6e4f0a23 | |||
| f66bc6d8aa | |||
| 845bb4763b | |||
| e476b203c7 | |||
| dd163630cb | |||
| 5d8a5ede7d | |||
| 35ccb03c2b | |||
| f6df068787 | |||
| b60a3601cb | |||
| 8676844930 | |||
| 7e80e19eec | |||
| e21c7ce1d0 | |||
| 42f2baca5e | |||
| d9c0c8f1d8 | |||
| b98e184d32 | |||
| f764466199 | |||
| 6adfd9f3fa | |||
| dbf9db1c92 | |||
| 6cb7a8cb43 | |||
| 2913960bcb | |||
| 8d0382a279 | |||
| aa5ef50ed0 | |||
| d87b869633 | |||
| 99782bdf67 | |||
| 6fa459e88e | |||
| 954f2beea7 | |||
| f216413a23 | |||
| 63572a2740 | |||
| aeb7595166 | |||
| f507d198a7 | |||
| 9b5166c570 | |||
| 2271aae557 | |||
| 8ed07e539f | |||
| b029574fa5 | |||
| e9d903ce79 | |||
| 1c9100e5de | |||
| 1a59ac955d | |||
| 4d8e58f920 | |||
|
|
55ce8e0d9e | ||
|
|
0d1a3f8dbf | ||
|
|
9687a3c7a8 | ||
|
|
471534021e | ||
| 8c75abf16a | |||
| 472abaf30b | |||
| 35426e1189 | |||
| 6507d57424 | |||
| 4252878019 | |||
|
|
8451cc1547 | ||
|
|
70ecefb007 | ||
| 4e7be1a18c | |||
| d1cc468dfa | |||
| 484512f2c7 | |||
| 83b4df3462 | |||
| 8ea46b4ea8 | |||
| a68faa11b0 | |||
| 541cd93c99 | |||
| c5a7982945 | |||
| 5cee36453e | |||
| 47ea87b614 | |||
| 4ad0df2c39 | |||
| f2ff8398eb | |||
| 3f915d6964 | |||
| 3e6a9da0d1 | |||
|
|
ca5f4ffd84 | ||
|
|
b66f9f79d2 | ||
|
|
dc0bfe6d7a | ||
|
|
5de463bd02 | ||
|
|
f3d858d785 | ||
|
|
0e537a6b46 | ||
| 8d78b15751 | |||
|
|
e1fc2fa271 | ||
|
|
27466ad3a6 | ||
|
|
f0d63b4120 | ||
|
|
163dd98b7b | ||
| 8610a1678d | |||
|
|
d20c7832da | ||
|
|
fcba4015ed | ||
|
|
bb34a3c33a | ||
|
|
dbded3ba14 | ||
|
|
3a654e0480 | ||
|
|
4b358fba4f | ||
|
|
5aaeab686d | ||
|
|
5ff0a4e86f | ||
|
|
0c866ed009 | ||
|
|
f09bf02c10 | ||
|
|
ee2c30f938 | ||
|
|
82f28bc712 | ||
|
|
8020baf9d1 | ||
|
|
b1cac44432 | ||
|
|
ab46b6118d | ||
|
|
52a1bfe804 | ||
|
|
c7c5b5298c | ||
|
|
4c07917542 | ||
|
|
fe06a2dd55 | ||
| 143f002ead | |||
| 83c0ae5841 | |||
| 0c05386804 | |||
| 9a70d4de0d | |||
| 8950b5f50b | |||
| 59e077fd6a | |||
| c9fc5b2157 | |||
| e128bcfaf9 | |||
| 7cf6b0bba6 | |||
| c36d4783e7 | |||
| 29acd76051 | |||
| eacf33b642 | |||
| 46666db231 | |||
| 3dfa753f33 | |||
| 41ae64a8c9 | |||
| fcf5400f71 | |||
| 2257736ad9 | |||
| 147b55ae78 | |||
| 5b6c951dc0 | |||
| 0840d65011 | |||
| 6394234960 | |||
| e1dde655cb | |||
| e01d59cbd8 | |||
| 22d1e195ed | |||
| c776e7b102 | |||
|
|
3cd95a5a6b | ||
| aba7845a4b | |||
| f23c4c42b5 | |||
| 05149dc723 | |||
| a615c9d1d8 | |||
| eed9ac8ff4 | |||
| 258e7fe307 | |||
| a49a86a597 | |||
| b01c5d57c7 | |||
| 4b0c113941 | |||
| 277a0ae2e3 | |||
| a61aafdc6a | |||
| 3a2899f913 | |||
| 05b172cd47 | |||
| 351259909c | |||
| 0af44ffe02 | |||
| 06799a90b0 | |||
| c7fc9a1480 | |||
| d5b8a89776 | |||
| eada83aaf8 | |||
| 9a63a9de80 | |||
| b4859fd97f | |||
| 794a18cfa0 | |||
| 581b732b05 | |||
| 0119875d22 | |||
| 0f34c7dfb9 | |||
| 04be7fdb3c | |||
| 123d45d172 | |||
|
|
864ae189af | ||
|
|
13b2620d2e | ||
|
|
75c4ad73ed | ||
|
|
2c2f5621df | ||
|
|
855accab4f | ||
|
|
afaa702a02 | ||
|
|
15637d398e | ||
|
|
f346625bb1 | ||
| 9764fef01c | |||
| 338d6c6f9d | |||
| 9da6f39e6e | |||
| 5759794f71 | |||
| ee9d96a5bf | |||
| 9197a86670 | |||
| 64e45b1892 | |||
| 6890a0939d | |||
| 61c78534d8 | |||
| 5a611f96a8 | |||
| 3e7f34d5c4 | |||
|
|
78d16bec5f | ||
| 33f658e088 | |||
| 0b46c34abe | |||
| f1ad20cb0b | |||
| 511da54909 | |||
| 104407646c | |||
| 622229cfc9 | |||
| f50e6ad209 | |||
| d7529cef80 | |||
|
|
f7432158e1 | ||
|
|
2df6597771 | ||
| 60a15c2227 | |||
| a369db9ca1 | |||
|
|
ac35d61ae2 | ||
| 489668a2ff | |||
| c9087d5df4 | |||
| ac06b3700c | |||
| 31578f5ed3 | |||
| 9b178ade4b | |||
| 92522b5494 | |||
| ccebb4eb73 | |||
| 16873e7477 | |||
| 79318e2f28 | |||
| f44a4f5d9d | |||
| b28925079b | |||
| cbf6803812 | |||
|
|
a0e804aa62 | ||
| d1b87bd64b | |||
| 5b783035a3 | |||
| a06363da75 | |||
| a68c691f75 | |||
|
|
8a61d258fb | ||
|
|
fd3f220752 | ||
|
|
0a0b2927ae | ||
|
|
4c19773818 | ||
|
|
071af03577 | ||
|
|
58da0b54b3 | ||
|
|
528ea4bcfb | ||
|
|
ca124d34cd | ||
| 70b53ce21a | |||
| 6dc226ab0b | |||
| d6524942f7 | |||
| 3ca5e81e34 | |||
| 561b5ad1b9 | |||
| 229bb9a5e0 | |||
| 280d3e9043 | |||
| a2384f4b35 | |||
| d65bf5bcd5 | |||
| e763a9140c | |||
| 3a06a375ef | |||
| bdf3f38190 | |||
| 5b2f6e44b1 | |||
| 250401fd62 | |||
| c1fb03add1 | |||
|
|
56bf7efcef | ||
| cc0508683e | |||
|
|
b232b65860 | ||
| 406d1d31c0 | |||
| f8fe5c92aa | |||
| 69623bd248 | |||
| 6d4995074b | |||
| ac94068864 | |||
| 31ed355d64 | |||
| 8a54fb272a | |||
| 6ecf807081 | |||
| 728472b897 | |||
| 30a8c8a03a | |||
| 00e7490037 | |||
| 1d152d730a | |||
| a010d91da2 | |||
| 3717248764 | |||
| 27753e903b | |||
| b621f71b54 | |||
| d4b3300b88 | |||
| 242fb9dda0 | |||
| 4f505cd155 | |||
| dca70a0f53 | |||
| b9a8c826ec | |||
| 363deb3ca7 | |||
| f77b5f7556 | |||
| d60efe38e2 | |||
| f779342e02 | |||
| 204e62b3bb | |||
| 5adc24f997 | |||
| ab25b0f64a | |||
| dd8e59cd4f | |||
| 0c4c36eb74 | |||
|
|
3481f10033 | ||
|
|
fdf61fef3d | ||
|
|
30c3c5d33f | ||
|
|
6cd7df79d9 | ||
|
|
b5b0b5d7bd | ||
|
|
d0266c7d0c | ||
|
|
283fd30c19 | ||
|
|
5d13135bd0 | ||
|
|
6c2961eef6 | ||
|
|
f9c006403e | ||
|
|
1f65f0fe30 | ||
|
|
a49a287855 | ||
| bf7f830f9e | |||
| ffce564a47 | |||
| 2cdcd9a424 | |||
| ffbc733571 | |||
| 3ea7188253 | |||
| 97c6a4c4ef | |||
| f3fe112427 | |||
| 189e4ef230 | |||
| d35b895ff4 | |||
| c47c511674 | |||
| 20be21c87d | |||
| 1d57dc519f | |||
| 644b42afe9 | |||
| 9ad11f24c2 | |||
| 1e2564f753 | |||
| f1ab544aae | |||
|
|
aa85d24952 | ||
|
|
b0f8817aae | ||
|
|
b9e3e9f5f2 | ||
|
|
ea05f5992d | ||
|
|
9c138d6bee | ||
|
|
7325880a70 | ||
|
|
320631e91d | ||
|
|
0997864cd6 | ||
|
|
9e0451d541 | ||
|
|
84245c5584 | ||
|
|
d72c0ea9f5 | ||
|
|
bf9500f960 | ||
|
|
f18cda6c00 | ||
| 0ab20a75ac | |||
| 133a6ed4ea | |||
| bc424b7a00 | |||
| be3c6d89ee | |||
| d814ed1972 | |||
| 8322229001 | |||
| da2a76d6cf | |||
|
|
abf7a2783c | ||
| 6690c69efe | |||
| 67044b7cf9 | |||
| 048d3af39b | |||
| 816989d472 | |||
| 8f6310b463 | |||
| 3cebdd838b | |||
| 9996404e29 | |||
| 1598efac35 | |||
| bfacb86f35 | |||
|
|
e5e5c7e19c | ||
|
|
9ede1d7eea | ||
| ff8cf83f1b | |||
| 326c8e7b81 | |||
| daeecfbd4f | |||
| 15c330c784 | |||
| 7ba80ccc58 | |||
| ef4efe723f | |||
| 64ef8e9acd | |||
| d88b6f6e95 | |||
| 440d66322c | |||
|
|
469a646ae3 | ||
| 9cb9ebbe4f | |||
|
|
d004855dd8 | ||
|
|
911645c9f5 | ||
|
|
6a16e78d80 | ||
| 937c5024cb | |||
|
|
7e12ba1a00 | ||
| 89d57bb915 | |||
| a111387a3f | |||
| 234fcb13af | |||
| 377fdad6e0 | |||
| 68020b0201 | |||
| f0628c5c05 | |||
| 66d2a2c48c | |||
| 6f1229418e | |||
| a430fee568 | |||
| 53b7ce651e | |||
| 1028064abe | |||
| ab285870e3 | |||
| 1a02d46151 | |||
| 1bb70bbe66 | |||
| c158155194 | |||
| 7bfd4c1198 | |||
| ea959d1a10 | |||
| 9fc5d81877 | |||
| 719aac6727 | |||
| c8398920c5 | |||
|
|
55bd914b8f | ||
|
|
2b06a52705 | ||
|
|
2c9c997d5a | ||
|
|
17f305d9cb | ||
|
|
44d071696f | ||
|
|
fa8f44135c | ||
|
|
b38e79ef8f | ||
|
|
e2e39fbdf5 | ||
|
|
a8262932cc | ||
|
|
6d3e9b3c1d | ||
|
|
b91619801d | ||
|
|
f1e32096f3 | ||
|
|
f5a327e72c | ||
| 4fe05e39f7 | |||
|
|
c3779bf371 | ||
| 54aa7e249e | |||
| 1744d192b5 | |||
| 3f7426c550 | |||
| c4e017c7b7 | |||
| e723831548 | |||
| 56b5dcd7d8 | |||
|
|
913d229630 | ||
| 3dfb11d692 | |||
| 759ab14899 | |||
| 329ff7c478 | |||
| a6022f7251 | |||
| d345be889e | |||
| 2dbe9955d9 | |||
|
|
8fcd33e0a1 | ||
| 14aa5e3b28 | |||
| 2cb9aac070 | |||
| 1c6a5c9d04 | |||
| 936aabf412 | |||
| fa7478a5b5 | |||
| 8992554ba6 | |||
| c8895137fa | |||
| f8bc75f1f9 | |||
| 43faa0f020 | |||
| 8e76a18590 | |||
| 9c1df26b4b | |||
| 6d89a499b1 | |||
| 03430c272f | |||
| baf15296ce | |||
| 56f74964ed | |||
| afad2df8f5 | |||
| d17ff1f2e7 | |||
| 4d9be34b4e | |||
|
|
5213b28c2e | ||
|
|
e0df5a53dc | ||
|
|
f13022ee1d | ||
|
|
c063badb38 | ||
|
|
693cf4cd2a | ||
| cc70b1a67f | |||
| 08d3366fe1 | |||
| 080b2fcfc4 | |||
| 5b1d02e3c1 | |||
| b322a405c7 | |||
| 0ed05b103b | |||
| 5431da3930 | |||
| 2a6e5b7992 | |||
| 85af95a8a0 | |||
| e0b04a57ae | |||
| 0533cd24fe | |||
| 9598031dd1 | |||
| 9f808717d2 | |||
| b4aa71b81b | |||
|
|
321a8f0946 | ||
|
|
93124cdad0 | ||
|
|
26eae9b1cf | ||
| f803bc0a59 | |||
| be5925f40d | |||
| b25b697e7b | |||
| 66e2a68cde | |||
| 673f6051c1 | |||
| 0478ab9eb2 | |||
| b7fde520be | |||
| 6f031f78e8 | |||
| 2f850ce152 | |||
|
|
a6240a3ca9 | ||
| 8906936e51 | |||
| fd6867740e | |||
| 183231206b | |||
| d4e832b526 | |||
| 667ff5cf94 | |||
| 6d2db21a62 | |||
| df398faddb | |||
| e07e2d2e2c | |||
| ca29189f9e | |||
|
|
15a1a3f666 | ||
|
|
8c4c09bc90 | ||
|
|
5a926d2d41 | ||
|
|
5127d8b283 | ||
|
|
c043a43fc5 | ||
|
|
013930d7c3 | ||
|
|
6b0d66be25 | ||
|
|
3b492d2005 | ||
|
|
29f4bfd3cc | ||
|
|
86e42c36cb | ||
|
|
c1d81c65d2 | ||
|
|
fd864b03d9 | ||
|
|
97eb51a434 | ||
|
|
76f9b96369 | ||
|
|
13e5cf2133 | ||
|
|
1c92f6449e | ||
|
|
3ed6cc8d5c | ||
|
|
5b79e415e0 | ||
|
|
98036c7266 | ||
|
|
8c8c59d8bd | ||
| fdbadbac7f | |||
| 9d788f919a | |||
| fac00bc4f6 | |||
| 6e511fc4a9 | |||
| 2f6214c48d | |||
| b2f791fc5f | |||
| 39140611ca | |||
| 567ee3062b | |||
| 584e0903c8 | |||
| 8990006d4c | |||
| 7feb78ba70 | |||
| d67ca133eb | |||
| f95557aa3a | |||
| f539ab7294 | |||
|
|
79284e2271 | ||
|
|
e303b565fc | ||
|
|
985e8a5cd6 | ||
|
|
541e1c4c2c | ||
|
|
10c1d500f3 | ||
|
|
678f16788c | ||
|
|
8871a1b7ae | ||
|
|
05c2f28f25 | ||
|
|
30179fe353 | ||
|
|
6846dd760d | ||
|
|
408f285cf3 | ||
|
|
fa76fc0f78 | ||
|
|
ade9cd6b05 | ||
|
|
933d18b784 | ||
| 48bae3b181 | |||
| 78f6ed1ef6 | |||
| 6d503939a5 | |||
| 3677f1c45b | |||
|
|
a23ce4e0e6 | ||
|
|
e7c43fa53a | ||
|
|
0de6735855 | ||
|
|
aa274b1df4 | ||
|
|
51261a4a5c | ||
|
|
9e92561502 | ||
| 2b28ebc014 | |||
| 196d9c358c | |||
|
|
38d58d92b4 | ||
| e136c910b5 | |||
| d0c4f7eea2 | |||
| bf9b0f3973 | |||
| 4534b46e97 | |||
| 68affe4e4c | |||
| aa2671f167 | |||
| 2178b61602 | |||
| 6a6b8ed9b2 | |||
| 784e8cf787 | |||
| 89a8b6926a | |||
| 9c926d15c1 | |||
|
|
1b1144c628 | ||
|
|
e9b1802af3 | ||
|
|
fe7c1d93ae | ||
|
|
8d1be827a7 | ||
|
|
cd4fe13117 | ||
|
|
34e169adba | ||
|
|
d064756cc6 | ||
|
|
bf7e1658f4 | ||
| 8de3c5dcba | |||
| e8827cbd50 | |||
| f839003f5e | |||
| b68d97455b | |||
|
|
e9dcb8b3f0 | ||
|
|
5e838ad61e | ||
|
|
a365977702 | ||
| 8b2542ebef | |||
|
|
69c5018367 | ||
|
|
4f536ae5a9 | ||
|
|
95395d1da7 | ||
|
|
fbf437ac99 | ||
|
|
5faf49688d | ||
|
|
4d7d0ed74d | ||
|
|
979b9f704c | ||
|
|
4124cf39db | ||
|
|
c83e21d588 | ||
|
|
c88630e9af | ||
|
|
40b265e145 | ||
|
|
3ad2b2fb8e | ||
|
|
8b671065e9 | ||
|
|
028e1a191e | ||
|
|
a133f82997 | ||
|
|
c4f3eb9a4e | ||
|
|
8a52c4529f | ||
|
|
d0493f3dd0 | ||
|
|
b845552c37 |
27
.env.example
27
.env.example
@@ -3,7 +3,6 @@ APP_ENV=local
|
|||||||
APP_KEY=
|
APP_KEY=
|
||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
APP_URL_API="${APP_URL}/api/"
|
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
LOG_CHANNEL=stack
|
||||||
LOG_DEPRECATIONS_CHANNEL=null
|
LOG_DEPRECATIONS_CHANNEL=null
|
||||||
@@ -30,7 +29,7 @@ REDIS_PASSWORD=null
|
|||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
|
|
||||||
MAIL_MAILER=smtp
|
MAIL_MAILER=smtp
|
||||||
MAIL_HOST=mailhog
|
MAIL_HOST=mailpit
|
||||||
MAIL_PORT=1025
|
MAIL_PORT=1025
|
||||||
MAIL_USERNAME=null
|
MAIL_USERNAME=null
|
||||||
MAIL_PASSWORD=null
|
MAIL_PASSWORD=null
|
||||||
@@ -38,24 +37,11 @@ MAIL_ENCRYPTION=null
|
|||||||
MAIL_FROM_ADDRESS="hello@example.com"
|
MAIL_FROM_ADDRESS="hello@example.com"
|
||||||
MAIL_FROM_NAME="${APP_NAME}"
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
AWS_PUBLIC_ACCESS_KEY_ID=
|
AWS_ACCESS_KEY_ID=
|
||||||
AWS_PUBLIC_SECRET_ACCESS_KEY=
|
AWS_SECRET_ACCESS_KEY=
|
||||||
AWS_PUBLIC_DEFAULT_REGION="us-west-002"
|
AWS_DEFAULT_REGION=us-east-1
|
||||||
AWS_PUBLIC_BUCKET=
|
AWS_BUCKET=
|
||||||
AWS_PUBLIC_USE_PATH_STYLE_ENDPOINT=false
|
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||||
AWS_PUBLIC_ENDPOINT=
|
|
||||||
AWS_PUBLIC_URL=
|
|
||||||
|
|
||||||
AWS_PRIVATE_ACCESS_KEY_ID=
|
|
||||||
AWS_PRIVATE_SECRET_ACCESS_KEY=
|
|
||||||
AWS_PRIVATE_DEFAULT_REGION="us-west-002"
|
|
||||||
AWS_PRIVATE_BUCKET=
|
|
||||||
AWS_PRIVATE_USE_PATH_STYLE_ENDPOINT=false
|
|
||||||
AWS_PRIVATE_ENDPOINT=
|
|
||||||
AWS_PRIVATE_URL=
|
|
||||||
|
|
||||||
CLOUDFLARE_ZONE_ID=
|
|
||||||
CLOUDFLARE_API_KEY=
|
|
||||||
|
|
||||||
PUSHER_APP_ID=
|
PUSHER_APP_ID=
|
||||||
PUSHER_APP_KEY=
|
PUSHER_APP_KEY=
|
||||||
@@ -65,6 +51,7 @@ PUSHER_PORT=443
|
|||||||
PUSHER_SCHEME=https
|
PUSHER_SCHEME=https
|
||||||
PUSHER_APP_CLUSTER=mt1
|
PUSHER_APP_CLUSTER=mt1
|
||||||
|
|
||||||
|
VITE_APP_NAME="${APP_NAME}"
|
||||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
||||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
||||||
|
|||||||
59
.env.testing
59
.env.testing
@@ -1,59 +0,0 @@
|
|||||||
APP_NAME=Laravel
|
|
||||||
APP_ENV=local
|
|
||||||
APP_KEY=base64:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=
|
|
||||||
APP_DEBUG=true
|
|
||||||
APP_URL=http://127.0.0.1
|
|
||||||
APP_URL_API="${APP_URL}/api/"
|
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
|
||||||
LOG_LEVEL=debug
|
|
||||||
|
|
||||||
DB_CONNECTION=sqlite
|
|
||||||
DB_DATABASE=:memory:
|
|
||||||
|
|
||||||
BROADCAST_DRIVER=log
|
|
||||||
CACHE_DRIVER=array
|
|
||||||
QUEUE_CONNECTION=sync
|
|
||||||
SESSION_DRIVER=file
|
|
||||||
SESSION_LIFETIME=120
|
|
||||||
|
|
||||||
MEMCACHED_HOST=127.0.0.1
|
|
||||||
|
|
||||||
REDIS_HOST=127.0.0.1
|
|
||||||
REDIS_PASSWORD=null
|
|
||||||
REDIS_PORT=6379
|
|
||||||
|
|
||||||
MAIL_MAILER=log
|
|
||||||
MAIL_HOST=null
|
|
||||||
MAIL_PORT=null
|
|
||||||
MAIL_USERNAME=null
|
|
||||||
MAIL_PASSWORD=null
|
|
||||||
MAIL_ENCRYPTION=null
|
|
||||||
MAIL_FROM_ADDRESS="hello@example.com"
|
|
||||||
MAIL_FROM_NAME="${APP_NAME}"
|
|
||||||
|
|
||||||
AWS_ACCESS_KEY_ID=
|
|
||||||
AWS_SECRET_ACCESS_KEY=
|
|
||||||
AWS_DEFAULT_REGION=us-east-1
|
|
||||||
AWS_BUCKET=
|
|
||||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
|
||||||
|
|
||||||
PUSHER_APP_ID=
|
|
||||||
PUSHER_APP_KEY=
|
|
||||||
PUSHER_APP_SECRET=
|
|
||||||
PUSHER_HOST=
|
|
||||||
PUSHER_PORT=443
|
|
||||||
PUSHER_SCHEME=https
|
|
||||||
PUSHER_APP_CLUSTER=mt1
|
|
||||||
|
|
||||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
|
||||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
|
||||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
|
||||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
|
||||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
|
||||||
|
|
||||||
CONTACT_ADDRESS="hello@stemmechanics.com.au"
|
|
||||||
CONTACT_SUBJECT="Contact from website"
|
|
||||||
|
|
||||||
STORAGE_LOCAL_URL="${APP_URL}/api/media/%ID%/download"
|
|
||||||
STORAGE_PUBLIC_URL="${APP_URL}/uploads/%NAME%"
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
.github/
|
|
||||||
.vscode/
|
|
||||||
vendor/
|
|
||||||
22
.eslintrc.js
22
.eslintrc.js
@@ -1,22 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
env: {
|
|
||||||
node: true,
|
|
||||||
},
|
|
||||||
extends: [
|
|
||||||
"eslint:recommended",
|
|
||||||
"plugin:vue/vue3-strongly-recommended",
|
|
||||||
"prettier",
|
|
||||||
"plugin:jsdoc/recommended",
|
|
||||||
"plugin:@typescript-eslint/recommended",
|
|
||||||
],
|
|
||||||
rules: {
|
|
||||||
"vue/multi-word-component-names": "off",
|
|
||||||
indent: ["off", 4, { ignoredNodes: ["ConditionalExpression"] }],
|
|
||||||
"@typescript-eslint/no-inferrable-types": "off",
|
|
||||||
},
|
|
||||||
plugins: ["jsdoc", "@typescript-eslint"],
|
|
||||||
parser: "vue-eslint-parser",
|
|
||||||
parserOptions: {
|
|
||||||
parser: "@typescript-eslint/parser",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -1,4 +1,4 @@
|
|||||||
* text=auto
|
* text=auto eol=lf
|
||||||
|
|
||||||
*.blade.php diff=html
|
*.blade.php diff=html
|
||||||
*.css diff=css
|
*.css diff=css
|
||||||
|
|||||||
15
.github/dependabot.yml
vendored
15
.github/dependabot.yml
vendored
@@ -1,15 +0,0 @@
|
|||||||
# To get started with Dependabot version updates, you'll need to specify which
|
|
||||||
# package ecosystems to update and where the package manifests are located.
|
|
||||||
# Please see the documentation for all configuration options:
|
|
||||||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
||||||
|
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: "npm"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "daily"
|
|
||||||
- package-ecosystem: "composer"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "daily"
|
|
||||||
42
.github/workflows/laravel.yml
vendored
42
.github/workflows/laravel.yml
vendored
@@ -1,42 +0,0 @@
|
|||||||
name: Laravel
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: ["main"]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
laravel-tests:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: shivammathur/setup-php@v2
|
|
||||||
with:
|
|
||||||
php-version: "8.1"
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Copy .env
|
|
||||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
|
||||||
- name: Install Dependencies
|
|
||||||
run: composer install -q --no-interaction --no-progress --prefer-dist
|
|
||||||
- name: Generate key
|
|
||||||
run: php artisan key:generate
|
|
||||||
- name: Directory Permissions
|
|
||||||
run: chmod -R 777 storage bootstrap/cache
|
|
||||||
- name: Create Database
|
|
||||||
run: |
|
|
||||||
mkdir -p database
|
|
||||||
touch database/database.sqlite
|
|
||||||
- name: Execute tests (Unit and Feature tests) via PHPUnit
|
|
||||||
env:
|
|
||||||
DB_CONNECTION: sqlite
|
|
||||||
DB_DATABASE: database/database.sqlite
|
|
||||||
run: vendor/bin/phpunit
|
|
||||||
- name: Install Node.js
|
|
||||||
uses: actions/setup-node@v2
|
|
||||||
with:
|
|
||||||
node-version: "16.x"
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm ci
|
|
||||||
- name: Run Vue tests
|
|
||||||
env:
|
|
||||||
LARAVEL_BYPASS_ENV_CHECK: "1"
|
|
||||||
run: npm run test
|
|
||||||
261
.gitignore
vendored
261
.gitignore
vendored
@@ -1,247 +1,20 @@
|
|||||||
### Composer ###
|
/.phpunit.cache
|
||||||
composer.phar
|
/node_modules
|
||||||
/vendor/
|
/public/build
|
||||||
|
/public/hot
|
||||||
# composer.lock
|
/public/storage
|
||||||
|
/storage/*.key
|
||||||
### Laravel ###
|
/vendor
|
||||||
node_modules/
|
.env
|
||||||
|
.env.backup
|
||||||
|
.env.production
|
||||||
|
.phpunit.result.cache
|
||||||
|
Homestead.json
|
||||||
|
Homestead.yaml
|
||||||
|
auth.json
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
|
/.fleet
|
||||||
# Laravel 4 specific
|
/.idea
|
||||||
bootstrap/compiled.php
|
/.vscode
|
||||||
app/storage/
|
|
||||||
|
|
||||||
# Laravel 5 & Lumen specific
|
|
||||||
public/storage
|
|
||||||
public/hot
|
|
||||||
|
|
||||||
# Laravel 5 & Lumen specific with changed public path
|
|
||||||
public_html/storage
|
|
||||||
public_html/hot
|
|
||||||
|
|
||||||
storage/*.key
|
|
||||||
.env
|
|
||||||
Homestead.yaml
|
|
||||||
Homestead.json
|
|
||||||
/.vagrant
|
|
||||||
.phpunit.result.cache
|
|
||||||
|
|
||||||
### macOS ###
|
|
||||||
# General
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.AppleDouble
|
|
||||||
.LSOverride
|
|
||||||
|
|
||||||
# Icon must end with two \r
|
|
||||||
Icon
|
|
||||||
|
|
||||||
|
|
||||||
# Thumbnails
|
|
||||||
._*
|
|
||||||
|
|
||||||
# Files that might appear in the root of a volume
|
|
||||||
.DocumentRevisions-V100
|
|
||||||
.fseventsd
|
|
||||||
.Spotlight-V100
|
|
||||||
.TemporaryItems
|
|
||||||
.Trashes
|
|
||||||
.VolumeIcon.icns
|
|
||||||
.com.apple.timemachine.donotpresent
|
|
||||||
|
|
||||||
# Directories potentially created on remote AFP share
|
|
||||||
.AppleDB
|
|
||||||
.AppleDesktop
|
|
||||||
Network Trash Folder
|
|
||||||
Temporary Items
|
|
||||||
.apdisk
|
|
||||||
|
|
||||||
### macOS Patch ###
|
|
||||||
# iCloud generated files
|
|
||||||
*.icloud
|
|
||||||
|
|
||||||
### Node ###
|
|
||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
lerna-debug.log*
|
|
||||||
.pnpm-debug.log*
|
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
||||||
|
|
||||||
# Runtime data
|
|
||||||
pids
|
|
||||||
*.pid
|
|
||||||
*.seed
|
|
||||||
*.pid.lock
|
|
||||||
|
|
||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
||||||
lib-cov
|
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
|
||||||
coverage
|
|
||||||
*.lcov
|
|
||||||
|
|
||||||
# nyc test coverage
|
|
||||||
.nyc_output
|
|
||||||
|
|
||||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
||||||
.grunt
|
|
||||||
|
|
||||||
# Bower dependency directory (https://bower.io/)
|
|
||||||
bower_components
|
|
||||||
|
|
||||||
# node-waf configuration
|
|
||||||
.lock-wscript
|
|
||||||
|
|
||||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
||||||
build/Release
|
|
||||||
|
|
||||||
# Dependency directories
|
|
||||||
jspm_packages/
|
|
||||||
|
|
||||||
# Snowpack dependency directory (https://snowpack.dev/)
|
|
||||||
web_modules/
|
|
||||||
|
|
||||||
# TypeScript cache
|
|
||||||
*.tsbuildinfo
|
|
||||||
|
|
||||||
# Optional npm cache directory
|
|
||||||
.npm
|
|
||||||
|
|
||||||
# Optional eslint cache
|
|
||||||
.eslintcache
|
|
||||||
|
|
||||||
# Optional stylelint cache
|
|
||||||
.stylelintcache
|
|
||||||
|
|
||||||
# Microbundle cache
|
|
||||||
.rpt2_cache/
|
|
||||||
.rts2_cache_cjs/
|
|
||||||
.rts2_cache_es/
|
|
||||||
.rts2_cache_umd/
|
|
||||||
|
|
||||||
# Optional REPL history
|
|
||||||
.node_repl_history
|
|
||||||
|
|
||||||
# Output of 'npm pack'
|
|
||||||
*.tgz
|
|
||||||
|
|
||||||
# Yarn Integrity file
|
|
||||||
.yarn-integrity
|
|
||||||
|
|
||||||
# dotenv environment variable files
|
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
.env.local
|
|
||||||
|
|
||||||
# parcel-bundler cache (https://parceljs.org/)
|
|
||||||
.cache
|
|
||||||
.parcel-cache
|
|
||||||
|
|
||||||
# Next.js build output
|
|
||||||
.next
|
|
||||||
out
|
|
||||||
|
|
||||||
# Nuxt.js build / generate output
|
|
||||||
.nuxt
|
|
||||||
dist
|
|
||||||
|
|
||||||
# Gatsby files
|
|
||||||
.cache/
|
|
||||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
||||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
||||||
# public
|
|
||||||
|
|
||||||
# vuepress build output
|
|
||||||
.vuepress/dist
|
|
||||||
|
|
||||||
# vuepress v2.x temp and cache directory
|
|
||||||
.temp
|
|
||||||
|
|
||||||
# Docusaurus cache and generated files
|
|
||||||
.docusaurus
|
|
||||||
|
|
||||||
# Serverless directories
|
|
||||||
.serverless/
|
|
||||||
|
|
||||||
# FuseBox cache
|
|
||||||
.fusebox/
|
|
||||||
|
|
||||||
# DynamoDB Local files
|
|
||||||
.dynamodb/
|
|
||||||
|
|
||||||
# TernJS port file
|
|
||||||
.tern-port
|
|
||||||
|
|
||||||
# Stores VSCode versions used for testing VSCode extensions
|
|
||||||
.vscode-test
|
|
||||||
|
|
||||||
# yarn v2
|
|
||||||
.yarn/cache
|
|
||||||
.yarn/unplugged
|
|
||||||
.yarn/build-state.yml
|
|
||||||
.yarn/install-state.gz
|
|
||||||
.pnp.*
|
|
||||||
|
|
||||||
### Node Patch ###
|
|
||||||
# Serverless Webpack directories
|
|
||||||
.webpack/
|
|
||||||
|
|
||||||
# Optional stylelint cache
|
|
||||||
|
|
||||||
# SvelteKit build / generate output
|
|
||||||
.svelte-kit
|
|
||||||
|
|
||||||
### VisualStudioCode ###
|
|
||||||
.vscode/*
|
|
||||||
!.vscode/settings.json
|
|
||||||
!.vscode/tasks.json
|
|
||||||
!.vscode/launch.json
|
|
||||||
!.vscode/extensions.json
|
|
||||||
!.vscode/*.code-snippets
|
|
||||||
|
|
||||||
# Local History for Visual Studio Code
|
|
||||||
.history/
|
|
||||||
|
|
||||||
# Built Visual Studio Code Extensions
|
|
||||||
*.vsix
|
|
||||||
|
|
||||||
### VisualStudioCode Patch ###
|
|
||||||
# Ignore all local history of files
|
|
||||||
.history
|
|
||||||
.ionide
|
|
||||||
|
|
||||||
### Vue ###
|
|
||||||
# gitignore template for Vue.js projects
|
|
||||||
#
|
|
||||||
# Recommended template: Node.gitignore
|
|
||||||
|
|
||||||
# TODO: where does this rule come from?
|
|
||||||
docs/_book
|
|
||||||
|
|
||||||
# TODO: where does this rule come from?
|
|
||||||
test/
|
|
||||||
|
|
||||||
### Vuejs ###
|
|
||||||
# Recommended template: Node.gitignore
|
|
||||||
|
|
||||||
dist/
|
|
||||||
|
|
||||||
### This Project ###
|
|
||||||
/public/uploads
|
|
||||||
/public/build
|
|
||||||
# /public/tinymce
|
|
||||||
*.key
|
|
||||||
|
|
||||||
### Synk ###
|
|
||||||
.dccache
|
|
||||||
|
|
||||||
### TempCodeRunner ###
|
|
||||||
tempCodeRunnerFile.*
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"bracketSameLine": true,
|
|
||||||
"tabWidth": 4
|
|
||||||
}
|
|
||||||
21
.vscode/settings.json
vendored
21
.vscode/settings.json
vendored
@@ -1,20 +1,5 @@
|
|||||||
{
|
{
|
||||||
"editor.formatOnType": true,
|
"files.associations": {
|
||||||
"editor.formatOnSave": true,
|
"*.css": "tailwindcss"
|
||||||
"editor.codeActionsOnSave": {
|
}
|
||||||
"source.fixAll.eslint": true
|
|
||||||
// "source.organizeImports": true // <-- when enabled, breaks tinymce required import order
|
|
||||||
},
|
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
||||||
"[vue]": {
|
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
||||||
},
|
|
||||||
"[javascript]": {
|
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
||||||
},
|
|
||||||
"[php]": {
|
|
||||||
// "editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
|
|
||||||
"editor.defaultFormatter": "wongjn.php-sniffer"
|
|
||||||
},
|
|
||||||
"cSpell.words": ["TIMESTAMPDIFF"]
|
|
||||||
}
|
}
|
||||||
|
|||||||
18
README.md
18
README.md
@@ -1,7 +1,7 @@
|
|||||||
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
|
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://travis-ci.org/laravel/framework"><img src="https://travis-ci.org/laravel/framework.svg" alt="Build Status"></a>
|
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
|
||||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
|
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
|
||||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
|
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
|
||||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
|
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
|
||||||
@@ -31,23 +31,23 @@ If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Lar
|
|||||||
|
|
||||||
## Laravel Sponsors
|
## Laravel Sponsors
|
||||||
|
|
||||||
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell).
|
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
|
||||||
|
|
||||||
### Premium Partners
|
### Premium Partners
|
||||||
|
|
||||||
- **[Vehikl](https://vehikl.com/)**
|
- **[Vehikl](https://vehikl.com/)**
|
||||||
- **[Tighten Co.](https://tighten.co)**
|
- **[Tighten Co.](https://tighten.co)**
|
||||||
|
- **[WebReinvent](https://webreinvent.com/)**
|
||||||
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
|
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
|
||||||
- **[64 Robots](https://64robots.com)**
|
- **[64 Robots](https://64robots.com)**
|
||||||
- **[Cubet Techno Labs](https://cubettech.com)**
|
|
||||||
- **[Cyber-Duck](https://cyber-duck.co.uk)**
|
|
||||||
- **[Many](https://www.many.co.uk)**
|
|
||||||
- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)**
|
|
||||||
- **[DevSquad](https://devsquad.com)**
|
|
||||||
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
|
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
|
||||||
|
- **[Cyber-Duck](https://cyber-duck.co.uk)**
|
||||||
|
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
|
||||||
|
- **[Jump24](https://jump24.co.uk)**
|
||||||
|
- **[Redberry](https://redberry.international/laravel/)**
|
||||||
|
- **[Active Logic](https://activelogic.com)**
|
||||||
|
- **[byte5](https://byte5.de)**
|
||||||
- **[OP.GG](https://op.gg)**
|
- **[OP.GG](https://op.gg)**
|
||||||
- **[WebReinvent](https://webreinvent.com/?utm_source=laravel&utm_medium=github&utm_campaign=patreon-sponsors)**
|
|
||||||
- **[Lendio](https://lendio.com)**
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Conductors;
|
|
||||||
|
|
||||||
use App\Models\Media;
|
|
||||||
use App\Models\User;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\InvalidCastException;
|
|
||||||
use Illuminate\Database\Eloquent\MissingAttributeException;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use LogicException;
|
|
||||||
|
|
||||||
class AnalyticsConductor extends Conductor
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The Model Class
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $class = '\App\Models\Analytics';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default sorting field
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $sort = 'created_at';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default includes to include in a request.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $includes = ['duration'];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is visible.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow model to be visible.
|
|
||||||
*/
|
|
||||||
public static function viewable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/analytics') === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is creatable.
|
|
||||||
*
|
|
||||||
* @return boolean Allow creating model.
|
|
||||||
*/
|
|
||||||
public static function creatable()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is updatable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow updating model.
|
|
||||||
*/
|
|
||||||
public static function updatable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/analytics') === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is destroyable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow deleting model.
|
|
||||||
*/
|
|
||||||
public static function destroyable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/analytics') === true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,152 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Conductors;
|
|
||||||
|
|
||||||
use App\Models\Media;
|
|
||||||
use App\Models\User;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\InvalidCastException;
|
|
||||||
use Illuminate\Database\Eloquent\MissingAttributeException;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use LogicException;
|
|
||||||
|
|
||||||
class ArticleConductor extends Conductor
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The Model Class
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $class = '\App\Models\Article';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default sorting field
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $sort = '-publish_at';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The included fields
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected $includes = ['attachments', 'user'];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run a scope query on the collection before anything else.
|
|
||||||
*
|
|
||||||
* @param Builder $builder The builder in use.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function scope(Builder $builder)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
if ($user === null || $user->hasPermission('admin/articles') === false) {
|
|
||||||
$builder
|
|
||||||
->where('publish_at', '<=', now());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is visible.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow model to be visible.
|
|
||||||
*/
|
|
||||||
public static function viewable(Model $model)
|
|
||||||
{
|
|
||||||
if (Carbon::parse($model->publish_at)->isFuture() === true) {
|
|
||||||
$user = auth()->user();
|
|
||||||
if ($user === null || $user->hasPermission('admin/articles') === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is creatable.
|
|
||||||
*
|
|
||||||
* @return boolean Allow creating model.
|
|
||||||
*/
|
|
||||||
public static function creatable()
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/articles') === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is updatable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow updating model.
|
|
||||||
*/
|
|
||||||
public static function updatable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/articles') === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is destroyable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow deleting model.
|
|
||||||
*/
|
|
||||||
public static function destroyable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/articles') === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform the final model data
|
|
||||||
*
|
|
||||||
* @param array $data The model data to transform.
|
|
||||||
* @return array The transformed model.
|
|
||||||
*/
|
|
||||||
public function transformFinal(array $data)
|
|
||||||
{
|
|
||||||
unset($data['user_id']);
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Include Attachments Field.
|
|
||||||
*
|
|
||||||
* @param Model $model Them model.
|
|
||||||
* @return mixed The model result.
|
|
||||||
*/
|
|
||||||
public function includeAttachments(Model $model)
|
|
||||||
{
|
|
||||||
return $model->attachments()->get()->map(function ($attachment) {
|
|
||||||
return MediaConductor::includeModel(request(), 'attachments', $attachment->media);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Include User Field.
|
|
||||||
*
|
|
||||||
* @param Model $model Them model.
|
|
||||||
* @return mixed The model result.
|
|
||||||
*/
|
|
||||||
public function includeUser(Model $model)
|
|
||||||
{
|
|
||||||
return UserConductor::includeModel(request(), 'user', User::find($model['user_id']));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform the Hero field.
|
|
||||||
*
|
|
||||||
* @param mixed $value The current value.
|
|
||||||
* @return array The new value.
|
|
||||||
*/
|
|
||||||
public function transformHero(mixed $value)
|
|
||||||
{
|
|
||||||
return MediaConductor::includeModel(request(), 'hero', Media::find($value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,989 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Conductors;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class Conductor
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The Conductors Model class.
|
|
||||||
*
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
protected $class = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default sorting fields of a collection. Can be an array. Supports - and + prefixes.
|
|
||||||
*
|
|
||||||
* @var string|array
|
|
||||||
*/
|
|
||||||
protected $sort = "id";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default collection size limit per request.
|
|
||||||
*
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
protected $limit = 50;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The maximum collection size limit per request.
|
|
||||||
*
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
protected $maxLimit = 100;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default includes to include in a request.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $includes = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default filters to use in a request.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $defaultFilters = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The conductor collection.
|
|
||||||
*
|
|
||||||
* @var Collection
|
|
||||||
*/
|
|
||||||
protected $collection = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The collection filter to apply.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $filterArray = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The conductor query.
|
|
||||||
*
|
|
||||||
* @var Builder
|
|
||||||
*/
|
|
||||||
private $query = null;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Split a string on commas, keeping quotes intact.
|
|
||||||
*
|
|
||||||
* @param string $string The string to split.
|
|
||||||
* @return array The split string.
|
|
||||||
*/
|
|
||||||
private function splitString(string $string)
|
|
||||||
{
|
|
||||||
$parts = [];
|
|
||||||
$start = 0;
|
|
||||||
$len = strlen($string);
|
|
||||||
|
|
||||||
while ($start < $len) {
|
|
||||||
$commaPos = strpos($string, ',', $start);
|
|
||||||
$singlePos = strpos($string, '\'', $start);
|
|
||||||
$doublePos = strpos($string, '"', $start);
|
|
||||||
|
|
||||||
// Find the smallest position that is not false
|
|
||||||
$minPos = false;
|
|
||||||
if ($commaPos !== false) {
|
|
||||||
$minPos = $commaPos;
|
|
||||||
}
|
|
||||||
if ($singlePos !== false && ($minPos === false || $singlePos < $minPos)) {
|
|
||||||
$minPos = $singlePos;
|
|
||||||
}
|
|
||||||
if ($doublePos !== false && ($minPos === false || $doublePos < $minPos)) {
|
|
||||||
$minPos = $doublePos;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($minPos === false) {
|
|
||||||
// No more commas, single quotes, or double quotes found
|
|
||||||
$part = substr($string, $start);
|
|
||||||
$parts[] = trim($part);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
// Add the current part to the parts array
|
|
||||||
$part = substr($string, $start, ($minPos - $start));
|
|
||||||
$parts[] = trim($part);
|
|
||||||
|
|
||||||
// Update the start position to the next character after the comma, single quote, or double quote
|
|
||||||
if ($string[$minPos] === ',') {
|
|
||||||
$start = ($minPos + 1);
|
|
||||||
} else {
|
|
||||||
$quoteChar = $string[$minPos];
|
|
||||||
$endPos = strpos($string, $quoteChar, ($minPos + 1));
|
|
||||||
if ($endPos === false) {
|
|
||||||
$part = substr($string, ($minPos + 1));
|
|
||||||
$parts[] = trim($part);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
$part = substr($string, ($minPos + 1), ($endPos - $minPos - 1));
|
|
||||||
$parts[] = trim($part);
|
|
||||||
$start = ($endPos + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}//end if
|
|
||||||
}//end while
|
|
||||||
|
|
||||||
return array_filter($parts, function ($value) {
|
|
||||||
return $value !== '';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter Collection based on the Request.
|
|
||||||
*
|
|
||||||
* @param Request $request The user request.
|
|
||||||
* @param array|null $limitFields A list of fields to limit the filter request to.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function filter(Request $request, array|null $limitFields = null)
|
|
||||||
{
|
|
||||||
if (is_array($limitFields) === true && count($limitFields) === 0) {
|
|
||||||
$limitFields = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$filterFields = $request->all();
|
|
||||||
if ($limitFields !== null) {
|
|
||||||
$filterFields = array_intersect_key($filterFields, array_flip($limitFields));
|
|
||||||
}
|
|
||||||
$filterFields += $this->defaultFilters;
|
|
||||||
|
|
||||||
foreach ($filterFields as $field => $value) {
|
|
||||||
if (
|
|
||||||
is_array($limitFields) === false ||
|
|
||||||
in_array(strtolower($field), array_map('strtolower', $limitFields)) !== false
|
|
||||||
) {
|
|
||||||
$value = trim($value);
|
|
||||||
$operator = '';
|
|
||||||
$join = 'OR';
|
|
||||||
|
|
||||||
// Check if value has a operator and remove it if it's a number
|
|
||||||
if (preg_match('/^(!?=|[<>]=?|<>|!)([^=!<>].*)*$/', $value, $matches) > 0) {
|
|
||||||
$operator = $matches[1];
|
|
||||||
$value = ($matches[2] ?? '');
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($operator) {
|
|
||||||
case '=':
|
|
||||||
$operator = '==';
|
|
||||||
break;
|
|
||||||
case '!':
|
|
||||||
$operator = 'NOT LIKE';
|
|
||||||
$value = "%{$value}%";
|
|
||||||
break;
|
|
||||||
case '>':
|
|
||||||
case '<':
|
|
||||||
case '>=':
|
|
||||||
case '<=':
|
|
||||||
case '!=':
|
|
||||||
break;
|
|
||||||
case '<>':
|
|
||||||
$separatorPos = strpos($value, '|');
|
|
||||||
if ($separatorPos === false) {
|
|
||||||
$operator = '!=';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$operator = 'LIKE';
|
|
||||||
$value = "%{$value}%";
|
|
||||||
break;
|
|
||||||
}//end switch
|
|
||||||
|
|
||||||
$this->appendFilter($field, $operator, $value, $join);
|
|
||||||
}//end if
|
|
||||||
}//end foreach
|
|
||||||
if ($request->has('filter') === true) {
|
|
||||||
$this->appendFilterString($request->input('filter', ''), $limitFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->applyFilters();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apple the filter array to the collection.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
final public function applyFilters()
|
|
||||||
{
|
|
||||||
$parseFunc = function ($filterArray, $query) use (&$parseFunc) {
|
|
||||||
$item = null;
|
|
||||||
$result = null;
|
|
||||||
$join = 'AND';
|
|
||||||
|
|
||||||
if (gettype($query) === 'array') {
|
|
||||||
$item = $query;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($filterArray as $condition) {
|
|
||||||
$currentResult = false;
|
|
||||||
|
|
||||||
if (is_array($condition) === true) {
|
|
||||||
if (isset($condition[0]) === true && is_array($condition[0]) === true) {
|
|
||||||
if ($item !== null) {
|
|
||||||
$currentResult = $parseFunc($condition, $item);
|
|
||||||
} else {
|
|
||||||
if ($join === 'OR') {
|
|
||||||
$query->orWhere(function ($subQuery) use ($parseFunc, $condition) {
|
|
||||||
$parseFunc($condition, $subQuery);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$query->where(function ($subQuery) use ($parseFunc, $condition) {
|
|
||||||
$parseFunc($condition, $subQuery);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
list($field, $operator, $value) = $condition;
|
|
||||||
|
|
||||||
if ($item !== null) {
|
|
||||||
if (array_key_exists($field, $item) === true) {
|
|
||||||
switch ($operator) {
|
|
||||||
case '==':
|
|
||||||
$currentResult = ($item[$field] == $value);
|
|
||||||
break;
|
|
||||||
case 'NOT LIKE':
|
|
||||||
$currentResult = (stripos($item[$field], substr($value, 1, -1)) === false);
|
|
||||||
break;
|
|
||||||
case '>':
|
|
||||||
$currentResult = ($item[$field] > $value);
|
|
||||||
break;
|
|
||||||
case '<':
|
|
||||||
$currentResult = ($item[$field] < $value);
|
|
||||||
break;
|
|
||||||
case '>=':
|
|
||||||
$currentResult = ($item[$field] >= $value);
|
|
||||||
break;
|
|
||||||
case '<=':
|
|
||||||
$currentResult = ($item[$field] <= $value);
|
|
||||||
break;
|
|
||||||
case '!=':
|
|
||||||
$currentResult = ($item[$field] != $value);
|
|
||||||
break;
|
|
||||||
case '<>':
|
|
||||||
$separatorPos = strpos($value, '|');
|
|
||||||
if ($separatorPos !== false) {
|
|
||||||
$fieldInt = intval($item[$field]);
|
|
||||||
$currentResult = (
|
|
||||||
$fieldInt > intVal(
|
|
||||||
substr($value, 0, $separatorPos)
|
|
||||||
) && $fieldInt < intVal(substr($value, ($separatorPos + 1))));
|
|
||||||
} else {
|
|
||||||
$currentResult = ($item[$field] != $value);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'LIKE':
|
|
||||||
$currentResult = (stripos($item[$field], substr($value, 1, -1)) !== false);
|
|
||||||
break;
|
|
||||||
}//end switch
|
|
||||||
}//end if
|
|
||||||
} else {
|
|
||||||
if ($operator === '==') {
|
|
||||||
$operator = '=';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($join === 'OR') {
|
|
||||||
if ($operator === '<>') {
|
|
||||||
$separatorPos = strpos($value, '|');
|
|
||||||
if ($separatorPos !== false) {
|
|
||||||
$query->orWhereBetween(
|
|
||||||
$field,
|
|
||||||
[substr($value, 0, $separatorPos), substr($value, ($separatorPos + 1))]
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$query->orWhere($field, '!=', $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$query->orWhere($field, $operator, $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($operator === '<>') {
|
|
||||||
$separatorPos = strpos($value, '|');
|
|
||||||
if ($separatorPos !== false) {
|
|
||||||
$query->whereBetween(
|
|
||||||
$field,
|
|
||||||
[substr($value, 0, $separatorPos), substr($value, ($separatorPos + 1))]
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$query->where($field, '!=', $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$query->where($field, $operator, $value);
|
|
||||||
}
|
|
||||||
}//end if
|
|
||||||
}//end if
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
if ($item !== null) {
|
|
||||||
if ($result === null) {
|
|
||||||
$result = $currentResult;
|
|
||||||
} else {
|
|
||||||
if ($join === 'OR') {
|
|
||||||
$result = $result || $currentResult;
|
|
||||||
} else {
|
|
||||||
$result = $result && $currentResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$join = 'OR';
|
|
||||||
} else {
|
|
||||||
$join = $condition;
|
|
||||||
}//end if
|
|
||||||
}//end foreach
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
};
|
|
||||||
|
|
||||||
$filterArray = $this->filterArray;
|
|
||||||
if (count($filterArray) === 0) {
|
|
||||||
$filterArray = $this->defaultFilters;
|
|
||||||
}
|
|
||||||
if (count($filterArray) !== 0) {
|
|
||||||
if ($this->collection !== null) {
|
|
||||||
$this->collection = $this->collection->filter(function ($item) use ($parseFunc) {
|
|
||||||
return $parseFunc($this->filterArray, $item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$parseFunc($this->filterArray, $this->query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the conductor on a Request to generate a collection and total.
|
|
||||||
*
|
|
||||||
* @param Request $request The request data.
|
|
||||||
* @return array The processed and transformed collection | the total rows found.
|
|
||||||
*/
|
|
||||||
final public static function request(Request $request)
|
|
||||||
{
|
|
||||||
$conductor_class = get_called_class();
|
|
||||||
$conductor = new $conductor_class();
|
|
||||||
|
|
||||||
$total = 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$conductor->query = $conductor->class::query();
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
throw new \Exception('Failed to create query builder instance for ' . $conductor->class . '.', 0, $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter request
|
|
||||||
$limitFields = $conductor->fields(new $conductor->class());
|
|
||||||
if (is_array($limitFields) === false) {
|
|
||||||
$limitFields = [];
|
|
||||||
}
|
|
||||||
$conductor->filter($request, $limitFields);
|
|
||||||
|
|
||||||
// After Scope query
|
|
||||||
$conductor->query->where(function ($query) use ($conductor) {
|
|
||||||
$conductor->scope($query);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Sort request
|
|
||||||
$sort = $request->input('sort', $conductor->sort);
|
|
||||||
if (strlen($sort) === 0) {
|
|
||||||
if (strlen($conductor->sort) > 0) {
|
|
||||||
$conductor->sort($conductor->sort);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$conductor->sort($sort);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get total
|
|
||||||
$total = $conductor->count();
|
|
||||||
|
|
||||||
// Paginate
|
|
||||||
$conductor->paginate($request->input('page', 1), $request->input('limit', -1), $request->input('offset', 0));
|
|
||||||
|
|
||||||
// Filter request
|
|
||||||
$fields = $conductor->fields(new $conductor->class());
|
|
||||||
if (is_array($fields) === false) {
|
|
||||||
$fields = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Limit fields
|
|
||||||
$limitFields = array_map(function ($field) {
|
|
||||||
if (strpos($field, '.') !== false) {
|
|
||||||
return substr($field, 0, strpos($field, '.'));
|
|
||||||
}
|
|
||||||
return $field;
|
|
||||||
}, explode(',', $request->input('fields')));
|
|
||||||
if ($limitFields === null) {
|
|
||||||
$limitFields = $fields;
|
|
||||||
} else {
|
|
||||||
$limitFields = array_intersect($limitFields, $fields);
|
|
||||||
}
|
|
||||||
$conductor->limitFields($limitFields);
|
|
||||||
$conductor->collection = $conductor->query->get();
|
|
||||||
|
|
||||||
// Transform and Includes
|
|
||||||
$includes = $conductor->includes;
|
|
||||||
if (count($limitFields) > 0) {
|
|
||||||
$includes = array_intersect($limitFields, $conductor->includes);
|
|
||||||
}
|
|
||||||
|
|
||||||
$conductor->collection = $conductor->collection->map(
|
|
||||||
function ($model) use ($conductor, $includes, $limitFields) {
|
|
||||||
$conductor->applyIncludes($model, $includes);
|
|
||||||
|
|
||||||
if (count($limitFields) > 0) {
|
|
||||||
$model->setAppends(array_intersect($model->getAppends(), $limitFields));
|
|
||||||
}
|
|
||||||
|
|
||||||
$model = $conductor->transformModel($model);
|
|
||||||
|
|
||||||
return $model;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return [$conductor->collection, $total];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the conductor on a collection with the data stored in a Request.
|
|
||||||
*
|
|
||||||
* @param Request $request The request data.
|
|
||||||
* @param Collection $collection The collection.
|
|
||||||
* @return array The processed and transformed model data.
|
|
||||||
*/
|
|
||||||
final public static function collection(Request $request, Collection $collection)
|
|
||||||
{
|
|
||||||
$conductor_class = get_called_class();
|
|
||||||
$conductor = new $conductor_class();
|
|
||||||
|
|
||||||
$conductor->collection = collect();
|
|
||||||
|
|
||||||
foreach ($collection as $item) {
|
|
||||||
if ($conductor->viewable($item) === true) {
|
|
||||||
$conductor->collection->push($conductor->transformModel($item));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter request
|
|
||||||
$limitFields = $conductor->fields(new $conductor->class());
|
|
||||||
if (is_array($limitFields) === false) {
|
|
||||||
$limitFields = [];
|
|
||||||
}
|
|
||||||
$conductor->filter($request, $limitFields);
|
|
||||||
|
|
||||||
// Get total
|
|
||||||
$total = $conductor->collection->count();
|
|
||||||
|
|
||||||
// Sort request
|
|
||||||
$sort = $request->input('sort', $conductor->sort);
|
|
||||||
if (strlen($sort) === 0) {
|
|
||||||
if (strlen($conductor->sort) > 0) {
|
|
||||||
$conductor->sort($sort);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$conductor->sort($sort);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Paginate
|
|
||||||
$conductor->paginate($request->input('page', 1), $request->input('limit', -1), $request->input('offset', 0));
|
|
||||||
|
|
||||||
|
|
||||||
return [$conductor->collection, $total];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter a custom query on a user request.
|
|
||||||
*
|
|
||||||
* @param Builder $query The custom query.
|
|
||||||
* @param Request $request The request.
|
|
||||||
* @param array|null $limitFields Limit the request to these fields.
|
|
||||||
* @return Builder
|
|
||||||
*/
|
|
||||||
public static function filterQuery(Builder $query, Request $request, array|null $limitFields = null)
|
|
||||||
{
|
|
||||||
$conductor_class = get_called_class();
|
|
||||||
$conductor = new $conductor_class();
|
|
||||||
|
|
||||||
$conductor->query = $query;
|
|
||||||
$conductor->filter($request, $limitFields);
|
|
||||||
|
|
||||||
return $conductor->query;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the conductor on a Model with the data stored in a Request.
|
|
||||||
*
|
|
||||||
* @param Request $request The request data.
|
|
||||||
* @param string $key The key prefix to use.
|
|
||||||
* @param Model|null $model The model.
|
|
||||||
* @return array The processed and transformed model data.
|
|
||||||
*/
|
|
||||||
final public static function includeModel(Request $request, string $key, mixed $model)
|
|
||||||
{
|
|
||||||
$fields = [];
|
|
||||||
|
|
||||||
if ($request !== null && $request->has('fields') === true) {
|
|
||||||
$requestFields = $request->input('fields');
|
|
||||||
if ($requestFields !== null) {
|
|
||||||
$requestFields = explode(',', $requestFields);
|
|
||||||
if (in_array($key, $requestFields) === false) {
|
|
||||||
foreach ($requestFields as $field) {
|
|
||||||
if (strpos($field, $key . '.') === 0) {
|
|
||||||
$fields[] = substr($field, (strlen($key) + 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return static::model($fields, $model);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the conductor on a Model with the data stored in a Request.
|
|
||||||
*
|
|
||||||
* @param mixed $fields The fields to show.
|
|
||||||
* @param Model|null $model The model.
|
|
||||||
* @return array The processed and transformed model data.
|
|
||||||
*/
|
|
||||||
final public static function model(mixed $fields, mixed $model)
|
|
||||||
{
|
|
||||||
if ($model === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$conductor_class = get_called_class();
|
|
||||||
$conductor = new $conductor_class();
|
|
||||||
|
|
||||||
$modelFields = $conductor->fields(new $conductor->class());
|
|
||||||
|
|
||||||
// Limit fields
|
|
||||||
$limitFields = $modelFields;
|
|
||||||
if ($fields instanceof Request) {
|
|
||||||
if ($fields !== null && $fields->has('fields') === true) {
|
|
||||||
$requestFields = $fields->input('fields');
|
|
||||||
if ($requestFields !== null) {
|
|
||||||
$limitFields = array_intersect(explode(',', $requestFields), $modelFields);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif (is_array($fields) === true && count($fields) > 0) {
|
|
||||||
$limitFields = array_intersect($fields, $modelFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($limitFields) === false) {
|
|
||||||
$modelAppends = $model->getAppends();
|
|
||||||
|
|
||||||
foreach (array_diff($modelFields, $limitFields) as $attribute) {
|
|
||||||
$key = array_search($attribute, $modelAppends);
|
|
||||||
if ($key !== false) {
|
|
||||||
unset($modelAppends[$key]);
|
|
||||||
} else {
|
|
||||||
unset($model[$attribute]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$model->setAppends($modelAppends);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Includes
|
|
||||||
$includes = array_intersect($limitFields, $conductor->includes);
|
|
||||||
$conductor->applyIncludes($model, $includes);
|
|
||||||
|
|
||||||
// Transform
|
|
||||||
$model = $conductor->transformModel($model);
|
|
||||||
|
|
||||||
return $model;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the current conductor collection count.
|
|
||||||
*
|
|
||||||
* @return integer The current collection count.
|
|
||||||
*/
|
|
||||||
final public function count()
|
|
||||||
{
|
|
||||||
if ($this->query !== null) {
|
|
||||||
return $this->query->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sort the conductor collection.
|
|
||||||
*
|
|
||||||
* @param mixed $fields A field name or array of field names to sort. Supports prefix of +/- to change direction.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
final public function sort(mixed $fields = null)
|
|
||||||
{
|
|
||||||
$collectionSort = [];
|
|
||||||
|
|
||||||
if (is_string($fields) === true) {
|
|
||||||
$fields = explode(',', $fields);
|
|
||||||
} elseif ($fields === null) {
|
|
||||||
$fields = $this->sort;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($fields) === true) {
|
|
||||||
foreach ($fields as $orderByField) {
|
|
||||||
$direction = 'asc';
|
|
||||||
$directionChar = substr($orderByField, 0, 1);
|
|
||||||
|
|
||||||
if (in_array($directionChar, ['-', '+']) === true) {
|
|
||||||
$orderByField = substr($orderByField, 1);
|
|
||||||
if ($directionChar === '-') {
|
|
||||||
$direction = 'desc';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->collection !== null) {
|
|
||||||
$collectionSort[] = [trim($orderByField), $direction];
|
|
||||||
} else {
|
|
||||||
$this->query->orderBy(trim($orderByField), $direction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new \InvalidArgumentException('Expected string or array, got ' . gettype($fields));
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
if ($this->collection !== null) {
|
|
||||||
$this->collection = $this->collection->sortBy($collectionSort)->values();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Paginate the conductor collection.
|
|
||||||
*
|
|
||||||
* @param integer $page The current page to return.
|
|
||||||
* @param integer $limit The limit of items to include or use default.
|
|
||||||
* @param integer $offset Offset the page count after this count of rows.
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
final public function paginate(int $page = 1, int $limit = -1, int $offset = 0)
|
|
||||||
{
|
|
||||||
// Limit
|
|
||||||
if ($limit < 1) {
|
|
||||||
$limit = $this->limit;
|
|
||||||
} else {
|
|
||||||
$limit = min($limit, $this->maxLimit);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Page
|
|
||||||
if ($page < 1) {
|
|
||||||
$page = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// After
|
|
||||||
if ($offset < 0) {
|
|
||||||
$offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->collection !== null) {
|
|
||||||
$this->collection = $this->collection->splice(((($page - 1) * $limit) + $offset), $limit);
|
|
||||||
} else {
|
|
||||||
$this->query->limit($limit);
|
|
||||||
$this->query->offset((($page - 1) * $limit) + $offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply a list of includes to the model.
|
|
||||||
*
|
|
||||||
* @param Model $model The model to append.
|
|
||||||
* @param array $includes The list of includes to include.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
final public function applyIncludes(Model $model, array $includes)
|
|
||||||
{
|
|
||||||
foreach ($includes as $include) {
|
|
||||||
$includeMethodName = 'include' . Str::studly($include);
|
|
||||||
if (method_exists($this, $includeMethodName) === true) {
|
|
||||||
$attributeName = Str::snake($include);
|
|
||||||
$attributeValue = $this->{$includeMethodName}($model);
|
|
||||||
if ($attributeValue !== null) {
|
|
||||||
$model->$attributeName = $this->{$includeMethodName}($model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Limit the returned fields in the conductor collection.
|
|
||||||
*
|
|
||||||
* @param array $fields An array of field names.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
final public function limitFields(array $fields)
|
|
||||||
{
|
|
||||||
if (empty($fields) !== true) {
|
|
||||||
$this->query->select(array_diff($fields, $this->includes));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter the conductor collection using raw data.
|
|
||||||
*
|
|
||||||
* @param string $rawFilter The raw filter string to parse.
|
|
||||||
* @param array|null $limitFields The fields to allow in the filter string.
|
|
||||||
* @param string $outerJoin The join for this filter group.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
final public function appendFilterString(string $rawFilter, array|null $limitFields = null, string $outerJoin = 'OR')
|
|
||||||
{
|
|
||||||
if ($rawFilter === '') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (substr($rawFilter, -1) !== ',') {
|
|
||||||
$rawFilter .= ',';
|
|
||||||
}
|
|
||||||
|
|
||||||
$parseFunc = function ($string, &$i = 0) use (&$parseFunc, $limitFields) {
|
|
||||||
$tokens = [];
|
|
||||||
$ignoreUntil = '';
|
|
||||||
$skipUntil = '';
|
|
||||||
$field = '';
|
|
||||||
$value = null;
|
|
||||||
$set = &$field;
|
|
||||||
|
|
||||||
for (; $i < strlen($string); $i++) {
|
|
||||||
$char = $string[$i];
|
|
||||||
|
|
||||||
if ($skipUntil !== '' && $char !== $skipUntil) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($ignoreUntil === '') {
|
|
||||||
if ($char === '\'' || $char === '"') {
|
|
||||||
$ignoreUntil = $char;
|
|
||||||
} elseif ($char === ':') {
|
|
||||||
if ($field === '') {
|
|
||||||
$skipUntil = ',';
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($field[0] === '\'' || $field[0] === '"') {
|
|
||||||
$field = substr($field, 1, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$set = &$value;
|
|
||||||
continue;
|
|
||||||
} elseif (($char === ')' && $string[($i + 1)] === ',') || $char === ',') {
|
|
||||||
if ($value === null) {
|
|
||||||
$tokens[] = $field;
|
|
||||||
} else {
|
|
||||||
$value = trim($value);
|
|
||||||
$operator = 'LIKE';
|
|
||||||
|
|
||||||
// Check if value has a operator and remove it if it's a number
|
|
||||||
if (preg_match('/^(!?=|[<>]=?|<>|!)([^=!<>].*)*$/', $value, $matches) > 0) {
|
|
||||||
$operator = $matches[1];
|
|
||||||
$value = ($matches[2] ?? '');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($value[0] === '\'' || $value[0] === '"') {
|
|
||||||
$value = substr($value, 1, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($operator === 'LIKE') {
|
|
||||||
$value = "%{$value}%";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
is_array($limitFields) === false ||
|
|
||||||
in_array(strtolower($field), array_map('strtolower', $limitFields)) !== false
|
|
||||||
) {
|
|
||||||
$tokens[] = [$field, $operator, $value];
|
|
||||||
}
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
$field = '';
|
|
||||||
$value = null;
|
|
||||||
$set = &$field;
|
|
||||||
|
|
||||||
if ($char === ')') {
|
|
||||||
$i++;
|
|
||||||
return $tokens;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
} elseif ($char === '(') {
|
|
||||||
if ($field === '') {
|
|
||||||
$i++;
|
|
||||||
$tokens[] = $parseFunc($string, $i);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}//end if
|
|
||||||
} elseif ($char === $ignoreUntil) {
|
|
||||||
$ignoreUntil = '';
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
$set .= $char;
|
|
||||||
}//end for
|
|
||||||
|
|
||||||
return $tokens;
|
|
||||||
};
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
$filterArray = $parseFunc($rawFilter, $i);
|
|
||||||
|
|
||||||
if (count($this->filterArray) !== 0) {
|
|
||||||
$this->filterArray[] = $outerJoin;
|
|
||||||
}
|
|
||||||
$this->filterArray[] = $filterArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append a field to the filter array.
|
|
||||||
*
|
|
||||||
* @param string $field The field name to append.
|
|
||||||
* @param string $operator The operator to append.
|
|
||||||
* @param string $value The value to append.
|
|
||||||
* @param string $join The join to append.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
final public function appendFilter(string $field, string $operator, string $value, string $join = 'OR')
|
|
||||||
{
|
|
||||||
if (count($this->filterArray) !== 0) {
|
|
||||||
$this->filterArray[] = $join;
|
|
||||||
}
|
|
||||||
$this->filterArray[] = [$field, $operator, $value];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run a scope query on the collection before anything else.
|
|
||||||
*
|
|
||||||
* @param Builder $builder The builder in use.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function scope(Builder $builder)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an array of model fields visible to the current user.
|
|
||||||
*
|
|
||||||
* @param Model $model The model in question.
|
|
||||||
* @return array The array of field names.
|
|
||||||
*/
|
|
||||||
public function fields(Model $model)
|
|
||||||
{
|
|
||||||
$visibleFields = $model->getVisible();
|
|
||||||
if (empty($visibleFields) === true) {
|
|
||||||
$visibleFields = $model->getConnection()
|
|
||||||
->getSchemaBuilder()
|
|
||||||
->getColumnListing($model->getTable());
|
|
||||||
}
|
|
||||||
|
|
||||||
$appends = $model->getAppends();
|
|
||||||
if (is_array($appends) === true) {
|
|
||||||
$visibleFields = array_merge($visibleFields, $appends);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($this->includes) === true) {
|
|
||||||
$visibleFields = array_merge($visibleFields, $this->includes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $visibleFields;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform the passed Model to an array
|
|
||||||
*
|
|
||||||
* @param Model $model The model to transform.
|
|
||||||
* @return array The transformed model.
|
|
||||||
*/
|
|
||||||
protected function transformModel(Model $model)
|
|
||||||
{
|
|
||||||
$result = $this->transform($model);
|
|
||||||
foreach ($result as $key => $value) {
|
|
||||||
$transformFunction = 'transform' . Str::studly($key);
|
|
||||||
if (method_exists($this, $transformFunction) === true) {
|
|
||||||
$result[$key] = $this->$transformFunction($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $this->transformFinal($result);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform the passed Model to an array
|
|
||||||
*
|
|
||||||
* @param Model $model The model to transform.
|
|
||||||
* @return array The transformed model.
|
|
||||||
*/
|
|
||||||
public function transform(Model $model)
|
|
||||||
{
|
|
||||||
$result = $model->toArray();
|
|
||||||
|
|
||||||
$fields = $this->fields($model);
|
|
||||||
|
|
||||||
if (is_array($fields) === true) {
|
|
||||||
$result = array_intersect_key($result, array_flip($fields));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Final Transform of the model array
|
|
||||||
*
|
|
||||||
* @param array $data The model array to transform.
|
|
||||||
* @return array The transformed model.
|
|
||||||
*/
|
|
||||||
public function transformFinal(array $data)
|
|
||||||
{
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the passed model viewable by the current user?
|
|
||||||
*
|
|
||||||
* @param Model $model The model in question.
|
|
||||||
* @return boolean Is the model viewable.
|
|
||||||
*/
|
|
||||||
public static function viewable(Model $model)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the model creatable by the current user?
|
|
||||||
*
|
|
||||||
* @return boolean Is the model creatable.
|
|
||||||
*/
|
|
||||||
public static function creatable()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the passed model updatable by the current user?
|
|
||||||
*
|
|
||||||
* @param Model $model The model in question.
|
|
||||||
* @return boolean Is the model updatable.
|
|
||||||
*/
|
|
||||||
public static function updatable(Model $model)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the passed model destroyable by the current user?
|
|
||||||
*
|
|
||||||
* @param Model $model The model in question.
|
|
||||||
* @return boolean Is the model destroyable.
|
|
||||||
*/
|
|
||||||
public static function destroyable(Model $model)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Conductors;
|
|
||||||
|
|
||||||
use App\Models\Media;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\InvalidCastException;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class EventConductor extends Conductor
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The Model Class
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $class = '\App\Models\Event';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default sorting field
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $sort = '-start_at';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The included fields
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected $includes = ['attachments'];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run a scope query on the collection before anything else.
|
|
||||||
*
|
|
||||||
* @param Builder $builder The builder in use.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function scope(Builder $builder)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
if ($user === null || $user->hasPermission('admin/events') === false) {
|
|
||||||
$builder
|
|
||||||
->where('status', '!=', 'draft')
|
|
||||||
->where('publish_at', '<=', now());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is visible.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow model to be visible.
|
|
||||||
*/
|
|
||||||
public static function viewable(Model $model)
|
|
||||||
{
|
|
||||||
if (strtolower($model->status) === 'draft' || Carbon::parse($model->publish_at)->isFuture() === true) {
|
|
||||||
$user = auth()->user();
|
|
||||||
if ($user === null || $user->hasPermission('admin/events') === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is creatable.
|
|
||||||
*
|
|
||||||
* @return boolean Allow creating model.
|
|
||||||
*/
|
|
||||||
public static function creatable()
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/events') === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is updatable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow updating model.
|
|
||||||
*/
|
|
||||||
public static function updatable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/events') === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is destroyable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow deleting model.
|
|
||||||
*/
|
|
||||||
public static function destroyable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/events') === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Include Attachments Field.
|
|
||||||
*
|
|
||||||
* @param Model $model Them model.
|
|
||||||
* @return mixed The model result.
|
|
||||||
*/
|
|
||||||
public function includeAttachments(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
|
|
||||||
return $model->attachments()->get()->map(function ($attachment) use ($user) {
|
|
||||||
if ($attachment->private === false || ($user !== null && ($user->hasPermission('admin/events') === true || $attachment->users->contains($user) === true))) {
|
|
||||||
return MediaConductor::includeModel(request(), 'attachments', $attachment->media);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform the Hero field.
|
|
||||||
*
|
|
||||||
* @param mixed $value The current value.
|
|
||||||
* @return array The new value.
|
|
||||||
*/
|
|
||||||
public function transformHero(mixed $value)
|
|
||||||
{
|
|
||||||
return MediaConductor::includeModel(request(), 'hero', Media::find($value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Conductors;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Foundation\Auth\User;
|
|
||||||
|
|
||||||
class MediaConductor extends Conductor
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The Model Class
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $class = '\App\Models\Media';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default sorting field
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $sort = 'created_at';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The included fields
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected $includes = ['user'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default filters to use in a request.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $defaultFilters = [
|
|
||||||
'status' => 'OK'
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an array of model fields visible to the current user.
|
|
||||||
*
|
|
||||||
* @param Model $model The model in question.
|
|
||||||
* @return array The array of field names.
|
|
||||||
*/
|
|
||||||
public function fields(Model $model)
|
|
||||||
{
|
|
||||||
$fields = parent::fields($model);
|
|
||||||
|
|
||||||
$user = auth()->user();
|
|
||||||
if ($user === null || $user->hasPermission('admin/media') === false) {
|
|
||||||
$fields = arrayRemoveItem($fields, ['permission', 'storage']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run a scope query on the collection before anything else.
|
|
||||||
*
|
|
||||||
* @param Builder $builder The builder in use.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function scope(Builder $builder)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
if ($user === null) {
|
|
||||||
$builder->where('permission', '');
|
|
||||||
} else {
|
|
||||||
$builder->where('permission', '')->orWhereIn('permission', $user->permissions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is visible.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow model to be visible.
|
|
||||||
*/
|
|
||||||
public static function viewable(Model $model)
|
|
||||||
{
|
|
||||||
if ($model->permission !== '') {
|
|
||||||
$user = auth()->user();
|
|
||||||
if ($user === null || $user->hasPermission($model->permission) === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is creatable.
|
|
||||||
*
|
|
||||||
* @return boolean Allow creating model.
|
|
||||||
*/
|
|
||||||
public static function creatable()
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is updatable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow updating model.
|
|
||||||
*/
|
|
||||||
public static function updatable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && (strcasecmp($model->user_id, $user->id) === 0 || $user->hasPermission('admin/media') === true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is destroyable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow deleting model.
|
|
||||||
*/
|
|
||||||
public static function destroyable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && ($model->user_id === $user->id || $user->hasPermission('admin/media') === true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform the final model data
|
|
||||||
*
|
|
||||||
* @param array $data The model data to transform.
|
|
||||||
* @return array The transformed model.
|
|
||||||
*/
|
|
||||||
public function transformFinal(array $data)
|
|
||||||
{
|
|
||||||
unset($data['user_id']);
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Include User Field.
|
|
||||||
*
|
|
||||||
* @param Model $model Them model.
|
|
||||||
* @return mixed The model result.
|
|
||||||
*/
|
|
||||||
public function includeUser(Model $model)
|
|
||||||
{
|
|
||||||
return UserConductor::includeModel(request(), 'user', User::find($model['user_id']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Conductors;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Foundation\Auth\User;
|
|
||||||
|
|
||||||
class ShortlinkConductor extends Conductor
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The Model Class
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $class = '\App\Models\Shortlink';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default sorting field
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $sort = 'created_at';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is creatable.
|
|
||||||
*
|
|
||||||
* @return boolean Allow creating model.
|
|
||||||
*/
|
|
||||||
public static function creatable()
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/shortlinks') === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is updatable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow updating model.
|
|
||||||
*/
|
|
||||||
public static function updatable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/shortlinks') === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is destroyable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow deleting model.
|
|
||||||
*/
|
|
||||||
public static function destroyable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/shortlinks') === true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Conductors;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class SubscriptionConductor extends Conductor
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The Model Class
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $class = '\App\Models\Subscription';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is updatable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow updating model.
|
|
||||||
*/
|
|
||||||
public static function updatable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && ((strcasecmp($model->email, $user->email) === 0 && $user->email_verified_at !== null) || $user->hasPermission('admin/subscriptions') === true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is destroyable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow deleting model.
|
|
||||||
*/
|
|
||||||
public static function destroyable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && ((strcasecmp($model->email, $user->email) === 0 && $user->email_verified_at !== null) || $user->hasPermission('admin/subscriptions') === true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Conductors;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class UserConductor extends Conductor
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The Model Class
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $class = '\App\Models\User';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the visible API fields.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return string[] The fields visible.
|
|
||||||
*/
|
|
||||||
public function fields(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
if ($user === null || $user->hasPermission('admin/users') === false) {
|
|
||||||
return ['id', 'display_name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::fields($model);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform the passed Model to an array
|
|
||||||
*
|
|
||||||
* @param Model $model The model to transform.
|
|
||||||
* @return array The transformed model.
|
|
||||||
*/
|
|
||||||
public function transform(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
$data = $model->toArray();
|
|
||||||
|
|
||||||
if ($user === null || ($user->hasPermission('admin/users') === false && strcasecmp($user->id, $model->id) !== 0)) {
|
|
||||||
$fields = ['id', 'display_name'];
|
|
||||||
$data = arrayLimitKeys($data, $fields);
|
|
||||||
} else {
|
|
||||||
$data['permissions'] = $user->permissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is updatable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow updating model.
|
|
||||||
*/
|
|
||||||
public static function updatable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
if ($user !== null) {
|
|
||||||
return ($user->hasPermission('admin/users') === true || strcasecmp($user->id, $model->id) === 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return if the current model is destroyable.
|
|
||||||
*
|
|
||||||
* @param Model $model The model.
|
|
||||||
* @return boolean Allow deleting model.
|
|
||||||
*/
|
|
||||||
public static function destroyable(Model $model)
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
return ($user !== null && $user->hasPermission('admin/users') === true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use App\Jobs\StoreUploadedFileJob;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use App\Models\Media;
|
|
||||||
use File;
|
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
|
||||||
|
|
||||||
class MediaMigrate extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'media:migrate';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Migrate the uploads folder to the CDN';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure the command options.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function configure()
|
|
||||||
{
|
|
||||||
$this->addOption(
|
|
||||||
'replace',
|
|
||||||
null,
|
|
||||||
InputOption::VALUE_NONE,
|
|
||||||
'Replace existing files'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$replace = $this->option('replace');
|
|
||||||
|
|
||||||
$files = File::allFiles(public_path('uploads'));
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$filename = pathinfo($file, PATHINFO_BASENAME);
|
|
||||||
|
|
||||||
$medium = Media::where('name', $filename)->first();
|
|
||||||
|
|
||||||
if ($medium !== null) {
|
|
||||||
$medium->update(['status' => 'Processing media']);
|
|
||||||
StoreUploadedFileJob::dispatch($medium, $file, $replace)->onQueue('media');
|
|
||||||
} else {
|
|
||||||
unlink($file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use App\Jobs\StoreUploadedFileJob;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use App\Models\Media;
|
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
|
||||||
|
|
||||||
class MediaRebuild extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'media:rebuild';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Rebuild the media table';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure the command options.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function configure()
|
|
||||||
{
|
|
||||||
$this->addOption(
|
|
||||||
'replace',
|
|
||||||
null,
|
|
||||||
InputOption::VALUE_NONE,
|
|
||||||
'Replace existing files'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->addOption(
|
|
||||||
'all',
|
|
||||||
null,
|
|
||||||
InputOption::VALUE_NONE,
|
|
||||||
'Rebuild all variants'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$replace = $this->option('replace');
|
|
||||||
$all = $this->option('replace');
|
|
||||||
|
|
||||||
$media = [];
|
|
||||||
if ($all === true) {
|
|
||||||
$media = Media::all();
|
|
||||||
} else {
|
|
||||||
$media = Media::where(['variants' => ''])->orWhere(['variants' => '[]'])->orWhere(['variants' => '{}'])->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($media as $medium) {
|
|
||||||
StoreUploadedFileJob::dispatch($medium, '', $replace)->onQueue('media');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,23 +9,18 @@ class Kernel extends ConsoleKernel
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Define the application's command schedule.
|
* Define the application's command schedule.
|
||||||
*
|
|
||||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule The schedule.
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule): void
|
||||||
{
|
{
|
||||||
// $schedule->command('inspire')->hourly();
|
// $schedule->command('inspire')->hourly();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the commands for the application.
|
* Register the commands for the application.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
protected function commands()
|
protected function commands(): void
|
||||||
{
|
{
|
||||||
$this->load(__DIR__ . '/Commands');
|
$this->load(__DIR__.'/Commands');
|
||||||
|
|
||||||
require base_path('routes/console.php');
|
require base_path('routes/console.php');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,169 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Enum;
|
|
||||||
|
|
||||||
class CurlErrorCodes extends Enum
|
|
||||||
{
|
|
||||||
public const CURLE_UNSUPPORTED_PROTOCOL = 1;
|
|
||||||
public const CURLE_FAILED_INIT = 2;
|
|
||||||
public const CURLE_URL_MALFORMAT = 3;
|
|
||||||
public const CURLE_URL_MALFORMAT_USER = 4;
|
|
||||||
public const CURLE_COULDNT_RESOLVE_PROXY = 5;
|
|
||||||
public const CURLE_COULDNT_RESOLVE_HOST = 6;
|
|
||||||
public const CURLE_COULDNT_CONNECT = 7;
|
|
||||||
public const CURLE_FTP_WEIRD_SERVER_REPLY = 8;
|
|
||||||
public const CURLE_REMOTE_ACCESS_DENIED = 9;
|
|
||||||
public const CURLE_FTP_WEIRD_PASS_REPLY = 11;
|
|
||||||
public const CURLE_FTP_WEIRD_PASV_REPLY = 13;
|
|
||||||
public const CURLE_FTP_WEIRD_227_FORMAT = 14;
|
|
||||||
public const CURLE_FTP_CANT_GET_HOST = 15;
|
|
||||||
public const CURLE_FTP_COULDNT_SET_TYPE = 17;
|
|
||||||
public const CURLE_PARTIAL_FILE = 18;
|
|
||||||
public const CURLE_FTP_COULDNT_RETR_FILE = 19;
|
|
||||||
public const CURLE_QUOTE_ERROR = 21;
|
|
||||||
public const CURLE_HTTP_RETURNED_ERROR = 22;
|
|
||||||
public const CURLE_WRITE_ERROR = 23;
|
|
||||||
public const CURLE_UPLOAD_FAILED = 25;
|
|
||||||
public const CURLE_READ_ERROR = 26;
|
|
||||||
public const CURLE_OUT_OF_MEMORY = 27;
|
|
||||||
public const CURLE_OPERATION_TIMEDOUT = 28;
|
|
||||||
public const CURLE_FTP_PORT_FAILED = 30;
|
|
||||||
public const CURLE_FTP_COULDNT_USE_REST = 31;
|
|
||||||
public const CURLE_RANGE_ERROR = 33;
|
|
||||||
public const CURLE_HTTP_POST_ERROR = 34;
|
|
||||||
public const CURLE_SSL_CONNECT_ERROR = 35;
|
|
||||||
public const CURLE_BAD_DOWNLOAD_RESUME = 36;
|
|
||||||
public const CURLE_FILE_COULDNT_READ_FILE = 37;
|
|
||||||
public const CURLE_LDAP_CANNOT_BIND = 38;
|
|
||||||
public const CURLE_LDAP_SEARCH_FAILED = 39;
|
|
||||||
public const CURLE_FUNCTION_NOT_FOUND = 41;
|
|
||||||
public const CURLE_ABORTED_BY_CALLBACK = 42;
|
|
||||||
public const CURLE_BAD_FUNCTION_ARGUMENT = 43;
|
|
||||||
public const CURLE_INTERFACE_FAILED = 45;
|
|
||||||
public const CURLE_TOO_MANY_REDIRECTS = 47;
|
|
||||||
public const CURLE_UNKNOWN_TELNET_OPTION = 48;
|
|
||||||
public const CURLE_TELNET_OPTION_SYNTAX = 49;
|
|
||||||
public const CURLE_PEER_FAILED_VERIFICATION = 51;
|
|
||||||
public const CURLE_GOT_NOTHING = 52;
|
|
||||||
public const CURLE_SSL_ENGINE_NOTFOUND = 53;
|
|
||||||
public const CURLE_SSL_ENGINE_SETFAILED = 54;
|
|
||||||
public const CURLE_SEND_ERROR = 55;
|
|
||||||
public const CURLE_RECV_ERROR = 56;
|
|
||||||
public const CURLE_SSL_CERTPROBLEM = 58;
|
|
||||||
public const CURLE_SSL_CIPHER = 59;
|
|
||||||
public const CURLE_SSL_CACERT = 60;
|
|
||||||
public const CURLE_BAD_CONTENT_ENCODING = 61;
|
|
||||||
public const CURLE_LDAP_INVALID_URL = 62;
|
|
||||||
public const CURLE_FILESIZE_EXCEEDED = 63;
|
|
||||||
public const CURLE_USE_SSL_FAILED = 64;
|
|
||||||
public const CURLE_SEND_FAIL_REWIND = 65;
|
|
||||||
public const CURLE_SSL_ENGINE_INITFAILED = 66;
|
|
||||||
public const CURLE_LOGIN_DENIED = 67;
|
|
||||||
public const CURLE_TFTP_NOTFOUND = 68;
|
|
||||||
public const CURLE_TFTP_PERM = 69;
|
|
||||||
public const CURLE_REMOTE_DISK_FULL = 70;
|
|
||||||
public const CURLE_TFTP_ILLEGAL = 71;
|
|
||||||
public const CURLE_TFTP_UNKNOWNID = 72;
|
|
||||||
public const CURLE_REMOTE_FILE_EXISTS = 73;
|
|
||||||
public const CURLE_TFTP_NOSUCHUSER = 74;
|
|
||||||
public const CURLE_CONV_FAILED = 75;
|
|
||||||
public const CURLE_CONV_REQD = 76;
|
|
||||||
public const CURLE_SSL_CACERT_BADFILE = 77;
|
|
||||||
public const CURLE_REMOTE_FILE_NOT_FOUND = 78;
|
|
||||||
public const CURLE_SSH = 79;
|
|
||||||
public const CURLE_SSL_SHUTDOWN_FAILED = 80;
|
|
||||||
public const CURLE_AGAIN = 81;
|
|
||||||
public const CURLE_SSL_CRL_BADFILE = 82;
|
|
||||||
public const CURLE_SSL_ISSUER_ERROR = 83;
|
|
||||||
public const CURLE_FTP_PRET_FAILED = 84;
|
|
||||||
public const CURLE_RTSP_CSEQ_ERROR = 85;
|
|
||||||
public const CURLE_RTSP_SESSION_ERROR = 86;
|
|
||||||
public const CURLE_FTP_BAD_FILE_LIST = 87;
|
|
||||||
public const CURLE_CHUNK_FAILED = 88;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Curl Error messages
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
public static $messages = [
|
|
||||||
1 => 'Unsupported protocol.',
|
|
||||||
2 => 'Failed initalization.',
|
|
||||||
3 => 'Invalid URL format.',
|
|
||||||
4 => 'CURLE_URL_MALFORMAT_USER.',
|
|
||||||
5 => 'Could not resolve proxy.',
|
|
||||||
6 => 'Could not resolve host.',
|
|
||||||
7 => 'Could not connect to host.',
|
|
||||||
8 => 'Invalid reply from FTP server.',
|
|
||||||
9 => 'Access denied on host.',
|
|
||||||
11 => 'Invalid pass reply from FTP server.',
|
|
||||||
13 => 'Invalid pasv reply from FTP server.',
|
|
||||||
14 => 'Invalid 227 format from FTP server.',
|
|
||||||
15 => 'Could not get FTP host.',
|
|
||||||
17 => 'Could not set type for FTP transfer.',
|
|
||||||
18 => 'Invalid partial size.',
|
|
||||||
19 => 'Could not retrieve file from FTP server.',
|
|
||||||
21 => 'Quote error.',
|
|
||||||
22 => 'HTTP server returned error.',
|
|
||||||
23 => 'File write error.',
|
|
||||||
25 => 'Upload file error.',
|
|
||||||
26 => 'File read error.',
|
|
||||||
27 => 'Out of memory.',
|
|
||||||
28 => 'File transfer timed out.',
|
|
||||||
30 => 'Invalid port for FTP server.',
|
|
||||||
31 => 'Could not use rest for FTP server.',
|
|
||||||
33 => 'File range error.',
|
|
||||||
34 => 'Invalid POST for HTTP server.',
|
|
||||||
35 => 'SSL connectio error.',
|
|
||||||
36 => 'Invalid resume download.',
|
|
||||||
37 => 'Could not read file.',
|
|
||||||
38 => 'Could not bind to LDAP.',
|
|
||||||
39 => 'LDAP search failed.',
|
|
||||||
41 => 'Function not found.',
|
|
||||||
42 => 'Aborted by callback.',
|
|
||||||
43 => 'Bad function argument.',
|
|
||||||
45 => 'Interface failed.',
|
|
||||||
47 => 'Too many redirects.',
|
|
||||||
48 => 'Unknown telnet option.',
|
|
||||||
49 => 'Telnet option syntax invalid.',
|
|
||||||
51 => 'Peer failed verification.',
|
|
||||||
52 => 'Did not receive any data.',
|
|
||||||
53 => 'SSL engine was not found.',
|
|
||||||
54 => 'SSL engine failed.',
|
|
||||||
55 => 'Send data error.',
|
|
||||||
56 => 'Receive data error.',
|
|
||||||
58 => 'SSL certificate error.',
|
|
||||||
59 => 'SSL cipher error.',
|
|
||||||
60 => 'SSL CACertificate failed.',
|
|
||||||
61 => 'Invalid content encoding.',
|
|
||||||
62 => 'Invalid LDAP url.',
|
|
||||||
63 => 'Filesize exceeded.',
|
|
||||||
64 => 'SSL Failed.',
|
|
||||||
65 => 'CURLE_SEND_FAIL_REWIND.',
|
|
||||||
66 => 'SSL engine initalization failed.',
|
|
||||||
67 => 'CURLE_LOGIN_DENIED.',
|
|
||||||
68 => 'CURLE_TFTP_NOTFOUND.',
|
|
||||||
69 => 'CURLE_TFTP_PERM.',
|
|
||||||
70 => 'CURLE_REMOTE_DISK_FULL.',
|
|
||||||
71 => 'CURLE_TFTP_ILLEGAL.',
|
|
||||||
72 => 'CURLE_TFTP_UNKNOWNID.',
|
|
||||||
73 => 'Remote file already exists.',
|
|
||||||
74 => 'No such user on FTP server.',
|
|
||||||
75 => 'Conversion failed.',
|
|
||||||
76 => 'Conversion required.',
|
|
||||||
77 => 'SSL CACertificate bad file.',
|
|
||||||
78 => 'Remove file not found.',
|
|
||||||
79 => 'SSH error.',
|
|
||||||
80 => 'SSL Shutdown failed.',
|
|
||||||
81 => 'Again.',
|
|
||||||
82 => 'SSL bad CRL file.',
|
|
||||||
83 => 'SSL issuer error.',
|
|
||||||
84 => 'FTP pret failed.',
|
|
||||||
85 => 'CURLE_RTSP_CSEQ_ERROR.',
|
|
||||||
86 => 'CURLE_RTSP_SESSION_ERROR.',
|
|
||||||
87 => 'CURLE_FTP_BAD_FILE_LIST.',
|
|
||||||
88 => 'CURLE_CHUNK_FAILED.',
|
|
||||||
|
|
||||||
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Enum;
|
|
||||||
|
|
||||||
use ReflectionClass;
|
|
||||||
|
|
||||||
class Enum
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Message list
|
|
||||||
*
|
|
||||||
* @var array<string<static>>
|
|
||||||
*/
|
|
||||||
public static $messages = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Caches reflections of enum subclasses.
|
|
||||||
*
|
|
||||||
* @var array<class-string<static>, ReflectionClass<static>>
|
|
||||||
*/
|
|
||||||
public static $reflectionCache = [];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a reflection of the enum subclass.
|
|
||||||
*
|
|
||||||
* @return ReflectionClass<static>
|
|
||||||
*/
|
|
||||||
public static function getReflection(): ReflectionClass
|
|
||||||
{
|
|
||||||
$class = static::class;
|
|
||||||
|
|
||||||
return static::$reflectionCache[$class] ??= new ReflectionClass($class);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the constants in the enum subclass
|
|
||||||
*
|
|
||||||
* @return array<static>
|
|
||||||
*/
|
|
||||||
public static function getConstants(): array
|
|
||||||
{
|
|
||||||
return static::getReflection()->getConstants();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the constants values in the enum subclass
|
|
||||||
*
|
|
||||||
* @return array<static>
|
|
||||||
*/
|
|
||||||
public static function getConstantValues(): array
|
|
||||||
{
|
|
||||||
return array_values(static::getReflection()->getConstants());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a message from the enum subclass
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getMessage(int $messageIndex, string $defaultMessage = 'Unknown'): string
|
|
||||||
{
|
|
||||||
if (array_key_exists($messageIndex, self::$messages) === true) {
|
|
||||||
return self::$messages[$messageIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $defaultMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Enum;
|
|
||||||
|
|
||||||
class HttpResponseCodes extends Enum
|
|
||||||
{
|
|
||||||
public const HTTP_CONTINUE = 100;
|
|
||||||
public const HTTP_SWITCHING_PROTOCOLS = 101;
|
|
||||||
public const HTTP_PROCESSING = 102;
|
|
||||||
|
|
||||||
public const HTTP_OK = 200;
|
|
||||||
public const HTTP_CREATED = 201;
|
|
||||||
public const HTTP_ACCEPTED = 202;
|
|
||||||
public const HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
|
|
||||||
public const HTTP_NO_CONTENT = 204;
|
|
||||||
public const HTTP_RESET_CONTENT = 205;
|
|
||||||
public const HTTP_PARTIAL_CONTENT = 206;
|
|
||||||
public const HTTP_MULTI_STATUS = 207;
|
|
||||||
|
|
||||||
public const HTTP_ALREADY_REPORTED = 208;
|
|
||||||
|
|
||||||
public const HTTP_IM_USED = 226;
|
|
||||||
|
|
||||||
public const HTTP_MULTIPLE_CHOICES = 300;
|
|
||||||
public const HTTP_MOVED_PERMANENTLY = 301;
|
|
||||||
public const HTTP_FOUND = 302;
|
|
||||||
public const HTTP_SEE_OTHER = 303;
|
|
||||||
public const HTTP_NOT_MODIFIED = 304;
|
|
||||||
public const HTTP_USE_PROXY = 305;
|
|
||||||
public const HTTP_RESERVED = 306;
|
|
||||||
public const HTTP_TEMPORARY_REDIRECT = 307;
|
|
||||||
public const HTTP_PERMANENTLY_REDIRECT = 308;
|
|
||||||
|
|
||||||
public const HTTP_BAD_REQUEST = 400;
|
|
||||||
public const HTTP_UNAUTHORIZED = 401;
|
|
||||||
public const HTTP_PAYMENT_REQUIRED = 402;
|
|
||||||
public const HTTP_FORBIDDEN = 403;
|
|
||||||
public const HTTP_NOT_FOUND = 404;
|
|
||||||
public const HTTP_METHOD_NOT_ALLOWED = 405;
|
|
||||||
public const HTTP_NOT_ACCEPTABLE = 406;
|
|
||||||
public const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407;
|
|
||||||
public const HTTP_REQUEST_TIMEOUT = 408;
|
|
||||||
public const HTTP_CONFLICT = 409;
|
|
||||||
public const HTTP_GONE = 410;
|
|
||||||
public const HTTP_LENGTH_REQUIRED = 411;
|
|
||||||
public const HTTP_PRECONDITION_FAILED = 412;
|
|
||||||
public const HTTP_REQUEST_ENTITY_TOO_LARGE = 413;
|
|
||||||
public const HTTP_REQUEST_URI_TOO_LONG = 414;
|
|
||||||
public const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
|
|
||||||
public const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
|
|
||||||
public const HTTP_EXPECTATION_FAILED = 417;
|
|
||||||
public const HTTP_I_AM_A_TEAPOT = 418;
|
|
||||||
|
|
||||||
public const HTTP_MISDIRECTED_REQUEST = 421;
|
|
||||||
public const HTTP_UNPROCESSABLE_ENTITY = 422;
|
|
||||||
public const HTTP_LOCKED = 423;
|
|
||||||
public const HTTP_FAILED_DEPENDENCY = 424;
|
|
||||||
public const HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL = 425;
|
|
||||||
public const HTTP_UPGRADE_REQUIRED = 426;
|
|
||||||
public const HTTP_PRECONDITION_REQUIRED = 428;
|
|
||||||
public const HTTP_TOO_MANY_REQUESTS = 429;
|
|
||||||
public const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
|
|
||||||
public const HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451;
|
|
||||||
|
|
||||||
public const HTTP_INTERNAL_SERVER_ERROR = 500;
|
|
||||||
public const HTTP_NOT_IMPLEMENTED = 501;
|
|
||||||
public const HTTP_BAD_GATEWAY = 502;
|
|
||||||
public const HTTP_SERVICE_UNAVAILABLE = 503;
|
|
||||||
public const HTTP_GATEWAY_TIMEOUT = 504;
|
|
||||||
public const HTTP_VERSION_NOT_SUPPORTED = 505;
|
|
||||||
public const HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506;
|
|
||||||
public const HTTP_INSUFFICIENT_STORAGE = 507;
|
|
||||||
public const HTTP_LOOP_DETECTED = 508;
|
|
||||||
public const HTTP_NOT_EXTENDED = 510;
|
|
||||||
public const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HTTP Response Messages
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
public static $statusTexts = [
|
|
||||||
100 => 'Continue.',
|
|
||||||
101 => 'Switching Protocols.',
|
|
||||||
102 => 'Processing.',
|
|
||||||
// RFC2518
|
|
||||||
200 => 'OK.',
|
|
||||||
201 => 'Created.',
|
|
||||||
202 => 'Accepted.',
|
|
||||||
203 => 'Non-Authoritative Information.',
|
|
||||||
204 => 'No Content.',
|
|
||||||
205 => 'Reset Content.',
|
|
||||||
206 => 'Partial Content.',
|
|
||||||
207 => 'Multi-Status.',
|
|
||||||
// RFC4918
|
|
||||||
208 => 'Already Reported.',
|
|
||||||
// RFC5842
|
|
||||||
226 => 'IM Used.',
|
|
||||||
// RFC3229
|
|
||||||
300 => 'Multiple Choices.',
|
|
||||||
301 => 'Moved Permanently.',
|
|
||||||
302 => 'Found.',
|
|
||||||
303 => 'See Other.',
|
|
||||||
304 => 'Not Modified.',
|
|
||||||
305 => 'Use Proxy.',
|
|
||||||
307 => 'Temporary Redirect.',
|
|
||||||
308 => 'Permanent Redirect.',
|
|
||||||
// RFC7238
|
|
||||||
400 => 'Bad Request.',
|
|
||||||
401 => 'Unauthorized.',
|
|
||||||
402 => 'Payment Required.',
|
|
||||||
403 => 'Forbidden.',
|
|
||||||
404 => 'Not Found.',
|
|
||||||
405 => 'Method Not Allowed.',
|
|
||||||
406 => 'Not Acceptable.',
|
|
||||||
407 => 'Proxy Authentication Required.',
|
|
||||||
408 => 'Request Timeout.',
|
|
||||||
409 => 'Conflict.',
|
|
||||||
410 => 'Gone.',
|
|
||||||
411 => 'Length Required.',
|
|
||||||
412 => 'Precondition Failed.',
|
|
||||||
413 => 'Payload Too Large.',
|
|
||||||
414 => 'URI Too Long.',
|
|
||||||
415 => 'Unsupported Media Type.',
|
|
||||||
416 => 'Range Not Satisfiable.',
|
|
||||||
417 => 'Expectation Failed.',
|
|
||||||
418 => 'I\'m a teapot.',
|
|
||||||
// RFC2324
|
|
||||||
421 => 'Misdirected Request.',
|
|
||||||
// RFC7540
|
|
||||||
422 => 'Unprocessable Entity.',
|
|
||||||
// RFC4918
|
|
||||||
423 => 'Locked.',
|
|
||||||
// RFC4918
|
|
||||||
424 => 'Failed Dependency.',
|
|
||||||
// RFC4918
|
|
||||||
425 => 'Reserved for WebDAV advanced collections expired proposal.',
|
|
||||||
// RFC2817
|
|
||||||
426 => 'Upgrade Required.',
|
|
||||||
// RFC2817
|
|
||||||
428 => 'Precondition Required.',
|
|
||||||
// RFC6585
|
|
||||||
429 => 'Too Many Requests.',
|
|
||||||
// RFC6585
|
|
||||||
431 => 'Request Header Fields Too Large.',
|
|
||||||
// RFC6585
|
|
||||||
451 => 'Unavailable For Legal Reasons.',
|
|
||||||
// RFC7725
|
|
||||||
500 => 'Internal Server Error.',
|
|
||||||
501 => 'Not Implemented.',
|
|
||||||
502 => 'Bad Gateway.',
|
|
||||||
503 => 'Service Unavailable.',
|
|
||||||
504 => 'Gateway Timeout.',
|
|
||||||
505 => 'HTTP Version Not Supported.',
|
|
||||||
506 => 'Variant Also Negotiates.',
|
|
||||||
// RFC2295
|
|
||||||
507 => 'Insufficient Storage.',
|
|
||||||
// RFC4918
|
|
||||||
508 => 'Loop Detected.',
|
|
||||||
// RFC5842
|
|
||||||
510 => 'Not Extended.',
|
|
||||||
// RFC2774
|
|
||||||
511 => 'Network Authentication Required.',
|
|
||||||
// RFC6585
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -2,36 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Exceptions;
|
namespace App\Exceptions;
|
||||||
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use Exception;
|
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use PDOException;
|
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* A list of exception types with their corresponding custom log levels.
|
* The list of the inputs that are never flashed to the session on validation exceptions.
|
||||||
*
|
|
||||||
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
|
|
||||||
*/
|
|
||||||
protected $levels = [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of the exception types that are not reported.
|
|
||||||
*
|
|
||||||
* @var array<int, class-string<\Throwable>>
|
|
||||||
*/
|
|
||||||
protected $dontReport = [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of the inputs that are never flashed to the session on validation exceptions.
|
|
||||||
*
|
*
|
||||||
* @var array<int, string>
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
@@ -41,43 +18,11 @@ class Handler extends ExceptionHandler
|
|||||||
'password_confirmation',
|
'password_confirmation',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the exception handling callbacks for the application.
|
* Register the exception handling callbacks for the application.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register(): void
|
||||||
{
|
{
|
||||||
// $this->renderable(function (HttpException $e, $request) {
|
|
||||||
// if ($request->is('api/*')) {
|
|
||||||
// $message = $e->getMessage();
|
|
||||||
// if ($message === '') {
|
|
||||||
// $message = HttpResponseCodes::$statusTexts[$e->getStatusCode()];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return response()->json([
|
|
||||||
// 'message' => $message
|
|
||||||
// ], $e->getStatusCode());
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
$this->renderable(function (NotFoundHttpException $e, $request) {
|
|
||||||
if ($request->is('api/*') === true) {
|
|
||||||
return response()->json([
|
|
||||||
'message' => 'Resource not found'
|
|
||||||
], 404);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->renderable(function (PDOException $e, $request) {
|
|
||||||
if ($request->is('api/*') === true) {
|
|
||||||
return response()->json([
|
|
||||||
'message' => 'The server is currently unavailable'
|
|
||||||
], 503);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->reportable(function (Throwable $e) {
|
$this->reportable(function (Throwable $e) {
|
||||||
//
|
//
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Filters;
|
|
||||||
|
|
||||||
use App\Models\Subscriber;
|
|
||||||
|
|
||||||
class SubscriptionFilter extends FilterAbstract
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The model class to filter
|
|
||||||
*
|
|
||||||
* @var mixed
|
|
||||||
*/
|
|
||||||
protected $class = '\App\Models\Subscription';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an array of attributes visible in the results
|
|
||||||
*
|
|
||||||
* @param array $attributes Attributes currently visible.
|
|
||||||
* @param User|null $user Current logged in user or null.
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
protected function seeAttributes(array $attributes, mixed $user)
|
|
||||||
{
|
|
||||||
if ($user?->hasPermission('admin/users') !== true) {
|
|
||||||
return ['id', 'email', 'confirmed_at'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/* Array Helper Functions */
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove an item from an array.
|
|
||||||
*
|
|
||||||
* @param array $arr The array to check.
|
|
||||||
* @param string|array $item The item or items to remove.
|
|
||||||
* @return array The filtered array.
|
|
||||||
*/
|
|
||||||
function arrayRemoveItem(array $arr, string|array $item): array
|
|
||||||
{
|
|
||||||
$filteredArr = $arr;
|
|
||||||
|
|
||||||
if (is_string($item) === true) {
|
|
||||||
$item = [$item];
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($item as $str) {
|
|
||||||
$filteredArr = array_filter($arr, function ($item) use ($str) {
|
|
||||||
return $item !== $str;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return $filteredArr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an array with specified the keys
|
|
||||||
*
|
|
||||||
* @param array $arr The array to filter.
|
|
||||||
* @param string|array $keys The keys to keep.
|
|
||||||
* @return array The filtered array.
|
|
||||||
*/
|
|
||||||
function arrayLimitKeys(array $arr, array $keys): array
|
|
||||||
{
|
|
||||||
return array_intersect_key($arr, array_flip($keys));
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/* Temp File Helper Functions */
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a temporary file path.
|
|
||||||
*
|
|
||||||
* @return str The filtered array.
|
|
||||||
*/
|
|
||||||
function generateTempFilePath(): string
|
|
||||||
{
|
|
||||||
$temporaryDir = storage_path('app/tmp');
|
|
||||||
if (is_dir($temporaryDir) === false) {
|
|
||||||
mkdir($temporaryDir, 0777, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $temporaryDir . DIRECTORY_SEPARATOR . uniqid('upload_', true);
|
|
||||||
}
|
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Conductors\AnalyticsConductor;
|
|
||||||
use App\Conductors\Conductor;
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use App\Http\Requests\AnalyticsRequest;
|
|
||||||
use App\Models\Media;
|
|
||||||
use App\Models\Analytics;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
use Carbon\Exceptions\InvalidFormatException;
|
|
||||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
|
||||||
use Illuminate\Database\Eloquent\InvalidCastException;
|
|
||||||
use Illuminate\Database\Eloquent\MassAssignmentException;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class AnalyticsController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* AnalyticsController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('auth:sanctum')
|
|
||||||
->only([
|
|
||||||
'index',
|
|
||||||
'update',
|
|
||||||
'delete'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index(Request $request)
|
|
||||||
{
|
|
||||||
if ($request->user() !== null && $request->user()?->hasPermission('admin/analytics') === true) {
|
|
||||||
$searchFields = ['attribute', 'type', 'useragent', 'ip'];
|
|
||||||
|
|
||||||
$queryRequest = new Request();
|
|
||||||
$queryRequest->merge($request->only($searchFields));
|
|
||||||
foreach ($searchFields as $field) {
|
|
||||||
unset($request[$field]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = Analytics::query()
|
|
||||||
->selectRaw('session,
|
|
||||||
MIN(created_at) as created_at,
|
|
||||||
TIMESTAMPDIFF(MINUTE, MIN(created_at), MAX(created_at)) as duration');
|
|
||||||
$query = Conductor::filterQuery($query, $queryRequest);
|
|
||||||
|
|
||||||
list($collection, $total) = AnalyticsConductor::collection($request, $query
|
|
||||||
->groupBy('session')
|
|
||||||
->get());
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
$collection,
|
|
||||||
['isCollection' => true,
|
|
||||||
'appendData' => ['total' => $total]
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @param \App\Models\Analytics $analytics The analyics model.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(Request $request, int $session)
|
|
||||||
{
|
|
||||||
if ($request->user() !== null && $request->user()?->hasPermission('admin/analytics') === true) {
|
|
||||||
list($collection, $total) = AnalyticsConductor::collection($request, Analytics::query()
|
|
||||||
->where('session', $session)
|
|
||||||
->get());
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
$collection,
|
|
||||||
['isCollection' => true,
|
|
||||||
'appendData' => ['total' => $total]
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\AnalyticsRequest $request The user request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function store(AnalyticsRequest $request)
|
|
||||||
{
|
|
||||||
if (AnalyticsConductor::creatable() === true) {
|
|
||||||
$analytics = null;
|
|
||||||
$user = $request->user();
|
|
||||||
|
|
||||||
$data = [
|
|
||||||
'type' => $request->input('type'),
|
|
||||||
'attribute' => $request->input('attribute', ''),
|
|
||||||
'useragent' => $request->userAgent(),
|
|
||||||
'ip' => $request->ip()
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($user !== null && $user->hasPermission('admin/analytics') === true && $request->has('session') === true) {
|
|
||||||
$data['session'] = $request->input('session');
|
|
||||||
$analytics = Analytics::create($data);
|
|
||||||
} else {
|
|
||||||
$analytics = Analytics::createWithSession($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
AnalyticsConductor::model($request, $analytics),
|
|
||||||
['respondCode' => HttpResponseCodes::HTTP_CREATED]
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}//end if
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the specified resource in storage.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\AnalyticsRequest $request The analytics update request.
|
|
||||||
* @param \App\Models\Analytics $analytics The specified analytics.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function update(AnalyticsRequest $request, Analytics $analytics)
|
|
||||||
{
|
|
||||||
if (AnalyticsConductor::updatable($analytics) === true) {
|
|
||||||
$analytics->update($request->all());
|
|
||||||
return $this->respondAsResource(AnalyticsConductor::model($request, $analytics));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the specified resource from storage.
|
|
||||||
*
|
|
||||||
* @param \App\Models\Analytics $analytics The specified analytics.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function destroy(Analytics $analytics)
|
|
||||||
{
|
|
||||||
if (AnalyticsConductor::destroyable($analytics) === true) {
|
|
||||||
$analytics->delete();
|
|
||||||
return $this->respondNoContent();
|
|
||||||
} else {
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,192 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class ApiController extends Controller
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Resource name
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $resourceName = '';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return generic json response with the given data.
|
|
||||||
*
|
|
||||||
* @param array $data Response data.
|
|
||||||
* @param integer $respondCode Response status code.
|
|
||||||
* @param array $headers Response headers.
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function respondJson(array $data, int $respondCode = HttpResponseCodes::HTTP_OK, array $headers = [])
|
|
||||||
{
|
|
||||||
return response()->json($data, $respondCode, $headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return forbidden message
|
|
||||||
*
|
|
||||||
* @param string $message Response message.
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function respondForbidden(string $message = 'You do not have permission to access the resource.')
|
|
||||||
{
|
|
||||||
return response()->json(['message' => $message], HttpResponseCodes::HTTP_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return forbidden message
|
|
||||||
*
|
|
||||||
* @param string $message Response message.
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function respondNotFound(string $message = 'The resource was not found.')
|
|
||||||
{
|
|
||||||
return response()->json(['message' => $message], HttpResponseCodes::HTTP_NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return too large message
|
|
||||||
*
|
|
||||||
* @param string $message Response message.
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function respondTooLarge(string $message = 'The request entity is too large.')
|
|
||||||
{
|
|
||||||
return response()->json(['message' => $message], HttpResponseCodes::HTTP_REQUEST_ENTITY_TOO_LARGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return no content
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function respondNoContent()
|
|
||||||
{
|
|
||||||
return response()->json([], HttpResponseCodes::HTTP_NO_CONTENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return created
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function respondCreated()
|
|
||||||
{
|
|
||||||
return response()->json([], HttpResponseCodes::HTTP_CREATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return accepted
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function respondAccepted()
|
|
||||||
{
|
|
||||||
return response()->json([], HttpResponseCodes::HTTP_ACCEPTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return single error message
|
|
||||||
*
|
|
||||||
* @param string $message Error message.
|
|
||||||
* @param integer $responseCode Resource code.
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function respondError(string $message, int $responseCode = HttpResponseCodes::HTTP_UNPROCESSABLE_ENTITY)
|
|
||||||
{
|
|
||||||
return response()->json([
|
|
||||||
'message' => $message
|
|
||||||
], $responseCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return formatted errors
|
|
||||||
*
|
|
||||||
* @param array $errors Error messages.
|
|
||||||
* @param integer $responseCode Resource code.
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function respondWithErrors(array $errors, int $responseCode = HttpResponseCodes::HTTP_UNPROCESSABLE_ENTITY)
|
|
||||||
{
|
|
||||||
$keys = array_keys($errors);
|
|
||||||
$error = $errors[$keys[0]];
|
|
||||||
|
|
||||||
if (count($keys) > 1) {
|
|
||||||
$additional_errors = (count($keys) - 1);
|
|
||||||
$error .= sprintf(' (and %d more %s', $additional_errors, Str::plural('error', $additional_errors));
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'message' => $error,
|
|
||||||
'errors' => $errors
|
|
||||||
], $responseCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return resource data
|
|
||||||
*
|
|
||||||
* @param array|Model|Collection $data Resource data.
|
|
||||||
* @param array $options Respond options.
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
protected function respondAsResource(
|
|
||||||
mixed $data,
|
|
||||||
array $options = [],
|
|
||||||
$validationFn = null
|
|
||||||
) {
|
|
||||||
$isCollection = $options['isCollection'] ?? false;
|
|
||||||
$appendData = $options['appendData'] ?? null;
|
|
||||||
$resourceName = $options['resourceName'] ?? null;
|
|
||||||
$respondCode = ($options['respondCode'] ?? HttpResponseCodes::HTTP_OK);
|
|
||||||
|
|
||||||
if ($data === null || ($data instanceof Collection && $data->count() === 0)) {
|
|
||||||
$validationData = [];
|
|
||||||
if (array_key_exists('appendData', $options) === true) {
|
|
||||||
$validationData = $options['appendData'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($validationFn === null || $validationFn($validationData) === true) {
|
|
||||||
return $this->respondNotFound();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($resourceName) === true || empty($resourceName) === true) {
|
|
||||||
$resourceName = $this->resourceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($resourceName) === true || empty($resourceName) === true) {
|
|
||||||
$resourceName = get_class($this);
|
|
||||||
$resourceName = substr($resourceName, (strrpos($resourceName, '\\') + 1));
|
|
||||||
$resourceName = substr($resourceName, 0, strpos($resourceName, 'Controller'));
|
|
||||||
$resourceName = strtolower($resourceName);
|
|
||||||
}
|
|
||||||
|
|
||||||
$dataArray = [];
|
|
||||||
if ($data instanceof Collection) {
|
|
||||||
$dataArray = $data->toArray();
|
|
||||||
} elseif (is_array($data) === true) {
|
|
||||||
$dataArray = $data;
|
|
||||||
} elseif ($data instanceof Model) {
|
|
||||||
$is_multiple = false;
|
|
||||||
$dataArray = $data->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
$resource = [];
|
|
||||||
if ($isCollection === true) {
|
|
||||||
$resource = [Str::plural($resourceName) => $dataArray];
|
|
||||||
} else {
|
|
||||||
$resource = [Str::singular($resourceName) => $dataArray];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($appendData !== null) {
|
|
||||||
$resource += $appendData;
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json($resource, $respondCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,247 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Conductors\MediaConductor;
|
|
||||||
use App\Conductors\ArticleConductor;
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use App\Http\Requests\ArticleRequest;
|
|
||||||
use App\Models\Media;
|
|
||||||
use App\Models\Article;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
use Carbon\Exceptions\InvalidFormatException;
|
|
||||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
|
||||||
use Illuminate\Database\Eloquent\InvalidCastException;
|
|
||||||
use Illuminate\Database\Eloquent\MassAssignmentException;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class ArticleController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* ApplicationController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('auth:sanctum')
|
|
||||||
->only([
|
|
||||||
'store',
|
|
||||||
'update',
|
|
||||||
'delete'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index(Request $request)
|
|
||||||
{
|
|
||||||
list($collection, $total) = ArticleConductor::request($request);
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
$collection,
|
|
||||||
['isCollection' => true,
|
|
||||||
'appendData' => ['total' => $total]
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @param \App\Models\Article $article The article model.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(Request $request, Article $article)
|
|
||||||
{
|
|
||||||
if (ArticleConductor::viewable($article) === true) {
|
|
||||||
return $this->respondAsResource(ArticleConductor::model($request, $article));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\ArticleRequest $request The user request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function store(ArticleRequest $request)
|
|
||||||
{
|
|
||||||
if (ArticleConductor::creatable() === true) {
|
|
||||||
$article = Article::create($request->all());
|
|
||||||
return $this->respondAsResource(
|
|
||||||
ArticleConductor::model($request, $article),
|
|
||||||
['respondCode' => HttpResponseCodes::HTTP_CREATED]
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the specified resource in storage.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\ArticleRequest $request The article update request.
|
|
||||||
* @param \App\Models\Article $article The specified article.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function update(ArticleRequest $request, Article $article)
|
|
||||||
{
|
|
||||||
if (ArticleConductor::updatable($article) === true) {
|
|
||||||
$article->update($request->all());
|
|
||||||
return $this->respondAsResource(ArticleConductor::model($request, $article));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the specified resource from storage.
|
|
||||||
*
|
|
||||||
* @param \App\Models\Article $article The specified article.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function destroy(Article $article)
|
|
||||||
{
|
|
||||||
if (ArticleConductor::destroyable($article) === true) {
|
|
||||||
$article->delete();
|
|
||||||
return $this->respondNoContent();
|
|
||||||
} else {
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of attachments related to this model.
|
|
||||||
*
|
|
||||||
* @param Request $request The user request.
|
|
||||||
* @param Article $article The article model.
|
|
||||||
* @return JsonResponse Returns the article attachments.
|
|
||||||
* @throws InvalidFormatException
|
|
||||||
* @throws BindingResolutionException
|
|
||||||
* @throws InvalidCastException
|
|
||||||
*/
|
|
||||||
public function getAttachments(Request $request, Article $article)
|
|
||||||
{
|
|
||||||
if (ArticleConductor::viewable($article) === true) {
|
|
||||||
$medium = $article->attachments->map(function ($attachment) {
|
|
||||||
return $attachment->media;
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this->respondAsResource(MediaConductor::collection($request, $medium), ['isCollection' => true, 'resourceName' => 'attachment']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store an attachment related to this model.
|
|
||||||
*
|
|
||||||
* @param Request $request The user request.
|
|
||||||
* @param Article $article The article model.
|
|
||||||
* @return JsonResponse The response.
|
|
||||||
* @throws BindingResolutionException
|
|
||||||
* @throws MassAssignmentException
|
|
||||||
*/
|
|
||||||
public function storeAttachment(Request $request, Article $article)
|
|
||||||
{
|
|
||||||
if (ArticleConductor::updatable($article) === true) {
|
|
||||||
if ($request->has("medium") && Media::find($request->medium)) {
|
|
||||||
$article->attachments()->create(['media_id' => $request->medium]);
|
|
||||||
return $this->respondCreated();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondWithErrors(['media' => 'The media ID was not found']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update/replace attachments related to this model.
|
|
||||||
*
|
|
||||||
* @param Request $request The user request.
|
|
||||||
* @param Article $article The related model.
|
|
||||||
* @return JsonResponse
|
|
||||||
* @throws BindingResolutionException
|
|
||||||
* @throws MassAssignmentException
|
|
||||||
*/
|
|
||||||
public function updateAttachments(Request $request, Article $article)
|
|
||||||
{
|
|
||||||
if (ArticleConductor::updatable($article) === true) {
|
|
||||||
$mediaIds = $request->attachments;
|
|
||||||
if (is_array($mediaIds) === false) {
|
|
||||||
$mediaIds = explode(',', $request->attachments);
|
|
||||||
}
|
|
||||||
|
|
||||||
$mediaIds = array_map('trim', $mediaIds); // trim each media ID
|
|
||||||
$attachments = $article->attachments;
|
|
||||||
|
|
||||||
// Delete attachments that are not in $mediaIds
|
|
||||||
foreach ($attachments as $attachment) {
|
|
||||||
if (!in_array($attachment->media_id, $mediaIds)) {
|
|
||||||
$attachment->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new attachments for media IDs that are not already in $article->attachments()
|
|
||||||
foreach ($mediaIds as $mediaId) {
|
|
||||||
$found = false;
|
|
||||||
|
|
||||||
foreach ($attachments as $attachment) {
|
|
||||||
if ($attachment->media_id == $mediaId) {
|
|
||||||
$found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$found) {
|
|
||||||
$article->attachments()->create(['media_id' => $mediaId]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a specific related attachment.
|
|
||||||
* @param Request $request The user request.
|
|
||||||
* @param Article $article The model.
|
|
||||||
* @param Media $medium The attachment medium.
|
|
||||||
* @return JsonResponse
|
|
||||||
* @throws BindingResolutionException
|
|
||||||
*/
|
|
||||||
public function deleteAttachment(Request $request, Article $article, Media $medium)
|
|
||||||
{
|
|
||||||
if (ArticleConductor::updatable($article) === true) {
|
|
||||||
$attachments = $article->attachments;
|
|
||||||
$deleted = false;
|
|
||||||
|
|
||||||
foreach ($attachments as $attachment) {
|
|
||||||
if ($attachment->media_id === $medium->id) {
|
|
||||||
$attachment->delete();
|
|
||||||
$deleted = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($deleted) {
|
|
||||||
// Attachment was deleted successfully
|
|
||||||
return $this->respondNoContent();
|
|
||||||
} else {
|
|
||||||
// Attachment with matching media ID was not found
|
|
||||||
return $this->respondNotFound();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Models\Attachment;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class AttachmentController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* ApplicationController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('auth:sanctum')
|
|
||||||
->except(['store', 'destroyByEmail']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function store(Request $request)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param \App\Models\Attachment $attachment
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(Attachment $attachment)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the form for editing the specified resource.
|
|
||||||
*
|
|
||||||
* @param \App\Models\Attachment $attachment
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function edit(Attachment $attachment)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the specified resource in storage.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @param \App\Models\Attachment $attachment
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function update(Request $request, Attachment $attachment)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the specified resource from storage.
|
|
||||||
*
|
|
||||||
* @param \App\Models\Attachment $attachment
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function destroy(Attachment $attachment)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use App\Http\Requests\AuthLoginRequest;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
|
|
||||||
class AuthController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Resource name
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $resourceName = 'user';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ApplicationController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
// $this->middleware('auth:sanctum')
|
|
||||||
// ->only(['me']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Current User details
|
|
||||||
*
|
|
||||||
* @param Request $request Current request data.
|
|
||||||
* @return JsonResponse
|
|
||||||
*/
|
|
||||||
public function me(Request $request)
|
|
||||||
{
|
|
||||||
$user = $request->user()->makeVisible(['permissions']);
|
|
||||||
return $this->respondAsResource($user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Login user with supplied creditials
|
|
||||||
*
|
|
||||||
* @param App\Http\Controllers\Api\AuthLoginRequest $request Created request data.
|
|
||||||
* @return JsonResponse|void
|
|
||||||
*/
|
|
||||||
public function login(AuthLoginRequest $request)
|
|
||||||
{
|
|
||||||
$user = User::where('email', '=', $request->input('email'))->first();
|
|
||||||
|
|
||||||
if ($user !== null && strlen($user->password) > 0 && Hash::check($request->input('password'), $user->password) === true) {
|
|
||||||
if ($user->email_verified_at === null) {
|
|
||||||
return $this->respondWithErrors([
|
|
||||||
'email' => 'Email address has not been verified.'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($user->disabled === true) {
|
|
||||||
return $this->respondWithErrors([
|
|
||||||
'email' => 'Account has been disabled.'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$token = $user->createToken('user_token')->plainTextToken;
|
|
||||||
|
|
||||||
$user->logins()->create([
|
|
||||||
'token' => $token,
|
|
||||||
'login' => now(),
|
|
||||||
'ip_address' => $request->ip(),
|
|
||||||
'user_agent' => $request->userAgent()
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
$user->makeVisible(['permissions']),
|
|
||||||
['appendData' => ['token' => $token]]
|
|
||||||
);
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondWithErrors([
|
|
||||||
'email' => 'Invalid email or password',
|
|
||||||
'password' => 'Invalid email or password',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logout current user
|
|
||||||
*
|
|
||||||
* @param Request $request Current request data.
|
|
||||||
* @return JsonResponse
|
|
||||||
*/
|
|
||||||
public function logout(Request $request)
|
|
||||||
{
|
|
||||||
$user = $request->user();
|
|
||||||
|
|
||||||
$user->logins()->where('token', $user->currentAccessToken())->update(['logout' => now()]);
|
|
||||||
$user->currentAccessToken()->delete();
|
|
||||||
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Http\Requests\ContactSendRequest;
|
|
||||||
use App\Jobs\SendEmailJob;
|
|
||||||
use App\Mail\Contact;
|
|
||||||
|
|
||||||
class ContactController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Send the request to the site admin by email
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\User\ContactSendRequest $request Request data.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function send(ContactSendRequest $request)
|
|
||||||
{
|
|
||||||
dispatch((new SendEmailJob(
|
|
||||||
config('contact.contact_address'),
|
|
||||||
new Contact(
|
|
||||||
$request->input('name'),
|
|
||||||
$request->input('email'),
|
|
||||||
$request->input('content')
|
|
||||||
)
|
|
||||||
)))->onQueue('mail');
|
|
||||||
|
|
||||||
return $this->respondCreated();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,311 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use App\Models\Event;
|
|
||||||
use App\Conductors\EventConductor;
|
|
||||||
use App\Conductors\MediaConductor;
|
|
||||||
use App\Conductors\UserConductor;
|
|
||||||
use App\Http\Requests\EventRequest;
|
|
||||||
use App\Models\Media;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class EventController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* ApplicationController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('auth:sanctum')
|
|
||||||
->only(['store','update','destroy', 'userAdd', 'userUpdate', 'userDelete']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index(Request $request)
|
|
||||||
{
|
|
||||||
list($collection, $total) = EventConductor::request($request);
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
$collection,
|
|
||||||
['isCollection' => true,
|
|
||||||
'appendData' => ['total' => $total]
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @param \App\Models\Event $event The specified event.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(Request $request, Event $event)
|
|
||||||
{
|
|
||||||
if (EventConductor::viewable($event) === true) {
|
|
||||||
return $this->respondAsResource(EventConductor::model($request, $event));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\EventRequest $request The request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function store(EventRequest $request)
|
|
||||||
{
|
|
||||||
if (EventConductor::creatable() === true) {
|
|
||||||
$event = Event::create($request->all());
|
|
||||||
return $this->respondAsResource(
|
|
||||||
EventConductor::model($request, $event),
|
|
||||||
['respondCode' => HttpResponseCodes::HTTP_CREATED]
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the specified resource in storage.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\EventRequest $request The endpoint request.
|
|
||||||
* @param \App\Models\Event $event The specified event.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function update(EventRequest $request, Event $event)
|
|
||||||
{
|
|
||||||
if (EventConductor::updatable($event) === true) {
|
|
||||||
$event->update($request->all());
|
|
||||||
return $this->respondAsResource(EventConductor::model($request, $event));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the specified resource from storage.
|
|
||||||
*
|
|
||||||
* @param \App\Models\Event $event The specified event.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function destroy(Event $event)
|
|
||||||
{
|
|
||||||
if (EventConductor::destroyable($event) === true) {
|
|
||||||
$event->delete();
|
|
||||||
return $this->respondNoContent();
|
|
||||||
} else {
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of attachments related to this model.
|
|
||||||
*
|
|
||||||
* @param Request $request The user request.
|
|
||||||
* @param Event $event The event model.
|
|
||||||
* @return JsonResponse Returns the event attachments.
|
|
||||||
*/
|
|
||||||
public function getAttachments(Request $request, Event $event)
|
|
||||||
{
|
|
||||||
if (EventConductor::viewable($event) === true) {
|
|
||||||
$medium = $event->attachments->map(function ($attachment) {
|
|
||||||
return $attachment->media;
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this->respondAsResource(MediaConductor::collection($request, $medium), ['isCollection' => true, 'resourceName' => 'attachment']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store an attachment related to this model.
|
|
||||||
*
|
|
||||||
* @param Request $request The user request.
|
|
||||||
* @param Event $event The event model.
|
|
||||||
* @return JsonResponse The response.
|
|
||||||
*/
|
|
||||||
public function storeAttachment(Request $request, Event $event)
|
|
||||||
{
|
|
||||||
if (EventConductor::updatable($event) === true) {
|
|
||||||
if ($request->has("medium") === true && Media::find($request->medium) !== null) {
|
|
||||||
$event->attachments()->create(['media_id' => $request->medium]);
|
|
||||||
return $this->respondCreated();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondWithErrors(['media' => 'The media ID was not found']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update/replace attachments related to this model.
|
|
||||||
*
|
|
||||||
* @param Request $request The user request.
|
|
||||||
* @param Event $event The related model.
|
|
||||||
* @return JsonResponse
|
|
||||||
*/
|
|
||||||
public function updateAttachments(Request $request, Event $event)
|
|
||||||
{
|
|
||||||
if (EventConductor::updatable($event) === true) {
|
|
||||||
$mediaIds = $request->attachments;
|
|
||||||
if (is_array($mediaIds) === false) {
|
|
||||||
$mediaIds = explode(',', $request->attachments);
|
|
||||||
}
|
|
||||||
|
|
||||||
$mediaIds = array_map('trim', $mediaIds); // trim each media ID
|
|
||||||
$attachments = $event->attachments;
|
|
||||||
|
|
||||||
// Delete attachments that are not in $mediaIds
|
|
||||||
foreach ($attachments as $attachment) {
|
|
||||||
if (in_array($attachment->media_id, $mediaIds) === false) {
|
|
||||||
$attachment->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new attachments for media IDs that are not already in $article->attachments()
|
|
||||||
foreach ($mediaIds as $mediaId) {
|
|
||||||
$found = false;
|
|
||||||
|
|
||||||
foreach ($attachments as $attachment) {
|
|
||||||
if ($attachment->media_id === $mediaId) {
|
|
||||||
$found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($found === false) {
|
|
||||||
$event->attachments()->create(['media_id' => $mediaId]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a specific related attachment.
|
|
||||||
*
|
|
||||||
* @param Request $request The user request.
|
|
||||||
* @param Event $event The model.
|
|
||||||
* @param Media $medium The attachment medium.
|
|
||||||
* @return JsonResponse
|
|
||||||
*/
|
|
||||||
public function deleteAttachment(Request $request, Event $event, Media $medium)
|
|
||||||
{
|
|
||||||
if (EventConductor::updatable($event) === true) {
|
|
||||||
$attachments = $event->attachments;
|
|
||||||
$deleted = false;
|
|
||||||
|
|
||||||
foreach ($attachments as $attachment) {
|
|
||||||
if ($attachment->media_id === $medium->id) {
|
|
||||||
$attachment->delete();
|
|
||||||
$deleted = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($deleted === true) {
|
|
||||||
// Attachment was deleted successfully
|
|
||||||
return $this->respondNoContent();
|
|
||||||
} else {
|
|
||||||
// Attachment with matching media ID was not found
|
|
||||||
return $this->respondNotFound();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function userList(Request $request, Event $event)
|
|
||||||
{
|
|
||||||
$authUser = $request->user();
|
|
||||||
$eventUsers = $event->users;
|
|
||||||
|
|
||||||
if ($authUser !== null) {
|
|
||||||
$isAdmin = $authUser->hasPermission('admin/events');
|
|
||||||
$isEventUser = $eventUsers->contains($authUser->id);
|
|
||||||
|
|
||||||
if ($isAdmin === true || $isEventUser === true) {
|
|
||||||
if ($isAdmin === false) {
|
|
||||||
$eventUsers = $eventUsers->filter(function ($user) use ($authUser) {
|
|
||||||
return $user->id === $authUser->id;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondAsResource(UserConductor::collection($request, $eventUsers), ['isCollection' => true, 'resourceName' => 'users']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function userAdd(Request $request, Event $event)
|
|
||||||
{
|
|
||||||
$authUser = $request->user();
|
|
||||||
if ($authUser !== null && $authUser->hasPermission('admin/events') === true) {
|
|
||||||
if ($request->has("users") === true) {
|
|
||||||
$eventUsers = $event->users()->pluck('user_id')->toArray(); // Get the current users in the event
|
|
||||||
$requestedUsers = $request->input("users"); // Get the requested users
|
|
||||||
|
|
||||||
$usersToAdd = array_diff($requestedUsers, $eventUsers); // Users to add
|
|
||||||
$usersToRemove = array_diff($eventUsers, $requestedUsers); // Users to remove
|
|
||||||
|
|
||||||
// Add missing users
|
|
||||||
foreach ($usersToAdd as $userToAdd) {
|
|
||||||
if (User::find($userToAdd) !== null) {
|
|
||||||
$event->users()->attach($userToAdd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove extra users
|
|
||||||
foreach ($usersToRemove as $userToRemove) {
|
|
||||||
$event->users()->detach($userToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondWithErrors(['users' => 'The user list was not found']);
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function userUpdate(Request $request, Event $event)
|
|
||||||
{
|
|
||||||
// only admin/events permitted
|
|
||||||
}
|
|
||||||
|
|
||||||
public function userDelete(Request $request, Event $event, User $user)
|
|
||||||
{
|
|
||||||
$authUser = $request->user();
|
|
||||||
if ($authUser !== null && $authUser->hasPermission('admin/events') === true) {
|
|
||||||
$eventUsers = $event->users;
|
|
||||||
if ($eventUsers->find($user->id) !== null) {
|
|
||||||
$eventUsers->detach($user->id);
|
|
||||||
return $this->respondNoContent();
|
|
||||||
} else {
|
|
||||||
return $this->respondNotFound();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class LogController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* ApplicationController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('auth:sanctum')
|
|
||||||
->only(['show']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param Request $request The log request.
|
|
||||||
* @param string $name The log name.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(Request $request, string $name)
|
|
||||||
{
|
|
||||||
if ($request->user()?->hasPermission('logs/' . $name) === true) {
|
|
||||||
switch (strtolower($name)) {
|
|
||||||
case 'discord':
|
|
||||||
$data = [];
|
|
||||||
|
|
||||||
$log = $request->get('log');
|
|
||||||
if ($log === null) {
|
|
||||||
$log = ['output', 'error'];
|
|
||||||
} else {
|
|
||||||
$log = explode(',', strtolower($log));
|
|
||||||
}
|
|
||||||
|
|
||||||
$lines = intval($request->get('lines', 50));
|
|
||||||
if ($lines > 100) {
|
|
||||||
$lines = 100;
|
|
||||||
} elseif ($lines < 0) {
|
|
||||||
$lines = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$before = $request->get('before');
|
|
||||||
if ($before !== null) {
|
|
||||||
$before = preg_split("/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/", $before, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
|
|
||||||
if (count($before) !== 6) {
|
|
||||||
$before = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$after = $request->get('after');
|
|
||||||
if ($after !== null) {
|
|
||||||
$after = preg_split("/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/", $after, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
|
|
||||||
if (count($after) !== 6) {
|
|
||||||
$after = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$logFiles = [
|
|
||||||
[
|
|
||||||
'name' => 'output',
|
|
||||||
'path' => '/home/discordbot/.pm2/logs/stemmech-discordbot-out-0.log'
|
|
||||||
],[
|
|
||||||
'name' => 'error',
|
|
||||||
'path' => '/home/discordbot/.pm2/logs/stemmech-discordbot-error-0.log'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($logFiles as $logFile) {
|
|
||||||
if (in_array($logFile['name'], $log) === true) {
|
|
||||||
$logContent = '';
|
|
||||||
|
|
||||||
if (file_exists($logFile['path']) === true) {
|
|
||||||
$logContent = file_get_contents($logFile['path']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$logArray = preg_split("/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: (?:(?!\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: )[\s\S])*)/", $logContent, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
|
|
||||||
|
|
||||||
$logContent = '';
|
|
||||||
$logLineCount = 0;
|
|
||||||
$logLineSkip = false;
|
|
||||||
foreach (array_reverse($logArray) as $logLine) {
|
|
||||||
$lineDate = preg_split("/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}): /", $logLine, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
|
|
||||||
if (count($lineDate) >= 6) {
|
|
||||||
$logLineSkip = false;
|
|
||||||
|
|
||||||
// Is line before
|
|
||||||
if ($before !== null && ($lineDate[0] > $before[0] || $lineDate[1] > $before[1] || $lineDate[2] > $before[2] || $lineDate[3] > $before[3] || $lineDate[4] > $before[4] || $lineDate[5] > $before[5])) {
|
|
||||||
$logLineSkip = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is line after
|
|
||||||
if ($after !== null && ($after[0] > $lineDate[0] || $after[1] > $lineDate[1] || $after[2] > $lineDate[2] || $after[3] > $lineDate[3] || $after[4] > $lineDate[4] || $after[5] > $lineDate[5])) {
|
|
||||||
$logLineSkip = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$logLineCount += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($logLineCount > $lines) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($logLineSkip === false) {
|
|
||||||
$logContent .= $logLine;
|
|
||||||
}
|
|
||||||
}//end foreach
|
|
||||||
|
|
||||||
$data[$logFile['name']] = $logContent;
|
|
||||||
}//end if
|
|
||||||
}//end foreach
|
|
||||||
|
|
||||||
return $this->respondJson([
|
|
||||||
'log' => $data
|
|
||||||
]);
|
|
||||||
}//end switch
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,254 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Conductors\MediaConductor;
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use App\Http\Requests\MediaRequest;
|
|
||||||
use App\Models\Media;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Carbon;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Laravel\Sanctum\PersonalAccessToken;
|
|
||||||
|
|
||||||
class MediaController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* ApplicationController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('auth:sanctum')
|
|
||||||
->only(['store','update','destroy']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index(Request $request)
|
|
||||||
{
|
|
||||||
list($collection, $total) = MediaConductor::request($request);
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
$collection,
|
|
||||||
['isCollection' => true,
|
|
||||||
'appendData' => ['total' => $total]
|
|
||||||
],
|
|
||||||
function ($options) {
|
|
||||||
return $options['total'] === 0;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @param \App\Models\Media $medium The request media.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(Request $request, Media $medium)
|
|
||||||
{
|
|
||||||
if (MediaConductor::viewable($medium) === true) {
|
|
||||||
return $this->respondAsResource(MediaConductor::model($request, $medium));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a new media resource
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\MediaRequest $request The uploaded media.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function store(MediaRequest $request)
|
|
||||||
{
|
|
||||||
if (MediaConductor::creatable() === true) {
|
|
||||||
$file = $request->file('file');
|
|
||||||
if ($file === null) {
|
|
||||||
return $this->respondWithErrors(['file' => 'The browser did not upload the file correctly to the server.']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($file->isValid() !== true) {
|
|
||||||
switch ($file->getError()) {
|
|
||||||
case UPLOAD_ERR_INI_SIZE:
|
|
||||||
case UPLOAD_ERR_FORM_SIZE:
|
|
||||||
return $this->respondTooLarge();
|
|
||||||
case UPLOAD_ERR_PARTIAL:
|
|
||||||
return $this->respondWithErrors(['file' => 'The file upload was interrupted.']);
|
|
||||||
default:
|
|
||||||
return $this->respondWithErrors(['file' => 'An error occurred uploading the file to the server.']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($file->getSize() > Media::getMaxUploadSize()) {
|
|
||||||
return $this->respondTooLarge();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$media = Media::createFromUploadedFile($request, $file);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
if ($e->getCode() === Media::FILE_SIZE_EXCEEDED_ERROR) {
|
|
||||||
return $this->respondTooLarge();
|
|
||||||
} else {
|
|
||||||
return $this->respondWithErrors(['file' => $e->getMessage()]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
MediaConductor::model($request, $media),
|
|
||||||
['respondCode' => HttpResponseCodes::HTTP_ACCEPTED]
|
|
||||||
);
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the media resource in storage.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\MediaRequest $request The update request.
|
|
||||||
* @param \App\Models\Media $medium The specified media.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function update(MediaRequest $request, Media $medium)
|
|
||||||
{
|
|
||||||
if (MediaConductor::updatable($medium) === true) {
|
|
||||||
$file = $request->file('file');
|
|
||||||
if ($file !== null) {
|
|
||||||
if ($file->isValid() !== true) {
|
|
||||||
switch ($file->getError()) {
|
|
||||||
case UPLOAD_ERR_INI_SIZE:
|
|
||||||
case UPLOAD_ERR_FORM_SIZE:
|
|
||||||
return $this->respondTooLarge();
|
|
||||||
case UPLOAD_ERR_PARTIAL:
|
|
||||||
return $this->respondWithErrors(['file' => 'The file upload was interrupted.']);
|
|
||||||
default:
|
|
||||||
return $this->respondWithErrors(['file' => 'An error occurred uploading the file to the server.']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($file->getSize() > Media::getMaxUploadSize()) {
|
|
||||||
return $this->respondTooLarge();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$medium->update($request->all());
|
|
||||||
|
|
||||||
if ($file !== null) {
|
|
||||||
try {
|
|
||||||
$medium->updateWithUploadedFile($file);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $this->respondWithErrors(
|
|
||||||
['file' => $e->getMessage()],
|
|
||||||
HttpResponseCodes::HTTP_INTERNAL_SERVER_ERROR
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondAsResource(MediaConductor::model($request, $medium));
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the specified resource from storage.
|
|
||||||
*
|
|
||||||
* @param \App\Models\Media $medium Specified media file.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function destroy(Media $medium)
|
|
||||||
{
|
|
||||||
if (MediaConductor::destroyable($medium) === true) {
|
|
||||||
$medium->delete();
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @param \App\Models\Media $medium Specified media.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function download(Request $request, Media $medium)
|
|
||||||
{
|
|
||||||
$respondJson = in_array('application/json', explode(',', $request->header('Accept', 'application/json')));
|
|
||||||
|
|
||||||
$headers = [];
|
|
||||||
$path = $medium->path();
|
|
||||||
|
|
||||||
/* File exists */
|
|
||||||
if (file_exists($path) === false) {
|
|
||||||
if ($respondJson === false) {
|
|
||||||
return redirect('/not-found');
|
|
||||||
} else {
|
|
||||||
return $this->respondNotFound();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$updated_at = Carbon::parse(filemtime($path));
|
|
||||||
|
|
||||||
$headerPragma = 'no-cache';
|
|
||||||
$headerCacheControl = 'max-age=0, must-revalidate';
|
|
||||||
$headerExpires = $updated_at->toRfc2822String();
|
|
||||||
|
|
||||||
if (empty($medium->permission) === true) {
|
|
||||||
if ($request->user() === null && $request->has('token') === true) {
|
|
||||||
$accessToken = PersonalAccessToken::findToken(urldecode($request->input('token')));
|
|
||||||
|
|
||||||
if (
|
|
||||||
$accessToken !== null && (config('sanctum.expiration') === null ||
|
|
||||||
$accessToken->created_at->lte(now()->subMinutes(config('sanctum.expiration'))) === false)
|
|
||||||
) {
|
|
||||||
$user = $accessToken->tokenable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($request->user() === null || $user->hasPermission($medium->permission) === false) {
|
|
||||||
if ($respondJson === false) {
|
|
||||||
return redirect('/login?redirect=' . $request->path());
|
|
||||||
} else {
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$headerPragma = 'public';
|
|
||||||
$headerExpires = $updated_at->addMonth()->toRfc2822String();
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
// deepcode ignore InsecureHash: Browsers expect Etag to be a md5 hash
|
|
||||||
$headerEtag = md5($updated_at->format('U'));
|
|
||||||
$headerLastModified = $updated_at->toRfc2822String();
|
|
||||||
|
|
||||||
$headers = [
|
|
||||||
'Cache-Control' => $headerCacheControl,
|
|
||||||
'Content-Disposition' => sprintf('inline; filename="%s"', basename($path)),
|
|
||||||
'Etag' => $headerEtag,
|
|
||||||
'Expires' => $headerExpires,
|
|
||||||
'Last-Modified' => $headerLastModified,
|
|
||||||
'Pragma' => $headerPragma,
|
|
||||||
];
|
|
||||||
|
|
||||||
$server = request()->server;
|
|
||||||
|
|
||||||
$requestModifiedSince = $server->has('HTTP_IF_MODIFIED_SINCE') &&
|
|
||||||
$server->get('HTTP_IF_MODIFIED_SINCE') === $headerLastModified;
|
|
||||||
|
|
||||||
$requestNoneMatch = $server->has('HTTP_IF_NONE_MATCH') &&
|
|
||||||
$server->get('HTTP_IF_NONE_MATCH') === $headerEtag;
|
|
||||||
|
|
||||||
if ($requestModifiedSince === true || $requestNoneMatch === true) {
|
|
||||||
return response()->make('', 304, $headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->file($path, $headers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,231 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use thiagoalessio\TesseractOCR\TesseractOCR;
|
|
||||||
use FFMpeg;
|
|
||||||
use App\Enum\CurlErrorCodes;
|
|
||||||
|
|
||||||
class OCRController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* ApplicationController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
// $this->middleware('auth:sanctum')
|
|
||||||
// ->only(['show']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param Request $request The log request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(Request $request)
|
|
||||||
{
|
|
||||||
// if ($request->user()?->hasPermission('logs/' . $name) === true) {
|
|
||||||
$url = $request->get('url');
|
|
||||||
if ($url !== null) {
|
|
||||||
$data = ['ocr' => []];
|
|
||||||
|
|
||||||
$filters = $request->get('filters', ['tesseract']);
|
|
||||||
if (is_array($filters) === false) {
|
|
||||||
$filters = explode(',', $filters);
|
|
||||||
}
|
|
||||||
|
|
||||||
$tesseractOEM = $request->get('tesseract.oem');
|
|
||||||
$tesseractDigits = $request->get('tesseract.digits');
|
|
||||||
$tesseractAllowlist = $request->get('tesseract.allowlist');
|
|
||||||
|
|
||||||
// Download URL
|
|
||||||
$urlDownloadFilePath = tempnam(sys_get_temp_dir(), 'download');
|
|
||||||
$maxDownloadSize = (1024 * 1024); // 1MB
|
|
||||||
$ch = curl_init();
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
||||||
|
|
||||||
// We need progress updates to break the connection mid-way
|
|
||||||
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128); // more progress info
|
|
||||||
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
|
|
||||||
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function (
|
|
||||||
$downloadSize,
|
|
||||||
$downloaded,
|
|
||||||
$uploadSize,
|
|
||||||
$uploaded
|
|
||||||
) use ($maxDownloadSize) {
|
|
||||||
return ($downloaded > $maxDownloadSize) ? 1 : 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
$curlResult = curl_exec($ch);
|
|
||||||
$curlError = curl_errno($ch);
|
|
||||||
$curlSize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
|
|
||||||
curl_close($ch);
|
|
||||||
if ($curlError !== 0) {
|
|
||||||
$error = 'File size is larger then allowed';
|
|
||||||
if ($curlError !== CurlErrorCodes::CURLE_ABORTED_BY_CALLBACK) {
|
|
||||||
$error = CurlErrorCodes::getMessage($curlError);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondWithErrors(['url' => $error]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save url file
|
|
||||||
file_put_contents($urlDownloadFilePath, $curlResult);
|
|
||||||
$urlDownloadFilePathBase = preg_replace('/\\.[^.\\s]{3,4}$/', '', $urlDownloadFilePath);
|
|
||||||
|
|
||||||
// tesseract (overall)
|
|
||||||
$ocr = null;
|
|
||||||
foreach ($filters as $filterItem) {
|
|
||||||
if (str_starts_with($filterItem, 'tesseract') === true) {
|
|
||||||
$ocr = new TesseractOCR();
|
|
||||||
$ocr->image($urlDownloadFilePath);
|
|
||||||
if ($tesseractOEM !== null) {
|
|
||||||
$ocr->oem($tesseractOEM);
|
|
||||||
}
|
|
||||||
if ($tesseractDigits !== null) {
|
|
||||||
$ocr->digits();
|
|
||||||
}
|
|
||||||
if ($tesseractAllowlist !== null) {
|
|
||||||
$ocr->allowlist($tesseractAllowlist);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Image Filter Function
|
|
||||||
$tesseractImageFilterFunc = function ($filter, $options = null) use ($curlResult, $curlSize, $ocr) {
|
|
||||||
$result = '';
|
|
||||||
$img = imagecreatefromstring($curlResult);
|
|
||||||
if ($img !== false && (($options !== null && imagefilter($img, $filter, $options) === true) || ($options === null && imagefilter($img, $filter) === true))) {
|
|
||||||
ob_start();
|
|
||||||
imagepng($img);
|
|
||||||
$imgData = ob_get_contents();
|
|
||||||
ob_end_clean();
|
|
||||||
$imgDataSize = strlen($imgData);
|
|
||||||
|
|
||||||
$ocr->imageData($imgData, $imgDataSize);
|
|
||||||
imagedestroy($img);
|
|
||||||
|
|
||||||
$result = $ocr->run(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Image Scale Function
|
|
||||||
$tesseractImageScaleFunc = function ($scaleFunc) use ($curlResult, $ocr) {
|
|
||||||
$result = '';
|
|
||||||
$srcImage = imagecreatefromstring($curlResult);
|
|
||||||
$srcWidth = imagesx($srcImage);
|
|
||||||
$srcHeight = imagesy($srcImage);
|
|
||||||
|
|
||||||
$dstWidth = $scaleFunc($srcWidth);
|
|
||||||
$dstHeight = $scaleFunc($srcHeight);
|
|
||||||
$dstImage = imagecreatetruecolor($dstWidth, $dstHeight);
|
|
||||||
|
|
||||||
imagecopyresampled($dstImage, $srcImage, 0, 0, 0, 0, $dstWidth, $dstHeight, $srcWidth, $srcHeight);
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
imagepng($dstImage);
|
|
||||||
$imgData = ob_get_contents();
|
|
||||||
ob_end_clean();
|
|
||||||
$imgDataSize = strlen($imgData);
|
|
||||||
|
|
||||||
imagedestroy($srcImage);
|
|
||||||
imagedestroy($dstImage);
|
|
||||||
|
|
||||||
$ocr->imageData($imgData, $imgDataSize);
|
|
||||||
$result = $ocr->run(500);
|
|
||||||
return $result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// filter: tesseract
|
|
||||||
if (in_array('tesseract', $filters) === true) {
|
|
||||||
$data['ocr']['tesseract'] = $ocr->run(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter: tesseract.grayscale
|
|
||||||
if (in_array('tesseract.grayscale', $filters) === true) {
|
|
||||||
$data['ocr']['tesseract.grayscale'] = $tesseractImageFilterFunc(IMG_FILTER_GRAYSCALE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter: tesseract.double_scale
|
|
||||||
if (in_array('tesseract.double_scale', $filters) === true) {
|
|
||||||
$data['ocr']['tesseract.double_scale'] = $tesseractImageScaleFunc(function ($size) {
|
|
||||||
return $size * 2;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter: tesseract.half_scale
|
|
||||||
if (in_array('tesseract.half_scale', $filters) === true) {
|
|
||||||
$data['ocr']['tesseract.half_scale'] = $tesseractImageScaleFunc(function ($size) {
|
|
||||||
return $size / 2;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter: tesseract.edgedetect
|
|
||||||
if (in_array('tesseract.edgedetect', $filters) === true) {
|
|
||||||
$data['ocr']['tesseract.edgedetect'] = $tesseractImageFilterFunc(IMG_FILTER_EDGEDETECT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter: tesseract.mean_removal
|
|
||||||
if (in_array('tesseract.mean_removal', $filters) === true) {
|
|
||||||
$data['ocr']['tesseract.mean_removal'] = $tesseractImageFilterFunc(IMG_FILTER_MEAN_REMOVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter: tesseract.negate
|
|
||||||
if (in_array('tesseract.negate', $filters) === true) {
|
|
||||||
$data['ocr']['tesseract.negate'] = $tesseractImageFilterFunc(IMG_FILTER_NEGATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter: tesseract.pixelate
|
|
||||||
if (in_array('tesseract.pixelate', $filters) === true) {
|
|
||||||
$data['ocr']['tesseract.pixelate'] = $tesseractImageFilterFunc(IMG_FILTER_PIXELATE, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter: keras
|
|
||||||
if (in_array('keras', $filters) === true) {
|
|
||||||
$cmd = '/usr/bin/python3 ' . base_path() . '/scripts/keras_oc.py ' . urlencode($url);
|
|
||||||
$command = escapeshellcmd($cmd);
|
|
||||||
$output = shell_exec($cmd);
|
|
||||||
if ($output !== null && strlen($output) > 0) {
|
|
||||||
$output = substr($output, (strpos($output, '----------START----------') + 25));
|
|
||||||
} else {
|
|
||||||
$output = '';
|
|
||||||
}
|
|
||||||
$data['ocr']['keras'] = $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
unlink($urlDownloadFilePath);
|
|
||||||
return $this->respondJson($data);
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondWithErrors(['url' => 'url is missing']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// $ffmpeg = FFMpeg\FFMpeg::create();
|
|
||||||
|
|
||||||
// // Load the input video
|
|
||||||
// $inputFile = $ffmpeg->open('input.mp4');
|
|
||||||
|
|
||||||
// // Split the video into individual frames
|
|
||||||
// $videoFrames = $inputFile->frames();
|
|
||||||
// foreach ($videoFrames as $frame) {
|
|
||||||
// // Save the frame as a PNG
|
|
||||||
// $frame->save(new FFMpeg\Format\Video\PNG(), 'frame-' . $frame->getMetadata('pts') . '.png');
|
|
||||||
|
|
||||||
// // Pass the PNG to Tesseract for processing
|
|
||||||
// exec("tesseract frame-" . $frame->getMetadata('pts') . ".png output");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Read the output from Tesseract
|
|
||||||
// $text = file_get_contents("output.txt");
|
|
||||||
|
|
||||||
// // Do something with the text from Tesseract
|
|
||||||
// echo $text;
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Conductors\MediaConductor;
|
|
||||||
use App\Conductors\ShortlinkConductor;
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use App\Http\Requests\MediaRequest;
|
|
||||||
use App\Http\Requests\ShortlinkRequest;
|
|
||||||
use App\Models\Media;
|
|
||||||
use App\Models\Shortlink;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Carbon;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Laravel\Sanctum\PersonalAccessToken;
|
|
||||||
|
|
||||||
class ShortlinkController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* ApplicationController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('auth:sanctum')
|
|
||||||
->only(['store','update','destroy']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index(Request $request)
|
|
||||||
{
|
|
||||||
list($collection, $total) = ShortlinkConductor::request($request);
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
$collection,
|
|
||||||
['isCollection' => true,
|
|
||||||
'appendData' => ['total' => $total]
|
|
||||||
],
|
|
||||||
function ($options) {
|
|
||||||
return $options['total'] === 0;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @param \App\Models\Shortlink $shortlink The request shortlink.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(Request $request, Shortlink $shortlink)
|
|
||||||
{
|
|
||||||
if (ShortlinkConductor::viewable($shortlink) === true) {
|
|
||||||
return $this->respondAsResource(ShortlinkConductor::model($request, $shortlink));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a new media resource
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\ShortlinkRequest $request The shortlink.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function store(ShortlinkRequest $request)
|
|
||||||
{
|
|
||||||
if (ShortlinkConductor::creatable() === true) {
|
|
||||||
$shortlink = Shortlink::create($request->all());
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
ShortlinkConductor::model($request, $shortlink),
|
|
||||||
['respondCode' => HttpResponseCodes::HTTP_ACCEPTED]
|
|
||||||
);
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the media resource in storage.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\ShortlinkRequest $request The update request.
|
|
||||||
* @param \App\Models\Shortlink $medium The specified shortlink.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function update(ShortlinkRequest $request, Shortlink $shortlink)
|
|
||||||
{
|
|
||||||
if (ShortlinkConductor::updatable($shortlink) === true) {
|
|
||||||
$shortlink->update($request->all());
|
|
||||||
return $this->respondAsResource(ShortlinkConductor::model($request, $shortlink));
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the specified resource from storage.
|
|
||||||
*
|
|
||||||
* @param \App\Models\Shortlink $medium Specified shortlink.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function destroy(Shortlink $shortlink)
|
|
||||||
{
|
|
||||||
if (ShortlinkConductor::destroyable($shortlink) === true) {
|
|
||||||
$shortlink->delete();
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Conductors\SubscriptionConductor;
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use App\Models\Subscription;
|
|
||||||
use App\Http\Requests\SubscriptionRequest;
|
|
||||||
use App\Jobs\SendEmailJob;
|
|
||||||
use App\Mail\SubscriptionConfirm;
|
|
||||||
use App\Mail\SubscriptionUnsubscribed;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class SubscriptionController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* ApplicationController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('auth:sanctum')
|
|
||||||
->except(['store', 'destroyByEmail']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of subscribers.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index(Request $request)
|
|
||||||
{
|
|
||||||
list($collection, $total) = SubscriptionConductor::request($request);
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
$collection,
|
|
||||||
['isCollection' => true,
|
|
||||||
'appendData' => ['total' => $total]
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified user.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @param \App\Models\Subscription $subscription The subscription model.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(Request $request, Subscription $subscription)
|
|
||||||
{
|
|
||||||
if (SubscriptionConductor::viewable($subscription) === true) {
|
|
||||||
return $this->respondAsResource(SubscriptionConductor::model($request, $subscription));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a subscriber email in the database.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\SubscriptionRequest $request The subscriber update request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function store(SubscriptionRequest $request)
|
|
||||||
{
|
|
||||||
if (SubscriptionConductor::creatable() === true) {
|
|
||||||
Subscription::create($request->all());
|
|
||||||
dispatch((new SendEmailJob($request->email, new SubscriptionConfirm($request->email))))->onQueue('mail');
|
|
||||||
|
|
||||||
return $this->respondCreated();
|
|
||||||
} else {
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the specified resource in storage.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\SubscriptionRequest $request The subscription update request.
|
|
||||||
* @param \App\Models\Subscription $subscription The specified subscription.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function update(SubscriptionRequest $request, Subscription $subscription)
|
|
||||||
{
|
|
||||||
// if (EventConductor::updatable($event) === true) {
|
|
||||||
// $event->update($request->all());
|
|
||||||
// return $this->respondAsResource(EventConductor::model($request, $event));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return $this->respondForbidden();
|
|
||||||
|
|
||||||
|
|
||||||
// $input = [];
|
|
||||||
// $updatable = ['username', 'first_name', 'last_name', 'email', 'phone', 'password'];
|
|
||||||
|
|
||||||
// if ($request->user()->hasPermission('admin/user') === true) {
|
|
||||||
// $updatable = array_merge($updatable, ['email_verified_at']);
|
|
||||||
// } elseif ($request->user()->is($user) !== true) {
|
|
||||||
// return $this->respondForbidden();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $input = $request->only($updatable);
|
|
||||||
// if (array_key_exists('password', $input) === true) {
|
|
||||||
// $input['password'] = Hash::make($request->input('password'));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $user->update($input);
|
|
||||||
|
|
||||||
// return $this->respondAsResource((new UserFilter($request))->filter($user));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the user from the database.
|
|
||||||
*
|
|
||||||
* @param Subscription $subscription The specified subscription.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function destroy(Subscription $subscription)
|
|
||||||
{
|
|
||||||
if (SubscriptionConductor::destroyable($subscription) === true) {
|
|
||||||
$subscription->delete();
|
|
||||||
return $this->respondNoContent();
|
|
||||||
} else {
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the user from the database.
|
|
||||||
*
|
|
||||||
* @param SubscriptionRequest $request The specified subscription.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function destroyByEmail(SubscriptionRequest $request)
|
|
||||||
{
|
|
||||||
$subscription = Subscription::where('email', $request->email)->first();
|
|
||||||
if ($subscription !== null) {
|
|
||||||
$subscription->delete();
|
|
||||||
dispatch((new SendEmailJob($request->email, new SubscriptionUnsubscribed($request->email))))->onQueue('mail');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,362 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Conductors\EventConductor;
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use App\Http\Requests\UserRequest;
|
|
||||||
use App\Http\Requests\UserForgotPasswordRequest;
|
|
||||||
use App\Http\Requests\UserRegisterRequest;
|
|
||||||
use App\Http\Requests\UserResendVerifyEmailRequest;
|
|
||||||
use App\Http\Requests\UserResetPasswordRequest;
|
|
||||||
use App\Http\Requests\UserVerifyEmailRequest;
|
|
||||||
use App\Jobs\SendEmailJob;
|
|
||||||
use App\Mail\ChangedEmail;
|
|
||||||
use App\Mail\ChangedPassword;
|
|
||||||
use App\Mail\ChangeEmailVerify;
|
|
||||||
use App\Mail\ForgotPassword;
|
|
||||||
use App\Mail\EmailVerify;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\UserCode;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
use App\Conductors\UserConductor;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
|
||||||
|
|
||||||
class UserController extends ApiController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* ApplicationController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('auth:sanctum')
|
|
||||||
->except([
|
|
||||||
'index',
|
|
||||||
'show',
|
|
||||||
'register',
|
|
||||||
'exists',
|
|
||||||
'forgotPassword',
|
|
||||||
'resetPassword',
|
|
||||||
'verifyEmail',
|
|
||||||
'resendVerifyEmailCode',
|
|
||||||
'eventList',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index(Request $request)
|
|
||||||
{
|
|
||||||
list($collection, $total) = UserConductor::request($request);
|
|
||||||
|
|
||||||
return $this->respondAsResource(
|
|
||||||
$collection,
|
|
||||||
['isCollection' => true,
|
|
||||||
'appendData' => ['total' => $total]
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created user in the database.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\UserRequest $request The endpoint request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function store(UserRequest $request)
|
|
||||||
{
|
|
||||||
if (UserConductor::creatable() === true) {
|
|
||||||
$user = User::create($request->all());
|
|
||||||
return $this->respondAsResource(UserConductor::model($request, $user), ['respondCode' => HttpResponseCodes::HTTP_CREATED]);
|
|
||||||
} else {
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified user.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
|
||||||
* @param \App\Models\User $user The user model.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(Request $request, User $user)
|
|
||||||
{
|
|
||||||
if (UserConductor::viewable($user) === true) {
|
|
||||||
return $this->respondAsResource(UserConductor::model($request, $user));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the specified resource in storage.
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\UserRequest $request The user update request.
|
|
||||||
* @param \App\Models\User $user The specified user.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function update(UserRequest $request, User $user)
|
|
||||||
{
|
|
||||||
if (UserConductor::updatable($user) === true) {
|
|
||||||
$input = [];
|
|
||||||
$updatable = ['first_name', 'last_name', 'email', 'phone', 'password', 'display_name'];
|
|
||||||
|
|
||||||
if ($request->user()->hasPermission('admin/user') === true) {
|
|
||||||
$updatable = array_merge($updatable, ['email_verified_at']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$input = $request->only($updatable);
|
|
||||||
if (array_key_exists('password', $input) === true) {
|
|
||||||
$input['password'] = Hash::make($request->input('password'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->update($input);
|
|
||||||
|
|
||||||
return $this->respondAsResource(UserConductor::model($request, $user));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the user from the database.
|
|
||||||
*
|
|
||||||
* @param \App\Models\User $user The specified user.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function destroy(User $user)
|
|
||||||
{
|
|
||||||
if (UserConductor::destroyable($user) === true) {
|
|
||||||
$user->delete();
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new user
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\UserRegisterRequest $request The register user request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function register(UserRegisterRequest $request)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$userData = $request->only([
|
|
||||||
'first_name',
|
|
||||||
'last_name',
|
|
||||||
'email',
|
|
||||||
'phone',
|
|
||||||
'password',
|
|
||||||
'display_name',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$userData['password'] = Hash::make($userData['password']);
|
|
||||||
|
|
||||||
$user = User::where('email', $request->input('email'))
|
|
||||||
->whereNull('password')
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if ($user === null) {
|
|
||||||
$user = User::create($userData);
|
|
||||||
} else {
|
|
||||||
unset($userData['email']);
|
|
||||||
$user->update($userData);
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
$code = $user->codes()->create([
|
|
||||||
'action' => 'verify-email',
|
|
||||||
]);
|
|
||||||
|
|
||||||
dispatch((new SendEmailJob($user->email, new EmailVerify($user, $code->code))))->onQueue('mail');
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'message' => 'Check your email for a welcome code.'
|
|
||||||
]);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return response()->json([
|
|
||||||
'message' => 'A server error occurred. Please try again later' . $e
|
|
||||||
], 500);
|
|
||||||
}//end try
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a new reset password code
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\UserForgotPasswordRequest $request The reset password request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function forgotPassword(UserForgotPasswordRequest $request)
|
|
||||||
{
|
|
||||||
$user = User::where('email', $request->input('email'))->first();
|
|
||||||
if ($user !== null) {
|
|
||||||
$user->codes()->where('action', 'reset-password')->delete();
|
|
||||||
$code = $user->codes()->create([
|
|
||||||
'action' => 'reset-password'
|
|
||||||
]);
|
|
||||||
|
|
||||||
dispatch((new SendEmailJob($user->email, new ForgotPassword($user, $code->code))))->onQueue('mail');
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resets a user password
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\UserResetPasswordRequest $request The reset password request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function resetPassword(UserResetPasswordRequest $request)
|
|
||||||
{
|
|
||||||
UserCode::clearExpired();
|
|
||||||
|
|
||||||
$code = UserCode::where('code', $request->input('code'))->where('action', 'reset-password')->first();
|
|
||||||
if ($code !== null) {
|
|
||||||
$user = $code->user()->first();
|
|
||||||
|
|
||||||
$code->delete();
|
|
||||||
$user->codes()->where('action', 'verify-email')->delete();
|
|
||||||
|
|
||||||
$user->password = Hash::make($request->input('password'));
|
|
||||||
|
|
||||||
if ($user->email_verified_at === null) {
|
|
||||||
$user->email_verified_at = now();
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
dispatch((new SendEmailJob($user->email, new ChangedPassword($user))))->onQueue('mail');
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondError([
|
|
||||||
'code' => 'The code was not found or has expired.'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify an email code
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\UserVerifyEmailRequest $request The verify email request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function verifyEmail(UserVerifyEmailRequest $request)
|
|
||||||
{
|
|
||||||
UserCode::clearExpired();
|
|
||||||
|
|
||||||
$code = UserCode::where('code', $request->input('code'))->where('action', 'verify-email')->first();
|
|
||||||
if ($code !== null) {
|
|
||||||
$user = $code->user()->first();
|
|
||||||
$new_email = $code->data;
|
|
||||||
|
|
||||||
if ($new_email === null) {
|
|
||||||
if ($user->email_verified_at === null) {
|
|
||||||
$user->email_verified_at = now();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dispatch((new SendEmailJob($user->email, new ChangedEmail($user, $user->email, $new_email))))
|
|
||||||
->onQueue('mail');
|
|
||||||
|
|
||||||
$user->email = $new_email;
|
|
||||||
$user->email_verified_at = now();
|
|
||||||
}
|
|
||||||
|
|
||||||
$code->delete();
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return $this->respondWithErrors([
|
|
||||||
'code' => 'The code was not found or has expired.'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resend a new verify email
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\UserResendVerifyEmailRequest $request The resend verify email request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function resendVerifyEmail(UserResendVerifyEmailRequest $request)
|
|
||||||
{
|
|
||||||
UserCode::clearExpired();
|
|
||||||
|
|
||||||
$user = User::where('email', $request->input('email'))->first();
|
|
||||||
if ($user !== null) {
|
|
||||||
$code = $user->codes()->where('action', 'verify-email')->first();
|
|
||||||
$code->regenerate();
|
|
||||||
$code->save();
|
|
||||||
|
|
||||||
if ($code->data === null) {
|
|
||||||
dispatch((new SendEmailJob($user->email, new EmailVerify($user, $code->code))))->onQueue('mail');
|
|
||||||
} else {
|
|
||||||
dispatch((new SendEmailJob($user->email, new ChangeEmailVerify($user, $code->code, $code->data))))
|
|
||||||
->onQueue('mail');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json(['message' => 'Verify email sent if user registered and required']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resend verification email
|
|
||||||
*
|
|
||||||
* @param \App\Http\Requests\UserResendVerifyEmailRequest $request The resend user request.
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function resendVerifyEmailCode(UserResendVerifyEmailRequest $request)
|
|
||||||
{
|
|
||||||
$user = User::where('email', $request->input('email'))->first();
|
|
||||||
if ($user !== null) {
|
|
||||||
$user->codes()->where('action', 'verify-email')->delete();
|
|
||||||
|
|
||||||
if ($user->email_verified_at === null) {
|
|
||||||
$code = $user->codes()->create([
|
|
||||||
'action' => 'verify-email'
|
|
||||||
]);
|
|
||||||
|
|
||||||
dispatch((new SendEmailJob($user->email, new EmailVerify($user, $code->code))))->onQueue('mail');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondNoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->respondNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a JSON event list of a user.
|
|
||||||
*
|
|
||||||
* @param Request $request The http request.
|
|
||||||
* @param User $user The specified user.
|
|
||||||
* @return JsonResponse
|
|
||||||
*/
|
|
||||||
public function eventList(Request $request, User $user)
|
|
||||||
{
|
|
||||||
if ($request->user() !== null && ($request->user() === $user || $request->user()->hasPermission('admin/events') === true)) {
|
|
||||||
$collection = $user->events;
|
|
||||||
$total = $collection->count();
|
|
||||||
|
|
||||||
$collection = EventConductor::collection($request, $collection);
|
|
||||||
return $this->respondAsResource(
|
|
||||||
$collection,
|
|
||||||
['isCollection' => true,
|
|
||||||
'appendData' => ['total' => $total]
|
|
||||||
]
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return $this->respondForbidden();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,13 +3,10 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
||||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||||
use Illuminate\Routing\Controller as BaseController;
|
use Illuminate\Routing\Controller as BaseController;
|
||||||
|
|
||||||
class Controller extends BaseController
|
class Controller extends BaseController
|
||||||
{
|
{
|
||||||
use AuthorizesRequests;
|
use AuthorizesRequests, ValidatesRequests;
|
||||||
use DispatchesJobs;
|
|
||||||
use ValidatesRequests;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ class Kernel extends HttpKernel
|
|||||||
\Illuminate\Http\Middleware\HandleCors::class,
|
\Illuminate\Http\Middleware\HandleCors::class,
|
||||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||||
// \App\Http\Middleware\TrimStrings::class,
|
\App\Http\Middleware\TrimStrings::class,
|
||||||
// \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,22 +40,19 @@ class Kernel extends HttpKernel
|
|||||||
|
|
||||||
'api' => [
|
'api' => [
|
||||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||||
'throttle:api',
|
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
// \App\Http\Middleware\ForceJsonResponse::class,
|
|
||||||
'useSanctumGuard',
|
|
||||||
\App\Http\Middleware\LogRequest::class,
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The application's route middleware.
|
* The application's middleware aliases.
|
||||||
*
|
*
|
||||||
* These middleware may be assigned to groups or used individually.
|
* Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
|
||||||
*
|
*
|
||||||
* @var array<string, class-string|string>
|
* @var array<string, class-string|string>
|
||||||
*/
|
*/
|
||||||
protected $routeMiddleware = [
|
protected $middlewareAliases = [
|
||||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||||
@@ -63,9 +60,9 @@ class Kernel extends HttpKernel
|
|||||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||||
|
'precognitive' => \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
|
||||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||||
'useSanctumGuard' => \App\Http\Middleware\UseSanctumGuard::class
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,15 @@
|
|||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class Authenticate extends Middleware
|
class Authenticate extends Middleware
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get the path the user should be redirected to when they are not authenticated.
|
* Get the path the user should be redirected to when they are not authenticated.
|
||||||
*
|
|
||||||
* @param mixed $request Request.
|
|
||||||
* @return string|null
|
|
||||||
*/
|
*/
|
||||||
protected function redirectTo(mixed $request)
|
protected function redirectTo(Request $request): ?string
|
||||||
{
|
{
|
||||||
if ($request->expectsJson() === false) {
|
return $request->expectsJson() ? null : route('login');
|
||||||
return route('login');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class ForceJsonResponse
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle an incoming request.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
|
||||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
|
||||||
*/
|
|
||||||
public function handle(Request $request, Closure $next)
|
|
||||||
{
|
|
||||||
$request->headers->set('Accept', 'application/json');
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Models\Analytics;
|
|
||||||
|
|
||||||
class LogRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle an incoming request.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
|
||||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
|
||||||
*/
|
|
||||||
public function handle(Request $request, Closure $next)
|
|
||||||
{
|
|
||||||
// Make it an after middleware
|
|
||||||
$response = $next($request);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Analytics::createWithSession([
|
|
||||||
'type' => 'apirequest',
|
|
||||||
'attribute' => $request->path(),
|
|
||||||
'useragent' => $request->userAgent(),
|
|
||||||
'ip' => $request->ip(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
} catch (\Error $e) {
|
|
||||||
report($e);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,23 +6,21 @@ use App\Providers\RouteServiceProvider;
|
|||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
class RedirectIfAuthenticated
|
class RedirectIfAuthenticated
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Handle an incoming request.
|
* Handle an incoming request.
|
||||||
*
|
*
|
||||||
* @param Request $request Request.
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||||
* @param Closure(Request): (Response|RedirectResponse) $next Next.
|
|
||||||
* @param string|null ...$guards Guards.
|
|
||||||
* @return Response|RedirectResponse
|
|
||||||
*/
|
*/
|
||||||
public function handle(Request $request, Closure $next, ...$guards)
|
public function handle(Request $request, Closure $next, string ...$guards): Response
|
||||||
{
|
{
|
||||||
$guards = empty($guards) === true ? [null] : $guards;
|
$guards = empty($guards) ? [null] : $guards;
|
||||||
|
|
||||||
foreach ($guards as $guard) {
|
foreach ($guards as $guard) {
|
||||||
if (Auth::guard($guard)->check() === true) {
|
if (Auth::guard($guard)->check()) {
|
||||||
return redirect(RouteServiceProvider::HOME);
|
return redirect(RouteServiceProvider::HOME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class TrustHosts extends Middleware
|
|||||||
*
|
*
|
||||||
* @return array<int, string|null>
|
* @return array<int, string|null>
|
||||||
*/
|
*/
|
||||||
public function hosts()
|
public function hosts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
$this->allSubdomainsOfApplicationUrl(),
|
$this->allSubdomainsOfApplicationUrl(),
|
||||||
|
|||||||
@@ -17,9 +17,12 @@ class TrustProxies extends Middleware
|
|||||||
/**
|
/**
|
||||||
* The headers that should be used to detect proxies.
|
* The headers that should be used to detect proxies.
|
||||||
*
|
*
|
||||||
* @var integer
|
* @var int
|
||||||
*/
|
*/
|
||||||
// @codingStandardsIgnoreStart
|
protected $headers =
|
||||||
protected $headers = (Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB);
|
Request::HEADER_X_FORWARDED_FOR |
|
||||||
// @codingStandardsIgnoreEnd
|
Request::HEADER_X_FORWARDED_HOST |
|
||||||
|
Request::HEADER_X_FORWARDED_PORT |
|
||||||
|
Request::HEADER_X_FORWARDED_PROTO |
|
||||||
|
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
|
|
||||||
class UseSanctumGuard
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle an incoming request.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
|
||||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
|
||||||
*/
|
|
||||||
public function handle(Request $request, Closure $next)
|
|
||||||
{
|
|
||||||
Auth::shouldUse('sanctum');
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
|
|
||||||
class AnalyticsRequest extends BaseRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to POST requests.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function postRules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'type' => 'required|string',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to PUT request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function putRules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'type' => 'string',
|
|
||||||
'useragent' => 'string',
|
|
||||||
'ip' => 'ipv4|ipv6',
|
|
||||||
'session' => 'number',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
|
|
||||||
class ArticleRequest extends BaseRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to POST requests.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function postRules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'slug' => 'required|string|min:6|unique:articles',
|
|
||||||
'title' => 'required|string|min:6|max:255',
|
|
||||||
'publish_at' => 'required|date',
|
|
||||||
'user_id' => 'required|uuid|exists:users,id',
|
|
||||||
'content' => 'required|string|min:6',
|
|
||||||
'hero' => 'required|uuid|exists:media,id',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to PUT request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function putRules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'slug' => [
|
|
||||||
'string',
|
|
||||||
'min:6',
|
|
||||||
Rule::unique('articles')->ignoreModel($this->article),
|
|
||||||
],
|
|
||||||
'title' => 'string|min:6|max:255',
|
|
||||||
'publish_at' => 'date',
|
|
||||||
'user_id' => 'uuid|exists:users,id',
|
|
||||||
'content' => 'string|min:6',
|
|
||||||
'hero' => 'uuid|exists:media,id',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class AuthLoginRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'email' => 'required|string|min:6|max:255',
|
|
||||||
'password' => 'required|string|min:6',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
|
|
||||||
class BaseRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function authorize()
|
|
||||||
{
|
|
||||||
if (request()->isMethod('post') === true && method_exists($this, 'postAuthorize') === true) {
|
|
||||||
return $this->postAuthorize();
|
|
||||||
} elseif ((request()->isMethod('put') === true || request()->isMethod('patch') === true) && method_exists($this, 'putAuthorize') === true) {
|
|
||||||
return $this->putAuthorize();
|
|
||||||
} elseif (request()->isMethod('delete') === true && method_exists($this, 'destroyAuthorize') === true) {
|
|
||||||
return $this->deleteAuthorize();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
$rules = [];
|
|
||||||
|
|
||||||
if (method_exists($this, 'baseRules') === true) {
|
|
||||||
$rules = $this->baseRules();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method_exists($this, 'postRules') === true && request()->isMethod('post') === true) {
|
|
||||||
$rules = $this->mergeRules($rules, $this->postRules());
|
|
||||||
} elseif (method_exists($this, 'putRules') === true && (request()->isMethod('put') === true || request()->isMethod('patch') === true)) {
|
|
||||||
$rules = $this->mergeRules($rules, $this->putRules());
|
|
||||||
} elseif (method_exists($this, 'destroyRules') === true && request()->isMethod('delete') === true) {
|
|
||||||
$rules = $this->mergeRules($rules, $this->destroyRules());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rules;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Merge two collections of rules.
|
|
||||||
*
|
|
||||||
* @param array $collection1 The first collection of rules.
|
|
||||||
* @param array $collection2 The second collection of rules to merge.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function mergeRules(array $collection1, array $collection2)
|
|
||||||
{
|
|
||||||
$rules = [];
|
|
||||||
|
|
||||||
foreach ($collection1 as $key => $ruleset) {
|
|
||||||
if (array_key_exists($key, $collection2) === true) {
|
|
||||||
if (is_string($collection1[$key]) === true && is_string($collection2[$key]) === true) {
|
|
||||||
$rules[$key] = $collection1[$key] . '|' . $collection2[$key];
|
|
||||||
} else {
|
|
||||||
$key_ruleset = [];
|
|
||||||
|
|
||||||
if (is_array($collection1[$key]) === true) {
|
|
||||||
$key_ruleset = $collection1[$key];
|
|
||||||
} elseif (is_string($collection1[$key]) === true) {
|
|
||||||
$key_ruleset = explode('|', $collection1[$key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($collection2[$key]) === true) {
|
|
||||||
$key_ruleset = array_merge($key_ruleset, $collection2[$key]);
|
|
||||||
} elseif (is_string($collection2[$key]) === true) {
|
|
||||||
$key_ruleset = array_merge($key_ruleset, explode('|', $collection2[$key]));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($key_ruleset) > 0) {
|
|
||||||
$rules[$key] = $key_ruleset;
|
|
||||||
}
|
|
||||||
}//end if
|
|
||||||
} else {
|
|
||||||
$rules[$key] = $ruleset;
|
|
||||||
}//end if
|
|
||||||
}//end foreach
|
|
||||||
|
|
||||||
foreach ($collection2 as $key => $ruleset) {
|
|
||||||
if (array_key_exists($key, $rules) === false) {
|
|
||||||
$rules[$key] = $collection2[$key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rules;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use App\Rules\Recaptcha;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class ContactSendRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'name' => 'required|max:255',
|
|
||||||
'email' => 'required|email|max:255',
|
|
||||||
'content' => 'required|max:2000',
|
|
||||||
// 'captcha_token' => [new Recaptcha()],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
|
|
||||||
class EventRequest extends BaseRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Apply the base rules to this request
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function baseRules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'title' => 'min:6',
|
|
||||||
'location' => [
|
|
||||||
Rule::in(['online', 'physical']),
|
|
||||||
],
|
|
||||||
'address' => 'string|nullable',
|
|
||||||
'start_at' => 'date',
|
|
||||||
'end_at' => 'date|after:start_date',
|
|
||||||
'publish_at' => 'date|nullable',
|
|
||||||
'status' => [
|
|
||||||
Rule::in(['draft', 'soon', 'open', 'closed', 'cancelled']),
|
|
||||||
],
|
|
||||||
'registration_type' => [
|
|
||||||
Rule::in(['none', 'email', 'link', 'message']),
|
|
||||||
],
|
|
||||||
'registration_data' => [
|
|
||||||
Rule::when(strcasecmp('email', $this->attributes->get('registration_type')) == 0, 'required|email'),
|
|
||||||
Rule::when(strcasecmp('link', $this->attributes->get('registration_type')) == 0, 'required|url'),
|
|
||||||
Rule::when(strcasecmp('message', $this->attributes->get('registration_type')) == 0, 'required|message'),
|
|
||||||
],
|
|
||||||
'hero' => 'uuid|exists:media,id',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply the additional POST base rules to this request
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
protected function postRules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'title' => 'required',
|
|
||||||
'location' => 'required',
|
|
||||||
'address' => 'required_if:location,physical',
|
|
||||||
'start_at' => 'required',
|
|
||||||
'end_at' => 'required',
|
|
||||||
'status' => 'required',
|
|
||||||
'registration_type' => 'required',
|
|
||||||
'hero' => 'required',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
class MediaRequest extends BaseRequest
|
|
||||||
{
|
|
||||||
/* empty */
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
|
|
||||||
class ShortlinkRequest extends BaseRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Apply the additional POST base rules to this request
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function postRules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'code' => 'required|string|max:255|min:2|unique:shortlinks',
|
|
||||||
'url' => 'required|string|max:255|min:2',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to PUT request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function putRules()
|
|
||||||
{
|
|
||||||
$shortlink = $this->route('shortlink');
|
|
||||||
|
|
||||||
return [
|
|
||||||
'code' => ['required', 'string', 'max:255', 'min:2', Rule::unique('shortlinks')->ignore($shortlink->id)],
|
|
||||||
'url' => 'required|string|max:255|min:2',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use App\Rules\Recaptcha;
|
|
||||||
|
|
||||||
class SubscriptionRequest extends BaseRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function postRules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'email' => 'required|email|unique:subscriptions',
|
|
||||||
// 'captcha_token' => [new Recaptcha()],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function destroyRules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'email' => 'required|email',
|
|
||||||
// 'captcha_token' => [new Recaptcha()],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the custom error messages.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function messages()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'email.unique' => 'This email address has already subscribed',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use App\Rules\Recaptcha;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class UserForgotPasswordRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'email' => 'required|exists:users,email',
|
|
||||||
// 'captcha_token' => [new Recaptcha()],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use App\Rules\Uniqueish;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class UserRegisterRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'display_name' => ['required','string','max:255', new Uniqueish('users')],
|
|
||||||
'email' => 'required|string|email|max:255|unique:users',
|
|
||||||
'password' => 'required|string|min:8',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use App\Rules\RequiredIfAny;
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
use Illuminate\Validation\Rules\RequiredIf;
|
|
||||||
use App\Rules\Uniqueish;
|
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
|
|
||||||
class UserRequest extends BaseRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Apply the additional POST base rules to this request
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function postRules()
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
$isAdminUser = $user->hasPermission('admin/users');
|
|
||||||
|
|
||||||
return [
|
|
||||||
'first_name' => ($isAdminUser === true ? 'required_with:last_name,display_name,phone' : 'required') . '|string|max:255|min:2',
|
|
||||||
'last_name' => ($isAdminUser === true ? 'required_with:first_name,display_name,phone' : 'required') . '|string|max:255|min:2',
|
|
||||||
'display_name' => [
|
|
||||||
$isAdminUser === true ? 'required_with:first_name,last_name,phone' : 'required',
|
|
||||||
'string',
|
|
||||||
'max:255',
|
|
||||||
new Uniqueish('users')
|
|
||||||
],
|
|
||||||
'email' => 'required|string|email|max:255|unique:users',
|
|
||||||
'phone' => ['string', 'regex:/^(\+|00)?[0-9][0-9 \-\(\)\.]{7,32}$/'],
|
|
||||||
'email_verified_at' => 'date'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to PUT request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function putRules()
|
|
||||||
{
|
|
||||||
$user = auth()->user();
|
|
||||||
$ruleUser = $this->route('user');
|
|
||||||
$isAdminUser = $user->hasPermission('admin/users');
|
|
||||||
|
|
||||||
$requiredIfFieldsPresent = function (array $fields) use ($ruleUser): RequiredIf {
|
|
||||||
return new RequiredIf(function () use ($fields, $ruleUser) {
|
|
||||||
$input = $this->all();
|
|
||||||
$values = Arr::only($input, $fields);
|
|
||||||
|
|
||||||
foreach ($values as $key => $value) {
|
|
||||||
if ($value !== null && $value !== '') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$fields = array_diff($fields, array_keys($values));
|
|
||||||
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
if ($ruleUser->$field !== '') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return [
|
|
||||||
'first_name' => [
|
|
||||||
'sometimes',
|
|
||||||
$isAdminUser === true ? $requiredIfFieldsPresent(['last_name', 'display_name', 'phone']) : 'required',
|
|
||||||
'string',
|
|
||||||
'between:2,255',
|
|
||||||
],
|
|
||||||
'last_name' => [
|
|
||||||
'sometimes',
|
|
||||||
$isAdminUser === true ? $requiredIfFieldsPresent(['first_name', 'last_name', 'phone']) : 'required',
|
|
||||||
'string',
|
|
||||||
'between:2,255',
|
|
||||||
],
|
|
||||||
'display_name' => [
|
|
||||||
'sometimes',
|
|
||||||
$isAdminUser === true ? $requiredIfFieldsPresent(['first_name', 'display_name', 'phone']) : 'required',
|
|
||||||
'string',
|
|
||||||
'between:2,255',
|
|
||||||
(new Uniqueish('users', 'display_name'))->ignore($ruleUser->id)
|
|
||||||
],
|
|
||||||
'email' => [
|
|
||||||
'string',
|
|
||||||
'email',
|
|
||||||
'max:255',
|
|
||||||
Rule::unique('users')->ignore($ruleUser->id)->when(
|
|
||||||
$this->email !== $ruleUser->email,
|
|
||||||
function ($query) {
|
|
||||||
return $query->where('email', $this->email);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
],
|
|
||||||
'phone' => ['nullable', 'regex:/^(\+|00)?[0-9][0-9 \-\(\)\.]{7,32}$/'],
|
|
||||||
'password' => "nullable|string|min:8"
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use App\Rules\Recaptcha;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class UserResendVerifyEmailRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'email' => 'required|exists:users,email',
|
|
||||||
// 'captcha_token' => [new Recaptcha()],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use App\Rules\Recaptcha;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class UserResetPasswordRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'code' => 'required|digits:6',
|
|
||||||
'password' => 'required|string|min:8',
|
|
||||||
// 'captcha_token' => [new Recaptcha()],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use App\Rules\Recaptcha;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class UserVerifyEmailRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'code' => 'required|digits:6',
|
|
||||||
// 'captcha_token' => [new Recaptcha()],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use App\Models\Media;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
|
|
||||||
class MoveMediaJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable;
|
|
||||||
use InteractsWithQueue;
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Media item
|
|
||||||
*
|
|
||||||
* @var Media
|
|
||||||
*/
|
|
||||||
public $media;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* New storage ID
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $newStorage;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param Media $media The media model.
|
|
||||||
* @param string $newStorage The new storage ID.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(Media $media, string $newStorage)
|
|
||||||
{
|
|
||||||
$this->media = $media;
|
|
||||||
$this->newStorage = $newStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
// Don't continue if the media is already on the new storage disk
|
|
||||||
if ($this->media->storage === $this->newStorage) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->media->status = 'Moving file';
|
|
||||||
$this->media->save();
|
|
||||||
|
|
||||||
$files = ["/{$this->media->name}"];
|
|
||||||
if (empty($this->media->variants) === false) {
|
|
||||||
foreach ($this->media->variants as $variant => $name) {
|
|
||||||
$files[] = "/{$name}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->media->invalidateCFCache();
|
|
||||||
|
|
||||||
// Move the files from the old storage disk to the new storage disk
|
|
||||||
foreach ($files as $file) {
|
|
||||||
Storage::disk($this->newStorage)->put($file, Storage::disk($this->media->storage)->get($file));
|
|
||||||
Storage::disk($this->media->storage)->delete($file);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the media model with the new storage and save it to the database
|
|
||||||
$this->media->storage = $this->newStorage;
|
|
||||||
$this->media->status = 'OK';
|
|
||||||
$this->media->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Mail\Mailable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Support\Facades\Mail;
|
|
||||||
|
|
||||||
class SendEmailJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable;
|
|
||||||
use InteractsWithQueue;
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mail to receipt
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $to;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mailable item
|
|
||||||
*
|
|
||||||
* @var Mailable
|
|
||||||
*/
|
|
||||||
public $mailable;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param string $to The email receipient.
|
|
||||||
* @param Mailable $mailable The mailable.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(string $to, Mailable $mailable)
|
|
||||||
{
|
|
||||||
$this->to = $to;
|
|
||||||
$this->mailable = $mailable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
Mail::to($this->to)->send($this->mailable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,179 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use App\Models\Media;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use SplFileInfo;
|
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|
||||||
use Intervention\Image\Facades\Image;
|
|
||||||
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
|
||||||
|
|
||||||
class StoreUploadedFileJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable;
|
|
||||||
use InteractsWithQueue;
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Media item
|
|
||||||
*
|
|
||||||
* @var Media
|
|
||||||
*/
|
|
||||||
protected $media;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uploaded file item
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $uploadedFilePath;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace existing files
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $replaceExisting;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param Media $media The media model.
|
|
||||||
* @param string $filePath The uploaded file.
|
|
||||||
* @param boolean $replaceExisting Replace existing files.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(Media $media, string $filePath, bool $replaceExisting = true)
|
|
||||||
{
|
|
||||||
$this->media = $media;
|
|
||||||
$this->uploadedFilePath = $filePath;
|
|
||||||
$this->replaceExisting = $replaceExisting;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$storageDisk = $this->media->storage;
|
|
||||||
$fileName = $this->media->name;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->media->status = "Uploading to CDN";
|
|
||||||
$this->media->save();
|
|
||||||
|
|
||||||
if (strlen($this->uploadedFilePath) > 0) {
|
|
||||||
if (Storage::disk($storageDisk)->exists($fileName) === false || $this->replaceExisting === true) {
|
|
||||||
Storage::disk($storageDisk)->putFileAs('/', new SplFileInfo($this->uploadedFilePath), $fileName);
|
|
||||||
Log::info("uploading file {$storageDisk} / {$fileName} / {$this->uploadedFilePath}");
|
|
||||||
} else {
|
|
||||||
Log::info("file {$fileName} already exists in {$storageDisk} / {$this->uploadedFilePath}. Not replacing file and using local {$fileName} for variants.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (Storage::disk($storageDisk)->exists($fileName) === true) {
|
|
||||||
Log::info("file {$fileName} already exists in {$storageDisk} / {$this->uploadedFilePath}. No local {$fileName} for variants, downloading from CDN.");
|
|
||||||
$readStream = Storage::disk($storageDisk)->readStream($fileName);
|
|
||||||
$tempFilePath = tempnam(sys_get_temp_dir(), 'download-');
|
|
||||||
$writeStream = fopen($tempFilePath, 'w');
|
|
||||||
while (feof($readStream) !== true) {
|
|
||||||
fwrite($writeStream, fread($readStream, 8192));
|
|
||||||
}
|
|
||||||
fclose($readStream);
|
|
||||||
fclose($writeStream);
|
|
||||||
$this->uploadedFilePath = $tempFilePath;
|
|
||||||
} else {
|
|
||||||
$errorStr = "cannot upload file {$storageDisk} / {$fileName} / {$this->uploadedFilePath} as temp file is empty";
|
|
||||||
Log::info($errorStr);
|
|
||||||
throw new \Exception($errorStr);
|
|
||||||
}
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
if (strpos($this->media->mime_type, 'image/') === 0) {
|
|
||||||
$this->media->status = "Optimizing image";
|
|
||||||
$this->media->save();
|
|
||||||
|
|
||||||
// Generate additional image sizes
|
|
||||||
$sizes = Media::getTypeVariants('image');
|
|
||||||
|
|
||||||
$originalImage = Image::make($this->uploadedFilePath);
|
|
||||||
|
|
||||||
$dimensions = [$originalImage->getWidth(), $originalImage->getHeight()];
|
|
||||||
$this->media->dimensions = implode('x', $dimensions);
|
|
||||||
|
|
||||||
foreach ($sizes as $variantName => $size) {
|
|
||||||
$postfix = "{$size['width']}x{$size['height']}";
|
|
||||||
if ($variantName === 'scaled') {
|
|
||||||
$postfix = 'scaled';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($this->media->variants) === true && array_key_exists($postfix, $this->media->variants) === true && Storage::disk($storageDisk)->exists($this->media->variants[$postfix]) === true && $this->replaceExisting === true) {
|
|
||||||
Storage::disk($storageDisk)->delete($this->media->variants[$postfix]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$newFilename = pathinfo($this->media->name, PATHINFO_FILENAME) . "-$postfix.webp";
|
|
||||||
|
|
||||||
if (Storage::disk($storageDisk)->exists($newFilename) === false || $this->replaceExisting === true) {
|
|
||||||
// Get the largest available variant
|
|
||||||
if ($dimensions[0] >= $size['width'] && $dimensions[1] >= $size['height']) {
|
|
||||||
// Store the variant in the variants array
|
|
||||||
$variants[$variantName] = $newFilename;
|
|
||||||
|
|
||||||
// Resize the image to the variant size if its dimensions are greater than the specified size
|
|
||||||
$image = clone $originalImage;
|
|
||||||
|
|
||||||
$imageSize = $image->getSize();
|
|
||||||
if ($imageSize->getWidth() > $size['width'] || $imageSize->getHeight() > $size['height']) {
|
|
||||||
$image->resize($size['width'], $size['height'], function ($constraint) {
|
|
||||||
$constraint->aspectRatio();
|
|
||||||
$constraint->upsize();
|
|
||||||
});
|
|
||||||
$image->resizeCanvas($size['width'], $size['height'], 'center', false, '#FFFFFF');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Optimize and store image
|
|
||||||
$tempImagePath = tempnam(sys_get_temp_dir(), 'optimize');
|
|
||||||
$image->encode('webp', 75)->save($tempImagePath);
|
|
||||||
Storage::disk($storageDisk)->putFileAs('/', new SplFileInfo($tempImagePath), $newFilename);
|
|
||||||
unlink($tempImagePath);
|
|
||||||
}//end if
|
|
||||||
} else {
|
|
||||||
Log::info("variant {$variantName} already exists for file {$fileName}");
|
|
||||||
}//end if
|
|
||||||
}//end foreach
|
|
||||||
|
|
||||||
// Set missing variants to the largest available variant
|
|
||||||
foreach ($sizes as $variantName => $size) {
|
|
||||||
if (isset($variants[$variantName]) === false) {
|
|
||||||
$variants[$variantName] = $this->media->name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->media->variants = $variants;
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
if (strlen($this->uploadedFilePath) > 0) {
|
|
||||||
unlink($this->uploadedFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->media->status = 'OK';
|
|
||||||
$this->media->save();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Log::error($e->getMessage());
|
|
||||||
$this->media->status = "Failed";
|
|
||||||
$this->media->save();
|
|
||||||
$this->fail($e);
|
|
||||||
}//end try
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Mail;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Mail\Mailable;
|
|
||||||
use Illuminate\Mail\Mailables\Content;
|
|
||||||
use Illuminate\Mail\Mailables\Envelope;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class ChangeEmailVerify extends Mailable
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The user instance.
|
|
||||||
*
|
|
||||||
* @var \App\Models\User
|
|
||||||
*/
|
|
||||||
public $user;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The registration code.
|
|
||||||
*
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
public $code;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The new email address.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $new_email;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new message instance.
|
|
||||||
*
|
|
||||||
* @param User $user The user the email applies to.
|
|
||||||
* @param integer $code The action code.
|
|
||||||
* @param string $new_email The new email address.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(User $user, int $code, string $new_email)
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
$this->code = $code;
|
|
||||||
$this->new_email = $new_email;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message envelope.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Envelope
|
|
||||||
*/
|
|
||||||
public function envelope()
|
|
||||||
{
|
|
||||||
return new Envelope(
|
|
||||||
subject: '👋🏻 Lets change your email!',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message content definition.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Content
|
|
||||||
*/
|
|
||||||
public function content()
|
|
||||||
{
|
|
||||||
return new Content(
|
|
||||||
view: 'emails.user.change_email_verify',
|
|
||||||
text: 'emails.user.change_email_verify_plain',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Mail;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Mail\Mailable;
|
|
||||||
use Illuminate\Mail\Mailables\Content;
|
|
||||||
use Illuminate\Mail\Mailables\Envelope;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class ChangedEmail extends Mailable
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The user instance.
|
|
||||||
*
|
|
||||||
* @var \App\Models\User
|
|
||||||
*/
|
|
||||||
public $user;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The old email.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $old_email;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The new email.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $new_email;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new message instance.
|
|
||||||
*
|
|
||||||
* @param User $user The user the email applies to.
|
|
||||||
* @param string $old_email The previous email address.
|
|
||||||
* @param string $new_email The new email address.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(User $user, string $old_email, string $new_email)
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
$this->old_email = $old_email;
|
|
||||||
$this->new_email = $new_email;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message envelope.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Envelope
|
|
||||||
*/
|
|
||||||
public function envelope()
|
|
||||||
{
|
|
||||||
return new Envelope(
|
|
||||||
subject: '👍 Your email has been changed!',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message content definition.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Content
|
|
||||||
*/
|
|
||||||
public function content()
|
|
||||||
{
|
|
||||||
return new Content(
|
|
||||||
view: 'emails.user.changed_email',
|
|
||||||
text: 'emails.user.changed_email_plain',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Mail;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Mail\Mailable;
|
|
||||||
use Illuminate\Mail\Mailables\Content;
|
|
||||||
use Illuminate\Mail\Mailables\Envelope;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class ChangedPassword extends Mailable
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The user instance.
|
|
||||||
*
|
|
||||||
* @var \App\Models\User
|
|
||||||
*/
|
|
||||||
public $user;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new message instance.
|
|
||||||
*
|
|
||||||
* @param User $user The user the email applies to.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(User $user)
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message envelope.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Envelope
|
|
||||||
*/
|
|
||||||
public function envelope()
|
|
||||||
{
|
|
||||||
return new Envelope(
|
|
||||||
subject: '👍 Your password has been changed!',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message content definition.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Content
|
|
||||||
*/
|
|
||||||
public function content()
|
|
||||||
{
|
|
||||||
return new Content(
|
|
||||||
view: 'emails.user.changed_password',
|
|
||||||
text: 'emails.user.changed_password_plain',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Mail;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Mail\Mailable;
|
|
||||||
use Illuminate\Mail\Mailables\Content;
|
|
||||||
use Illuminate\Mail\Mailables\Envelope;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class Contact extends Mailable
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The contact name.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The contact email.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $email;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The contact content.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $content;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new message instance.
|
|
||||||
*
|
|
||||||
* @param string $name The contact name.
|
|
||||||
* @param string $email The contact email.
|
|
||||||
* @param string $content The contact content.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(string $name, string $email, string $content)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
$this->email = $email;
|
|
||||||
$this->content = $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message envelope.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Envelope
|
|
||||||
*/
|
|
||||||
public function envelope()
|
|
||||||
{
|
|
||||||
return new Envelope(
|
|
||||||
subject: config('contact.contact_subject'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message content definition.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Content
|
|
||||||
*/
|
|
||||||
public function content()
|
|
||||||
{
|
|
||||||
return new Content(
|
|
||||||
view: 'emails.user.contact',
|
|
||||||
text: 'emails.user.contact_plain',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Mail;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Mail\Mailable;
|
|
||||||
use Illuminate\Mail\Mailables\Content;
|
|
||||||
use Illuminate\Mail\Mailables\Envelope;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class EmailVerify extends Mailable
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The user instance.
|
|
||||||
*
|
|
||||||
* @var \App\Models\User
|
|
||||||
*/
|
|
||||||
public $user;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The registration code.
|
|
||||||
*
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
public $code;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new message instance.
|
|
||||||
*
|
|
||||||
* @param User $user The user the email applies to.
|
|
||||||
* @param integer $code The action code.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(User $user, int $code)
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
$this->code = $code;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message envelope.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Envelope
|
|
||||||
*/
|
|
||||||
public function envelope()
|
|
||||||
{
|
|
||||||
return new Envelope(
|
|
||||||
subject: '👋🏻 Welcome to STEMMechanics!',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message content definition.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Content
|
|
||||||
*/
|
|
||||||
public function content()
|
|
||||||
{
|
|
||||||
return new Content(
|
|
||||||
view: 'emails.user.email_verify',
|
|
||||||
text: 'emails.user.email_verify_plain',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Mail;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Mail\Mailable;
|
|
||||||
use Illuminate\Mail\Mailables\Content;
|
|
||||||
use Illuminate\Mail\Mailables\Envelope;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class ForgotPassword extends Mailable
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The user
|
|
||||||
*
|
|
||||||
* @var \App\Models\User
|
|
||||||
*/
|
|
||||||
public $user;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The reset code
|
|
||||||
*
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
public $code;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new message instance.
|
|
||||||
*
|
|
||||||
* @param User $user The user the email applies to.
|
|
||||||
* @param integer $code The action code.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(User $user, int $code)
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
$this->code = $code;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message envelope.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Envelope
|
|
||||||
*/
|
|
||||||
public function envelope()
|
|
||||||
{
|
|
||||||
return new Envelope(
|
|
||||||
subject: '🤦 Forgot your password?',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message content definition.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Content
|
|
||||||
*/
|
|
||||||
public function content()
|
|
||||||
{
|
|
||||||
return new Content(
|
|
||||||
view: 'emails.user.forgot_password',
|
|
||||||
text: 'emails.user.forgot_password_plain',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Mail;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Mail\Mailable;
|
|
||||||
use Illuminate\Mail\Mailables\Content;
|
|
||||||
use Illuminate\Mail\Mailables\Envelope;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class SubscriptionConfirm extends Mailable
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The email address.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $email;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new message instance.
|
|
||||||
*
|
|
||||||
* @param string $email The email address.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(string $email)
|
|
||||||
{
|
|
||||||
$this->email = $email;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message envelope.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Envelope
|
|
||||||
*/
|
|
||||||
public function envelope()
|
|
||||||
{
|
|
||||||
return new Envelope(
|
|
||||||
subject: '🗞️ You\'re on the mailing list!',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message content definition.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Content
|
|
||||||
*/
|
|
||||||
public function content()
|
|
||||||
{
|
|
||||||
return new Content(
|
|
||||||
view: 'emails.user.subscription_confirm',
|
|
||||||
text: 'emails.user.subscription_confirm_plain',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Mail;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Mail\Mailable;
|
|
||||||
use Illuminate\Mail\Mailables\Content;
|
|
||||||
use Illuminate\Mail\Mailables\Envelope;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class SubscriptionUnsubscribed extends Mailable
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The email address.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $email;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new message instance.
|
|
||||||
*
|
|
||||||
* @param string $email The email address.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(string $email)
|
|
||||||
{
|
|
||||||
$this->email = $email;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message envelope.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Envelope
|
|
||||||
*/
|
|
||||||
public function envelope()
|
|
||||||
{
|
|
||||||
return new Envelope(
|
|
||||||
subject: 'You have been unsubscribed',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message content definition.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Mail\Mailables\Content
|
|
||||||
*/
|
|
||||||
public function content()
|
|
||||||
{
|
|
||||||
return new Content(
|
|
||||||
view: 'emails.user.subscription_unsubscribed',
|
|
||||||
text: 'emails.user.subscription_unsubscribed_plain',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Analytics extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that aren't mass assignable.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $guarded = [];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new row in the analytics table with the given attributes,
|
|
||||||
* automatically assigning a session value based on previous rows.
|
|
||||||
*
|
|
||||||
* @param array $attributes Model attributes.
|
|
||||||
* @return static
|
|
||||||
*/
|
|
||||||
public static function createWithSession(array $attributes)
|
|
||||||
{
|
|
||||||
$previousRow = self::where('useragent', $attributes['useragent'])
|
|
||||||
->where('ip', $attributes['ip'])
|
|
||||||
->where('created_at', '>=', now()->subMinutes(30))
|
|
||||||
->whereNotNull('session')
|
|
||||||
->orderBy('created_at', 'desc')
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if ($previousRow !== null) {
|
|
||||||
$attributes['session'] = $previousRow->session;
|
|
||||||
} else {
|
|
||||||
$lastSession = self::max('session');
|
|
||||||
$attributes['session'] = ($lastSession + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return static::create($attributes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Traits\Uuids;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
||||||
|
|
||||||
class Article extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
use Uuids;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'title',
|
|
||||||
'slug',
|
|
||||||
'publish_at',
|
|
||||||
'content',
|
|
||||||
'user_id',
|
|
||||||
'hero'
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the article user
|
|
||||||
*
|
|
||||||
* @return BelongsTo
|
|
||||||
*/
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(User::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all of the article's attachments.
|
|
||||||
*
|
|
||||||
* @return MorphMany
|
|
||||||
*/
|
|
||||||
public function attachments()
|
|
||||||
{
|
|
||||||
return $this->morphMany('App\Models\Attachment', 'attachable');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
||||||
|
|
||||||
class Attachment extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'media_id',
|
|
||||||
'private',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default attributes.
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected $attributes = [
|
|
||||||
'private' => 'false',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get attachments attachable
|
|
||||||
*
|
|
||||||
* @return MorphTo
|
|
||||||
*/
|
|
||||||
public function attachable()
|
|
||||||
{
|
|
||||||
return $this->morphTo();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the media for this attachment.
|
|
||||||
*
|
|
||||||
* @return BelongsTo
|
|
||||||
*/
|
|
||||||
public function media()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Media::class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Traits\Uuids;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
||||||
|
|
||||||
class Event extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
use Uuids;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'title',
|
|
||||||
'location',
|
|
||||||
'location_url',
|
|
||||||
'address',
|
|
||||||
'start_at',
|
|
||||||
'end_at',
|
|
||||||
'publish_at',
|
|
||||||
'status',
|
|
||||||
'registration_type',
|
|
||||||
'registration_data',
|
|
||||||
'hero',
|
|
||||||
'content',
|
|
||||||
'price',
|
|
||||||
'ages',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all of the article's attachments.
|
|
||||||
*
|
|
||||||
* @return MorphMany
|
|
||||||
*/
|
|
||||||
public function attachments()
|
|
||||||
{
|
|
||||||
return $this->morphMany('App\Models\Attachment', 'attachable');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all the associated users.
|
|
||||||
*
|
|
||||||
* @return BelongsToMany
|
|
||||||
*/
|
|
||||||
public function users()
|
|
||||||
{
|
|
||||||
return $this->belongsToMany(User::class, 'event_user', 'event_id', 'user_id');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Traits\Uuids;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class EventUser extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
use Uuids;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'event_id',
|
|
||||||
'user_id',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the event for this attachment.
|
|
||||||
*
|
|
||||||
* @return BelongsTo
|
|
||||||
*/
|
|
||||||
public function event()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Event::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the user for this attachment.
|
|
||||||
*
|
|
||||||
* @return BelongsTo
|
|
||||||
*/
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(User::class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,686 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use App\Jobs\MoveMediaJob;
|
|
||||||
use App\Jobs\OptimizeMediaJob;
|
|
||||||
use App\Jobs\StoreUploadedFileJob;
|
|
||||||
use App\Traits\Uuids;
|
|
||||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
||||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Config;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Support\Facades\Queue;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
||||||
|
|
||||||
class Media extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
use Uuids;
|
|
||||||
use DispatchesJobs;
|
|
||||||
|
|
||||||
public const INVALID_FILE_ERROR = 1;
|
|
||||||
public const FILE_SIZE_EXCEEDED_ERROR = 2;
|
|
||||||
public const FILE_NAME_EXISTS_ERROR = 3;
|
|
||||||
public const TEMP_FILE_ERROR = 4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'title',
|
|
||||||
'user_id',
|
|
||||||
'mime_type',
|
|
||||||
'permission',
|
|
||||||
'storage',
|
|
||||||
'description',
|
|
||||||
'name',
|
|
||||||
'size',
|
|
||||||
'status',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are appended.
|
|
||||||
*
|
|
||||||
* @var array<string>
|
|
||||||
*/
|
|
||||||
protected $appends = [
|
|
||||||
'url',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default attributes.
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected $attributes = [
|
|
||||||
'storage' => 'cdn',
|
|
||||||
'variants' => '[]',
|
|
||||||
'description' => '',
|
|
||||||
'dimensions' => '',
|
|
||||||
'permission' => '',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The storage file list cache.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected static $storageFileListCache = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The variant types.
|
|
||||||
*
|
|
||||||
* @var int[][][]
|
|
||||||
*/
|
|
||||||
protected static $variantTypes = [
|
|
||||||
'image' => [
|
|
||||||
'thumb' => ['width' => 150, 'height' => 150],
|
|
||||||
'small' => ['width' => 300, 'height' => 225],
|
|
||||||
'medium' => ['width' => 768, 'height' => 576],
|
|
||||||
'large' => ['width' => 1024, 'height' => 768],
|
|
||||||
'xlarge' => ['width' => 1536, 'height' => 1152],
|
|
||||||
'xxlarge' => ['width' => 2048, 'height' => 1536],
|
|
||||||
'scaled' => ['width' => 2560, 'height' => 1920]
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model Boot
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected static function boot()
|
|
||||||
{
|
|
||||||
parent::boot();
|
|
||||||
|
|
||||||
static::updating(function ($media) {
|
|
||||||
if (array_key_exists('permission', $media->getChanges()) === true) {
|
|
||||||
$origPermission = $media->getOriginal()['permission'];
|
|
||||||
$newPermission = $media->permission;
|
|
||||||
|
|
||||||
$newPermissionLen = strlen($newPermission);
|
|
||||||
|
|
||||||
if ($newPermissionLen !== strlen($origPermission)) {
|
|
||||||
if ($newPermissionLen === 0) {
|
|
||||||
$this->moveToStorage('cdn');
|
|
||||||
} else {
|
|
||||||
$this->moveToStorage('private');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
static::deleting(function ($media) {
|
|
||||||
$media->deleteFile();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Type Variants.
|
|
||||||
*
|
|
||||||
* @param string $type The variant type to get.
|
|
||||||
* @return array The variant data.
|
|
||||||
*/
|
|
||||||
public static function getTypeVariants(string $type)
|
|
||||||
{
|
|
||||||
if (isset(self::$variantTypes[$type]) === true) {
|
|
||||||
return self::$variantTypes[$type];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Variants Get Mutator.
|
|
||||||
*
|
|
||||||
* @param mixed $value The value to mutate.
|
|
||||||
* @return array The mutated value.
|
|
||||||
*/
|
|
||||||
public function getVariantsAttribute(mixed $value)
|
|
||||||
{
|
|
||||||
if (is_string($value) === true) {
|
|
||||||
return json_decode($value, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Variants Set Mutator.
|
|
||||||
*
|
|
||||||
* @param mixed $value The value to mutate.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setVariantsAttribute(mixed $value)
|
|
||||||
{
|
|
||||||
if (is_array($value) !== true) {
|
|
||||||
$value = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->attributes['variants'] = json_encode(($value ?? []));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get previous variant.
|
|
||||||
*
|
|
||||||
* @param string $type The variant type.
|
|
||||||
* @param string $variant The initial variant.
|
|
||||||
* @return string The previous variant name (or '').
|
|
||||||
*/
|
|
||||||
public function getPreviousVariant(string $type, string $variant)
|
|
||||||
{
|
|
||||||
if (isset(self::$variantTypes[$type]) === false) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$variants = self::$variantTypes[$type];
|
|
||||||
$keys = array_keys($variants);
|
|
||||||
|
|
||||||
$currentIndex = array_search($variant, $keys);
|
|
||||||
if ($currentIndex === false || $currentIndex === 0) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $keys[($currentIndex - 1)];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get next variant.
|
|
||||||
*
|
|
||||||
* @param string $type The variant type.
|
|
||||||
* @param string $variant The initial variant.
|
|
||||||
* @return string The next variant name (or '').
|
|
||||||
*/
|
|
||||||
public function getNextVariant(string $type, string $variant)
|
|
||||||
{
|
|
||||||
if (isset(self::$variantTypes[$type]) === false) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$variants = self::$variantTypes[$type];
|
|
||||||
$keys = array_keys($variants);
|
|
||||||
|
|
||||||
$currentIndex = array_search($variant, $keys);
|
|
||||||
if ($currentIndex === false || $currentIndex === (count($keys) - 1)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $keys[($currentIndex + 1)];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get variant URL.
|
|
||||||
*
|
|
||||||
* @param string $variant The variant to find.
|
|
||||||
* @param boolean $returnNearest Return the nearest variant if request is not found.
|
|
||||||
* @return string The URL.
|
|
||||||
*/
|
|
||||||
public function getVariantURL(string $variant, bool $returnNearest = true)
|
|
||||||
{
|
|
||||||
$variants = $this->variants;
|
|
||||||
if (isset($variants[$variant]) === true) {
|
|
||||||
return self::getUrlPath() . $variants[$variant];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($returnNearest === true) {
|
|
||||||
$variantType = explode('/', $this->mime_type)[0];
|
|
||||||
$previousVariant = $variant;
|
|
||||||
while (empty($previousVariant) === false) {
|
|
||||||
$previousVariant = $this->getPreviousVariant($variantType, $previousVariant);
|
|
||||||
if (empty($previousVariant) === false && isset($variants[$previousVariant]) === true) {
|
|
||||||
return self::getUrlPath() . $variants[$previousVariant];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete file and associated files with the modal.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function deleteFile()
|
|
||||||
{
|
|
||||||
$fileName = $this->name;
|
|
||||||
$baseName = pathinfo($fileName, PATHINFO_FILENAME);
|
|
||||||
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
|
|
||||||
|
|
||||||
$files = Storage::disk($this->storage)->files();
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if (preg_match("/{$baseName}(-[a-zA-Z0-9]+)?\.{$extension}/", $file) === 1) {
|
|
||||||
Storage::disk($this->storage)->delete($file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->invalidateCFCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invalidate Cloudflare Cache.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws InvalidArgumentException Exception.
|
|
||||||
*/
|
|
||||||
private function invalidateCFCache()
|
|
||||||
{
|
|
||||||
$zone_id = env("CLOUDFLARE_ZONE_ID");
|
|
||||||
$api_key = env("CLOUDFLARE_API_KEY");
|
|
||||||
if ($zone_id !== null && $api_key !== null && $this->url !== "") {
|
|
||||||
$urls = [$this->url];
|
|
||||||
|
|
||||||
foreach ($this->variants as $variant => $name) {
|
|
||||||
$urls[] = str_replace($this->name, $name, $this->url);
|
|
||||||
}
|
|
||||||
|
|
||||||
$curl = curl_init();
|
|
||||||
curl_setopt_array($curl, [
|
|
||||||
CURLOPT_URL => "https://api.cloudflare.com/client/v4/zones/" . $zone_id . "/purge_cache",
|
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
|
||||||
CURLOPT_CUSTOMREQUEST => "DELETE",
|
|
||||||
CURLOPT_POSTFIELDS => json_encode(["files" => $urls]),
|
|
||||||
CURLOPT_HTTPHEADER => [
|
|
||||||
"Content-Type: application/json",
|
|
||||||
"Authorization: Bearer " . $api_key
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
curl_exec($curl);
|
|
||||||
curl_close($curl);
|
|
||||||
}//end if
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get URL path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getUrlPath()
|
|
||||||
{
|
|
||||||
$url = config("filesystems.disks.$this->storage.url");
|
|
||||||
return "$url/";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the file URL
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getUrlAttribute()
|
|
||||||
{
|
|
||||||
if (isset($this->attributes['name']) === true) {
|
|
||||||
return self::getUrlPath() . $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the file owner
|
|
||||||
*
|
|
||||||
* @return BelongsTo
|
|
||||||
*/
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(User::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move files to new storage device.
|
|
||||||
*
|
|
||||||
* @param string $storage The storage ID to move to.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function moveToStorage(string $storage)
|
|
||||||
{
|
|
||||||
if ($storage !== $this->storage && Config::has("filesystems.disks.$storage") === true) {
|
|
||||||
$this->status = "Processing media";
|
|
||||||
MoveMediaJob::dispatch($this, $storage)->onQueue('media');
|
|
||||||
$this->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new Media from UploadedFile data.
|
|
||||||
*
|
|
||||||
* @param App\Models\Request $request The request data.
|
|
||||||
* @param Illuminate\Http\UploadedFile $file The file.
|
|
||||||
* @return null|Media The result or null if not successful.
|
|
||||||
*/
|
|
||||||
public static function createFromUploadedFile(Request $request, UploadedFile $file)
|
|
||||||
{
|
|
||||||
$request->merge([
|
|
||||||
'title' => $request->get('title', ''),
|
|
||||||
'name' => '',
|
|
||||||
'size' => 0,
|
|
||||||
'mime_type' => '',
|
|
||||||
'status' => '',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($request->get('storage') === null) {
|
|
||||||
// We store images by default locally
|
|
||||||
if (strpos($file->getMimeType(), 'image/') === 0) {
|
|
||||||
$request->merge([
|
|
||||||
'storage' => 'local',
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$request->merge([
|
|
||||||
'storage' => 'cdn',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$mediaItem = $request->user()->media()->create($request->all());
|
|
||||||
$mediaItem->updateWithUploadedFile($file);
|
|
||||||
|
|
||||||
return $mediaItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update Media with UploadedFile data.
|
|
||||||
*
|
|
||||||
* @param Illuminate\Http\UploadedFile $file The file.
|
|
||||||
* @return null|Media The media item.
|
|
||||||
*/
|
|
||||||
public function updateWithUploadedFile(UploadedFile $file)
|
|
||||||
{
|
|
||||||
if ($file === null || $file->isValid() !== true) {
|
|
||||||
throw new \Exception('The file is invalid.', self::INVALID_FILE_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($file->getSize() > static::getMaxUploadSize()) {
|
|
||||||
throw new \Exception('The file size is larger then permitted.', self::FILE_SIZE_EXCEEDED_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
$name = static::generateUniqueFileName($file->getClientOriginalName());
|
|
||||||
if ($name === false) {
|
|
||||||
throw new \Exception('The file name already exists in storage.', self::FILE_NAME_EXISTS_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove file if there is an existing entry in this medium item
|
|
||||||
if (strlen($this->name) > 0 && strlen($this->storage) > 0) {
|
|
||||||
Storage::disk($this->storage)->delete($this->name);
|
|
||||||
foreach ($this->variants as $variantName => $fileName) {
|
|
||||||
Storage::disk($this->storage)->delete($fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->name = '';
|
|
||||||
$this->variants = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen($this->title) === 0) {
|
|
||||||
$this->title = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->name = $name;
|
|
||||||
$this->size = $file->getSize();
|
|
||||||
$this->mime_type = $file->getMimeType();
|
|
||||||
$this->status = 'Processing media';
|
|
||||||
$this->save();
|
|
||||||
|
|
||||||
$temporaryFilePath = generateTempFilePath();
|
|
||||||
copy($file->path(), $temporaryFilePath);
|
|
||||||
|
|
||||||
try {
|
|
||||||
StoreUploadedFileJob::dispatch($this, $temporaryFilePath)->onQueue('media');
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->status = 'Error';
|
|
||||||
$this->save();
|
|
||||||
|
|
||||||
throw $e;
|
|
||||||
}//end try
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Download the file from the storage to the user.
|
|
||||||
*
|
|
||||||
* @param string $variant The variant to download or null if none.
|
|
||||||
* @param boolean $fallback Fallback to the original file if the variant is not found.
|
|
||||||
* @return JsonResponse|StreamedResponse The response.
|
|
||||||
* @throws BindingResolutionException The Exception.
|
|
||||||
*/
|
|
||||||
public function download(string $variant = null, bool $fallback = true)
|
|
||||||
{
|
|
||||||
$path = $this->name;
|
|
||||||
if ($variant !== null) {
|
|
||||||
if (array_key_exists($variant, $this->variant) === true) {
|
|
||||||
$path = $this->variant[$variant];
|
|
||||||
} else {
|
|
||||||
return response()->json(['message' => 'The resource was not found.'], HttpResponseCodes::HTTP_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$disk = Storage::disk($this->storage);
|
|
||||||
if ($disk->exists($path) === true) {
|
|
||||||
$stream = $disk->readStream($path);
|
|
||||||
$response = response()->stream(
|
|
||||||
function () use ($stream) {
|
|
||||||
fpassthru($stream);
|
|
||||||
},
|
|
||||||
200,
|
|
||||||
[
|
|
||||||
'Content-Type' => $this->mime_type,
|
|
||||||
'Content-Length' => $disk->size($path),
|
|
||||||
'Content-Disposition' => 'attachment; filename="' . basename($path) . '"',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json(['message' => 'The resource was not found.'], HttpResponseCodes::HTTP_NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the server maximum upload size
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public static function getMaxUploadSize()
|
|
||||||
{
|
|
||||||
$sizes = [
|
|
||||||
ini_get('upload_max_filesize'),
|
|
||||||
ini_get('post_max_size'),
|
|
||||||
ini_get('memory_limit')
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($sizes as &$size) {
|
|
||||||
$size = trim($size);
|
|
||||||
$last = strtolower($size[(strlen($size) - 1)]);
|
|
||||||
switch ($last) {
|
|
||||||
case 'g':
|
|
||||||
$size = (intval($size) * 1024);
|
|
||||||
// Size is in MB - fallthrough
|
|
||||||
case 'm':
|
|
||||||
$size = (intval($size) * 1024);
|
|
||||||
// Size is in KB - fallthrough
|
|
||||||
case 'k':
|
|
||||||
$size = (intval($size) * 1024);
|
|
||||||
// Size is in B - fallthrough
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return min($sizes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a file name that is available within storage.
|
|
||||||
*
|
|
||||||
* @param string $fileName The proposed file name.
|
|
||||||
* @return string|boolean The available file name or false if failed.
|
|
||||||
*/
|
|
||||||
public static function generateUniqueFileName(string $fileName)
|
|
||||||
{
|
|
||||||
$index = 1;
|
|
||||||
$maxTries = 100;
|
|
||||||
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
|
|
||||||
$fileName = static::sanitizeFilename(pathinfo($fileName, PATHINFO_FILENAME));
|
|
||||||
|
|
||||||
if (static::fileNameHasSuffix($fileName) === true || static::fileExistsInStorage("$fileName.$extension") === true || Media::where('name', "$fileName.$extension")->where('status', 'not like', 'failed%')->exists() === true) {
|
|
||||||
$fileName .= '-';
|
|
||||||
for ($i = 1; $i < $maxTries; $i++) {
|
|
||||||
$fileNameIndex = $fileName . $index;
|
|
||||||
if (static::fileExistsInStorage("$fileNameIndex.$extension") !== true && Media::where('name', "$fileNameIndex.$extension")->where('status', 'not like', 'Failed%')->exists() !== true) {
|
|
||||||
return "$fileNameIndex.$extension";
|
|
||||||
}
|
|
||||||
|
|
||||||
++$index;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "$fileName.$extension";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if the file name exists in any of the storage disks.
|
|
||||||
*
|
|
||||||
* @param string $fileName The file name to check.
|
|
||||||
* @param boolean $ignoreCache Ignore the file list cache.
|
|
||||||
* @return boolean If the file exists on any storage disks.
|
|
||||||
*/
|
|
||||||
public static function fileExistsInStorage(string $fileName, bool $ignoreCache = false)
|
|
||||||
{
|
|
||||||
$disks = array_keys(Config::get('filesystems.disks'));
|
|
||||||
|
|
||||||
if ($ignoreCache === false) {
|
|
||||||
if (count(static::$storageFileListCache) === 0) {
|
|
||||||
$disks = array_keys(Config::get('filesystems.disks'));
|
|
||||||
|
|
||||||
foreach ($disks as $disk) {
|
|
||||||
try {
|
|
||||||
static::$storageFileListCache[$disk] = Storage::disk($disk)->allFiles();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Log::error($e->getMessage());
|
|
||||||
throw new \Exception("Cannot get a file list for storage device '$disk'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (static::$storageFileListCache as $disk => $files) {
|
|
||||||
if (in_array($fileName, $files) === true) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$disks = array_keys(Config::get('filesystems.disks'));
|
|
||||||
|
|
||||||
foreach ($disks as $disk) {
|
|
||||||
try {
|
|
||||||
if (Storage::disk($disk)->exists($fileName) === true) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Log::error($e->getMessage());
|
|
||||||
throw new \Exception("Cannot verify if file '$fileName' already exists in storage device '$disk'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test if the file name contains a special suffix.
|
|
||||||
*
|
|
||||||
* @param string $fileName The file name to test.
|
|
||||||
* @return boolean If the file name contains the special suffix.
|
|
||||||
*/
|
|
||||||
public static function fileNameHasSuffix(string $fileName)
|
|
||||||
{
|
|
||||||
$suffix = '/(-\d+x\d+|-scaled)$/i';
|
|
||||||
$fileNameWithoutExtension = pathinfo($fileName, PATHINFO_FILENAME);
|
|
||||||
|
|
||||||
return preg_match($suffix, $fileNameWithoutExtension) === 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sanitize fileName for upload
|
|
||||||
*
|
|
||||||
* @param string $fileName Filename to sanitize.
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private static function sanitizeFilename(string $fileName)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
# file system reserved https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
|
||||||
[<>:"/\\\|?*]|
|
|
||||||
|
|
||||||
# control characters http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
|
|
||||||
[\x00-\x1F]|
|
|
||||||
|
|
||||||
# non-printing characters DEL, NO-BREAK SPACE, SOFT HYPHEN
|
|
||||||
[\x7F\xA0\xAD]|
|
|
||||||
|
|
||||||
# URI reserved https://www.rfc-editor.org/rfc/rfc3986#section-2.2
|
|
||||||
[#\[\]@!$&\'()+,;=]|
|
|
||||||
|
|
||||||
# URL unsafe characters https://www.ietf.org/rfc/rfc1738.txt
|
|
||||||
[{}^\~`]
|
|
||||||
*/
|
|
||||||
|
|
||||||
$fileName = preg_replace(
|
|
||||||
'~
|
|
||||||
[<>:"/\\\|?*]|
|
|
||||||
[\x00-\x1F]|
|
|
||||||
[\x7F\xA0\xAD]|
|
|
||||||
[#\[\]@!$&\'()+,;=]|
|
|
||||||
[{}^\~`]
|
|
||||||
~x',
|
|
||||||
'-',
|
|
||||||
$fileName
|
|
||||||
);
|
|
||||||
|
|
||||||
$fileName = ltrim($fileName, '.-');
|
|
||||||
|
|
||||||
$fileName = preg_replace([
|
|
||||||
// "file name.zip" becomes "file-name.zip"
|
|
||||||
'/ +/',
|
|
||||||
// "file___name.zip" becomes "file-name.zip"
|
|
||||||
'/_+/',
|
|
||||||
// "file---name.zip" becomes "file-name.zip"
|
|
||||||
'/-+/'
|
|
||||||
], '-', $fileName);
|
|
||||||
$fileName = preg_replace([
|
|
||||||
// "file--.--.-.--name.zip" becomes "file.name.zip"
|
|
||||||
'/-*\.-*/',
|
|
||||||
// "file...name..zip" becomes "file.name.zip"
|
|
||||||
'/\.{2,}/'
|
|
||||||
], '.', $fileName);
|
|
||||||
// lowercase for windows/unix interoperability http://support.microsoft.com/kb/100625
|
|
||||||
$fileName = mb_strtolower($fileName, mb_detect_encoding($fileName));
|
|
||||||
// ".file-name.-" becomes "file-name"
|
|
||||||
$fileName = trim($fileName, '.-');
|
|
||||||
|
|
||||||
$ext = pathinfo($fileName, PATHINFO_EXTENSION);
|
|
||||||
$fileName = mb_strcut(
|
|
||||||
pathinfo($fileName, PATHINFO_FILENAME),
|
|
||||||
0,
|
|
||||||
(255 - ($ext !== '' ? strlen($ext) + 1 : 0)),
|
|
||||||
mb_detect_encoding($fileName)
|
|
||||||
) . ($ext !== '' ? '.' . $ext : '');
|
|
||||||
return $fileName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Traits\Uuids;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Permission extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
use Uuids;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'permission',
|
|
||||||
'user',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the User associated with this model
|
|
||||||
*
|
|
||||||
* @return BelongsTo
|
|
||||||
*/
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(User::class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Enum\HttpResponseCodes;
|
|
||||||
use App\Jobs\MoveMediaJob;
|
|
||||||
use App\Jobs\OptimizeMediaJob;
|
|
||||||
use App\Jobs\StoreUploadedFileJob;
|
|
||||||
use App\Traits\Uuids;
|
|
||||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
||||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Config;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Support\Facades\Queue;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
||||||
|
|
||||||
class Shortlink extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'code',
|
|
||||||
'url',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Traits\Uuids;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Subscription extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
use Uuids;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'email',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -3,22 +3,14 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
|
|
||||||
use App\Traits\Uuids;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Laravel\Sanctum\HasApiTokens;
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
use OwenIt\Auditing\Contracts\Auditable;
|
|
||||||
|
|
||||||
class User extends Authenticatable implements Auditable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
use HasApiTokens;
|
use HasApiTokens, HasFactory, Notifiable;
|
||||||
use HasFactory;
|
|
||||||
use Notifiable;
|
|
||||||
use Uuids;
|
|
||||||
use \OwenIt\Auditing\Auditable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* The attributes that are mass assignable.
|
||||||
@@ -26,12 +18,9 @@ class User extends Authenticatable implements Auditable
|
|||||||
* @var array<int, string>
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'first_name',
|
'name',
|
||||||
'last_name',
|
|
||||||
'email',
|
'email',
|
||||||
'phone',
|
|
||||||
'password',
|
'password',
|
||||||
'display_name',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +31,6 @@ class User extends Authenticatable implements Auditable
|
|||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'password',
|
'password',
|
||||||
'remember_token',
|
'remember_token',
|
||||||
'permissions'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,151 +40,6 @@ class User extends Authenticatable implements Auditable
|
|||||||
*/
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'email_verified_at' => 'datetime',
|
'email_verified_at' => 'datetime',
|
||||||
|
'password' => 'hashed',
|
||||||
];
|
];
|
||||||
|
|
||||||
// protected $hidden = [
|
|
||||||
// 'permissions'
|
|
||||||
// ];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes to append.
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected $appends = [
|
|
||||||
'permissions'
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default attributes.
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected $attributes = [
|
|
||||||
'phone' => '',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of files of the user
|
|
||||||
*
|
|
||||||
* @return HasMany
|
|
||||||
*/
|
|
||||||
public function permissions()
|
|
||||||
{
|
|
||||||
return $this->hasMany(Permission::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the permission attribute
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getPermissionsAttribute()
|
|
||||||
{
|
|
||||||
return $this->permissions()->pluck('permission')->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test if user has permission
|
|
||||||
*
|
|
||||||
* @param string $permission Permission to test.
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function hasPermission(string $permission)
|
|
||||||
{
|
|
||||||
return ($this->permissions()->where('permission', $permission)->first() !== null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Give permissions to the user
|
|
||||||
*
|
|
||||||
* @param string|array $permissions The permission(s) to give.
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function givePermission($permissions)
|
|
||||||
{
|
|
||||||
if (is_array($permissions) === false) {
|
|
||||||
$permissions = [$permissions];
|
|
||||||
}
|
|
||||||
|
|
||||||
$permissions = collect($permissions)->map(function ($permission) {
|
|
||||||
return ['permission' => $permission];
|
|
||||||
});
|
|
||||||
|
|
||||||
$existingPermissions = $this->permissions()->whereIn('permission', $permissions->pluck('permission'))->get();
|
|
||||||
$newPermissions = $permissions->reject(function ($permission) use ($existingPermissions) {
|
|
||||||
return $existingPermissions->contains('permission', $permission['permission']);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this->permissions()->createMany($newPermissions->toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Revoke permissions from the user
|
|
||||||
*
|
|
||||||
* @param string|array $permissions The permission(s) to revoke.
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function revokePermission($permissions)
|
|
||||||
{
|
|
||||||
if (is_array($permissions) === false) {
|
|
||||||
$permissions = [$permissions];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->permissions()
|
|
||||||
->whereIn('permission', $permissions)
|
|
||||||
->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of files of the user
|
|
||||||
*
|
|
||||||
* @return HasMany
|
|
||||||
*/
|
|
||||||
public function media()
|
|
||||||
{
|
|
||||||
return $this->hasMany(Media::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of files of the user
|
|
||||||
*
|
|
||||||
* @return HasMany
|
|
||||||
*/
|
|
||||||
public function articles()
|
|
||||||
{
|
|
||||||
return $this->hasMany(Article::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get associated user codes
|
|
||||||
*
|
|
||||||
* @return HasMany
|
|
||||||
*/
|
|
||||||
public function codes()
|
|
||||||
{
|
|
||||||
return $this->hasMany(UserCode::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of logins of the user
|
|
||||||
*
|
|
||||||
* @return HasMany
|
|
||||||
*/
|
|
||||||
public function logins()
|
|
||||||
{
|
|
||||||
return $this->hasMany(UserLogins::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the events associated with the user.
|
|
||||||
*
|
|
||||||
* @return BelongsToMany
|
|
||||||
*/
|
|
||||||
public function events()
|
|
||||||
{
|
|
||||||
return $this->belongsToMany(Event::class, 'event_user', 'user_id', 'event_id');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class UserCode extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'action',
|
|
||||||
'user_id',
|
|
||||||
'data',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Boot function from Laravel.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected static function boot()
|
|
||||||
{
|
|
||||||
parent::boot();
|
|
||||||
static::creating(function ($model) {
|
|
||||||
UserCode::clearExpired();
|
|
||||||
|
|
||||||
if (empty($model->{'code'}) === true) {
|
|
||||||
while (true) {
|
|
||||||
$code = random_int(100000, 999999);
|
|
||||||
if (UserCode::where('code', $code)->count() === 0) {
|
|
||||||
$model->{'code'} = $code;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate new code
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function regenerate()
|
|
||||||
{
|
|
||||||
while (true) {
|
|
||||||
$code = random_int(100000, 999999);
|
|
||||||
if (UserCode::where('code', $code)->count() === 0) {
|
|
||||||
$this->code = $code;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear expired user codes
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function clearExpired()
|
|
||||||
{
|
|
||||||
UserCode::where('updated_at', '<=', now()->subDays(5))->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get associated user
|
|
||||||
*
|
|
||||||
* @return BelongsTo
|
|
||||||
*/
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(User::class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Traits\Uuids;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class UserLogins extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
use Uuids;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array<int, string>
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'user_id',
|
|
||||||
'token',
|
|
||||||
'login',
|
|
||||||
'logout',
|
|
||||||
'ip_address',
|
|
||||||
'user_agent',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the file user
|
|
||||||
*
|
|
||||||
* @return BelongsTo
|
|
||||||
*/
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(User::class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,38 +2,23 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Rules\RequiredIfAny;
|
|
||||||
use App\Rules\Uniqueish;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Exception;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use PDOException;
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Register any application services.
|
* Register any application services.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register(): void
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrap any application services.
|
* Bootstrap any application services.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot(): void
|
||||||
{
|
{
|
||||||
Storage::macro('public', function ($diskName) {
|
//
|
||||||
$public = config("filesystems.disks.{$diskName}.public", false);
|
|
||||||
return $public;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,19 +13,14 @@ class AuthServiceProvider extends ServiceProvider
|
|||||||
* @var array<class-string, class-string>
|
* @var array<class-string, class-string>
|
||||||
*/
|
*/
|
||||||
protected $policies = [
|
protected $policies = [
|
||||||
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
|
//
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register any authentication / authorization services.
|
* Register any authentication / authorization services.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot(): void
|
||||||
{
|
{
|
||||||
$this->registerPolicies();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,8 @@ class BroadcastServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Bootstrap any application services.
|
* Bootstrap any application services.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot(): void
|
||||||
{
|
{
|
||||||
Broadcast::routes();
|
Broadcast::routes();
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ namespace App\Providers;
|
|||||||
use Illuminate\Auth\Events\Registered;
|
use Illuminate\Auth\Events\Registered;
|
||||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||||
use Illuminate\Queue\Events\JobProcessed;
|
|
||||||
use Illuminate\Support\Facades\Queue;
|
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class EventServiceProvider extends ServiceProvider
|
class EventServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -23,23 +20,18 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register any events for your application.
|
* Register any events for your application.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot(): void
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if events and listeners should be automatically discovered.
|
* Determine if events and listeners should be automatically discovered.
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
*/
|
||||||
public function shouldDiscoverEvents()
|
public function shouldDiscoverEvents(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,11 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvi
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\RateLimiter;
|
use Illuminate\Support\Facades\RateLimiter;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class RouteServiceProvider extends ServiceProvider
|
class RouteServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The path to the "home" route for your application.
|
* The path to your application's "home" route.
|
||||||
*
|
*
|
||||||
* Typically, users are redirected here after authentication.
|
* Typically, users are redirected here after authentication.
|
||||||
*
|
*
|
||||||
@@ -20,15 +19,14 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public const HOME = '/home';
|
public const HOME = '/home';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define your route model bindings, pattern filters, and other route configuration.
|
* Define your route model bindings, pattern filters, and other route configuration.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot(): void
|
||||||
{
|
{
|
||||||
$this->configureRateLimiting();
|
RateLimiter::for('api', function (Request $request) {
|
||||||
|
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||||
|
});
|
||||||
|
|
||||||
$this->routes(function () {
|
$this->routes(function () {
|
||||||
Route::middleware('api')
|
Route::middleware('api')
|
||||||
@@ -38,53 +36,5 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
Route::middleware('web')
|
Route::middleware('web')
|
||||||
->group(base_path('routes/web.php'));
|
->group(base_path('routes/web.php'));
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::macro('apiAttachmentResource', function ($uri, $controller) {
|
|
||||||
$singularUri = Str::singular($uri);
|
|
||||||
|
|
||||||
Route::get("$uri/{{$singularUri}}/attachments", [$controller, 'getAttachments'])
|
|
||||||
->name("{{$singularUri}}.attachments.index");
|
|
||||||
|
|
||||||
Route::post("$uri/{{$singularUri}}/attachments", [$controller, 'storeAttachment'])
|
|
||||||
->name("{{$singularUri}}.attachments.store");
|
|
||||||
|
|
||||||
Route::match(['put', 'patch'], "$uri/{{$singularUri}}/attachments", [$controller, 'updateAttachments'])
|
|
||||||
->name("{{$singularUri}}.attachments.update");
|
|
||||||
|
|
||||||
Route::delete("$uri/{{$singularUri}}/attachments/{medium}", [$controller, 'deleteAttachment'])
|
|
||||||
->name("{{$singularUri}}.attachments.destroy");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure the rate limiters for the application.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function configureRateLimiting()
|
|
||||||
{
|
|
||||||
// RateLimiter::for('api', function (Request $request) {
|
|
||||||
// return Limit::perMinute(60)->by($request->user()?->id !== null ?: $request->ip());
|
|
||||||
// });
|
|
||||||
|
|
||||||
$rateLimitEnabled = true;
|
|
||||||
$user = auth()->user();
|
|
||||||
|
|
||||||
if (app()->environment('testing')) {
|
|
||||||
$rateLimitEnabled = false;
|
|
||||||
} elseif ($user !== null && $user->hasPermission('admin/ratelimit') === true) {
|
|
||||||
// Admin users with the "admin/ratelimit" permission are not rate limited
|
|
||||||
$rateLimitEnabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($rateLimitEnabled === true) {
|
|
||||||
RateLimiter::for('api', function (Request $request) {
|
|
||||||
return Limit::perMinute(180)->by($request->user()?->id ?: $request->ip());
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
RateLimiter::for('api', function () {
|
|
||||||
return Limit::none();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Rules;
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use Illuminate\Contracts\Validation\Rule;
|
|
||||||
|
|
||||||
class Recaptcha implements Rule
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create a new rule instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the validation rule passes.
|
|
||||||
*
|
|
||||||
* @param mixed $attribute Attribute name.
|
|
||||||
* @param mixed $value Attribute value.
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function passes(mixed $attribute, mixed $value)
|
|
||||||
{
|
|
||||||
$endpoint = config('services.google_recaptcha');
|
|
||||||
|
|
||||||
$response = Http::asForm()->post($endpoint['url'], [
|
|
||||||
'secret' => $endpoint['secret_key'],
|
|
||||||
'response' => $value,
|
|
||||||
])->json();
|
|
||||||
|
|
||||||
if ($response['success'] === true && $response['score'] > 0.5) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation error message.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function message()
|
|
||||||
{
|
|
||||||
return 'Captcha failed. Refresh the page and try again';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Rules;
|
|
||||||
|
|
||||||
use App\Models\Media;
|
|
||||||
use Illuminate\Contracts\Validation\Rule;
|
|
||||||
|
|
||||||
class UniqueFileName implements Rule
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create a new rule instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the validation rule passes.
|
|
||||||
*
|
|
||||||
* @param string $attribute
|
|
||||||
* @param mixed $value
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function passes($attribute, $value)
|
|
||||||
{
|
|
||||||
return (Media::fileExists($value) === false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation error message.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function message()
|
|
||||||
{
|
|
||||||
return 'The file name already exists.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Rules;
|
|
||||||
|
|
||||||
use Illuminate\Contracts\Validation\Rule;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use PDO;
|
|
||||||
|
|
||||||
class Uniqueish implements Rule
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The table name to compare.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $table;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The column name to compare.
|
|
||||||
*
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
protected $column;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ID of the record to be ignored.
|
|
||||||
*
|
|
||||||
* @var mixed
|
|
||||||
*/
|
|
||||||
protected $ignoreId;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new rule instance.
|
|
||||||
*
|
|
||||||
* @param string $table The table name to compare.
|
|
||||||
* @param string $column The column name to compare.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(string $table, string $column = null)
|
|
||||||
{
|
|
||||||
$this->table = $table;
|
|
||||||
$this->column = $column;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the ID of the record to be ignored.
|
|
||||||
*
|
|
||||||
* @param mixed $id The ID to ignore.
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function ignore(mixed $id)
|
|
||||||
{
|
|
||||||
$this->ignoreId = $id;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the validation rule passes.
|
|
||||||
*
|
|
||||||
* @param mixed $attribute Not used.
|
|
||||||
* @param mixed $value The value to compare.
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function passes(mixed $attribute, mixed $value)
|
|
||||||
{
|
|
||||||
$columnName = ($this->column ?? $attribute);
|
|
||||||
$similarValue = preg_replace('/[^A-Za-z]/', '', strtolower($value));
|
|
||||||
|
|
||||||
try {
|
|
||||||
$query = DB::table($this->table)
|
|
||||||
->where($columnName, 'like', '%' . $similarValue . '%');
|
|
||||||
|
|
||||||
if ($this->ignoreId !== null) {
|
|
||||||
$query->where('id', '<>', $this->ignoreId);
|
|
||||||
}
|
|
||||||
|
|
||||||
$query->whereRaw('LOWER(REGEXP_REPLACE(' . $columnName . ', \'[^A-Za-z0-9]\', \'\')) = ?', [$similarValue]);
|
|
||||||
$result = $query->first();
|
|
||||||
} catch (\Illuminate\Database\QueryException $e) {
|
|
||||||
// Fall back to performing the regex replace in PHP
|
|
||||||
// $results = $query->get();
|
|
||||||
$query = DB::table($this->table);
|
|
||||||
$results = $query->get();
|
|
||||||
|
|
||||||
foreach ($results as $result) {
|
|
||||||
$resultValue = preg_replace('/[^A-Za-z0-9]/', '', strtolower($result->{$columnName}));
|
|
||||||
if ($resultValue === $similarValue && $result->id != $this->ignoreId) {
|
|
||||||
return false; // Value already exists in the table
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true; // Value does not exist in the table
|
|
||||||
}//end try
|
|
||||||
|
|
||||||
return $result === null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation error message.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function message()
|
|
||||||
{
|
|
||||||
return 'The :attribute is similar to one that already exists. Please choose another.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,698 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services;
|
|
||||||
|
|
||||||
class AnimatedGifService
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Check if a GIF file at a path is animated or not
|
|
||||||
*
|
|
||||||
* @param string $filenameOrBlob GIF file path or data blob if dataSize > 0.
|
|
||||||
* @param integer $dataSize GIF blob size.
|
|
||||||
* @return boolean GIF file/blob is animated.
|
|
||||||
*/
|
|
||||||
public static function isAnimatedGif(string $filenameOrBlob, int $dataSize = 0)
|
|
||||||
{
|
|
||||||
$regex = '#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s';
|
|
||||||
$count = 0;
|
|
||||||
|
|
||||||
if ($dataSize > 0) {
|
|
||||||
if (($fh = @fopen($filenameOrBlob, 'rb')) === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$chunk = false;
|
|
||||||
while (feof($fh) === false && $count < 2) {
|
|
||||||
$chunk = ($chunk !== '' ? substr($chunk, -20) : "") . fread($fh, (1024 * 100)); //read 100kb at a time
|
|
||||||
$count += preg_match_all($regex, $chunk, $matches);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose($fh);
|
|
||||||
} else {
|
|
||||||
$count = preg_match_all($regex, $filenameOrBlob, $matches);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $count > 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract frames of a GIF
|
|
||||||
*
|
|
||||||
* @param string $filenameOrBlob GIF filename path
|
|
||||||
* @param integer $dataSize GIF blob size.
|
|
||||||
* @param boolean $originalFrames Get original frames (with transparent background)
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function extract(string $filenameOrBlob, int $dataSize = 0, $originalFrames = false)
|
|
||||||
{
|
|
||||||
if (self::isAnimatedGif($filenameOrBlob) === false) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->reset();
|
|
||||||
$this->parseFramesInfo($filename);
|
|
||||||
$prevImg = null;
|
|
||||||
|
|
||||||
for ($i = 0; $i < count($this->frameSources); $i++) {
|
|
||||||
$this->frames[$i] = [];
|
|
||||||
$this->frameDurations[$i] = $this->frames[$i]['duration'] = $this->frameSources[$i]['delay_time'];
|
|
||||||
|
|
||||||
$img = imagecreatefromstring($this->fileHeader["gifheader"] . $this->frameSources[$i]["graphicsextension"] . $this->frameSources[$i]["imagedata"] . chr(0x3b));
|
|
||||||
|
|
||||||
if (!$originalFrames) {
|
|
||||||
if ($i > 0) {
|
|
||||||
$prevImg = $this->frames[($i - 1)]['image'];
|
|
||||||
} else {
|
|
||||||
$prevImg = $img;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sprite = imagecreate($this->gifMaxWidth, $this->gifMaxHeight);
|
|
||||||
imagesavealpha($sprite, true);
|
|
||||||
|
|
||||||
$transparent = imagecolortransparent($prevImg);
|
|
||||||
|
|
||||||
if ($transparent > -1 && imagecolorstotal($prevImg) > $transparent) {
|
|
||||||
$actualTrans = imagecolorsforindex($prevImg, $transparent);
|
|
||||||
imagecolortransparent($sprite, imagecolorallocate($sprite, $actualTrans['red'], $actualTrans['green'], $actualTrans['blue']));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((int) $this->frameSources[$i]['disposal_method'] == 1 && $i > 0) {
|
|
||||||
imagecopy($sprite, $prevImg, 0, 0, 0, 0, $this->gifMaxWidth, $this->gifMaxHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
imagecopyresampled($sprite, $img, $this->frameSources[$i]["offset_left"], $this->frameSources[$i]["offset_top"], 0, 0, $this->gifMaxWidth, $this->gifMaxHeight, $this->gifMaxWidth, $this->gifMaxHeight);
|
|
||||||
$img = $sprite;
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
$this->frameImages[$i] = $this->frames[$i]['image'] = $img;
|
|
||||||
}//end for
|
|
||||||
|
|
||||||
return $this->frames;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class GifFrameExtractor
|
|
||||||
{
|
|
||||||
// Properties
|
|
||||||
// ===================================================================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var resource
|
|
||||||
*/
|
|
||||||
private $gif;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $frames;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $frameDurations;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $frameImages;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $framePositions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $frameDimensions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var integer
|
|
||||||
*
|
|
||||||
* (old: $this->index)
|
|
||||||
*/
|
|
||||||
private $frameNumber;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*
|
|
||||||
* (old: $this->imagedata)
|
|
||||||
*/
|
|
||||||
private $frameSources;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*
|
|
||||||
* (old: $this->fileHeader)
|
|
||||||
*/
|
|
||||||
private $fileHeader;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var integer The reader pointer in the file source
|
|
||||||
*
|
|
||||||
* (old: $this->pointer)
|
|
||||||
*/
|
|
||||||
private $pointer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
private $gifMaxWidth;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
private $gifMaxHeight;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
private $totalDuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
private $handle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*
|
|
||||||
* (old: globaldata)
|
|
||||||
*/
|
|
||||||
private $globaldata;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*
|
|
||||||
* (old: orgvars)
|
|
||||||
*/
|
|
||||||
private $orgvars;
|
|
||||||
|
|
||||||
// Methods
|
|
||||||
// ===================================================================================
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the frame informations contained in the GIF file
|
|
||||||
*
|
|
||||||
* @param string $filename GIF filename path
|
|
||||||
*/
|
|
||||||
private function parseFramesInfo($filename)
|
|
||||||
{
|
|
||||||
$this->openFile($filename);
|
|
||||||
$this->parseGifHeader();
|
|
||||||
$this->parseGraphicsExtension(0);
|
|
||||||
$this->getApplicationData();
|
|
||||||
$this->getApplicationData();
|
|
||||||
$this->getFrameString(0);
|
|
||||||
$this->parseGraphicsExtension(1);
|
|
||||||
$this->getCommentData();
|
|
||||||
$this->getApplicationData();
|
|
||||||
$this->getFrameString(1);
|
|
||||||
|
|
||||||
while (!$this->checkByte(0x3b) && !$this->checkEOF()) {
|
|
||||||
$this->getCommentData(1);
|
|
||||||
$this->parseGraphicsExtension(2);
|
|
||||||
$this->getFrameString(2);
|
|
||||||
$this->getApplicationData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the gif header (old: get_gif_header)
|
|
||||||
*/
|
|
||||||
private function parseGifHeader()
|
|
||||||
{
|
|
||||||
$this->pointerForward(10);
|
|
||||||
|
|
||||||
if ($this->readBits(($mybyte = $this->readByteInt()), 0, 1) == 1) {
|
|
||||||
$this->pointerForward(2);
|
|
||||||
$this->pointerForward(pow(2, ($this->readBits($mybyte, 5, 3) + 1)) * 3);
|
|
||||||
} else {
|
|
||||||
$this->pointerForward(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->fileHeader["gifheader"] = $this->dataPart(0, $this->pointer);
|
|
||||||
|
|
||||||
// Decoding
|
|
||||||
$this->orgvars["gifheader"] = $this->fileHeader["gifheader"];
|
|
||||||
$this->orgvars["background_color"] = $this->orgvars["gifheader"][11];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the application data of the frames (old: get_application_data)
|
|
||||||
*/
|
|
||||||
private function getApplicationData()
|
|
||||||
{
|
|
||||||
$startdata = $this->readByte(2);
|
|
||||||
|
|
||||||
if ($startdata == chr(0x21) . chr(0xff)) {
|
|
||||||
$start = ($this->pointer - 2);
|
|
||||||
$this->pointerForward($this->readByteInt());
|
|
||||||
$this->readDataStream($this->readByteInt());
|
|
||||||
$this->fileHeader["applicationdata"] = $this->dataPart($start, ($this->pointer - $start));
|
|
||||||
} else {
|
|
||||||
$this->pointerRewind(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the comment data of the frames (old: get_comment_data)
|
|
||||||
*/
|
|
||||||
private function getCommentData()
|
|
||||||
{
|
|
||||||
$startdata = $this->readByte(2);
|
|
||||||
|
|
||||||
if ($startdata == chr(0x21) . chr(0xfe)) {
|
|
||||||
$start = ($this->pointer - 2);
|
|
||||||
$this->readDataStream($this->readByteInt());
|
|
||||||
$this->fileHeader["commentdata"] = $this->dataPart($start, ($this->pointer - $start));
|
|
||||||
} else {
|
|
||||||
$this->pointerRewind(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the graphic extension of the frames (old: get_graphics_extension)
|
|
||||||
*
|
|
||||||
* @param integer $type
|
|
||||||
*/
|
|
||||||
private function parseGraphicsExtension($type)
|
|
||||||
{
|
|
||||||
$startdata = $this->readByte(2);
|
|
||||||
|
|
||||||
if ($startdata == chr(0x21) . chr(0xf9)) {
|
|
||||||
$start = ($this->pointer - 2);
|
|
||||||
$this->pointerForward($this->readByteInt());
|
|
||||||
$this->pointerForward(1);
|
|
||||||
|
|
||||||
if ($type == 2) {
|
|
||||||
$this->frameSources[$this->frameNumber]["graphicsextension"] = $this->dataPart($start, ($this->pointer - $start));
|
|
||||||
} elseif ($type == 1) {
|
|
||||||
$this->orgvars["hasgx_type_1"] = 1;
|
|
||||||
$this->globaldata["graphicsextension"] = $this->dataPart($start, ($this->pointer - $start));
|
|
||||||
} elseif ($type == 0) {
|
|
||||||
$this->orgvars["hasgx_type_0"] = 1;
|
|
||||||
$this->globaldata["graphicsextension_0"] = $this->dataPart($start, ($this->pointer - $start));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->pointerRewind(2);
|
|
||||||
}//end if
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the full frame string block (old: get_image_block)
|
|
||||||
*
|
|
||||||
* @param integer $type
|
|
||||||
*/
|
|
||||||
private function getFrameString($type)
|
|
||||||
{
|
|
||||||
if ($this->checkByte(0x2c)) {
|
|
||||||
$start = $this->pointer;
|
|
||||||
$this->pointerForward(9);
|
|
||||||
|
|
||||||
if ($this->readBits(($mybyte = $this->readByteInt()), 0, 1) == 1) {
|
|
||||||
$this->pointerForward(pow(2, ($this->readBits($mybyte, 5, 3) + 1)) * 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->pointerForward(1);
|
|
||||||
$this->readDataStream($this->readByteInt());
|
|
||||||
$this->frameSources[$this->frameNumber]["imagedata"] = $this->dataPart($start, ($this->pointer - $start));
|
|
||||||
|
|
||||||
if ($type == 0) {
|
|
||||||
$this->orgvars["hasgx_type_0"] = 0;
|
|
||||||
|
|
||||||
if (isset($this->globaldata["graphicsextension_0"])) {
|
|
||||||
$this->frameSources[$this->frameNumber]["graphicsextension"] = $this->globaldata["graphicsextension_0"];
|
|
||||||
} else {
|
|
||||||
$this->frameSources[$this->frameNumber]["graphicsextension"] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($this->globaldata["graphicsextension_0"]);
|
|
||||||
} elseif ($type == 1) {
|
|
||||||
if (isset($this->orgvars["hasgx_type_1"]) && $this->orgvars["hasgx_type_1"] == 1) {
|
|
||||||
$this->orgvars["hasgx_type_1"] = 0;
|
|
||||||
$this->frameSources[$this->frameNumber]["graphicsextension"] = $this->globaldata["graphicsextension"];
|
|
||||||
unset($this->globaldata["graphicsextension"]);
|
|
||||||
} else {
|
|
||||||
$this->orgvars["hasgx_type_0"] = 0;
|
|
||||||
$this->frameSources[$this->frameNumber]["graphicsextension"] = $this->globaldata["graphicsextension_0"];
|
|
||||||
unset($this->globaldata["graphicsextension_0"]);
|
|
||||||
}
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
$this->parseFrameData();
|
|
||||||
$this->frameNumber++;
|
|
||||||
}//end if
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse frame data string into an array (old: parse_image_data)
|
|
||||||
*/
|
|
||||||
private function parseFrameData()
|
|
||||||
{
|
|
||||||
$this->frameSources[$this->frameNumber]["disposal_method"] = $this->getImageDataBit("ext", 3, 3, 3);
|
|
||||||
$this->frameSources[$this->frameNumber]["user_input_flag"] = $this->getImageDataBit("ext", 3, 6, 1);
|
|
||||||
$this->frameSources[$this->frameNumber]["transparent_color_flag"] = $this->getImageDataBit("ext", 3, 7, 1);
|
|
||||||
$this->frameSources[$this->frameNumber]["delay_time"] = $this->dualByteVal($this->getImageDataByte("ext", 4, 2));
|
|
||||||
$this->totalDuration += (int) $this->frameSources[$this->frameNumber]["delay_time"];
|
|
||||||
$this->frameSources[$this->frameNumber]["transparent_color_index"] = ord($this->getImageDataByte("ext", 6, 1));
|
|
||||||
$this->frameSources[$this->frameNumber]["offset_left"] = $this->dualByteVal($this->getImageDataByte("dat", 1, 2));
|
|
||||||
$this->frameSources[$this->frameNumber]["offset_top"] = $this->dualByteVal($this->getImageDataByte("dat", 3, 2));
|
|
||||||
$this->frameSources[$this->frameNumber]["width"] = $this->dualByteVal($this->getImageDataByte("dat", 5, 2));
|
|
||||||
$this->frameSources[$this->frameNumber]["height"] = $this->dualByteVal($this->getImageDataByte("dat", 7, 2));
|
|
||||||
$this->frameSources[$this->frameNumber]["local_color_table_flag"] = $this->getImageDataBit("dat", 9, 0, 1);
|
|
||||||
$this->frameSources[$this->frameNumber]["interlace_flag"] = $this->getImageDataBit("dat", 9, 1, 1);
|
|
||||||
$this->frameSources[$this->frameNumber]["sort_flag"] = $this->getImageDataBit("dat", 9, 2, 1);
|
|
||||||
$this->frameSources[$this->frameNumber]["color_table_size"] = (pow(2, ($this->getImageDataBit("dat", 9, 5, 3) + 1)) * 3);
|
|
||||||
$this->frameSources[$this->frameNumber]["color_table"] = substr($this->frameSources[$this->frameNumber]["imagedata"], 10, $this->frameSources[$this->frameNumber]["color_table_size"]);
|
|
||||||
$this->frameSources[$this->frameNumber]["lzw_code_size"] = ord($this->getImageDataByte("dat", 10, 1));
|
|
||||||
|
|
||||||
$this->framePositions[$this->frameNumber] = [
|
|
||||||
'x' => $this->frameSources[$this->frameNumber]["offset_left"],
|
|
||||||
'y' => $this->frameSources[$this->frameNumber]["offset_top"],
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->frameDimensions[$this->frameNumber] = [
|
|
||||||
'width' => $this->frameSources[$this->frameNumber]["width"],
|
|
||||||
'height' => $this->frameSources[$this->frameNumber]["height"],
|
|
||||||
];
|
|
||||||
|
|
||||||
// Decoding
|
|
||||||
$this->orgvars[$this->frameNumber]["transparent_color_flag"] = $this->frameSources[$this->frameNumber]["transparent_color_flag"];
|
|
||||||
$this->orgvars[$this->frameNumber]["transparent_color_index"] = $this->frameSources[$this->frameNumber]["transparent_color_index"];
|
|
||||||
$this->orgvars[$this->frameNumber]["delay_time"] = $this->frameSources[$this->frameNumber]["delay_time"];
|
|
||||||
$this->orgvars[$this->frameNumber]["disposal_method"] = $this->frameSources[$this->frameNumber]["disposal_method"];
|
|
||||||
$this->orgvars[$this->frameNumber]["offset_left"] = $this->frameSources[$this->frameNumber]["offset_left"];
|
|
||||||
$this->orgvars[$this->frameNumber]["offset_top"] = $this->frameSources[$this->frameNumber]["offset_top"];
|
|
||||||
|
|
||||||
// Updating the max width
|
|
||||||
if ($this->gifMaxWidth < $this->frameSources[$this->frameNumber]["width"]) {
|
|
||||||
$this->gifMaxWidth = $this->frameSources[$this->frameNumber]["width"];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Updating the max height
|
|
||||||
if ($this->gifMaxHeight < $this->frameSources[$this->frameNumber]["height"]) {
|
|
||||||
$this->gifMaxHeight = $this->frameSources[$this->frameNumber]["height"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the image data byte (old: get_imagedata_byte)
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param integer $start
|
|
||||||
* @param integer $length
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getImageDataByte($type, $start, $length)
|
|
||||||
{
|
|
||||||
if ($type == "ext") {
|
|
||||||
return substr($this->frameSources[$this->frameNumber]["graphicsextension"], $start, $length);
|
|
||||||
}
|
|
||||||
|
|
||||||
// "dat"
|
|
||||||
return substr($this->frameSources[$this->frameNumber]["imagedata"], $start, $length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the image data bit (old: get_imagedata_bit)
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param integer $byteIndex
|
|
||||||
* @param integer $bitStart
|
|
||||||
* @param integer $bitLength
|
|
||||||
*
|
|
||||||
* @return number
|
|
||||||
*/
|
|
||||||
private function getImageDataBit($type, $byteIndex, $bitStart, $bitLength)
|
|
||||||
{
|
|
||||||
if ($type == "ext") {
|
|
||||||
return $this->readBits(ord(substr($this->frameSources[$this->frameNumber]["graphicsextension"], $byteIndex, 1)), $bitStart, $bitLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
// "dat"
|
|
||||||
return $this->readBits(ord(substr($this->frameSources[$this->frameNumber]["imagedata"], $byteIndex, 1)), $bitStart, $bitLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the value of 2 ASCII chars (old: dualbyteval)
|
|
||||||
*
|
|
||||||
* @param string $s
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
private function dualByteVal($s)
|
|
||||||
{
|
|
||||||
$i = (ord($s[1]) * 256 + ord($s[0]));
|
|
||||||
|
|
||||||
return $i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read the data stream (old: read_data_stream)
|
|
||||||
*
|
|
||||||
* @param integer $firstLength
|
|
||||||
*/
|
|
||||||
private function readDataStream($firstLength)
|
|
||||||
{
|
|
||||||
$this->pointerForward($firstLength);
|
|
||||||
$length = $this->readByteInt();
|
|
||||||
|
|
||||||
if ($length != 0) {
|
|
||||||
while ($length != 0) {
|
|
||||||
$this->pointerForward($length);
|
|
||||||
$length = $this->readByteInt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open the gif file (old: loadfile)
|
|
||||||
*
|
|
||||||
* @param string $filename
|
|
||||||
*/
|
|
||||||
private function openFile($filename)
|
|
||||||
{
|
|
||||||
$this->handle = fopen($filename, "rb");
|
|
||||||
$this->pointer = 0;
|
|
||||||
|
|
||||||
$imageSize = getimagesize($filename);
|
|
||||||
$this->gifWidth = $imageSize[0];
|
|
||||||
$this->gifHeight = $imageSize[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close the read gif file (old: closefile)
|
|
||||||
*/
|
|
||||||
private function closeFile()
|
|
||||||
{
|
|
||||||
fclose($this->handle);
|
|
||||||
$this->handle = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read the file from the beginning to $byteCount in binary (old: readbyte)
|
|
||||||
*
|
|
||||||
* @param integer $byteCount
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function readByte($byteCount)
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, $byteCount);
|
|
||||||
$this->pointer += $byteCount;
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read a byte and return ASCII value (old: readbyte_int)
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
private function readByteInt()
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, 1);
|
|
||||||
$this->pointer++;
|
|
||||||
|
|
||||||
return ord($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a $byte to decimal (old: readbits)
|
|
||||||
*
|
|
||||||
* @param string $byte
|
|
||||||
* @param integer $start
|
|
||||||
* @param integer $length
|
|
||||||
*
|
|
||||||
* @return number
|
|
||||||
*/
|
|
||||||
private function readBits($byte, $start, $length)
|
|
||||||
{
|
|
||||||
$bin = str_pad(decbin($byte), 8, "0", STR_PAD_LEFT);
|
|
||||||
$data = substr($bin, $start, $length);
|
|
||||||
|
|
||||||
return bindec($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rewind the file pointer reader (old: p_rewind)
|
|
||||||
*
|
|
||||||
* @param integer $length
|
|
||||||
*/
|
|
||||||
private function pointerRewind($length)
|
|
||||||
{
|
|
||||||
$this->pointer -= $length;
|
|
||||||
fseek($this->handle, $this->pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Forward the file pointer reader (old: p_forward)
|
|
||||||
*
|
|
||||||
* @param integer $length
|
|
||||||
*/
|
|
||||||
private function pointerForward($length)
|
|
||||||
{
|
|
||||||
$this->pointer += $length;
|
|
||||||
fseek($this->handle, $this->pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a section of the data from $start to $start + $length (old: datapart)
|
|
||||||
*
|
|
||||||
* @param integer $start
|
|
||||||
* @param integer $length
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function dataPart($start, $length)
|
|
||||||
{
|
|
||||||
fseek($this->handle, $start);
|
|
||||||
$data = fread($this->handle, $length);
|
|
||||||
fseek($this->handle, $this->pointer);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a character if a byte (old: checkbyte)
|
|
||||||
*
|
|
||||||
* @param integer $byte
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
private function checkByte($byte)
|
|
||||||
{
|
|
||||||
if (fgetc($this->handle) == chr($byte)) {
|
|
||||||
fseek($this->handle, $this->pointer);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek($this->handle, $this->pointer);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check the end of the file (old: checkEOF)
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
private function checkEOF()
|
|
||||||
{
|
|
||||||
if (fgetc($this->handle) === false) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek($this->handle, $this->pointer);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset and clear this current object
|
|
||||||
*/
|
|
||||||
private function reset()
|
|
||||||
{
|
|
||||||
$this->gif = null;
|
|
||||||
$this->totalDuration = $this->gifMaxHeight = $this->gifMaxWidth = $this->handle = $this->pointer = $this->frameNumber = 0;
|
|
||||||
$this->frameDimensions = $this->framePositions = $this->frameImages = $this->frameDurations = $this->globaldata = $this->orgvars = $this->frames = $this->fileHeader = $this->frameSources = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getter / Setter
|
|
||||||
// ===================================================================================
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the total of all added frame duration
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function getTotalDuration()
|
|
||||||
{
|
|
||||||
return $this->totalDuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the number of extracted frames
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function getFrameNumber()
|
|
||||||
{
|
|
||||||
return $this->frameNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the extracted frames (images and durations)
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getFrames()
|
|
||||||
{
|
|
||||||
return $this->frames;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the extracted frame positions
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getFramePositions()
|
|
||||||
{
|
|
||||||
return $this->framePositions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the extracted frame dimensions
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getFrameDimensions()
|
|
||||||
{
|
|
||||||
return $this->frameDimensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the extracted frame images
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getFrameImages()
|
|
||||||
{
|
|
||||||
return $this->frameImages;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the extracted frame durations
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getFrameDurations()
|
|
||||||
{
|
|
||||||
return $this->frameDurations;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Traits;
|
|
||||||
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
trait Uuids
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Boot function from Laravel.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected static function bootUuids()
|
|
||||||
{
|
|
||||||
static::creating(function ($model) {
|
|
||||||
if (empty($model->{$model->getKeyName()}) === true) {
|
|
||||||
$model->{$model->getKeyName()} = Str::uuid()->toString();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the value indicating whether the IDs are incrementing.
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function getIncrementing()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the auto-incrementing key type.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getKeyType()
|
|
||||||
{
|
|
||||||
return 'string';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "laravel/laravel",
|
"name": "laravel/laravel",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"description": "The Laravel Framework.",
|
"description": "The skeleton application for the Laravel framework.",
|
||||||
"keywords": [
|
"keywords": ["laravel", "framework"],
|
||||||
"framework",
|
|
||||||
"laravel"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.0.2",
|
"php": "^8.1",
|
||||||
"doctrine/dbal": "^3.5",
|
|
||||||
"guzzlehttp/guzzle": "^7.2",
|
"guzzlehttp/guzzle": "^7.2",
|
||||||
"intervention/image": "^2.7",
|
"itsgoingd/clockwork": "^5.1",
|
||||||
"laravel/framework": "^9.19",
|
"laravel/framework": "^10.10",
|
||||||
"laravel/sanctum": "^3.0",
|
"laravel/sanctum": "^3.3",
|
||||||
"laravel/tinker": "^2.7",
|
"laravel/tinker": "^2.8"
|
||||||
"league/flysystem-aws-s3-v3": "^3.12",
|
|
||||||
"owen-it/laravel-auditing": "^13.0",
|
|
||||||
"php-ffmpeg/php-ffmpeg": "^1.1",
|
|
||||||
"sunspikes/clamav-validator": "*",
|
|
||||||
"thiagoalessio/tesseract_ocr": "^2.12",
|
|
||||||
"vlucas/phpdotenv": "^5.5"
|
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.9.1",
|
"fakerphp/faker": "^1.9.1",
|
||||||
"laravel/pint": "^1.0",
|
"laravel/pint": "^1.0",
|
||||||
"laravel/sail": "^1.0.1",
|
"laravel/sail": "^1.18",
|
||||||
"mockery/mockery": "^1.4.4",
|
"mockery/mockery": "^1.4.4",
|
||||||
"nunomaduro/collision": "^7.1",
|
"nunomaduro/collision": "^7.0",
|
||||||
"phpunit/phpunit": "^10.1.3",
|
"phpunit/phpunit": "^10.1",
|
||||||
"spatie/laravel-ignition": "^1.0"
|
"spatie/laravel-ignition": "^2.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"files": [
|
|
||||||
"app/Helpers/Array.php",
|
|
||||||
"app/Helpers/Temp.php"
|
|
||||||
],
|
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "app/",
|
"App\\": "app/",
|
||||||
"Database\\Factories\\": "database/factories/",
|
"Database\\Factories\\": "database/factories/",
|
||||||
"Database\\Seeders\\": "database/seeders/",
|
"Database\\Seeders\\": "database/seeders/"
|
||||||
"Faker\\Provider\\": "faker/provider/"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Tests\\": "tests/",
|
"Tests\\": "tests/"
|
||||||
"Faker\\Provider\\": "faker/provider/"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -74,9 +58,10 @@
|
|||||||
"preferred-install": "dist",
|
"preferred-install": "dist",
|
||||||
"sort-packages": true,
|
"sort-packages": true,
|
||||||
"allow-plugins": {
|
"allow-plugins": {
|
||||||
"pestphp/pest-plugin": true
|
"pestphp/pest-plugin": true,
|
||||||
|
"php-http/discovery": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "stable",
|
||||||
"prefer-stable": true
|
"prefer-stable": true
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user