Browse Source

better template rendering, accept hub.topic as well as hub.url

master
Aaron Parecki 9 years ago
parent
commit
1bede8a928
5 changed files with 15 additions and 12 deletions
  1. +1
    -0
      CONTRIBUTING.md
  2. +3
    -9
      controllers/controllers.php
  3. +7
    -1
      controllers/push.php
  4. +3
    -1
      lib/helpers.php
  5. +1
    -1
      scripts/run.php

+ 1
- 0
CONTRIBUTING.md View File

@ -0,0 +1 @@
By submitting code to this project, you agree to irrevocably release it under the same license as this project. See README.md for more details.

+ 3
- 9
controllers/controllers.php View File

@ -2,12 +2,10 @@
$app->get('/', function() use($app) { $app->get('/', function() use($app) {
$res = $app->response(); $res = $app->response();
ob_start();
render('index', array(
$html = render('index', array(
'title' => 'Switchboard', 'title' => 'Switchboard',
'meta' => '' 'meta' => ''
)); ));
$html = ob_get_clean();
$res->body($html); $res->body($html);
}); });
@ -20,14 +18,12 @@ $app->get('/subscription/:hash', function($hash) use($app) {
if(!$subscription) { if(!$subscription) {
$app->response()->status(404); $app->response()->status(404);
} else { } else {
ob_start();
render('subscription-status', array(
$html = render('subscription-status', array(
'title' => 'Switchboard', 'title' => 'Switchboard',
'meta' => '', 'meta' => '',
'subscription' => $subscription, 'subscription' => $subscription,
'feed' => $feed 'feed' => $feed
)); ));
$html = ob_get_clean();
$res->body($html); $res->body($html);
} }
}); });
@ -42,15 +38,13 @@ $app->get('/feed/:hash', function($hash) use($app) {
if(!$feed) { if(!$feed) {
$app->response()->status(404); $app->response()->status(404);
} else { } else {
ob_start();
render('feed-status', array(
$html = render('feed-status', array(
'title' => 'Switchboard', 'title' => 'Switchboard',
'meta' => '', 'meta' => '',
'feed' => $feed, 'feed' => $feed,
'subscribers' => $subscribers, 'subscribers' => $subscribers,
'num_subscribers' => $num_subscribers 'num_subscribers' => $num_subscribers
)); ));
$html = ob_get_clean();
$res->body($html); $res->body($html);
} }
}); });

+ 7
- 1
controllers/push.php View File

@ -49,7 +49,7 @@ $app->post('/', function() use($app) {
$callback = k($params, 'hub_callback'); $callback = k($params, 'hub_callback');
if(!is_valid_push_url($topic)) { if(!is_valid_push_url($topic)) {
push_error($app, 'Topic URL was invalid');
push_error($app, 'Topic URL was invalid ('.$topic.')');
} }
if(!is_valid_push_url($callback)) { if(!is_valid_push_url($callback)) {
@ -102,6 +102,12 @@ $app->post('/', function() use($app) {
// Sanity check the request params // Sanity check the request params
$url = k($params, 'hub_url'); $url = k($params, 'hub_url');
if(!$url)
$url = k($params, 'hub_topic');
if(!$url) {
push_error($app, 'No URL was specified. When publishing, send the topic URL in a parameter named hub.topic');
}
if(!is_valid_push_url($url)) { if(!is_valid_push_url($url)) {
push_error($app, 'URL was invalid'); push_error($app, 'URL was invalid');

+ 3
- 1
lib/helpers.php View File

@ -97,7 +97,9 @@ function is_valid_push_url($url) {
function render($page, $data) { function render($page, $data) {
global $app; global $app;
return $app->render('layout.php', array_merge($data, array('page' => $page)));
ob_start();
$app->render('layout.php', array_merge($data, array('page' => $page)));
return ob_get_clean();
}; };
function partial($template, $data=array(), $debug=false) { function partial($template, $data=array(), $debug=false) {

+ 1
- 1
scripts/run.php View File

@ -1,7 +1,7 @@
<?php <?php
declare(ticks=1); declare(ticks=1);
chdir('..');
chdir(__DIR__.'/..');
$mode = 'run'; $mode = 'run';
if(array_key_exists(1, $argv) && $argv[1] == 'once') if(array_key_exists(1, $argv) && $argv[1] == 'once')

Loading…
Cancel
Save