Permalink
Browse files

Working..

  • Loading branch information...
bobdenotter committed Jun 25, 2012
1 parent 1bde54d commit 1665b5565ad3a4a48e319a8a162322663aa24cb8
Showing with 104 additions and 41 deletions.
  1. +37 −18 app/app_backend.php
  2. +14 −4 app/app_frontend.php
  3. +4 −0 app/bootstrap.php
  4. +17 −0 app/lib.php
  5. +6 −5 app/view/css/debugbar.css
  6. +1 −1 app/view/dashboard.twig
  7. +19 −11 app/view/debugbar.twig
  8. +1 −1 app/view/overview.twig
  9. +5 −1 index.php
View
@@ -7,11 +7,18 @@
* Middleware function to check whether a user is logged on.
*/
$checkLogin = function(Request $request) use ($app) {
-
+
+
+ $route = $request->get('_route');
+
+
+
// There's an active session, we're all good.
if ($app['session']->has('user')) {
return;
}
+
+
// If the users table is present, but there are no users, and we're on /pilex/users/edit,
// we let the user stay, because they need to set up the first user.
@@ -32,12 +39,15 @@
};
+use Silex\ControllerCollection;
+
+$backend = new ControllerCollection($app['route_factory']);
/**
* Dashboard or "root".
*/
-$app->get("/pilex", function(Silex\Application $app) {
+$backend->get("/", function(Silex\Application $app) {
// Check DB-tables integrity
if (!$app['storage']->checkTablesIntegrity()) {
@@ -55,11 +65,10 @@
-
/**
* Login page.
*/
-$app->match("/pilex/login", function(Silex\Application $app, Request $request) {
+$backend->match("/login", function(Silex\Application $app, Request $request) {
if ($request->getMethod() == "POST") {
@@ -83,7 +92,7 @@
/**
* Logout page.
*/
-$app->get("/pilex/logout", function(Silex\Application $app) {
+$backend->get("/logout", function(Silex\Application $app) {
$app['session']->setFlash('info', 'You have been logged out.');
$app['session']->remove('user');
@@ -97,7 +106,7 @@
/**
* Check the database, create tables, add missing/new columns to tables
*/
-$app->get("/pilex/dbupdate", function(Silex\Application $app) {
+$backend->get("/dbupdate", function(Silex\Application $app) {
$title = "Database check / update";
@@ -121,7 +130,7 @@
/**
* Generate some lipsum in the DB.
*/
-$app->get("/pilex/prefill", function(Silex\Application $app) {
+$backend->get("/prefill", function(Silex\Application $app) {
$title = "Database prefill";
@@ -135,7 +144,7 @@
/**
* Check the database, create tables, add missing/new columns to tables
*/
-$app->get("/pilex/overview/{contenttypeslug}", function(Silex\Application $app, $contenttypeslug) {
+$backend->get("/overview/{contenttypeslug}", function(Silex\Application $app, $contenttypeslug) {
$contenttype = $app['storage']->getContentType($contenttypeslug);
@@ -149,7 +158,7 @@
/**
* Edit a unit of content, or create a new one.
*/
-$app->match("/pilex/edit/{contenttypeslug}/{id}", function($contenttypeslug, $id, Silex\Application $app, Request $request) {
+$backend->match("/edit/{contenttypeslug}/{id}", function($contenttypeslug, $id, Silex\Application $app, Request $request) {
$twigvars = array();
@@ -193,7 +202,7 @@
use Symfony\Component\Form\CallbackValidator;
use Symfony\Component\Validator\Constraints as Assert;
-$app->match("/pilex/users/edit/{id}", function($id, Silex\Application $app, Request $request) {
+$backend->match("/users/edit/{id}", function($id, Silex\Application $app, Request $request) {
// Get the user we want to edit (if any)
if (!empty($id)) {
@@ -312,7 +321,7 @@
/**
* Show a list of all available users.
*/
-$app->get("/pilex/users", function(Silex\Application $app) {
+$backend->get("/users", function(Silex\Application $app) {
$title = "Users";
$users = $app['users']->getUsers();
@@ -325,7 +334,7 @@
/**
* Show a list of all available users.
*/
-$app->get("/pilex/user/{action}/{id}", function(Silex\Application $app, $action, $id) {
+$backend->get("/user/{action}/{id}", function(Silex\Application $app, $action, $id) {
$user = $app['users']->getUser($id);
@@ -392,6 +401,7 @@
}
});
+ /*
$app->after(function(Request $request, Response $response) use ($app, $logger) {
// Log all queries as DEBUG.
foreach ( $logger->queries as $query ) {
@@ -401,6 +411,7 @@
));
}
});
+ */
}
@@ -439,14 +450,17 @@
$twig = $app['twig.loader'];
$templates = hackislyParseRegexTemplates($twig);
+ $route = $request->get('_route') ;
+ $route_params = $request->get('_route_params') ;
+
$servervars = array(
- 'cookies' => $request->cookies->all(),
+ 'cookies <small>($_COOKIES)</small>' => $request->cookies->all(),
'headers' => makeValuepairs($request->headers->all(), '', '0'),
- 'query' => $request->query->all(),
- 'request' => $request->request->all(),
- 'session' => $request->getSession()->all(),
- 'server' => $request->server->all(),
+ 'query <small>($_GET)</small>' => $request->query->all(),
+ 'request <small>($_POST)</small>' => $request->request->all(),
+ 'session <small>($_SESSION)</small>' => $request->getSession()->all(),
+ 'server <small>($_SERVER)</small>' => $request->server->all(),
'response' => makeValuepairs($response->headers->all(), '', '0'),
'statuscode' => $response->getStatusCode()
);
@@ -457,11 +471,14 @@
'pilex_version' => $pilex_version,
'timetaken' => timeTaken(),
'memtaken' => getMem(),
+ 'memtaken' => getMaxMem(),
'querycount' => $querycount,
'querytime' => sprintf("%0.2f", $querytime),
'queries' => $queries,
'servervars' => $servervars,
- 'templates' => $templates
+ 'templates' => $templates,
+ 'route' => "/".$route,
+ 'route_params' => json_encode($route_params)
));
}
@@ -505,3 +522,5 @@
});
+$app->mount('/pilex', $backend);
+
View
@@ -1,5 +1,8 @@
<?php
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
/**
* Homepage..
*/
@@ -17,7 +20,9 @@
- return $app['twig']->render('index.twig');
+ $body = $app['twig']->render('index.twig');
+ return new Response($body, 200, array('Cache-Control' => 's-maxage=3600, public'));
+
});
@@ -35,10 +40,11 @@
$contentgroup = $app['storage']->getContent($contenttype['slug'], array('limit' => "10", 'order' => "datecreated DESC"));
- return $app['twig']->render('_sub_weblog.twig', array(
+ $body = $app['twig']->render('_sub_weblog.twig', array(
'contentgroup' => $contentgroup,
'contenttype' => $contenttype
));
+ return new Response($body, 200, array('Cache-Control' => 's-maxage=3600, public'));
});
@@ -57,11 +63,13 @@
$contentgroup = $app['storage']->getContent($contenttype['slug'], array('limit' => "10", 'order' => "datecreated DESC"));
- return $app['twig']->render('_sub_linklist.twig', array(
+ $body = $app['twig']->render('_sub_linklist.twig', array(
'contentgroup' => $contentgroup,
'contenttype' => $contenttype
));
+ return new Response($body, 200, array('Cache-Control' => 's-maxage=3600, public'));
+
});
@@ -94,8 +102,10 @@
}
+ $body = $app['twig']->render($contenttype['template'], array('content' => $content));
+ return new Response($body, 200, array('Cache-Control' => 's-maxage=3600, public'));
- return $app['twig']->render($contenttype['template'], array('content' => $content));
+ // return $app['twig']->render($contenttype['template'], array('content' => $content));
View
@@ -40,6 +40,10 @@
'db.options' => $dboptions
));
+$app->register(new Silex\Provider\HttpCacheServiceProvider(), array(
+ 'http_cache.cache_dir' => __DIR__.'/cache/',
+));
+
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
View
@@ -86,6 +86,23 @@ function getMem() {
+/**
+ * Get the maximum amount of used memory, if memory_get_usage is defined.
+ *
+ * @return string
+ */
+function getMaxMem() {
+
+ if (function_exists('memory_get_peak_usage')) {
+ $mem = memory_get_peak_usage();
+ return formatFilesize($mem);
+ } else {
+ return "unknown";
+ }
+}
+
+
+
/**
* Format a filesize like '10.3 kb' or '2.5 mb'
*
View
@@ -85,8 +85,8 @@
position: fixed;
right: 10px;
bottom: 34px;
- height: 300px;
- width: 700px;
+ max-height: 300px;
+ width: 640px;
box-shadow: 1px 1px 2px 1px rgba(0, 0, 0, 0.3);
z-index: 999;
overflow-y: auto;
@@ -106,6 +106,7 @@
color: #444;
border: 0;
padding: 0;
+ margin: 0;
}
#pilex-debugbar small,
@@ -130,7 +131,7 @@
}
.pilex-debugpanel {
- width: 540px;
+ width: 500px;
}
.pilex-debugpanel code,
@@ -154,12 +155,12 @@
display: inline;
}
- #pilex-debugbar ul li {
+/* #pilex-debugbar ul li {
background-position-x: 2px !important;
padding: 7px 4px 7px 20px;
}
-
+*/
.pilex-debugpanel {
width: 300px;
}
View
@@ -18,7 +18,7 @@
<table class='dashboardlisting'>
{% for content in multiplecontent %}
- <tr class="{{ content.status }}">
+ <tr class="{% if content.status!='published' %}dim{% endif %}">
<td class='id'>№ {{content.id}}</td>
<td class='excerpt'><span> <strong><a href="{{ path('editcontent', { 'contenttypeslug': contenttype, 'id': content.id }) }}">{{content.title}}</a></strong> {{ excerpt(content, 180) }} </span></td>
View
@@ -4,8 +4,7 @@
<div id='pilex-debugbar'>
<ul>
<li id='pd-pilex'><strong>Pilex {{pilex_version}}</strong><small>{% if pilex_name is defined %} - {{pilex_name}}{% endif %}</small></li>
- <li id='pd-timer'>{{timetaken}} s<span class='narrow'>ec / {{memtaken}}</span></li>
- <li id='pd-variables'><a href="#" data-for="pilex-varpanel">Var<span class='narrow'>iables</span></a></li>
+ <li id='pd-variables'><a href="#" data-for="pilex-varpanel">{{timetaken}} s<span class='narrow'>ec / {{memtaken}}</span></a></li>
<li id='pd-log'>Log<span class='narrow'>file</span></li>
<li id='pd-queries'>
{% if querycount==0 %}
@@ -19,6 +18,23 @@
</ul>
</div>
+
+<div id='pilex-varpanel' class='pilex-debugpanel'>
+<pre>
+<strong>Time taken:</strong> {{timetaken}} sec. / <strong>Memory</strong> {{memtaken}}.
+
+<strong>Used templates:</strong>
+<pre>{% for template in templates %}
+{{loop.index }}. {{template}}
+{% endfor %}
+
+<strong>Route:</strong> {{ route }}
+<strong>Parameters:</strong> {{ route_params }}
+<strong>Request URI:</strong> {{ servervars['server <small>($_SERVER)</small>']['REQUEST_URI'] }}
+</pre>
+</div>
+
+
<div id='pilex-queriespanel' class='pilex-debugpanel'>
<pre>{% for query in queries %}
{{loop.index }}. {{ query.query}} <small>({{ query.duration }} sec.)</small>
@@ -29,21 +45,13 @@
<div id='pilex-serverpanel' class='pilex-debugpanel'>
<pre>{% for key, var in servervars %}
-<strong>{{key}}:</strong>
+<strong>{{key|raw}}:</strong>
{{ printr(var, true) }}
{% endfor %}
</pre>
</div>
-<div id='pilex-varpanel' class='pilex-debugpanel'>
-<strong>Used templates:</strong>
-<pre>{% for template in templates %}
-{{loop.index }}. {{template}}
-{% endfor %}
-</pre>
-</div>
-
<script type="text/javascript">!window.jQuery && document.write('<script src="/app/view/js/jquery-1.7.2.min.js"><\/script>')</script>
View
@@ -14,7 +14,7 @@
{% for content in multiplecontent %}
<tr class="{% if content.status!='published' %}dim{% endif %}">
- <td class='id'>№ {{content.id}}</td>
+ <td class='id'>№ {{content.id}} {{ content.status }}</td>
<td class='excerpt large'><span> <strong>
<a href="{{ path('editcontent', { 'contenttypeslug': contenttype.slug, 'id': content.id }) }}">{{content.title}}</a></strong>
{{ excerpt(content, 200) }} <span></td>
Oops, something went wrong.

0 comments on commit 1665b55

Please sign in to comment.