Compare commits
20 Commits
master
...
5967a6c931
Author | SHA1 | Date | |
---|---|---|---|
5967a6c931 | |||
429e4187fb | |||
a527cc032d | |||
4220efce1c | |||
25cfefb73c | |||
09e6e537b6 | |||
5c384fddd5 | |||
a2ce28e8c7 | |||
50af0d7e9b | |||
b943a21890 | |||
c09165529f | |||
e64c01edb7 | |||
796115fb9a | |||
3f13358761 | |||
10343cbc88 | |||
2a34fa368e | |||
a878d6bc77 | |||
dad50537b2 | |||
a1311ee250 | |||
692c001cd5 |
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
.ENV
|
||||
/public/assets/images/eventos/*/
|
||||
|
||||
# Composer
|
||||
/vendor/
|
||||
|
51
bootstrap/app.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
use DI\ContainerBuilder as Builder;
|
||||
use DI\Bridge\Slim\Bridge;
|
||||
|
||||
include_once 'composer.php';
|
||||
include_once 'dotenv.php';
|
||||
|
||||
$builder = new Builder();
|
||||
$folders = ['common'];
|
||||
if (isset($__environment)) {
|
||||
$folders []= $__environment;
|
||||
}
|
||||
|
||||
$files = [
|
||||
'config',
|
||||
'setup'
|
||||
];
|
||||
foreach ($folders as $folder) {
|
||||
foreach ($files as $file) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
$folder,
|
||||
$file . '.php'
|
||||
]);
|
||||
if (file_exists($filename)) {
|
||||
$builder->addDefinitions($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$container = $builder->build();
|
||||
$app = Bridge::create($container);
|
||||
$app->setBasePath($container->get('urls.base'));
|
||||
$app->addRoutingMiddleware();
|
||||
$app->addErrorMiddleware(true, true, true);
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
$folder,
|
||||
'middleware.php'
|
||||
]);
|
||||
if (file_exists($filename)) {
|
||||
include_once $filename;
|
||||
}
|
||||
}
|
||||
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
$container->get('folders.routes'),
|
||||
'router.php'
|
||||
]);
|
19
bootstrap/common/config.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
return [
|
||||
'urls.base' => getenv('BASE_URL'),
|
||||
'folders.base' => dirname(__DIR__, 2),
|
||||
'folders.resources' => DI\string(implode(DIRECTORY_SEPARATOR, [
|
||||
'{folders.base}',
|
||||
'resources'
|
||||
])),
|
||||
'folders.routes' => DI\string(implode(DIRECTORY_SEPARATOR, [
|
||||
'{folders.resources}',
|
||||
'routes'
|
||||
])),
|
||||
'folders.images' => DI\string(implode(DIRECTORY_SEPARATOR, [
|
||||
'{folders.base}',
|
||||
'public',
|
||||
'assets',
|
||||
'images'
|
||||
]))
|
||||
];
|
8
bootstrap/common/setup.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
ProVM\TotalSport\Common\Service\DataHandler::class => function(Container $c) {
|
||||
return new ProVM\TotalSport\Common\Service\DataHandler($c->get('folders.data'));
|
||||
}
|
||||
];
|
6
bootstrap/composer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
3
bootstrap/dotenv.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
|
||||
$dotenv->load();
|
83
bootstrap/web/config.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
return [
|
||||
'folders.cache' => DI\string(implode(DIRECTORY_SEPARATOR, [
|
||||
'{folders.resources}',
|
||||
'cache'
|
||||
])),
|
||||
'folders.templates' => DI\string(implode(DIRECTORY_SEPARATOR, [
|
||||
'{folders.resources}',
|
||||
'views'
|
||||
])),
|
||||
'folders.data' => DI\string(implode(DIRECTORY_SEPARATOR, [
|
||||
'{folders.resources}',
|
||||
'data'
|
||||
])),
|
||||
'urls' => [
|
||||
'base' => DI\string('{urls.base}'),
|
||||
'assets' => DI\string(implode('/', [
|
||||
'{urls.base}',
|
||||
'assets'
|
||||
])),
|
||||
'styles' => DI\string(implode('/', [
|
||||
'{urls.base}',
|
||||
'assets',
|
||||
'styles'
|
||||
])),
|
||||
'scripts' => DI\string(implode('/', [
|
||||
'{urls.base}',
|
||||
'assets',
|
||||
'scripts'
|
||||
])),
|
||||
'images' => DI\string(implode('/', [
|
||||
'{urls.base}',
|
||||
'assets',
|
||||
'images'
|
||||
])),
|
||||
'servicios' => DI\string(implode('/', [
|
||||
'{urls.base}',
|
||||
'servicios'
|
||||
])),
|
||||
'eventos' => DI\string(implode('/', [
|
||||
'{urls.base}',
|
||||
'eventos'
|
||||
])),
|
||||
'admin' => DI\string(implode('/', [
|
||||
'{urls.base}',
|
||||
'admin'
|
||||
])),
|
||||
'map' => 'https://maps.google.com/maps?hl=es&q=Avenida%20Nueva%20Providencia%201945,%20Providencia&ie=UTF8&z=16&iwloc=B&output=embed'
|
||||
],
|
||||
'assets' => [
|
||||
'styles' => [
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/semantic.min.css',
|
||||
DI\string(implode('/', [
|
||||
'{urls.base}',
|
||||
'assets',
|
||||
'styles',
|
||||
'main.css'
|
||||
])),
|
||||
DI\string(implode('/', [
|
||||
'{urls.base}',
|
||||
'assets',
|
||||
'styles',
|
||||
'header.css'
|
||||
]))
|
||||
],
|
||||
'scripts' => [
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/semantic.min.js'
|
||||
],
|
||||
'fonts' => (object) [
|
||||
'text/css' => [
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/brand-icons.woff',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/brand-icons.woff2',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/icons.woff',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/icons.woff2',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/outline-icons.woff',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/outline-icons.woff2',
|
||||
'https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;900&display=swap',
|
||||
'https://fonts.googleapis.com/css2?family=Raleway:wght@800&display=swap'
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
31
bootstrap/web/setup.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
ProVM\TotalSport\Common\Service\ImageLoader::class => function(Container $c) {
|
||||
return new ProVM\TotalSport\Common\Service\ImageLoader($c->get('folders.images'), $c->get('urls')['images']);
|
||||
},
|
||||
Slim\Views\Blade::class => function(Container $c) {
|
||||
return new Slim\Views\Blade(
|
||||
$c->get('folders.templates'),
|
||||
$c->get('folders.cache'),
|
||||
null,
|
||||
[
|
||||
'urls' => (object) $c->get('urls'),
|
||||
'assets' => (object) $c->get('assets')
|
||||
]
|
||||
);
|
||||
},
|
||||
ProVM\TotalSport\Common\Service\MediaLoader::class => function(Container $c) {
|
||||
$obj = new ProVM\TotalSport\Common\Service\MediaLoader($c->get('folders.images'), $c->get('urls')['images']);
|
||||
$obj->setFFMpeg($c->get(FFMpeg\FFMpeg::class));
|
||||
return $obj;
|
||||
},
|
||||
FFMpeg\FFMpeg::class => function(Container $c) {
|
||||
$obj = null;
|
||||
try {
|
||||
$obj = FFMpeg\FFMpeg::create();
|
||||
} catch (\Exception $e) {}
|
||||
return $obj;
|
||||
}
|
||||
];
|
126
common/Controller/Web/Admin/Eventos.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
namespace ProVM\TotalSport\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\TotalSport\Common\Service\DataHandler;
|
||||
use ProVM\TotalSport\Common\Service\MediaLoader;
|
||||
|
||||
class Eventos {
|
||||
public function __invoke(Request $request, Response $response, View $view, DataHandler $handler): Response {
|
||||
$eventos = $handler->load('eventos');
|
||||
return $view->render($response, 'admin.eventos', compact('eventos'));
|
||||
}
|
||||
public function show(Request $request, Response $response, View $view, DataHandler $handler, MediaLoader $loader, $evento): Response {
|
||||
$eventos = $handler->load('eventos');
|
||||
$e = $eventos[$evento];
|
||||
$e->id = $evento;
|
||||
$imagenes = $loader->load($e);
|
||||
$servicios = $handler->load('servicios');
|
||||
return $view->render($response, 'admin.eventos.show', ['evento' => $e, 'imagenes' => $imagenes, 'servicios' => $servicios]);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Container $container, DataHandler $handler, $evento): Response {
|
||||
$eventos = $handler->load('eventos');
|
||||
$e = $eventos[$evento];
|
||||
$post = $request->getParsedBody();
|
||||
$servicios = $handler->load('servicios');
|
||||
$fields = ['titulo', 'empresa', 'servicio', 'descripcion'];
|
||||
$changed = false;
|
||||
foreach ($fields as $field) {
|
||||
if ($post[$field] != $e->{$field}) {
|
||||
$e->{$field} = $post[$field];
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
if ($changed) {
|
||||
$eventos[$evento] = $e;
|
||||
$handler->save('eventos', $eventos);
|
||||
}
|
||||
return $response->withHeader('Location', implode('/', [
|
||||
$container->get('urls')['admin'],
|
||||
'eventos'
|
||||
]));
|
||||
}
|
||||
public function add(Request $request, Response $response, View $view, DataHandler $handler): Response {
|
||||
$servicios = $handler->load('servicios');
|
||||
return $view->render($response, 'admin.eventos.add', compact('servicios'));
|
||||
}
|
||||
public function do_add(Request $request, Response $response, Container $container, DataHandler $handler): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$eventos = $handler->load('eventos');
|
||||
$evento = [
|
||||
'titulo' => $post['titulo'],
|
||||
'empresa' => $post['empresa'],
|
||||
'servicio' => $post['servicio'],
|
||||
'descripcion' => $post['descripcion']
|
||||
];
|
||||
$eventos []= $evento;
|
||||
$status = $handler->save('eventos', $eventos);
|
||||
return $response->withHeader('Location', implode('/', [
|
||||
$container->get('urls')['admin'],
|
||||
'eventos'
|
||||
]));
|
||||
}
|
||||
public function delete(Request $request, Response $response, Container $container, DataHandler $handler, MediaLoader $loader, $evento): Response {
|
||||
$eventos = $handler->load('eventos');
|
||||
unset($eventos[$evento]);
|
||||
$eventos = array_values($eventos);
|
||||
$handler->save('eventos', $eventos);
|
||||
return $response->withHeader('Location', implode('/', [
|
||||
$container->get('urls')['admin'],
|
||||
'eventos'
|
||||
]));
|
||||
}
|
||||
public function addImage(Request $request, Response $response, DataHandler $handler, MediaLoader $loader, $evento): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$files = $request->getUploadedFiles();
|
||||
if (count($files) == 0) {
|
||||
$output = [
|
||||
'informacion' => '',
|
||||
'evento' => $evento,
|
||||
'estado' => false
|
||||
];
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->withStatus(201);
|
||||
}
|
||||
$file = $files['imagen'];
|
||||
$eventos = $handler->load('eventos');
|
||||
$e = $eventos[$evento];
|
||||
if (is_array($file)) {
|
||||
$status = false;
|
||||
foreach ($file as $f) {
|
||||
$status |= $loader->add($e, $f);
|
||||
}
|
||||
} else {
|
||||
$status = $loader->add($e, $file);
|
||||
}
|
||||
$output = [
|
||||
'informacion' => $file,
|
||||
'evento' => $e,
|
||||
'estado' => $status
|
||||
];
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->withStatus(201);
|
||||
}
|
||||
public function deleteImage(Request $request, Response $response, DataHandler $handler, MediaLoader $loader, $evento): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$eventos = $handler->load('eventos');
|
||||
$e = $eventos[$evento];
|
||||
$status = $loader->delete($e, $post['media']);
|
||||
$output = [
|
||||
'informacion' => $post,
|
||||
'evento' => $e,
|
||||
'estado' => !$status
|
||||
];
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->withStatus(201);
|
||||
}
|
||||
}
|
18
common/Controller/Web/Eventos.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace ProVM\TotalSport\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\TotalSport\Common\Service\DataHandler;
|
||||
use ProVM\TotalSport\Common\Service\MediaLoader;
|
||||
|
||||
class Eventos {
|
||||
public function __invoke(Request $request, Response $response, View $view, DataHandler $handler, MediaLoader $loader, $evento): Response {
|
||||
$eventos = $handler->load('eventos');
|
||||
$e = $eventos[$evento];
|
||||
$imagenes = $loader->load($e);
|
||||
return $view->render($response, 'evento', ['evento' => $e, 'imagenes' => $imagenes]);
|
||||
}
|
||||
}
|
44
common/Controller/Web/Home.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace ProVM\TotalSport\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\TotalSport\Common\Service\DataHandler;
|
||||
use ProVM\TotalSport\Common\Service\MediaLoader;
|
||||
|
||||
class Home {
|
||||
public function __invoke(Request $request, Response $response, Container $container, View $view, DataHandler $handler, MediaLoader $loader): Response {
|
||||
$banner = (object) [
|
||||
'title' => 'BUSCAMOS LA MEJOR EXPERIENCA',
|
||||
'contenido' => 'Eventos hechos a tu medida'
|
||||
];
|
||||
$servicios = $handler->load('servicios');
|
||||
$frase = (object) [
|
||||
'titulo' => 'Lorem ipsum dolor sit amet, consectetur adipiscing',
|
||||
'contenido' => 'elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation'
|
||||
];
|
||||
$clientes = [];
|
||||
for ($i = 0; $i < 20; $i ++) {
|
||||
$clientes[$i] = '<div class="ui image"><img src="' . $container->get('urls')['images'] . '/clientes/logo_' . str_pad($i + 1, 2, '0', \STR_PAD_LEFT) . '.jpg" /></div>';
|
||||
}
|
||||
|
||||
$testimonios = $handler->load('testimonios');
|
||||
$eventos = $handler->load('eventos');
|
||||
foreach ($eventos as &$evento) {
|
||||
if (!isset($evento->imagen)) {
|
||||
$evento->imagen = '<img src="#" alt="Imagen no encontrada" title="Imagen no encontrada" />';
|
||||
$imagenes = $loader->load($evento);
|
||||
if ($imagenes !== false) {
|
||||
$evento->imagen = array_values($imagenes)[0]->thumb->html;
|
||||
}
|
||||
}
|
||||
if (!isset($evento->servicio)) {
|
||||
$evento->servicio = mt_rand(0, count($servicios) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return $view->render($response, 'home', compact('banner', 'servicios', 'frase', 'clientes', 'testimonios', 'eventos'));
|
||||
}
|
||||
}
|
25
common/Service/DataHandler.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace ProVM\TotalSport\Common\Service;
|
||||
|
||||
use Spyc;
|
||||
|
||||
class DataHandler {
|
||||
protected $folder;
|
||||
public function __construct(string $data_folder) {
|
||||
$this->folder = $data_folder;
|
||||
}
|
||||
public function load(string $file_name) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
$file_name . '.yml'
|
||||
]);
|
||||
return json_decode(json_encode(Spyc::YAMLLoad($filename)));
|
||||
}
|
||||
public function save(string $file_name, $data) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
$file_name . '.yml'
|
||||
]);
|
||||
return (file_put_contents($filename, Spyc::YAMLDump($data)) !== false);
|
||||
}
|
||||
}
|
84
common/Service/ImageLoader.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
namespace ProVM\TotalSport\Common\Service;
|
||||
|
||||
use function Stringy\create as s;
|
||||
|
||||
class ImageLoader {
|
||||
protected $folder;
|
||||
protected $assets_folder;
|
||||
public function __construct(string $images_folder, string $images_assets_folder) {
|
||||
$this->folder = $images_folder;
|
||||
$this->assets_folder = $images_assets_folder;
|
||||
}
|
||||
protected function getFolder($event) {
|
||||
return implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
'eventos',
|
||||
s($event->servicio)->removeLeft('Eventos '),
|
||||
rtrim(implode(', ', [
|
||||
$event->titulo,
|
||||
$event->empresa
|
||||
]), ', ')
|
||||
]);
|
||||
}
|
||||
public function load($event) {
|
||||
$folder = $this->getFolder($event);
|
||||
if (!file_exists($folder)) {
|
||||
return false;
|
||||
}
|
||||
$files = new \DirectoryIterator($folder);
|
||||
$images = [];
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$name = $file->getBasename('.' . $file->getExtension());
|
||||
$org = false;
|
||||
$thumb = false;
|
||||
if (strpos($name, '_') !== false) {
|
||||
$name = explode('_', $name)[0];
|
||||
if (strpos($name, '_org') !== false) {
|
||||
$org = true;
|
||||
}
|
||||
if (strpos($name, '_thumb') !== false) {
|
||||
$thumb = true;
|
||||
}
|
||||
}
|
||||
$images []= implode('/', [
|
||||
$this->assets_folder,
|
||||
'eventos',
|
||||
s($event->servicio)->removeLeft('Eventos '),
|
||||
rtrim(implode(', ', [
|
||||
$event->titulo,
|
||||
$event->empresa
|
||||
]), ', '),
|
||||
$file->getFilename()
|
||||
]);
|
||||
}
|
||||
return $images;
|
||||
}
|
||||
public function add($event, $file) {
|
||||
$folder = $this->getFolder($event);
|
||||
if (!file_exists($folder)) {
|
||||
mkdir($folder);
|
||||
chmod($folder, 777);
|
||||
}
|
||||
$images = $this->load($event);
|
||||
$base_name = '01';
|
||||
if ($images !== false and count($images) > 0) {
|
||||
$base_name = str_pad(count($images), 2, '0', \STR_PAD_LEFT);
|
||||
}
|
||||
$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
implode('.', [
|
||||
implode('_', [
|
||||
$base_name,
|
||||
'org'
|
||||
]),
|
||||
$extension
|
||||
])
|
||||
]);
|
||||
$file->moveTo($filename);
|
||||
}
|
||||
}
|
314
common/Service/MediaLoader.php
Normal file
@ -0,0 +1,314 @@
|
||||
<?php
|
||||
namespace ProVM\TotalSport\Common\Service;
|
||||
|
||||
use function Stringy\create as s;
|
||||
use FFMpeg\FFMpeg;
|
||||
|
||||
class MediaLoader {
|
||||
protected $folder;
|
||||
protected $media_url;
|
||||
public function __construct(string $media_folder, string $media_assets_url) {
|
||||
$this->folder = $media_folder;
|
||||
$this->media_url = $media_assets_url;
|
||||
}
|
||||
protected $ffmpeg;
|
||||
public function setFFMpeg(FFMpeg $ffmpeg) {
|
||||
$this->ffmpeg = $ffmpeg;
|
||||
}
|
||||
protected function getFolder($event) {
|
||||
return implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
'eventos',
|
||||
s($event->servicio)->removeLeft('Eventos '),
|
||||
rtrim(implode(', ', [
|
||||
$event->titulo,
|
||||
$event->empresa
|
||||
]), ', ')
|
||||
]);
|
||||
}
|
||||
protected function buildHtml($file, $filename) {
|
||||
switch ($file->getExtension()) {
|
||||
default:
|
||||
return implode('', [
|
||||
'<img src="',
|
||||
$filename,
|
||||
'" class="media" />'
|
||||
]);
|
||||
case 'mkv':
|
||||
case 'mp4':
|
||||
case 'mov':
|
||||
case 'avi':
|
||||
case 'ogg':
|
||||
case 'webm':
|
||||
return implode(PHP_EOL, [
|
||||
'<video class="media" controls="controls">',
|
||||
implode('', [
|
||||
'<source src="',
|
||||
$filename,
|
||||
'" type="video/',
|
||||
$file->getExtension(),
|
||||
'" />'
|
||||
]),
|
||||
'No se soporta el elemento de video para HTML5 en este navegador.',
|
||||
'</video>'
|
||||
]);
|
||||
}
|
||||
}
|
||||
public function load($event) {
|
||||
$folder = $this->getFolder($event);
|
||||
if (!file_exists($folder)) {
|
||||
return false;
|
||||
}
|
||||
$files = new \DirectoryIterator($folder);
|
||||
$medias = [];
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$name = $file->getBasename('.' . $file->getExtension());
|
||||
$type = 'media';
|
||||
if (strpos($name, '_') !== false) {
|
||||
if (strpos($name, '_org') !== false) {
|
||||
$type = 'original';
|
||||
}
|
||||
if (strpos($name, '_thumb') !== false) {
|
||||
$type = 'thumb';
|
||||
}
|
||||
$name = explode('_', $name)[0];
|
||||
}
|
||||
$filename = implode('/', [
|
||||
$this->media_url,
|
||||
'eventos',
|
||||
s($event->servicio)->removeLeft('Eventos '),
|
||||
($event->empresa != '') ?
|
||||
rtrim(implode(', ', [
|
||||
$event->titulo,
|
||||
$event->empresa
|
||||
]), ', ') :
|
||||
$event->titulo,
|
||||
$file->getFilename()
|
||||
]);
|
||||
$obj = (object) [
|
||||
'n' => $name,
|
||||
'filename' => $filename,
|
||||
'type' => $type,
|
||||
'html' => $this->buildHtml($file, $filename)
|
||||
];
|
||||
if (!isset($medias[$name])) {
|
||||
$medias[$name] = (object) [
|
||||
'media' => null,
|
||||
'thumb' => null,
|
||||
'original' => null
|
||||
];
|
||||
}
|
||||
$medias[$name]->{$type} = $obj;
|
||||
}
|
||||
array_walk($medias, function(&$item) {
|
||||
if ($item->thumb === null) {
|
||||
$item->thumb = $item->media;
|
||||
}
|
||||
});
|
||||
sort($medias);
|
||||
return $medias;
|
||||
}
|
||||
public function add($event, $file) {
|
||||
$folder = $this->getFolder($event);
|
||||
if (!file_exists($folder)) {
|
||||
mkdir($folder);
|
||||
chmod($folder, 0777);
|
||||
}
|
||||
$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
|
||||
switch ($extension) {
|
||||
default:
|
||||
return $this->addImage($event, $file);
|
||||
case 'mkv':
|
||||
case 'mp4':
|
||||
case 'mov':
|
||||
case 'avi':
|
||||
case 'ogg':
|
||||
case 'webm':
|
||||
return $this->addVideo($event, $file);
|
||||
}
|
||||
}
|
||||
public function addImage($event, $file) {
|
||||
$folder = $this->getFolder($event);
|
||||
$medias = $this->load($event);
|
||||
$base_name = '01';
|
||||
if ($medias !== false and count($medias) > 0) {
|
||||
$base_name = str_pad(count($medias) + 1, 2, '0', \STR_PAD_LEFT);
|
||||
}
|
||||
$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
implode('.', [
|
||||
implode('_', [
|
||||
$base_name,
|
||||
'org'
|
||||
]),
|
||||
$extension
|
||||
])
|
||||
]);
|
||||
$file->moveTo($filename);
|
||||
|
||||
try {
|
||||
gd_info();
|
||||
} catch(\Exception $e) {
|
||||
return file_exists($filename);
|
||||
}
|
||||
$thumb = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
implode('.', [
|
||||
implode('_', [
|
||||
$base_name,
|
||||
'thumb'
|
||||
]),
|
||||
'jpg'
|
||||
])
|
||||
]);
|
||||
$this->copyResize($filename, $thumb, 50, 300);
|
||||
$media = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
implode('.', [
|
||||
$base_name,
|
||||
'jpg'
|
||||
])
|
||||
]);
|
||||
$this->copyResize($filename, $media, 75, 1024);
|
||||
|
||||
return file_exists($filename);
|
||||
}
|
||||
protected function resize_image($source, $w, $h, $crop = FALSE) {
|
||||
list($width, $height) = getimagesize($source);
|
||||
$r = $width / $height;
|
||||
if ($crop) {
|
||||
if ($width > $height) {
|
||||
$width = ceil($width-($width*abs($r-$w/$h)));
|
||||
} else {
|
||||
$height = ceil($height-($height*abs($r-$w/$h)));
|
||||
}
|
||||
$newwidth = $w;
|
||||
$newheight = $h;
|
||||
} else {
|
||||
if ($w/$h > $r) {
|
||||
$newwidth = $h*$r;
|
||||
$newheight = $h;
|
||||
} else {
|
||||
$newheight = $w/$r;
|
||||
$newwidth = $w;
|
||||
}
|
||||
}
|
||||
$src = imagecreatefromjpeg($file);
|
||||
$dst = imagecreatetruecolor($newwidth, $newheight);
|
||||
imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
|
||||
|
||||
return $dst;
|
||||
}
|
||||
protected function copyResize($source, $destination, $quality, $w, $h = 0, $crop = false) {
|
||||
$info = getimagesize($source);
|
||||
if ($info['mime'] == 'image/jpeg') {
|
||||
$image = imagecreatefromjpeg($source);
|
||||
} elseif ($info['mime'] == 'image/gif') {
|
||||
$image = imagecreatefromgif($source);
|
||||
} elseif ($info['mime'] == 'image/png') {
|
||||
$image = imagecreatefrompng($source);
|
||||
}
|
||||
|
||||
list($width, $height) = getimagesize($source);
|
||||
$r = $width / $height;
|
||||
if ($h == 0) {
|
||||
$h = $w * $r;
|
||||
}
|
||||
if ($crop) {
|
||||
if ($width > $height) {
|
||||
$width = ceil($width-($width*abs($r-$w/$h)));
|
||||
} else {
|
||||
$height = ceil($height-($height*abs($r-$w/$h)));
|
||||
}
|
||||
$newwidth = $w;
|
||||
$newheight = $h;
|
||||
} else {
|
||||
if ($w/$h > $r) {
|
||||
$newwidth = $h*$r;
|
||||
$newheight = $h;
|
||||
} else {
|
||||
$newheight = $w/$r;
|
||||
$newwidth = $w;
|
||||
}
|
||||
}
|
||||
$dst = imagecreatetruecolor($newwidth, $newheight);
|
||||
imagecopyresampled($dst, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
|
||||
imagejpeg($dst, $destination, $quality);
|
||||
}
|
||||
public function addVideo($event, $file) {
|
||||
$folder = $this->getFolder($event);
|
||||
$medias = $this->load($event);
|
||||
$base_name = '01';
|
||||
if ($medias !== false and count($medias) > 0) {
|
||||
$base_name = str_pad(count($medias) + 1, 2, '0', \STR_PAD_LEFT);
|
||||
}
|
||||
$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
implode('.', [
|
||||
implode('_', [
|
||||
$base_name,
|
||||
'org'
|
||||
]),
|
||||
$extension
|
||||
])
|
||||
]);
|
||||
$file->moveTo($filename);
|
||||
|
||||
if ($this->ffmpeg === null) {
|
||||
return file_exists($filename);
|
||||
}
|
||||
|
||||
$thumb = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
implode('.', [
|
||||
implode('_', [
|
||||
$base_name,
|
||||
'thumb'
|
||||
]),
|
||||
'jpg'
|
||||
])
|
||||
]);
|
||||
|
||||
$video
|
||||
->filters()
|
||||
->resize(new FFMpeg\Coordinate\Dimension(320, 240))
|
||||
->synchronize();
|
||||
$video
|
||||
->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(1))
|
||||
->save($thumb);
|
||||
$media = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
implode('.', [
|
||||
$base_name,
|
||||
$extension
|
||||
])
|
||||
]);
|
||||
$video
|
||||
->save(new FFMpeg\Format\Video\X264(), $media);
|
||||
return file_exists($filename);
|
||||
}
|
||||
public function delete($event, $filename) {
|
||||
$folder = $this->getFolder($event);
|
||||
$media = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
$filename . '*.*'
|
||||
]);
|
||||
$files = glob($media);
|
||||
foreach ($files as $filename) {
|
||||
unlink($filename);
|
||||
}
|
||||
if (count(scandir($folder)) <= 2) {
|
||||
rmdir($folder);
|
||||
}
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
$filename . '.jpg'
|
||||
]);
|
||||
return file_exists($filename);
|
||||
}
|
||||
}
|
33
composer.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "provm/totalsport",
|
||||
"description": "Web para Total Sport",
|
||||
"type": "project",
|
||||
"license": "UNLICENSED",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Aldarien",
|
||||
"email": "aldarien85@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"slim/slim": "^4.4",
|
||||
"php-di/slim-bridge": "^3.0",
|
||||
"nyholm/psr7": "^1.2",
|
||||
"nyholm/psr7-server": "^0.4.1",
|
||||
"rubellum/slim-blade-view": "^0.1.1",
|
||||
"mustangostang/spyc": "^0.6.3",
|
||||
"voku/stringy": "^6.2",
|
||||
"vlucas/phpdotenv": "^4.1",
|
||||
"php-ffmpeg/php-ffmpeg": "^0.16.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.5",
|
||||
"kint-php/kint": "^3.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"ProVM\\TotalSport\\Common\\": "common",
|
||||
"ProVM\\TotalSport\\": "src"
|
||||
}
|
||||
}
|
||||
}
|
4
public/.htaccess
Normal file
@ -0,0 +1,4 @@
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^ index.php [QSA,L]
|
BIN
public/assets/images/banner.JPG
Normal file
After Width: | Height: | Size: 10 MiB |
BIN
public/assets/images/clientes/logo_01.jpg
Normal file
After Width: | Height: | Size: 585 KiB |
BIN
public/assets/images/clientes/logo_02.jpg
Normal file
After Width: | Height: | Size: 578 KiB |
BIN
public/assets/images/clientes/logo_03.jpg
Normal file
After Width: | Height: | Size: 588 KiB |
BIN
public/assets/images/clientes/logo_04.jpg
Normal file
After Width: | Height: | Size: 581 KiB |
BIN
public/assets/images/clientes/logo_05.jpg
Normal file
After Width: | Height: | Size: 578 KiB |
BIN
public/assets/images/clientes/logo_06.jpg
Normal file
After Width: | Height: | Size: 580 KiB |
BIN
public/assets/images/clientes/logo_07.jpg
Normal file
After Width: | Height: | Size: 603 KiB |
BIN
public/assets/images/clientes/logo_08.jpg
Normal file
After Width: | Height: | Size: 580 KiB |
BIN
public/assets/images/clientes/logo_09.jpg
Normal file
After Width: | Height: | Size: 577 KiB |
BIN
public/assets/images/clientes/logo_10.jpg
Normal file
After Width: | Height: | Size: 572 KiB |
BIN
public/assets/images/clientes/logo_11.jpg
Normal file
After Width: | Height: | Size: 581 KiB |
BIN
public/assets/images/clientes/logo_12.jpg
Normal file
After Width: | Height: | Size: 592 KiB |
BIN
public/assets/images/clientes/logo_13.jpg
Normal file
After Width: | Height: | Size: 580 KiB |
BIN
public/assets/images/clientes/logo_14.jpg
Normal file
After Width: | Height: | Size: 576 KiB |
BIN
public/assets/images/clientes/logo_15.jpg
Normal file
After Width: | Height: | Size: 587 KiB |
BIN
public/assets/images/equipo.JPG
Normal file
After Width: | Height: | Size: 310 KiB |
After Width: | Height: | Size: 278 KiB |
After Width: | Height: | Size: 290 KiB |
After Width: | Height: | Size: 219 KiB |
After Width: | Height: | Size: 270 KiB |
After Width: | Height: | Size: 293 KiB |
After Width: | Height: | Size: 325 KiB |
After Width: | Height: | Size: 304 KiB |
After Width: | Height: | Size: 331 KiB |
After Width: | Height: | Size: 316 KiB |
After Width: | Height: | Size: 270 KiB |
After Width: | Height: | Size: 359 KiB |
After Width: | Height: | Size: 276 KiB |
After Width: | Height: | Size: 377 KiB |
After Width: | Height: | Size: 382 KiB |
After Width: | Height: | Size: 385 KiB |
After Width: | Height: | Size: 368 KiB |
After Width: | Height: | Size: 365 KiB |
After Width: | Height: | Size: 373 KiB |
After Width: | Height: | Size: 228 KiB |
After Width: | Height: | Size: 242 KiB |
After Width: | Height: | Size: 252 KiB |
After Width: | Height: | Size: 219 KiB |
After Width: | Height: | Size: 271 KiB |
After Width: | Height: | Size: 224 KiB |
After Width: | Height: | Size: 229 KiB |
After Width: | Height: | Size: 237 KiB |
After Width: | Height: | Size: 224 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 246 KiB |
After Width: | Height: | Size: 200 KiB |
After Width: | Height: | Size: 284 KiB |
After Width: | Height: | Size: 178 KiB |
After Width: | Height: | Size: 188 KiB |
After Width: | Height: | Size: 239 KiB |
After Width: | Height: | Size: 236 KiB |
After Width: | Height: | Size: 159 KiB |
After Width: | Height: | Size: 220 KiB |
After Width: | Height: | Size: 202 KiB |
After Width: | Height: | Size: 225 KiB |
After Width: | Height: | Size: 233 KiB |
After Width: | Height: | Size: 185 KiB |
After Width: | Height: | Size: 234 KiB |
After Width: | Height: | Size: 231 KiB |
After Width: | Height: | Size: 157 KiB |
After Width: | Height: | Size: 192 KiB |
After Width: | Height: | Size: 138 KiB |
After Width: | Height: | Size: 163 KiB |
After Width: | Height: | Size: 199 KiB |
After Width: | Height: | Size: 179 KiB |
After Width: | Height: | Size: 187 KiB |
After Width: | Height: | Size: 182 KiB |
After Width: | Height: | Size: 184 KiB |
After Width: | Height: | Size: 176 KiB |
After Width: | Height: | Size: 176 KiB |
After Width: | Height: | Size: 366 KiB |
After Width: | Height: | Size: 341 KiB |
After Width: | Height: | Size: 309 KiB |
After Width: | Height: | Size: 390 KiB |
After Width: | Height: | Size: 311 KiB |
After Width: | Height: | Size: 256 KiB |
After Width: | Height: | Size: 306 KiB |
After Width: | Height: | Size: 378 KiB |
After Width: | Height: | Size: 345 KiB |
After Width: | Height: | Size: 358 KiB |
After Width: | Height: | Size: 345 KiB |
After Width: | Height: | Size: 380 KiB |
After Width: | Height: | Size: 240 KiB |