Skip to content
Snippets Groups Projects
Commit 2be9341a authored by Alex Barth's avatar Alex Barth
Browse files

Clean up loadSubscription() and make it public, add subscribed() query.

parent b77e7743
No related branches found
No related tags found
No related merge requests found
......@@ -108,7 +108,7 @@ class PuSHSubscriber {
* The callback to unsubscribe.
*/
public function unsubscribe($topic_url, $callback_url) {
if ($sub = $this->loadSubscription()) {
if ($sub = $this->subscription()) {
$this->request($sub->hub, $sub->topic, 'unsubscribe', $callback_url);
$sub->delete();
}
......@@ -156,7 +156,7 @@ class PuSHSubscriber {
if ($ignore_signature) {
return $raw;
}
if (isset($_SERVER['HTTP_X_HUB_SIGNATURE']) && ($sub = $this->loadSubscription())) {
if (isset($_SERVER['HTTP_X_HUB_SIGNATURE']) && ($sub = $this->subscription())) {
$result = array();
parse_str($_SERVER['HTTP_X_HUB_SIGNATURE'], $result);
if (isset($result['sha1']) && $result['sha1'] == hash_hmac('sha1', $raw, $sub->secret)) {
......@@ -192,7 +192,7 @@ class PuSHSubscriber {
*
* In all other cases confirm negative.
*/
if ($sub = $this->loadSubscription()) {
if ($sub = $this->subscription()) {
if ($_GET['hub_verify_token'] == $sub->post_fields['hub.verify_token']) {
if ($_GET['hub_mode'] == 'subscribe' && $sub->status == 'subscribe') {
$sub->status = 'subscribed';
......@@ -273,12 +273,28 @@ class PuSHSubscriber {
}
/**
* Helper for loading a subscription.
* Get the subscription associated with this subscriber.
*
* @return
* A PuSHSubscriptionInterface object if a subscription exist, NULL
* otherwise.
*/
protected function loadSubscription() {
public function subscription() {
return call_user_func(array($this->subscription_class, 'load'), $this->domain, $this->subscriber_id);
}
/**
* Determine whether this subscriber is successfully subscribed or not.
*/
public function subscribed() {
if ($sub = $this->subscription()) {
if ($sub->status == 'subscribed') {
return TRUE;
}
}
return FALSE;
}
/**
* Helper for messaging.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment