IndexController.php (4424B)
1 <?php 2 3 namespace PartKeepr\FrontendBundle\Controller; 4 5 use Doctrine\Common\Version as DoctrineCommonVersion; 6 use Doctrine\DBAL\Version as DBALVersion; 7 use Doctrine\ORM\Version as ORMVersion; 8 use Symfony\Bundle\FrameworkBundle\Controller\Controller; 9 use Symfony\Component\Routing\Annotation\Route; 10 11 class IndexController extends Controller 12 { 13 /** 14 * This is basically a copy of the PartKeepr's legacy index.php. 15 * 16 * @Route("/") 17 */ 18 public function indexAction() 19 { 20 return $this->render('PartKeeprFrontendBundle::index.html.twig', $this->getRenderParameters()); 21 } 22 23 public function getRenderParameters() 24 { 25 if ($this->getParameter('partkeepr.maintenance') !== false) { 26 $renderParams['maintenanceTitle'] = $this->getParameter('partkeepr.maintenance.title'); 27 $renderParams['maintenanceMessage'] = $this->getParameter('partkeepr.maintenance.message'); 28 29 return $this->render('@PartKeeprFrontend/maintenance.html.twig', $renderParams); 30 } 31 32 $aParameters = []; 33 $aParameters['doctrine_orm_version'] = ORMVersion::VERSION; 34 $aParameters['doctrine_dbal_version'] = DBALVersion::VERSION; 35 $aParameters['doctrine_common_version'] = DoctrineCommonVersion::VERSION; 36 $aParameters['php_version'] = phpversion(); 37 $aParameters['auto_start_session'] = true; 38 39 $maxPostSize = $this->get('partkeepr_systemservice')->getBytesFromHumanReadable(ini_get('post_max_size')); 40 $maxFileSize = $this->get('partkeepr_systemservice')->getBytesFromHumanReadable(ini_get('upload_max_filesize')); 41 42 $aParameters['maxUploadSize'] = min($maxPostSize, $maxFileSize); 43 44 if ($this->getParameterWithDefault('partkeepr.upload.limit', false) !== false) { 45 $aParameters['maxUploadSize'] = $this->getParameterWithDefault('partkeepr.upload.limit', false); 46 } 47 48 if ($this->getParameterWithDefault('partkeepr.octopart.apikey', "") !== "") { 49 $aParameters['isOctoPartAvailable'] = true; 50 } else { 51 $aParameters['isOctoPartAvailable'] = false; 52 } 53 54 // @todo Hardcoded for now due to GD, see #445 55 $aParameters['availableImageFormats'] = ['JPG', 'GIF', 'PNG']; 56 57 /* Automatic Login */ 58 if ($this->getParameterWithDefault('partkeepr.frontend.auto_login.enabled', false) === true) { 59 $aParameters['autoLoginUsername'] = $this->getParameter('partkeepr.frontend.auto_login.username'); 60 $aParameters['autoLoginPassword'] = $this->getParameter('partkeepr.frontend.auto_login.password'); 61 } 62 63 if ($this->getParameterWithDefault('partkeepr.frontend.motd', false) !== false) { 64 $aParameters['motd'] = $this->getParameterWithDefault('partkeepr.frontend.motd', false); 65 } 66 67 $aParameters['max_users'] = $this->getParameterWithDefault('partkeepr.auth.max_users', 'unlimited'); 68 69 $aParameters['authentication_provider'] = $this->getParameter('partkeepr.authentication_provider'); 70 $aParameters['tip_of_the_day_uri'] = $this->getParameter('partkeepr.tip_of_the_day_uri'); 71 72 $aParameters['password_change'] = $this->getParameterWithDefault('partkeepr.auth.allow_password_change', true); 73 $aParameters["patreonStatus"] = $this->get("partkeepr_systemservice")->getPatreonStatus(); 74 75 $aParameters["defaultGridPresets"] = json_encode($this->get("partkeepr.gridpresetservice")->getDefaultPresets()); 76 $renderParams = []; 77 $renderParams['parameters'] = $aParameters; 78 $renderParams['debug'] = $this->get('kernel')->isDebug(); 79 $renderParams['baseUrl'] = $this->getBaseURL(); 80 81 return $renderParams; 82 } 83 84 /** 85 * Returns the base_url, either from the router (default) or overridden by the 86 * partkeepr.frontend.base_url parameter. 87 * 88 * @return string 89 */ 90 public function getBaseURL() 91 { 92 $baseUrl = $this->getParameterWithDefault('partkeepr.frontend.base_url', false); 93 94 if ($baseUrl !== false) { 95 return $baseUrl; 96 } 97 98 return $this->container->get('router')->getContext()->getBaseUrl(); 99 } 100 101 public function getParameterWithDefault($name, $default) 102 { 103 if ($this->container->hasParameter($name)) { 104 return $this->container->getParameter($name); 105 } else { 106 return $default; 107 } 108 } 109 }