Compare commits
5 Commits
42f193efc1
...
develop
Author | SHA1 | Date | |
---|---|---|---|
c3ce84143f | |||
6e3418402c | |||
e378054972 | |||
450819f6b4 | |||
c65cc00a9e |
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,3 +12,4 @@ composer.lock
|
||||
# Uploads
|
||||
/public/uploads/
|
||||
/resources/data/
|
||||
/public/assets/images/*/
|
||||
|
@ -37,7 +37,7 @@ foreach ($files as $file) {
|
||||
$container = $builder->build();
|
||||
$container->set('env', $__environment);
|
||||
$app = Bridge::create($container);
|
||||
$app->setBasePath($container->get('base_url'));
|
||||
$app->setBasePath($container->get('urls.base'));
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
// Global visit counter
|
||||
//$app->add(new ProVM\KI\Common\Middleware\Visits($app->getContainer()->get('file.visits'), $app->getContainer()->get('visits.time')));
|
@ -60,8 +60,24 @@ return [
|
||||
$segmentos = json_decode(trim(file_get_contents($filename)));
|
||||
return $segmentos;
|
||||
},
|
||||
Slim\Views\Blade::class => function(Container $c) {
|
||||
return new Slim\Views\Blade(
|
||||
'email' => function(Container $c) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$c->get('folders.data'),
|
||||
'emails.json'
|
||||
]);
|
||||
$emails = json_decode(trim(file_get_contents($filename)));
|
||||
return $emails->settings;
|
||||
},
|
||||
'emails' => function(Container $c) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$c->get('folders.data'),
|
||||
'emails.json'
|
||||
]);
|
||||
$emails = json_decode(trim(file_get_contents($filename)));
|
||||
return $emails->emails;
|
||||
},
|
||||
ProVM\KI\Common\Alias\View::class => function(Container $c) {
|
||||
return new ProVM\KI\Common\Implementation\View(
|
||||
$c->get('folders.templates'),
|
||||
$c->get('folders.cache'),
|
||||
null,
|
||||
@ -91,5 +107,18 @@ return [
|
||||
$c->get('folders.data'),
|
||||
$c->get('folders.public')
|
||||
);
|
||||
},
|
||||
ProVM\KI\Common\Alias\Message::class => function(Container $c) {
|
||||
return new ProVM\KI\Common\Implementation\Message();
|
||||
},
|
||||
ProVM\KI\Common\Alias\Mailer::class => function(Container $c) {
|
||||
return new ProVM\KI\Common\Implementation\Mailer([
|
||||
'host' => $c->get('email')->host->name,
|
||||
'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']));
|
||||
}
|
||||
];
|
||||
|
6
common/Alias/Mailer.php
Normal file
6
common/Alias/Mailer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Common\Alias;
|
||||
|
||||
interface Mailer {
|
||||
public function send(Message $message): bool;
|
||||
}
|
4
common/Alias/Message.php
Normal file
4
common/Alias/Message.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Common\Alias;
|
||||
|
||||
interface Message {}
|
9
common/Alias/View.php
Normal file
9
common/Alias/View.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Common\Alias;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
|
||||
interface View {
|
||||
public function render(Response $response, $template, array $data = []);
|
||||
public function fetch($template, array $data = []);
|
||||
}
|
@ -4,7 +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 Slim\Views\Blade as View;
|
||||
use ProVM\KI\Common\Alias\View;
|
||||
|
||||
class Faq {
|
||||
public function __invoke(Request $request, Response $response, View $view, Container $container) {
|
||||
|
@ -4,7 +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 Slim\Views\Blade as View;
|
||||
use ProVM\KI\Common\Alias\View;
|
||||
|
||||
class Home {
|
||||
public function __invoke(Request $request, Response $response, View $view, Container $container): Response {
|
||||
|
@ -4,7 +4,8 @@ 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 Slim\Views\Blade as View;
|
||||
use Psr\Log\LoggerInterface as Logger;
|
||||
use ProVM\KI\Common\Alias\View;
|
||||
|
||||
class Nosotros {
|
||||
public function __invoke(Request $request, Response $response, View $view, Container $container) {
|
||||
@ -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;
|
||||
|
@ -4,7 +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 Slim\Views\Blade as View;
|
||||
use ProVM\KI\Common\Alias\View;
|
||||
use Carbon\Carbon;
|
||||
use ProVM\Common\Factory\Model as ModelFactory;
|
||||
use ProVM\KI\Producto;
|
||||
|
@ -4,8 +4,8 @@ namespace ProVM\KI\Common\Controller\Web;
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Slim\Views\Blade as View;
|
||||
use Carbon\Carbon;
|
||||
use ProVM\KI\Common\Alias\View;
|
||||
|
||||
class Base {
|
||||
public function __invoke(Request $request, Response $response, View $view, Container $container) {
|
||||
@ -37,6 +37,6 @@ class Base {
|
||||
]);
|
||||
$resumen = json_decode(trim(file_get_contents($filename)));
|
||||
$indicadores = ['uf' => 'UF', 'euro' => 'Euro', 'imacec' => 'IMACEC', 'dolar' => 'USD', 'ipc' => 'IPC', 'utm' => 'UTM', 'bitcoin' => 'BitCoin', 'libra_cobre' => 'Lb. Cu'];
|
||||
return $view->render($response, 'home', compact('aviso', 'avisos', 'destacados', 'segmentos', 'resumen', 'indicadores'));
|
||||
return $view->render($response, 'home', compact('avisos', 'destacados', 'segmentos', 'resumen', 'indicadores'));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,63 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Common\Controller\Web;
|
||||
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Slim\Views\Blade as View;
|
||||
use ProVM\KI\Common\Alias\Message;
|
||||
use ProVM\KI\Common\Alias\Mailer;
|
||||
use ProVM\KI\Common\Alias\View;
|
||||
|
||||
class Contacto {
|
||||
public function __invoke(Request $request, Response $response, View $view) {
|
||||
public function __invoke(Request $request, Response $response, View $view): Response {
|
||||
return $view->render($response, 'contacto');
|
||||
}
|
||||
public function enviar(Request $request, Response $response, Container $container, Mailer $mailer): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$body = [];
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$container->get('folders.templates'),
|
||||
'contacto',
|
||||
'email.php'
|
||||
]);
|
||||
$html = file_get_contents($filename);
|
||||
foreach ($post as $key => $val) {
|
||||
$body []= ucwords($key) . ': ' . $val;
|
||||
$html = str_replace('{{$' . $key . '}}', $val, $html);
|
||||
}
|
||||
$body = implode(PHP_EOL, $body);
|
||||
$subject = 'Contacto Web - ' . $post['nombre'];
|
||||
|
||||
$message = $container->make(Message::class)
|
||||
->setFrom($container->get('emails')[0])
|
||||
->addTo($container->get('emails')[0])
|
||||
->addCc($container->get('emails')[1])
|
||||
->setSubject($subject)
|
||||
->setBody($body)
|
||||
->setHTMLBody($html);
|
||||
$status = $mailer->send($message);
|
||||
$message = $container->make(Message::class)
|
||||
->setFrom($container->get('emails')[0])
|
||||
->addTo($post['mail'], $post['nombre'])
|
||||
->setSubject($subject)
|
||||
->setBody('Su correo a CapitalInvestments ha sido recibido.');
|
||||
$mailer->send($message);
|
||||
|
||||
$output = [
|
||||
'informacion' => $post,
|
||||
'estado' => $status,
|
||||
'mail' => [
|
||||
'from' => $post['mail'],
|
||||
'to' => $container->get('emails')[0],
|
||||
'cc' => $container->get('emails')[1],
|
||||
'asunto' => $subject,
|
||||
'mensaje' => $body,
|
||||
'html' => $html
|
||||
]
|
||||
];
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->withStatus(201);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ namespace ProVM\KI\Common\Controller\Web;
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Slim\Views\Blade as View;
|
||||
use ProVM\KI\Common\Alias\View;
|
||||
|
||||
class Faq {
|
||||
public function __invoke(Request $request, Response $response, View $view, Container $container) {
|
||||
|
@ -4,7 +4,7 @@ namespace ProVM\KI\Common\Controller\Web;
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Slim\Views\Blade as View;
|
||||
use ProVM\KI\Common\Alias\View;
|
||||
|
||||
class Nosotros {
|
||||
public function __invoke(Request $request, Response $response, View $view, Container $container) {
|
||||
@ -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)];
|
||||
|
@ -4,7 +4,7 @@ namespace ProVM\KI\Common\Controller\Web;
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Slim\Views\Blade as View;
|
||||
use ProVM\KI\Common\Alias\View;
|
||||
use ProVM\Common\Factory\Model as ModelFactory;
|
||||
use ProVM\KI\Producto;
|
||||
|
||||
|
102
common/Implementation/Mailer.php
Normal file
102
common/Implementation/Mailer.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Common\Implementation;
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer as BaseMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use ProVM\KI\Common\Alias\Mailer as MailerInterface;
|
||||
use ProVM\KI\Common\Alias\Message;
|
||||
|
||||
class Mailer implements MailerInterface {
|
||||
protected $host;
|
||||
protected $port;
|
||||
protected $user;
|
||||
protected $is_secure = false;
|
||||
public function __construct(array $settings) {
|
||||
if (!isset($settings['host'])) {
|
||||
throw new \Exception('Host is missing in ' . get_called_class());
|
||||
}
|
||||
$this->host = $settings['host'];
|
||||
if (!isset($settings['username'])) {
|
||||
throw new \Exception('User name is missing in ' . get_called_class());
|
||||
}
|
||||
$this->user = (object) ['name' => null, 'password' => null];
|
||||
$this->user->name = $settings['username'];
|
||||
if (!isset($settings['password'])) {
|
||||
throw new \Exception('User password is missing in ' . get_called_class());
|
||||
}
|
||||
$this->user->password = $settings['password'];
|
||||
$this->port = 25;
|
||||
if (isset($settings['secure']) and $settings['secure'] == 'ssl') {
|
||||
$this->is_secure = true;
|
||||
$this->port = 465;
|
||||
}
|
||||
if (isset($settings['port'])) {
|
||||
$this->port = $settings['port'];
|
||||
}
|
||||
}
|
||||
public function isSecure(): bool {
|
||||
return $this->is_secure;
|
||||
}
|
||||
public function send(Message $message): bool {
|
||||
$mailer = new BaseMailer();
|
||||
$mailer->isSMTP();
|
||||
//$mailer->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||
$mailer->Host = $this->host;
|
||||
$mailer->SMTPAuth = true;
|
||||
$mailer->Username = $this->user->name;
|
||||
$mailer->Password = $this->user->password;
|
||||
$mailer->Port = $this->port;
|
||||
if ($this->isSecure()) {
|
||||
$mailer->SMTPSecure = BaseMailer::ENCRYPTION_STARTTLS;
|
||||
}
|
||||
|
||||
try {
|
||||
$from = $message->getFrom();
|
||||
if ($from->name !== null) {
|
||||
$mailer->setFrom($from->email, $from->name);
|
||||
} else {
|
||||
$mailer->setFrom($from->email);
|
||||
}
|
||||
foreach ($message->getTo() as $to) {
|
||||
if ($to->name !== null) {
|
||||
$mailer->addAddress($to->email, $to->name);
|
||||
} else {
|
||||
$mailer->addAddress($to->email);
|
||||
}
|
||||
}
|
||||
$ccs = $message->getCc();
|
||||
if (!empty($ccs)) {
|
||||
foreach ($ccs as $cc) {
|
||||
if ($cc->name !== null) {
|
||||
$mailer->addCC($cc->email, $cc->name);
|
||||
} else {
|
||||
$mailer->addCC($cc->email);
|
||||
}
|
||||
}
|
||||
}
|
||||
$bccs = $message->getBcc();
|
||||
if (!empty($bccs)) {
|
||||
foreach ($bccs as $bcc) {
|
||||
if ($bcc->name !== null) {
|
||||
$mailer->addBCC($bcc->email, $bcc->name);
|
||||
} else {
|
||||
$mailer->addBCC($bcc->email);
|
||||
}
|
||||
}
|
||||
}
|
||||
$mailer->Subject = $message->getSubject();
|
||||
if ($message->isHtml()) {
|
||||
$mailer->Body = $message->getHtmlBody();
|
||||
$mailer->isHTML();
|
||||
$mailer->AltBody = $message->getBody();
|
||||
} else {
|
||||
$mailer->Body = $message->getBody();
|
||||
}
|
||||
|
||||
$mailer->send();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
100
common/Implementation/Message.php
Normal file
100
common/Implementation/Message.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Common\Implementation;
|
||||
|
||||
use ProVM\KI\Common\Alias\Message as MessageInterface;
|
||||
|
||||
class Message implements MessageInterface {
|
||||
protected $from;
|
||||
public function setFrom(string $email, string $name = null): Message {
|
||||
$this->from = $this->formatEmail($email, $name);
|
||||
return $this;
|
||||
}
|
||||
public function getFrom() {
|
||||
return $this->from;
|
||||
}
|
||||
protected $reply_to;
|
||||
public function addReplyTo(string $email, string $name = null): Message {
|
||||
if ($this->reply_to === null) {
|
||||
$this->reply_to = [];
|
||||
}
|
||||
$this->reply_to []= $this->formatEmail($email, $name);
|
||||
return $this;
|
||||
}
|
||||
public function getReplyTo() {
|
||||
return $this->reply_to;
|
||||
}
|
||||
protected $subject;
|
||||
public function setSubject(string $subject): Message {
|
||||
$this->subject = $subject;
|
||||
return $this;
|
||||
}
|
||||
public function getSubject(): string {
|
||||
return $this->subject;
|
||||
}
|
||||
protected $to;
|
||||
public function addTo(string $email, string $name = null): Message {
|
||||
if ($this->to === null) {
|
||||
$this->to = [];
|
||||
}
|
||||
$this->to []= $this->formatEmail($email, $name);
|
||||
return $this;
|
||||
}
|
||||
public function getTo(): array {
|
||||
return $this->to;
|
||||
}
|
||||
protected $cc;
|
||||
public function addCc(string $email, string $name = null): Message {
|
||||
if ($this->cc === null) {
|
||||
$this->cc = [];
|
||||
}
|
||||
$this->cc []= $this->formatEmail($email, $name);
|
||||
return $this;
|
||||
}
|
||||
public function getCc() {
|
||||
return $this->cc;
|
||||
}
|
||||
protected $bcc;
|
||||
public function addBcc(string $email, string $name = null): Message {
|
||||
if ($this->bcc === null) {
|
||||
$this->bcc = [];
|
||||
}
|
||||
$this->bcc []= $this->formatEmail($email, $name);
|
||||
return $this;
|
||||
}
|
||||
public function getBcc() {
|
||||
return $this->bcc;
|
||||
}
|
||||
protected $body;
|
||||
public function setBody(string $body): Message {
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
public function getBody(): string {
|
||||
return $this->body;
|
||||
}
|
||||
protected $html;
|
||||
protected $is_html = false;
|
||||
public function setHtmlBody(string $body): Message {
|
||||
$this->html = $body;
|
||||
$this->is_html = true;
|
||||
return $this;
|
||||
}
|
||||
public function getHtmlBody(): string {
|
||||
return $this->html;
|
||||
}
|
||||
public function isHtml(): bool {
|
||||
return $this->is_html;
|
||||
}
|
||||
|
||||
protected function formatEmail(string $email, string $name = null) {
|
||||
if (!$name && preg_match('#^(.+) +<(.*)>$#D', $email, $matches)) {
|
||||
[, $name, $email] = $matches;
|
||||
$name = stripslashes($name);
|
||||
$tmp = substr($name, 1, -1);
|
||||
if ($name === '"' . $tmp . '"') {
|
||||
$name = $tmp;
|
||||
}
|
||||
}
|
||||
return (object) ['name' => $name, 'email' => $email];
|
||||
}
|
||||
}
|
7
common/Implementation/View.php
Normal file
7
common/Implementation/View.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Common\Implementation;
|
||||
|
||||
use Slim\Views\Blade as BaseView;
|
||||
use ProVM\KI\Common\Alias\View as ViewInterface;
|
||||
|
||||
class View extends BaseView implements ViewInterface {}
|
@ -9,12 +9,12 @@
|
||||
"nyholm/psr7": "^1.2",
|
||||
"nyholm/psr7-server": "^0.4.1",
|
||||
"nesbot/carbon": "^2.32",
|
||||
"guzzlehttp/guzzle": "^6.5"
|
||||
"guzzlehttp/guzzle": "^6.5",
|
||||
"phpmailer/phpmailer": "^6.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.5",
|
||||
"kint-php/kint": "^3.3",
|
||||
"zeuxisoo/slim-whoops": "^0.7.2",
|
||||
"joshtronic/php-loremipsum": "^1.0"
|
||||
},
|
||||
"license": "UNLICENSED",
|
||||
|
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));
|
||||
}
|
||||
}
|
@ -2,3 +2,4 @@
|
||||
use ProVM\KI\Common\Controller\Web\Contacto;
|
||||
|
||||
$app->get('/contacto', Contacto::class);
|
||||
$app->post('/contacto', [Contacto::class, 'enviar']);
|
||||
|
@ -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'
|
||||
|
39
resources/views/contacto/email.php
Normal file
39
resources/views/contacto/email.php
Normal file
@ -0,0 +1,39 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Contacto Web - {{$nombre}}</title>
|
||||
<!--[if !mso]><!-- -->
|
||||
|
||||
<link href='http://fonts.googleapis.com/css2?family=Roboto' rel='stylesheet' type='text/css' />
|
||||
|
||||
<!--<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<table style="font-family: Roboto, sans-serif; font-size: 12pt; color: rgb(109, 110, 112);">
|
||||
<tr>
|
||||
<td style="font-weight: 700; text-align: right;">
|
||||
Nombre
|
||||
</td>
|
||||
<td colspan="6">
|
||||
{{$nombre}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-weight: 700; text-align: right;">
|
||||
Email
|
||||
</td>
|
||||
<td colspan="6">
|
||||
{{$mail}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-weight: 700; text-align: right; vertical-align: top;">
|
||||
Mensaje
|
||||
</td>
|
||||
<td colspan="6">
|
||||
{{$mensaje}}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
@ -14,7 +14,7 @@
|
||||
</div>
|
||||
<div class="content">
|
||||
<p>
|
||||
{{$faq->contenido}}
|
||||
{!!nl2br($faq->contenido)!!}
|
||||
</p>
|
||||
</div>
|
||||
@endforeach
|
||||
|
@ -27,6 +27,10 @@
|
||||
Enviar
|
||||
</button>
|
||||
</div>
|
||||
<div class="ui message transition hidden" id="mensaje_contacto">
|
||||
<i class="close icon"></i>
|
||||
<span id="msg"></span>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -65,3 +69,59 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
var contacto = {
|
||||
id: "contacto_form",
|
||||
data: {
|
||||
nombre: '',
|
||||
mail: '',
|
||||
mensaje: ''
|
||||
},
|
||||
output: {
|
||||
id: 'mensaje_contacto',
|
||||
success: 'Mensaje enviado.',
|
||||
},
|
||||
url: '{{$urls->base}}/contacto',
|
||||
getData: () => {
|
||||
var form = $(contacto.id)
|
||||
|
||||
contacto.data.nombre = form.find("[name='nombre']").val()
|
||||
contacto.data.mail = form.find("[name='mail']").val()
|
||||
contacto.data.mensaje = form.find("[name='mensaje']").val()
|
||||
},
|
||||
send: () => {
|
||||
$.post(contacto.url, contacto.data, (data) => {
|
||||
$(contacto.output.id).find('#msg').html(contacto.output.success)
|
||||
$(contacto.output.id).addClass('success').removeClass('hidden').show()
|
||||
$(contacto.output.id).find('.close').click(function() {
|
||||
$(contacto.output.id).find('#msg').html('')
|
||||
$(contacto.output.id).addClass('hidden').removeClass('success error')
|
||||
})
|
||||
}, 'json')
|
||||
},
|
||||
checkIds: () => {
|
||||
if (contacto.id.indexOf('#') < 0) {
|
||||
contacto.id = '#' + contacto.id
|
||||
}
|
||||
if (contacto.output.id.indexOf('#') < 0) {
|
||||
contacto.output.id = '#' + contacto.output.id
|
||||
}
|
||||
},
|
||||
setup: () => {
|
||||
contacto.checkIds()
|
||||
$(contacto.id).submit((e) => {
|
||||
e.preventDefault()
|
||||
|
||||
contacto.getData()
|
||||
contacto.send()
|
||||
return false
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
contacto.setup()
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -26,14 +26,6 @@
|
||||
 
|
||||
{{$header->hora}}
|
||||
</div>
|
||||
<div class="right menu">
|
||||
<div class="item">
|
||||
<div class="ui icon input">
|
||||
<input type="text" placeholder="Buscar" name="search" id="search" />
|
||||
<i class="search link icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -40,6 +40,7 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
$('#thumbnails .image').css('cursor', 'pointer')
|
||||
})
|
||||
$('#galeria').find('.grid .image').click(function(e) {
|
||||
var id = $(this).attr('data-id')
|
||||
@ -57,6 +58,7 @@
|
||||
var id = $(this).attr('data-id')
|
||||
galeria.changeImage(id)
|
||||
})
|
||||
$('#thumbnails .image').css('cursor', 'pointer')
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
|
@ -9,7 +9,6 @@ class Bodega extends Producto {
|
||||
'tamaño',
|
||||
'oficina',
|
||||
'superficie',
|
||||
'arriendo',
|
||||
'uf_m2'
|
||||
];
|
||||
|
||||
@ -34,7 +33,7 @@ class Bodega extends Producto {
|
||||
],
|
||||
[
|
||||
'label' => 'Valor Arriendo',
|
||||
'name' => 'arriendo',
|
||||
'name' => 'valor',
|
||||
'suffix' => ' UF'
|
||||
],
|
||||
[
|
||||
|
@ -10,26 +10,16 @@ class Oficina extends Producto {
|
||||
'm2',
|
||||
'baños',
|
||||
'privados',
|
||||
'gastos',
|
||||
'plazo',
|
||||
'uf_m2'
|
||||
];
|
||||
|
||||
/*public function uf_m2() {
|
||||
return $this->valor / ($this->m2 ?? 1);
|
||||
}*/
|
||||
public function privados() {
|
||||
if ($this->privados == 0) {
|
||||
return 'planta libre';
|
||||
}
|
||||
return 'privados ' . $this->privados;
|
||||
}
|
||||
public function map($data): Model {
|
||||
parent::map($data);
|
||||
if (strpos($this->gastos, '.') === false and $data->gastos != '') {
|
||||
$this->gastos = number_format($data->gastos, 0, ',', '.');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function getProperties(): array {
|
||||
$properties = parent::getProperties();
|
||||
foreach ($properties as &$property) {
|
||||
@ -70,9 +60,8 @@ class Oficina extends Producto {
|
||||
public function getShow() {
|
||||
$data = $this->getFicha();
|
||||
$data []= (object) [
|
||||
'label' => 'Gastos Comunes',
|
||||
'name' => 'gastos',
|
||||
'prefix' => '$'
|
||||
'label' => 'Plazo de Contrato',
|
||||
'name' => 'plazo'
|
||||
];
|
||||
$data []= (object) [
|
||||
'label' => 'UF/m²',
|
||||
|
Reference in New Issue
Block a user