"ext-libxml": "*",
"ext-json": "*",
"ext-redis": "*",
- "backpack/crud": "^4.1.69",
+ "backpack/crud": "^4.1.71",
"backpack/backupmanager": "^3.0",
"backpack/logmanager": "^4.0",
"backpack/permissionmanager": "^6.0",
"cviebrock/eloquent-sluggable": "^8.0",
"lavary/laravel-menu": "^v1.8",
"graham-campbell/markdown": "^v13.1",
- "barryvdh/laravel-debugbar": "^v3.6",
+ "barryvdh/laravel-debugbar": "^v3.7",
"league/commonmark": "^1.6",
"cviebrock/laravel-elasticsearch": "^8.0",
"spatie/laravel-honeypot": "^4.2",
"digitallyhappy/toggle-field-for-backpack": "^2.0",
"calebporzio/parental": "^v0.11",
"cache/filesystem-adapter": "^1.2",
- "laravel/framework": "^v8.83",
- "laravel-lang/lang": "^10.1",
+ "laravel/framework": "^v8.83.27",
+ "laravel-lang/lang": "^10.9",
"laravel-lang/publisher": "^10.3",
- "spatie/laravel-permission": "^4.4|^5.5"
+ "spatie/laravel-permission": "^4.4|^5.8"
},
"require-dev": {
"filp/whoops": "^2.14",
namespace Cubist\Backpack\Magic\Fields;
-class ExternalPath
+use Cubist\Backpack\CubistBackpackServiceProvider;
+use Cubist\Backpack\Magic\Models\ExternalServer;
+
+class ExternalPath extends Field
{
+ protected $_adminType = 'external_path';
+ protected $_cast = 'array';
+ protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+
+ public function getDefaultAttributes()
+ {
+ return array_merge(parent::getDefaultAttributes(), ['servers_model' => ExternalServer::class]);
+ }
}
use Cubist\Backpack\Magic\Fields\SelectFromArray;
use Cubist\Backpack\Magic\Fields\Text;
use Cubist\Backpack\Magic\Fields\URL;
+use Cubist\Net\Transfer\Driver;
+use Cubist\Net\Transfer\FTP;
+use Cubist\Net\Transfer\IServer;
+use Cubist\Net\Transfer\SFTP;
-class ExternalServer extends CubistMagicAbstractModel
+class ExternalServer extends CubistMagicAbstractModel implements IServer
{
+ /**
+ * @var array[]|null
+ */
+ public static $_servers = null;
+
public function setFields()
{
parent::setFields();
$this->addField('base_url', URL::class, __('URL de base'), ['default' => 'https://']);
}
+ public static function getAllServers()
+ {
+
+ if (null === static::$_servers) {
+ static::$_servers = [];
+ foreach (static::where('created_ok', '1')->get() as $server) {
+ static::$_servers[$server->id] = ['name' => $server->name, 'base_url' => $server->base_url];
+ }
+ }
+ return static::$_servers;
+ }
+
protected function getProtocols()
{
return ['FTP' => __('FTP non sécurisé'), 'FTPS' => __('FTP sécurisé explicite sur TLS'), 'FTPES' => __('FTP sécurisé implicite sur TLS'), 'SFTP' => 'SFTP'];
{
return $this->getUsernameProtocols();
}
+
+
+ /**
+ * @param $protocol
+ * @return Driver
+ */
+ public function getTransferDriver($protocol)
+ {
+ if (in_array($this->getProtocol(), $this->getFTPProtocols())) {
+ return new FTP($this);
+ } else if ($this->getProtocol() === 'sftp') {
+ return new SFTP($this);
+ }
+ return null;
+ }
+
+ public function getProtocol()
+ {
+ return $this->protocol;
+ }
+
+ public function getHost()
+ {
+ return $this->host;
+ }
+
+ public function getPort()
+ {
+ return $this->port;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ public function getPassword()
+ {
+ return $this->password;
+ }
+
+ public function getBasePath()
+ {
+ return $this->base_path;
+ }
+
+ public function getBaseURL()
+ {
+ return $this->base_url;
+ }
+
+ public function getSettings()
+ {
+ return ['ftp_port' => $this->ftp_port];
+ }
}
--- /dev/null
+<!-- range of values -->
+<?php
+$empty = ['server' => '', 'path' => ''];
+$value = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? $empty;
+if ($value == '') {
+ $value = $empty;
+}
+
+if (is_string($value)) {
+ $value = json_decode($value, true);
+}
+if (is_object($value)) {
+ $value = Cubist\Util\ArrayUtil::asArray($value);
+}
+
+if (!isset($value['server'])) {
+ $value['server'] = '';
+}
+if (!isset($value['path'])) {
+ $value['path'] = '';
+}
+
+$serversClass = $field['servers_model'];
+$servers = $serversClass::getAllServers();
+
+?>
+@include('crud::fields.inc.wrapper_start')
+<label>{!! $field['label'] !!}</label>
+<div class="external_path__wrapper">
+ <div class="external_path__field server">
+ <label>{!! __('Serveur') !!}</label>
+ <select data-class="external_path_server_select" @include('crud::fields.inc.attributes')
+ name="{{ $field['name'] }}[server]"
+ >
+ <option value="" @if(!$value['server']) selected @endif>--</option>
+ @foreach($servers as $i=>$server)
+ <option value="{{$i}}" @if($value['server']==$i) selected
+ @endif data-prefix="{{$server['base_url']}}">{!! $server['name'] !!}</option>
+ @endforeach
+ </select>
+ </div>
+ <div class="external_path__field path">
+ <label>{!! __('Chemin') !!}</label>
+ <div class="input-group">
+ <div class="input-group-prepend"><span class="input-group-text prefix"></span></div>
+ <input @include('crud::fields.inc.attributes')
+ value="{{ $value['path'] }}"
+ type="text"
+ name="{{ $field['name'] }}[path]"
+ ></div>
+ </div>
+</div>
+
+{{-- HINT --}}
+@if (isset($field['hint']))
+ <p class="help-block">{!! $field['hint'] !!}</p>
+@endif
+@include('crud::fields.inc.wrapper_end')
+
+@if ($crud->checkIfFieldIsFirstOfItsType($field))
+ {{-- FIELD EXTRA CSS --}}
+ {{-- push things in the after_styles section --}}
+
+ @push('crud_fields_styles')
+ <style type="text/css">
+ .external_path__wrapper {
+ width: 100%;
+ white-space: nowrap;
+ }
+
+ .external_path__field {
+ display: inline-block;
+ padding: 0 15px;
+ box-sizing: border-box;
+ vertical-align: top;
+ }
+
+ .external_path__field.server {
+ width: 30%;
+ }
+
+ .external_path__field.path {
+ width: 70%;
+ }
+
+
+ .external_path__field label {
+ font-weight: 400;
+ margin: 0;
+ }
+
+ .external_path__field:first-child {
+ padding-left: 0;
+ }
+
+ .external_path__field:last-child {
+ padding-right: 0;
+ }
+ </style>
+ @endpush
+
+ {{-- FIELD EXTRA JS --}}
+ {{-- push things in the after_scripts section --}}
+
+ @push('crud_fields_scripts')
+ <script>
+ $(function () {
+ function updateServer(s) {
+ var prefix = $(s).find('option[value="' + $(s).val() + '"]').data('prefix');
+ console.log($(s).val(), prefix,(s).find('option[value="' + $(s).val() + '"]'));
+ $(s).closest('.external_path__wrapper').find('.prefix').text(prefix);
+ }
+
+ $(document).on('change', '[data-class="external_path_server_select"]', function () {
+ updateServer($(this));
+ });
+
+ $('[data-class="external_path_server_select"]').each(function () {
+ updateServer($(this));
+ });
+ });
+ </script>
+ @endpush
+@endif