partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit c3891031907436bfd305db3bbf2ae18fd83bd254
parent 0c44f9729194496381157c6e6b88235d75c5013e
Author: Felicitus <felicitus@felicitus.org>
Date:   Mon, 19 Aug 2013 17:43:02 +0200

Added initial index controller

Diffstat:
Mapp/AppKernel.php | 2++
Mapp/config/routing_dev.yml | 5++---
Mcomposer.json | 3++-
Mcomposer.lock | 10+++++-----
Asrc/PartKeepr/FrontendBundle/Controller/IndexController.php | 114+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/FrontendBundle/PartKeeprFrontendBundle.php | 10++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/config/routing.yml | 3+++
Asrc/PartKeepr/FrontendBundle/Resources/views/index.html.twig | 46++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 184 insertions(+), 9 deletions(-)

diff --git a/app/AppKernel.php b/app/AppKernel.php @@ -17,6 +17,8 @@ class AppKernel extends Kernel new FOS\RestBundle\FOSRestBundle(), new JMS\SerializerBundle\JMSSerializerBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), + + new PartKeepr\FrontendBundle\PartKeeprFrontendBundle(), ); if (in_array($this->getEnvironment(), array('dev', 'test'))) { diff --git a/app/config/routing_dev.yml b/app/config/routing_dev.yml @@ -13,6 +13,5 @@ _configurator: _main: resource: routing.yml -# AcmeDemoBundle routes (to be removed) -_acme_demo: - resource: "@AcmeDemoBundle/Resources/config/routing.yml" +_frontend: + resource: "@PartKeeprFrontendBundle/Resources/config/routing.yml" diff --git a/composer.json b/composer.json @@ -40,7 +40,8 @@ "jms/serializer-bundle": "0.12.0" }, "autoload": { - "psr-0": { "": "src/" } + "psr-0": { "": "src/", + "PartKeepr": "src/backend"} }, "minimum-stability": "dev", "scripts": { diff --git a/composer.lock b/composer.lock @@ -557,12 +557,12 @@ "source": { "type": "git", "url": "https://github.com/doctrine/doctrine2.git", - "reference": "605c32dbb384e25117625a7cb4db4e7319a16bae" + "reference": "cc83ac6ce8d11f0c6c421cd4afd3503c8a69c35f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/doctrine2/zipball/605c32dbb384e25117625a7cb4db4e7319a16bae", - "reference": "605c32dbb384e25117625a7cb4db4e7319a16bae", + "url": "https://api.github.com/repos/doctrine/doctrine2/zipball/cc83ac6ce8d11f0c6c421cd4afd3503c8a69c35f", + "reference": "cc83ac6ce8d11f0c6c421cd4afd3503c8a69c35f", "shasum": "" }, "require": { @@ -600,7 +600,7 @@ ], "authors": [ { - "name": "Jonathan Wage", + "name": "Jonathan H. Wage", "email": "jonwage@gmail.com", "homepage": "http://www.jwage.com/" }, @@ -624,7 +624,7 @@ "database", "orm" ], - "time": "2013-08-16 04:36:22" + "time": "2013-08-19 04:33:45" }, { "name": "friendsofsymfony/rest", diff --git a/src/PartKeepr/FrontendBundle/Controller/IndexController.php b/src/PartKeepr/FrontendBundle/Controller/IndexController.php @@ -0,0 +1,113 @@ +<?php + +namespace PartKeepr\FrontendBundle\Controller; + +use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use PartKeepr\User\User, + PartKeepr\Service\ServiceManager, + PartKeepr\PartKeepr, + PartKeepr\Session\SessionManager, + PartKeepr\Util\Configuration; + +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; + +class IndexController extends Controller +{ + /** + * This is basically a copy of the PartKeepr's legacy index.php + * @Route("/") + */ + public function indexAction() + { + PartKeepr::initialize(""); + + $this->legacyAuthStuff(); + + $aParameters = array(); + $aParameters["doctrine_orm_version"] = \Doctrine\ORM\Version::VERSION; + $aParameters["doctrine_dbal_version"] = \Doctrine\DBAL\Version::VERSION; + $aParameters["doctrine_common_version"] = \Doctrine\Common\Version::VERSION; + $aParameters["php_version"] = phpversion(); + + $maxPostSize = PartKeepr::getBytesFromHumanReadable(ini_get("post_max_size")); + $maxFileSize = PartKeepr::getBytesFromHumanReadable(ini_get("upload_max_filesize")); + + $aParameters["maxUploadSize"] = min($maxPostSize, $maxFileSize); + + if (!class_exists("Imagick")) { + // @todo This check is deprecated and shouldn't be done here. Sf2 should automatically take care of this + $template = $twig->loadTemplate("error.tpl"); + echo $template->render(array( + "title" => PartKeepr::i18n("ImageMagick is not installed"), + "error" => PartKeepr::i18n("You are missing the ImageMagick extension. Please install it and restart the setup to verify that the library was installed correctly.") + )); + exit; + } + + /* ImageMagick formats */ + $imagick = new \Imagick(); + $aParameters["availableImageFormats"] = $imagick->queryFormats(); + + /* Automatic Login */ + if (Configuration::getOption("partkeepr.frontend.autologin.enabled", false) === true) { + $aParameters["autoLoginUsername"] = Configuration::getOption("partkeepr.frontend.autologin.username"); + $aParameters["autoLoginPassword"] = Configuration::getOption("partkeepr.frontend.autologin.password"); + } + + if (Configuration::getOption("partkeepr.frontend.motd", false) !== false) { + $aParameters["motd"] = Configuration::getOption("partkeepr.frontend.motd"); + } + + $renderParams = array(); + $renderParams["debug_all"] = Configuration::getOption("partkeepr.frontend.debug_all", false); + $renderParams["debug"] = Configuration::getOption("partkeepr.frontend.debug", false); + $renderParams["parameters"] = $aParameters; + + if ($renderParams["debug_all"]) { + $renderParams["scripts"] = unserialize(file_get_contents(PartKeepr::getRootDirectory() . "/partkeepr.jsfiles")); + } + + if (isset($_SERVER['HTTPS'])) { + $renderParams["https"] = true; + } else { + $renderParams["https"] = false; + } + return $this->render('PartKeeprFrontendBundle::index.html.twig', $renderParams); + } + + protected function legacyAuthStuff () { + /* HTTP auth */ + if (Configuration::getOption("partkeepr.auth.http", false) === true) { + if (!isset($_SERVER["PHP_AUTH_USER"])) { + // @todo Redirect to permission denied page + die("Permission denied"); + } + + try { + $user = User::loadByName($_SERVER['PHP_AUTH_USER']); + } catch (\Doctrine\ORM\NoResultException $e) { + $user = new User; + $user->setUsername($_SERVER['PHP_AUTH_USER']); + $user->setPassword("invalid"); + + PartKeepr::getEM()->persist($user); + PartKeepr::getEM()->flush(); + } + + + $session = SessionManager::getInstance()->startSession($user); + + $aParameters["autoLoginUsername"] = $user->getUsername(); + $aParameters["auto_start_session"] = $session->getSessionID(); + + $aPreferences = array(); + + foreach ($user->getPreferences() as $result) { + $aPreferences[] = $result->serialize(); + } + + $aParameters["userPreferences"] = array("response" => array("data" => $aPreferences)); + } + + } +}+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/PartKeeprFrontendBundle.php b/src/PartKeepr/FrontendBundle/PartKeeprFrontendBundle.php @@ -0,0 +1,9 @@ +<?php + +namespace PartKeepr\FrontendBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +class PartKeeprFrontendBundle extends Bundle +{ +}+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/config/routing.yml b/src/PartKeepr/FrontendBundle/Resources/config/routing.yml @@ -0,0 +1,3 @@ +_index: + resource: "@PartKeeprFrontendBundle/Controller/IndexController.php" + type: annotation diff --git a/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig b/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig @@ -0,0 +1,45 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + <title>PartKeepr</title> + + + <link href="{% if https %}https{% else %}http{% endif %}://fonts.googleapis.com/css?family=Ubuntu:400,700italic" rel="stylesheet" type="text/css"> + + <!-- Include the ExtJS CSS Theme --> + <link rel="stylesheet" type="text/css" href="css/partkeepr-theme.css"/> + + <link rel="stylesheet" type="text/css" href="js/Ext.ux/statusbar/css/statusbar.css"/> + + <link rel="stylesheet" type="text/css" href="css/PartKeepr.css"/> + + <link rel="icon" href="favicon.ico"/> + + <!-- Include the ExtJS JavaScript Library --> + {% if debug %} + {% if debug_all %} + <script type="text/javascript" src="extjs/ext-all-debug.js"></script> + {% for i in scripts %} + <script type="text/javascript" src="{{ i }}"></script> + {% endfor %} + {% else %} + <script type="text/javascript" src="extjs/ext-all-debug.js"></script> + <script type="text/javascript" src="js/partkeepr-debug.js"></script> + {% endif %} + {% else %} + <script type="text/javascript" src="extjs/ext-all.js"></script> + <script type="text/javascript" src="js/partkeepr.js"></script> + {% endif %} + + <script type="text/javascript" src="js/org.phpjs.lib/php.default.min.js"></script> + <script type="text/javascript" src="js/webcam.js"></script> +</head> +<body> +<div id="loading"><span class="logo"></span></div> +<script type="text/javascript"> + window.parameters = {{ parameters|json_encode|raw }}; +</script> +</body> +</html>+ \ No newline at end of file