Skip to content

Commit

Permalink
v0.2.1-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
FlamesONE committed Jun 2, 2024
1 parent 0c44372 commit d15c794
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 61 deletions.
4 changes: 2 additions & 2 deletions app/Core/Admin/Http/Controllers/Views/IndexView.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function buildLineChart()
protected function buildWeekArea()
{
$startDate = new \DateTime('monday this week');
$endDate = new \DateTime('friday this week');
$endDate = new \DateTime('sunday this week');

// Запрос к базе данных
$payments = rep(PaymentInvoice::class)->select()
Expand Down Expand Up @@ -113,7 +113,7 @@ protected function buildWeekArea()
protected function buildRegistrationsArea()
{
$startDate = new \DateTime('monday this week');
$endDate = (new \DateTime('friday this week'))->setTime(23, 59, 59);
$endDate = (new \DateTime('sunday this week'))->setTime(23, 59, 59);

// Запрос к базе данных
$userRegistrations = rep(User::class)->select()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ protected function getAllDrivers()
$gatewayClassShortName = substr($filename, 0, -4);
$gatewayClass = $namespace . $gatewayClassShortName;


if (payments()->gatewayExists($gatewayClass) && !Strings::startsWith($gatewayClassShortName, 'Abstract')) {
$gatewayInstance = new $gatewayClass();

Expand Down
2 changes: 1 addition & 1 deletion app/Core/Admin/Http/Views/assets/js/pages/payments/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $(function() {
$(document).on('change', '#adapter', function () {
var paymentSystem = $(this).val();
var handleUrl = u(`api/lk/handle/${paymentSystem}`); // Example URL format
$('#handleUrl').val(handleUrl);
$('#handleUrl').val(handleUrl).attr('data-copy', handleUrl);
updateParameters();
});

Expand Down
11 changes: 5 additions & 6 deletions app/Core/Admin/Http/Views/assets/js/pages/theme_edit.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var pickerInstances = {};

function updateValue($element, id, value) {
let unit = id === 'transition' ? 's' : 'px';
$element.find('#' + id + '-value').text(value + unit);
$('#theme-editor').css('--' + id, value + unit);

// Обновление --range у родительского элемента с классом range-control
let percentage =
((value - parseFloat($element.find('#' + id).attr('min'))) /
(parseFloat($element.find('#' + id).attr('max')) -
Expand All @@ -25,7 +26,6 @@ function parseColors() {
if (!editor) return;

const editorId = editor.getAttribute('id');
const pickrInstances = {};

// Initialize Pickr for each color input
editor.querySelectorAll('.color-picker').forEach(function (pickerElement) {
Expand Down Expand Up @@ -73,7 +73,7 @@ function parseColors() {
},
});

pickrInstances[colorVariable] = pickr;
pickerInstances[colorVariable] = pickr;

pickr.on('change', (color, source, instance) => {
const rgbaColor = color.toRGBA().toString();
Expand All @@ -84,8 +84,6 @@ function parseColors() {
pickerElement.value = rgbaColor;
});
});

window.pickrInstances = pickrInstances;
}

function addUnitsToProperties(settings) {
Expand Down Expand Up @@ -125,6 +123,7 @@ $(function () {
let $this = $(this).find('input[type="range"]');
initRange($(this), $this.attr('id'));
});

parseColors();
});

Expand All @@ -151,7 +150,7 @@ $(function () {
});

// Get values from Pickr instances
for (const [key, pickr] of Object.entries(window.pickrInstances)) {
for (const [key, pickr] of Object.entries(pickerInstances)) {
const color = pickr.getColor().toRGBA().toString();
themeSettings[key] = color;
}
Expand Down
6 changes: 3 additions & 3 deletions app/Core/Admin/Http/Views/pages/payments/add.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<div class="col-sm-3 col-form-label">
<label for="handleUrl">Handle URL</label>
</div>
<div class="col-sm-9" data-tooltip="Copy" data-tooltip-conf="top">
<div class="col-sm-9" data-tooltip="@t('def.copy')" data-tooltip-conf="top">
<input id="handleUrl" type="text" class="form-control" readonly
value="{{ url('/api/lk/handle/' . array_key_first($drivers)) }}"
data-copy="{{ url('/api/lk/handle/' . array_key_first($drivers)) }}">
Expand All @@ -83,7 +83,7 @@
<div class="col-sm-3 col-form-label">
<label for="successUrl">Success URL</label>
</div>
<div class="col-sm-9" data-tooltip="Copy" data-tooltip-conf="top">
<div class="col-sm-9" data-tooltip="@t('def.copy')" data-tooltip-conf="top">
<input id="successUrl" type="text" class="form-control" readonly value="{{ url('/lk/success') }}"
data-copy="{{ url('/lk/success') }}">
</div>
Expand All @@ -92,7 +92,7 @@
<div class="col-sm-3 col-form-label">
<label for="failUrl">Fail URL</label>
</div>
<div class="col-sm-9" data-tooltip="Copy" data-tooltip-conf="top">
<div class="col-sm-9" data-tooltip="@t('def.copy')" data-tooltip-conf="top">
<input id="failUrl" type="text" class="form-control" readonly value="{{ url('/lk/fail') }}"
data-copy="{{ url('/lk/fail') }}">
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/Core/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class App
*
* @var string
*/
public const VERSION = '0.2.0-alpha';
public const VERSION = '0.2.1-alpha';

/**
* Set the base path of the application
Expand Down
14 changes: 7 additions & 7 deletions app/Core/Cache/AbstractCacheDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ public function set(string $key, $value, $ttl = null): bool
{
$item = $this->cache->getItem($key);

// Если кэша с таким ключом нет, устанавливаем новое значение
if (!$item->isHit()) {
$item->set($value);
$item->expiresAfter($ttl);
return $this->cache->save($item);
$item->set($value);
$item->expiresAfter($ttl);
$result = $this->cache->save($item);

if (!$result) {
logs()->error("ERROR SAVE CACHE - $key");
}

return false;
return $result;
}


/**
* Удаляет значение из кэша по ключу
*
Expand Down
2 changes: 1 addition & 1 deletion app/Core/Database/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class User
public $created_at;

/**
* @Column(type="timestamp", default="CURRENT_TIMESTAMP")
* @Column(type="timestamp", nullable=true)
*/
public $last_logged;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public function search(FluteRequest $request, $value)
{
$redirectUrl = $request->input('else-redirect', null);

$user = rep(UserSocialNetwork::class)->findOne([
$user = rep(UserSocialNetwork::class)->select()->where([
'value' => $value
]);
])->load('user')->fetchOne();

if (!empty($redirectUrl) && empty($user))
return redirect($redirectUrl);
Expand Down
110 changes: 85 additions & 25 deletions app/Core/Services/EventNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Flute\Core\Services;

use Flute\Core\Database\Entities\EventNotification;
use Flute\Core\Database\Entities\Notification;

class EventNotifications
{
Expand All @@ -15,38 +14,99 @@ public function listen()
$events = rep(EventNotification::class)->findAll();

foreach ($events as $event) {
events()->addDeferredListener($event->event, function ($eventInstance) use ($event) {
$notification = new Notification;
$notification->content = $this->replaceContent($event->content, $eventInstance);
$notification->url = $event->url;
$notification->user = user()->getCurrentUser();
$notification->icon = $event->icon;
$notification->title = $event->title;

notification()->create($notification);
});
events()->addDeferredListener($event->event, [$this, 'handleEvent']);
}
}

private function replaceContent(string $content, $event)
public static function handleEvent($eventInstance)
{
$content = $this->replaceUserContent($content);

return preg_replace_callback('/\{(.*?)\}/', function ($matches) use ($event) {
$parts = explode('.', $matches[1]);
if (count($parts) == 2 && method_exists($event, $parts[0])) {
return $event->{$parts[0]}()->{$parts[1]};
} elseif (count($parts) == 1 && method_exists($event, $parts[0])) {
return $event->{$parts[0]}();
} elseif (property_exists($event, $matches[1])) {
return $event->{$matches[1]};
} else {
return $matches[0];
if ($eventInstance::NAME) {
$events = rep(EventNotification::class)->select()->where('event', $eventInstance::NAME)->fetchAll();

foreach ($events as $event) {
$table = db()->table('notifications');

$table->insertOne([
'content' => self::replaceContent($event->content, $eventInstance),
'icon' => $event->icon,
'url' => $event->url,
'title' => $event->title,
'user_id' => user()->getCurrentUser()->id,
'created_at' => new \DateTime()
]);
}
}
}

private static function replaceContent(string $content, $eventInstance): string
{
$content = self::replaceUserContent($content);

return preg_replace_callback('/\{(.*?)\}/', function ($matches) use ($eventInstance) {
return self::evaluateExpression($matches[1], $eventInstance);
}, $content);
}

private function replaceUserContent(string $content)
private static function evaluateExpression($expression, $eventInstance)
{
if (preg_match('/^(\w+)\((.*?)\)$/', $expression, $matches)) {
$func = $matches[1];
$args = self::parseArguments($matches[2]);
if (function_exists($func)) {
$result = call_user_func_array($func, $args);
return is_object($result) ? self::getNestedProperty($result, array_slice(explode('.', $expression), 1)) : $result;
}
}

$parts = explode('.', $expression);
return self::getNestedProperty($eventInstance, $parts);
}

private static function getNestedProperty($object, array $parts)
{
$current = $object;

foreach ($parts as $part) {
if (preg_match('/(\w+)\((.*?)\)$/', $part, $matches)) {
$func = $matches[1];
$args = self::parseArguments($matches[2]);
if (is_object($current) && method_exists($current, $func)) {
$current = call_user_func_array([$current, $func], $args);
} elseif (function_exists($func)) {
$current = call_user_func_array($func, $args);
} else {
return '{' . implode('.', $parts) . '}';
}
} elseif (is_object($current)) {
if (method_exists($current, $part)) {
$current = $current->{$part}();
} elseif (property_exists($current, $part)) {
$current = $current->{$part};
} else {
return '{' . implode('.', $parts) . '}';
}
} else {
return '{' . implode('.', $parts) . '}';
}
}

return $current;
}

private static function parseArguments($argsString)
{
$args = [];
if (!empty($argsString)) {
$parts = explode(',', $argsString);
foreach ($parts as $part) {
$part = trim($part, " \t\n\r\0\x0B'\"");
$args[] = $part;
}
}
return $args;
}

private static function replaceUserContent(string $content)
{
return str_replace(['{name}', '{login}', '{email}', '{balance}'], [
user()->getCurrentUser()->name,
Expand Down
Loading

0 comments on commit d15c794

Please sign in to comment.