147 lines
5.5 KiB
PHP
Executable File
147 lines
5.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
class HomeController extends AbstractController
|
|
{
|
|
public function home()
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$users = $em->getRepository("App:User")->findBy([],["pseudo"=>"ASC"]);
|
|
$illustrations = $em->getRepository("App:Illustration")->findBy([],["submittime"=>"DESC"]);
|
|
$links = $em->getRepository("App:Link")->findBy(["user"=>null]);
|
|
$webzines = $em->getRepository("App:Webzine")->findBy(["user"=>null], ['set' => 'ASC', 'order' => 'ASC']);
|
|
|
|
return $this->render('Home/home.html.twig',[
|
|
"useheader" => false,
|
|
"usesidebar" => false,
|
|
"usemonocolor" => true,
|
|
"users" => $users,
|
|
"illustrations" => $illustrations,
|
|
"links" => $links,
|
|
"webzines" => $webzines
|
|
]);
|
|
}
|
|
|
|
public function user($userpseudo)
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
$user=$em->getRepository("App:User")->findOneBy(["slug"=>$userpseudo]);
|
|
if(!$user) return $this->redirectToRoute("app_home");
|
|
|
|
$categorys = $em->getRepository("App:Category")->findBy(["user"=>$user]);
|
|
$links = $em->getRepository("App:Link")->findBy(["user"=>$user]);
|
|
$webzines = $em->getRepository("App:Webzine")->findBy(["user"=>$user], ['set' => 'ASC', 'order' => 'ASC']);
|
|
$config = $em->getRepository("App:Config")->getUserConfig($user);
|
|
|
|
return $this->render('Home/user.html.twig',[
|
|
"useheader" => false,
|
|
"usesidebar" => false,
|
|
"usemonocolor" => true,
|
|
"user" => $user,
|
|
"config" => $config,
|
|
"categorys" => $categorys,
|
|
"links" => $links,
|
|
"webzines" => $webzines
|
|
]);
|
|
}
|
|
|
|
|
|
public function feed($nb)
|
|
{
|
|
$feeds=[];
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$qb = $em ->createQueryBuilder()
|
|
->select('e')
|
|
->from("App:Illustration", 'e');
|
|
if($nb!=0) $qb->setMaxResults($nb);
|
|
$illustrations=$qb->getQuery()->getResult();
|
|
foreach($illustrations as $illustration) {
|
|
$tmp["path"] = "app_illustration_view";
|
|
$tmp["type"] = "illustration";
|
|
$tmp["idcat"] = $illustration->getCategory()->getId();
|
|
$tmp["cat"] = $illustration->getCategory()->getName();
|
|
$tmp["id"] = $illustration->getId();
|
|
$tmp["name"] = $illustration->getName();
|
|
$tmp["illustration"] = $illustration->getIllustration();
|
|
$tmp["pubtime"] = $illustration->getSubmittime();
|
|
$tmp["description"] = $illustration->getDescription();
|
|
|
|
array_push($feeds,$tmp);
|
|
}
|
|
|
|
|
|
|
|
$qb = $em ->createQueryBuilder()
|
|
->select('e')
|
|
->from("App:Webzine", 'e');
|
|
if($nb!=0) $qb->setMaxResults($nb);
|
|
$webzines=$qb->getQuery()->getResult();
|
|
foreach($webzines as $webzine) {
|
|
if($webzine->getWebzinepages()) {
|
|
$tmp["path"] = "app_webzine_view";
|
|
$tmp["type"] = "webzine";
|
|
$tmp["idcat"] = $webzine->getId();
|
|
$tmp["cat"] = "Webzine".($webzine->getSet()?" - ".$webzine->getSet():"");
|
|
$tmp["id"] = $webzine->getWebzinepages()[0]->getId();
|
|
$tmp["name"] = $webzine->getName();
|
|
$tmp["illustration"] = $webzine->getWebzinepages()[0]->getIllustration();
|
|
$tmp["pubtime"] = $webzine->getSubmittime();
|
|
$tmp["description"] = $webzine->getDescription();
|
|
|
|
array_push($feeds,$tmp);
|
|
}
|
|
}
|
|
|
|
$columns = array_column($feeds, 'pubtime');
|
|
array_multisort($columns, SORT_DESC, $feeds);
|
|
|
|
$response = new Response($this->renderView('Home/feed.xml.twig',["feeds" => $feeds]));
|
|
|
|
$response->headers->set('Content-Type', 'application/xml; charset=utf-8');
|
|
return $response;
|
|
}
|
|
|
|
public function admin()
|
|
{
|
|
return $this->render('Home/admin.html.twig',[
|
|
"useheader" => true,
|
|
"usesidebar" => true,
|
|
]);
|
|
}
|
|
|
|
public function upload(Request $request,$access=null) {
|
|
// Fichier temporaire uploadé
|
|
$tmpfile = $request->files->get('upload');
|
|
$extention = $tmpfile->getClientOriginalExtension();
|
|
|
|
// Répertoire de Destination
|
|
$fs = new Filesystem();
|
|
$rootdir = $this->getParameter('kernel.project_dir') . '/public';
|
|
$fs->mkdir($rootdir."/uploads/ckeditor");
|
|
|
|
// Fichier cible
|
|
$targetName = uniqid().".".$extention;
|
|
$targetFile = $rootdir."/uploads/ckeditor/".$targetName;
|
|
$targetUrl = "/".$this->getParameter('appAlias')."/uploads/ckeditor/".$targetName;
|
|
$message = "";
|
|
|
|
move_uploaded_file($tmpfile,$targetFile);
|
|
|
|
$output["uploaded"]=1;
|
|
$output["fileName"]=$targetName;
|
|
$output["url"]=$targetUrl;
|
|
|
|
return new Response(json_encode($output));
|
|
}
|
|
|
|
}
|