| Server IP : 54.94.228.101 / Your IP : 172.28.1.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/app/Modules/RedeSocial/Controllers/Admin/ |
Upload File : |
<?php
namespace App\Modules\RedeSocial\Controllers\Admin;
use Illuminate\Http\Request;
use Mail;
use Exception;
use App\Http\Requests;
use App\Http\Controllers\BaseController;
use App\Modules\RedeSocial\Models\RedeSocial;
class AdminRedeSocialController extends BaseController
{
private $modulo;
private $fields;
private $fks;
private $lastInsertId;
public function __construct(){
parent::__construct();
$this->middleware('auth');
$this->modulo = \App\Gerador::where('nome', 'RedeSocial')->with('campos', 'fks')->first();
$this->fields = $this->modulo->campos;
$this->fks = $this->modulo->fks;
$this->rede_social_m = new RedeSocial();
}
public function index(){
$query = $this->rede_social_m->select('rede_social.*');
$data['fields_listagem'] = array();
foreach ($this->fields as $field) {
if($field->listagem){
$data['fields_listagem'][] = $field;
}
}
foreach ($this->fks as $fk) {
if($fk->listagem){
if($fk->campoRelacionado->translatable){
$table = $fk->moduloRelacionado->nome_tabela.'_descricao';
$on = $fk->moduloRelacionado->nome_tabela.'_descricao.'.$fk->moduloRelacionado->nome_tabela.'_id';
}else{
$table = $fk->moduloRelacionado->nome_tabela;
$on = $fk->moduloRelacionado->nome_tabela.'.id';
}
$query->leftJoin($table, 'rede_social.'.$fk->nome, '=', $on);
$query->addSelect($table.'.'.$fk->campoRelacionado->nome.' as fk'.$fk->id);
$data['fields_listagem'][] = $fk;
}
}
$data['redes_sociais'] = $query->groupBy('rede_social.id')->get();
usort($data['fields_listagem'], function($a, $b) {
return $a->ordem - $b->ordem;
});
return view('RedeSocial::admin/rede-social',$data);
}
public function add(){
$data = array();
$data['modulo'] = $this->modulo;
$data['fields'] = [];
foreach ($this->fields as $field) {
$data['fields'][] = $field;
}
foreach ($this->fks as $fk) {
$data['fields'][] = $fk;
}
usort($data['fields'], function($a, $b) {
return $a->ordem - $b->ordem;
});
foreach ($this->fks as $fk) {
$classPath = '\App\Modules\\'.$fk->moduloRelacionado->nome.'\Models\\'.$fk->moduloRelacionado->nome;
$data['array_'.$fk->nome] = $classPath::get();
}
$data['nextId'] = $this->rede_social_m->getNextAutoIncrement();
return view('RedeSocial::admin/form-rede-social', $data);
}
public function edit($slug){
$id = RedeSocial::where('slug', $slug)->value('id');
$data['modulo'] = $this->modulo;
$data['fields'] = [];
foreach ($this->fields as $field) {
$data['fields'][] = $field;
}
foreach ($this->fks as $fk) {
$data['fields'][] = $fk;
}
usort($data['fields'], function($a, $b) {
return $a->ordem - $b->ordem;
});
foreach ($this->fks as $fk) {
$classPath = '\App\Modules\\'.$fk->moduloRelacionado->nome.'\Models\\'.$fk->moduloRelacionado->nome;
$data['array_'.$fk->nome] = $classPath::get();
}
$data['rede_social'] = $this->rede_social_m->find($id);
if($this->modulo->galeria){
$data['rede_social']->imagens = $this->rede_social_m->getImagens($id);
}
return view('RedeSocial::admin/form-rede-social',$data);
}
public function save(Request $request){
$post = $request->input();
$post['meta_keywords'] = (isset($post['meta_keywords'])) ? implode(',',$post['meta_keywords']) : null;
foreach ($this->fields as $field) {
$arrayFields[] = $field->nome;
}
foreach ($this->fks as $fk) {
$arrayFields[] = $fk->nome;
}
if($this->modulo->imagem){
$arrayFields[] = 'thumbnail_principal';
}
if($request->input('id')){
$id_rede_social = $this->rede_social_m->editar($arrayFields, $post, $request->input('id'));
}else{
$id_rede_social = $this->rede_social_m->criar($arrayFields, $post);
}
\Session::flash('type', 'success');
\Session::flash('message', "Alteracoes salvas com sucesso!");
return redirect('admin/rede-social');
}
public function upload_image(Request $request) {
if($request->hasFile('file')) {
//upload an image to the /img/tmp directory and return the filepath.
$file = $request->file('file');
$tmpFilePath = '/uploads/rede-social/';
$tmpFileName = time() . '-' . $file->getClientOriginalName();
$file = $file->move(public_path() . $tmpFilePath, $tmpFileName);
$path = $tmpFilePath . $tmpFileName;
return response()->json(array('path'=> $path, 'file_name'=>$tmpFileName), 200);
} else {
return response()->json(false, 200);
}
}
public function upload_galeria($id, Request $request) {
if($request->hasFile('file')) {
//upload an image to the /img/tmp directory and return the filepath.
$file = $request->file('file');
$tmpFilePath = '/uploads/rede-social/';
$tmpFileName = time() . '-' . $file->getClientOriginalName();
$file = $file->move(public_path() . $tmpFilePath, $tmpFileName);
$path = $tmpFilePath . $tmpFileName;
$this->rede_social_m->criar_imagem(array('id_rede_social' => $id, 'thumbnail_principal' => $tmpFileName));
return response()->json(array('path'=> $path, 'file_name'=>$tmpFileName), 200);
} else {
return response()->json(false, 200);
}
}
public function crop_image(Request $request) {
$img = \Image::make('uploads/rede-social/'.$request->input('file_name'));
$dataCrop = json_decode($request->input('data_crop'));
if($img->crop(intval($dataCrop->width), intval($dataCrop->height), intval($dataCrop->x), intval($dataCrop->y))->save('uploads/rede-social/thumb_'.$request->input('file_name'))){
@unlink('uploads/rede-social/'.$request->input('file_name'));
echo json_encode(array(
'status' => true,
'path' => '/uploads/rede-social/thumb_'.$request->input('file_name'),
'file_name' => 'thumb_'.$request->input('file_name'),
));
}else{
echo json_encode(array(
'status' => false,
'message' => 'Não foi possível alterar a imagem.'
));
}
}
public function delete($slug){
$id = RedeSocial::where('slug', $slug)->value('id');
$this->rede_social_m->deletar($id);
\Session::flash('type', 'success');
\Session::flash('message', "Registro removido com sucesso!");
return redirect('admin/rede-social');
}
public function delete_imagem($id){
try{
$imagem = $this->rede_social_m->getImagem($id);
$this->rede_social_m->deletar_imagem($id);
unlink('uploads/rede-social/'.$imagem->thumbnail_principal);
return response()->json(array('status' => true, 'message' => 'Registro removido com sucesso!'));
}catch(Exception $e){
return response()->json(array('status' => false, 'message' => $e->getMessage()));
}
}
private function slugify($string)
{
return strtolower(trim(preg_replace('~[^0-9a-z]+~i', '-', html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')), '-'));
}
}