From 2da201978ea6b0c48cfdf5c1a2ae3fae3c6f10be Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 20 Mar 2015 19:53:34 +0000 Subject: [PATCH] add subscription request detail page --- controllers/controllers.php | 34 +++++++++ lib/PushTask.php | 5 +- lib/db_helpers.php | 4 ++ public/css/style.css | 130 ++++++++++++++++++++++++++++++++++ views/index.php | 27 +++++++ views/layout.php | 65 +++++++++++++++++ views/subscription-status.php | 36 ++++++++++ 7 files changed, 300 insertions(+), 1 deletion(-) create mode 100644 public/css/style.css create mode 100644 views/index.php create mode 100644 views/layout.php create mode 100644 views/subscription-status.php diff --git a/controllers/controllers.php b/controllers/controllers.php index e69de29..9c4ac4e 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -0,0 +1,34 @@ +get('/', function() use($app) { + $res = $app->response(); + ob_start(); + render('index', array( + 'title' => 'Switchboard', + 'meta' => '' + )); + $html = ob_get_clean(); + $res->body($html); +}); + +$app->get('/subscription/:hash', function($hash) use($app) { + $res = $app->response(); + + $subscription = db\get_by_col('subscriptions', 'hash', $hash); + $feed = db\get_by_id('feeds', $subscription->feed_id); + + if(!$subscription) { + $app->response()->status(404); + } else { + ob_start(); + render('subscription-status', array( + 'title' => 'Switchboard', + 'meta' => '', + 'subscription' => $subscription, + 'feed' => $feed + )); + $html = ob_get_clean(); + $res->body($html); + } +}); + diff --git a/lib/PushTask.php b/lib/PushTask.php index d422730..05c138a 100644 --- a/lib/PushTask.php +++ b/lib/PushTask.php @@ -33,6 +33,8 @@ class PushTask { $response = request\get_url($url, true); + $subscription->challenge_response = $response['headers']."\n\n".$response['body']; + if(request\response_is($response['status'], 2) && $response['body'] == $subscription->challenge) { // The subscriber replied with a 2xx status code and confirmed the challenge string. // The subscription is confirmed and active. @@ -41,13 +43,14 @@ class PushTask { $subscription->date_expires = $exp_date; db\set_updated($subscription); $subscription->active = 1; - $subscription->save(); } else { // The subscriber did not confirm the subscription, so reject it } + $subscription->save(); + print_r($response); } diff --git a/lib/db_helpers.php b/lib/db_helpers.php index 6af6631..c72ba70 100644 --- a/lib/db_helpers.php +++ b/lib/db_helpers.php @@ -48,3 +48,7 @@ function feed_from_url($url) { function get_by_id($table, $id) { return ORM::for_table($table)->where('id', $id)->find_one(); } + +function get_by_col($table, $col, $val) { + return ORM::for_table($table)->where($col, $val)->find_one(); +} diff --git a/public/css/style.css b/public/css/style.css new file mode 100644 index 0000000..527a163 --- /dev/null +++ b/public/css/style.css @@ -0,0 +1,130 @@ +body { + padding-top: 10px; + background: #fff; +} + +body.logged-out { + background: white; +} +.logged-out .jumbotron { + background-color: #fffbeb; + border: 1px #fff2bc solid; +} + +.header { + font-family:; "Helvetica Neue",Helvetica,Arial,sans-serif; + font-size: 22px; + font-weight: 500; + color: #888; + border-bottom: 6px #ddd solid; + padding-bottom: 4px; +} + +.narrow { + max-width: 700px; + margin-right: auto; + margin-left: auto; +} + +.footer { + padding: 0; + margin-top: 20px; + text-align: center; + color: #999; + background-color: #f9f9f9; + border-top: 1px #e5e5e5 solid; + position: absolute; + bottom: 0; + width: 100%; +} + +.footer .nav { + max-width: 700px; + margin-right: auto; + margin-left: auto; +} + +.footer .credits { + padding: 20px; + font-size: 12px; +} + + +.jumbotron .tagline { + font-size: 23px; +} +.jumbotron p { + font-size: 18px; +} + + +/** + * Bootstrap callouts + */ + +/* Base styles (regardless of theme) */ +.bs-callout { + margin: 20px 0; + padding: 15px 30px 15px 15px; + border-left: 5px solid #eee; +} +.bs-callout h4 { + margin-top: 0; +} +.bs-callout p:last-child { + margin-bottom: 0; +} +.bs-callout code, +.bs-callout .highlight { + background-color: #fff; +} + +/* Themes for different contexts */ +.bs-callout-danger { + background-color: #fcf2f2; + border-color: #dFb5b4; +} + +.bs-callout-warning { + background-color: #fefbed; + border-color: #f1e7bc; +} + +.bs-callout-info { + background-color: #f0f7fd; + border-color: #d0e3f0; +} + +.bs-callout-success { + background-color: #dff0d8; + border-color: #b5dca5; +} + +.bs-callout-danger h4 { + color: #B94A48; +} + +.bs-callout-warning h4 { + color: #C09853; +} + +.bs-callout-info h4 { + color: #3A87AD; +} + +.bs-callout-success h4 { + color: #3c763d; +} + +.bs-callout.pre { + font-family: Menlo,Monaco,Consolas,"Courier New",monospace; + word-break: break-all; + word-wrap: break-word; +} + + +@-webkit-keyframes pulsate { + 0% {-webkit-transform: scale(0.9, 0.9); opacity: 1.0;} + 50% {opacity: 0.0;} + 100% {-webkit-transform: scale(1.1, 1.1); opacity: 1.0;} +} diff --git a/views/index.php b/views/index.php new file mode 100644 index 0000000..c621e98 --- /dev/null +++ b/views/index.php @@ -0,0 +1,27 @@ +
+ +
+

Switchboard

+ +

Switchboard is a PubSubHubbub 0.4 hub.

+ +

To publish content using Switchboard as your hub, add the following links to your home page:

+

<link rel="self" href="https://example.com/">
+<link rel="hub" href="https://switchboard.p3k.io/">

+ +

Then, send a POST request to https://switchboard.p3k.io/ with the following + parameters every time you add content to your home page:

+ +

+

    +
  • hub.mode=publish
  • +
  • hub.topic=https://example.com/
  • +
+

+ +

Read more info about how to publish and consume using PubSubHubbub.

+ + +
+ +
diff --git a/views/layout.php b/views/layout.php new file mode 100644 index 0000000..c7e8fe7 --- /dev/null +++ b/views/layout.php @@ -0,0 +1,65 @@ + + + + <?= $this->title ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ fetch($this->page . '.php') ?> +
+ + +
+ + + \ No newline at end of file diff --git a/views/subscription-status.php b/views/subscription-status.php new file mode 100644 index 0000000..759d2ce --- /dev/null +++ b/views/subscription-status.php @@ -0,0 +1,36 @@ +subscription->active): ?> +
This subscription is active!
+ +
This subscription is not active
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Feed URL (Topic)feed->feed_url ?>
Callback URLsubscription->callback_url ?>
Date Subscription was Requestedsubscription->date_requested ? friendly_date($this->subscription->date_requested, $tz) : '' ?>
Subscription Verification Response (from your server)
subscription->challenge_response) ?>
Date Subscription was Confirmedsubscription->date_confirmed ? friendly_date($this->subscription->date_confirmed, $tz) : '' ?>
Subscription Expirationsubscription->date_expires ? friendly_date($this->subscription->date_expires, $tz) : '' ?>
\ No newline at end of file