Compare commits
2 Commits
e378054972
...
develop
Author | SHA1 | Date | |
---|---|---|---|
c3ce84143f | |||
6e3418402c |
@ -117,5 +117,8 @@ return [
|
||||
'username' => $c->get('email')->user->name,
|
||||
'password' => $c->get('email')->user->password
|
||||
]);
|
||||
},
|
||||
Psr\Log\LoggerInterface::class => function(Container $c) {
|
||||
return new ProVM\Common\Implementation\Logger(implode(DIRECTORY_SEPARATOR, [$c->get('folders.base'), 'admin.log']));
|
||||
}
|
||||
];
|
||||
|
@ -4,6 +4,7 @@ namespace ProVM\KI\Common\Controller\Web\Admin;
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Log\LoggerInterface as Logger;
|
||||
use ProVM\KI\Common\Alias\View;
|
||||
|
||||
class Nosotros {
|
||||
@ -15,19 +16,30 @@ class Nosotros {
|
||||
$nosotros = trim(json_decode(trim(file_get_contents($filename))));
|
||||
return $view->render($response, 'admin.nosotros', compact('nosotros'));
|
||||
}
|
||||
public function guardar(Request $request, Response $response, Container $container) {
|
||||
public function guardar(Request $request, Response $response, Container $container, Logger $logger) {
|
||||
$logger->info('Llamado a guardar en Nosotros.');
|
||||
$post = $request->getParsedBody();
|
||||
$logger->info('Información en post:', compact('post'));
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$container->get('folders.data'),
|
||||
'nosotros.json'
|
||||
]);
|
||||
$nosotros = trim(json_decode(trim(file_get_contents($filename))));
|
||||
$logger->info('Contenido de nosotros.json', compact('nosotros'));
|
||||
$data = trim(json_decode(json_encode($post['nosotros'])));
|
||||
|
||||
$status = false;
|
||||
if ($nosotros != $data) {
|
||||
$status = (file_put_contents($filename, json_encode($post['nosotros'])) !== false);
|
||||
if ($status) {
|
||||
$logger->info('Guardados los cambios en nosotros.json');
|
||||
} else {
|
||||
$logger->notice('No se pudo guardar los cambios en nosotros.json');
|
||||
}
|
||||
} else {
|
||||
$logger->info('No se han hecho cambios en nosotros.');
|
||||
}
|
||||
|
||||
$code = 301;
|
||||
if ($status) {
|
||||
$code = 302;
|
||||
|
@ -17,11 +17,11 @@ class Nosotros {
|
||||
$max_phrase = 50;
|
||||
if (strlen($nosotros) > $min) {
|
||||
$half = strlen($nosotros) / 2;
|
||||
$pos = strpos($nosotros, '.', $half);
|
||||
if ($pos > $half + $max_phrase) {
|
||||
$pos = strrpos($nosotros, '.', -$half);
|
||||
$pos = mb_strpos($nosotros, '.', $half); // Siguiente punto despues de la mitad
|
||||
if ($pos > $half + $max_phrase) { // Si está muy lejos de la mitad busca otra posicion
|
||||
$pos = mb_strrpos($nosotros, '.', -$half) + 1; // Punto antes de la mitad
|
||||
}
|
||||
$nosotros = $this->str_split_unicode($nosotros, $pos, '-');
|
||||
$nosotros = $this->str_split_unicode($nosotros, $pos);
|
||||
if (count($nosotros) > 2) {
|
||||
$s1 = array_shift($nosotros);
|
||||
$nosotros = [$s1, implode('', $nosotros)];
|
||||
|
67
provm/common/Implementation/Logger.php
Normal file
67
provm/common/Implementation/Logger.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Implementation;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Logger implements LoggerInterface {
|
||||
protected $output_file;
|
||||
public function __construct(string $filename) {
|
||||
if (!file_exists($filename)) {
|
||||
$f = fopen($filename, 'c');
|
||||
fclose($f);
|
||||
}
|
||||
if (!file_exists($filename)) {
|
||||
throw new \Exception('Can not create log file.');
|
||||
}
|
||||
$this->output_file = $filename;
|
||||
}
|
||||
public function emergency($message, array $context = []) {
|
||||
return $this->log(LogLevel::EMERGENCY, $message, $context);
|
||||
}
|
||||
public function alert($message, array $context = []) {
|
||||
return $this->log(LogLevel::ALERT, $message, $context);
|
||||
}
|
||||
public function critical($message, array $context = []) {
|
||||
return $this->log(LogLevel::CRITICAL, $message, $context);
|
||||
}
|
||||
public function error($message, array $context = []) {
|
||||
return $this->log(LogLevel::ERROR, $message, $context);
|
||||
}
|
||||
public function warning($message, array $context = []) {
|
||||
return $this->log(LogLevel::WARNING, $message, $context);
|
||||
}
|
||||
public function notice($message, array $context = []) {
|
||||
return $this->log(LogLevel::NOTICE, $message, $context);
|
||||
}
|
||||
public function info($message, array $context = []) {
|
||||
return $this->log(LogLevel::INFO, $message, $context);
|
||||
}
|
||||
public function debug($message, array $context = []) {
|
||||
return $this->log(LogLevel::DEBUG, $message, $context);
|
||||
}
|
||||
public function log($level, $message, array $context = []) {
|
||||
$refl = new \ReflectionClass(LogLevel::class);
|
||||
$levels = $refl->getConstants();
|
||||
if (array_search($level, array_values($levels)) === false) {
|
||||
throw new \InvalidArgumentException('Invalid log level.');
|
||||
}
|
||||
|
||||
$f = Carbon::now('America/Santiago');
|
||||
$output = [
|
||||
'time' => $f->format('Y-m-d H:i:s,v'),
|
||||
'message' => $message
|
||||
];
|
||||
if (count($context) > 0) {
|
||||
$output['context'] = $context;
|
||||
}
|
||||
|
||||
$data = json_decode(trim(file_get_contents($this->output_file)));
|
||||
if ($data === null) {
|
||||
$data = [];
|
||||
}
|
||||
$data []= $output;
|
||||
file_put_contents($this->output_file, json_encode($data, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@
|
||||
@foreach ($faqs as $faq)
|
||||
{
|
||||
titulo: '{{$faq->titulo}}',
|
||||
contenido: '{{$faq->contenido}}'
|
||||
contenido: "{{implode("\\n", explode(PHP_EOL, $faq->contenido))}}"
|
||||
},
|
||||
@endforeach
|
||||
],
|
||||
@ -82,7 +82,7 @@
|
||||
titulo: $("input[name='titulo']").val(),
|
||||
contenido: $("textarea[name='contenido']").val()
|
||||
}
|
||||
if (edit) {
|
||||
if (faq.edit) {
|
||||
input['id'] = $("input[name='id']").val()
|
||||
}
|
||||
var url = '{{$urls->admin}}/faqs/add'
|
||||
|
@ -14,7 +14,7 @@
|
||||
</div>
|
||||
<div class="content">
|
||||
<p>
|
||||
{{$faq->contenido}}
|
||||
{!!nl2br($faq->contenido)!!}
|
||||
</p>
|
||||
</div>
|
||||
@endforeach
|
||||
|
Reference in New Issue
Block a user