1
|
|
|
<?php namespace kcfinder\integration; |
2
|
|
|
|
3
|
|
|
/** This file is part of KCFinder project |
4
|
|
|
* |
5
|
|
|
* @desc Integration code: Laravel Administrator (https://github.com/FrozenNode/Laravel-Administrator) |
6
|
|
|
* @package KCFinder |
7
|
|
|
* @version 3.12 |
8
|
|
|
* @author Zsombor Franczia <[email protected]> |
9
|
|
|
* @copyright 2010-2014 KCFinder Project |
10
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 |
11
|
|
|
* @license http://opensource.org/licenses/LGPL-3.0 LGPLv3 |
12
|
|
|
* @link http://kcfinder.sunhater.com |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
class LaravelAdministrator { |
16
|
|
|
protected static $authenticated = false; |
17
|
|
|
protected static $bootstrapAutoload = '/bootstrap/autoload.php'; |
18
|
|
|
protected static $bootstrapStart = '/bootstrap/start.php'; |
19
|
|
|
|
20
|
|
|
static function getLaravelPath() { |
21
|
|
|
|
22
|
|
|
//absolute path method |
23
|
|
|
if (!empty($_SERVER['SCRIPT_FILENAME'])) { |
24
|
|
|
$laravelPath = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])))))))); |
25
|
|
|
if (!file_exists($laravelPath . self::$bootstrapAutoload)) { |
26
|
|
|
$laravelPath = dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])))); |
27
|
|
|
$depth = 3; |
28
|
|
|
do { |
29
|
|
|
$laravelPath = dirname($laravelPath); |
30
|
|
|
$depth++; |
31
|
|
|
$autoloadFound = file_exists($laravelPath . self::$bootstrapAutoload); |
32
|
|
|
} while (!$autoloadFound && $depth < 10); |
33
|
|
|
} |
34
|
|
|
else { |
35
|
|
|
$autoloadFound = true; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
//relative path method |
40
|
|
|
if (!isset($autoloadFound) || !$autoloadFound) { |
41
|
|
|
$laravelPath = '../../../../../../..'; |
42
|
|
|
if (!file_exists($laravelPath . self::$bootstrapAutoload)) { |
43
|
|
|
$laravelPath = '../../..'; |
44
|
|
|
$depth = 3; |
45
|
|
|
do { |
46
|
|
|
$laravelPath .= '/..'; |
47
|
|
|
$depth++; |
48
|
|
|
} while (!($autoloadFound = file_exists($laravelPath . self::$bootstrapAutoload)) && $depth < 10); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
else { |
51
|
|
|
$autoloadFound = true; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $laravelPath; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
static function runIntegration() { |
|
|
|
|
59
|
|
|
|
60
|
|
|
$laravelPath = self::getLaravelPath(); |
61
|
|
|
|
62
|
|
|
if(file_exists($laravelPath . '/bootstrap/autoload.php')) { |
63
|
|
|
$currentCwd = getcwd(); |
64
|
|
|
|
65
|
|
|
// Simulate being in the laravel root folder so we can share the session (is this really needed?) |
66
|
|
|
// chdir($laravelPath); |
67
|
|
|
|
68
|
|
|
// bootstrap |
69
|
|
|
require $laravelPath.'/bootstrap/autoload.php'; |
70
|
|
|
$app = require_once $laravelPath.'/bootstrap/start.php'; |
71
|
|
|
$app->boot(); //Boot the application's service providers. |
72
|
|
|
|
73
|
|
|
//get the admin check closure that should be supplied in the admin config |
74
|
|
|
$permission = \Illuminate\Support\Facades\Config::get('administrator::administrator.permission'); |
|
|
|
|
75
|
|
|
$hasPermission = $permission(); |
76
|
|
|
self::$authenticated = $hasPermission; |
77
|
|
|
|
78
|
|
|
//start session if not started already |
79
|
|
|
if (session_id() == "") { |
80
|
|
|
session_start(); |
81
|
|
|
$iStartedTheSession = true; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if (!isset($_SESSION['KCFINDER'])) { |
85
|
|
|
$_SESSION['KCFINDER'] = array(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
//if this is a simple true value, user is logged in |
89
|
|
|
if ($hasPermission == true) { |
90
|
|
|
|
91
|
|
|
$configFactory = \Illuminate\Support\Facades\App::make('admin_config_factory'); |
|
|
|
|
92
|
|
|
$modelName = \Illuminate\Support\Facades\Input::get('model'); |
|
|
|
|
93
|
|
|
$fieldName = \Illuminate\Support\Facades\Input::get('field'); |
94
|
|
|
|
95
|
|
|
if(!empty($modelName) && !empty($fieldName)) { |
96
|
|
|
|
97
|
|
|
$modelConfig = $configFactory->make($modelName, true); |
98
|
|
|
$modelConfigOptions = $modelConfig->getOption('edit_fields'); |
99
|
|
|
$kcfinderOptions = $modelConfigOptions[$fieldName]["kcfinder"]; |
100
|
|
|
|
101
|
|
|
//allow users to use an option called 'enabled' instead of 'disabled' |
102
|
|
|
if(isset($kcfinderOptions["enabled"])) { |
103
|
|
|
$kcfinderOptions["disabled"] = !$kcfinderOptions["enabled"]; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
//save all options to the session |
107
|
|
|
foreach ($kcfinderOptions as $optKey => $optValue) { |
108
|
|
|
$_SESSION['KCFINDER'][$optKey] = $optValue; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
self::$authenticated = !$_SESSION['KCFINDER']['disabled']; |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
else { |
116
|
|
|
//clean and reset the session variable |
117
|
|
|
$_SESSION['KCFINDER'] = array(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
//close the session if I started it |
121
|
|
|
if (isset($iStartedTheSession)) { |
122
|
|
|
session_write_close(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
// chdir($currentCwd); |
126
|
|
|
return self::$authenticated; |
127
|
|
|
} |
128
|
|
|
else { |
129
|
|
|
die("The integration service for 'Laravel Administrator' failed. Laravel root path not found!"); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
\kcfinder\integration\LaravelAdministrator::runIntegration(); |
137
|
|
|
|