Skip to content

Commit 28a8c26

Browse files
committed
Merge pull request #4 from miniplay/fix-namespace
Fix namespace + autoloading issue. Fix example.
2 parents b47d17d + 91da356 commit 28a8c26

File tree

2 files changed

+43
-46
lines changed

2 files changed

+43
-46
lines changed

example.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,18 @@
55
// written by Josh Fraser | joshfraser.com | josh@eventvue.com
66
// Released under Apache License 2.0
77

8-
include("subscriber.php");
8+
include("./src/Subscriber.php");
99

1010
$hub_url = "http://pubsubhubbub.appspot.com";
1111
$callback_url = "put your own endpoint here";
1212

1313
$feed = "http://feeds.feedburner.com/onlineaspect";
1414

1515
// create a new subscriber
16-
$s = new Subscriber($hub_url, $callback_url);
16+
$s = new Pubsubhubbub\Subscriber\Subscriber($hub_url, $callback_url);
1717

1818
// subscribe to a feed
1919
$s->subscribe($feed);
2020

2121
// unsubscribe from a feed
2222
$s->unsubscribe($feed);
23-
24-
?>
25-
Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
11
<?php
22
/**
33
* A PHP client library for pubsubhubbub
4-
*
4+
*
55
* @link http://code.google.com/p/pubsubhubbub/
66
* @author Josh Fraser | joshfraser.com | josh@eventvue.com
77
* @license Apache License 2.0
88
*/
99

10-
namespace pubsubhubbub/subscriber;
10+
namespace Pubsubhubbub\Subscriber;
1111

1212
class Subscriber {
1313
/**
1414
* put your google key here
1515
* required if you want to use the google feed API to lookup RSS feeds
16-
*
16+
*
1717
* @var string
1818
*/
1919
protected $google_key = "";
20-
20+
2121
/** @var string */
2222
protected $hub_url;
23-
23+
2424
/** @var string */
2525
protected $callback_url;
26-
26+
2727
/** @var string */
2828
protected $credentials;
29-
29+
3030
/**
3131
* @var string accepted values are "async" and "sync"
3232
*/
33-
protected $verify = "async";
34-
33+
protected $verify = "async";
34+
3535
/** @var string */
3636
protected $verify_token;
37-
37+
3838
/** @var int */
3939
protected $lease_seconds;
40-
40+
4141
/**
4242
* create a new Subscriber (credentials added for SuperFeedr support)
43-
*
43+
*
4444
* @param string $hub_url
4545
* @param string $callback_url
4646
* @param string $credentials
4747
*/
4848
public function __construct($hub_url, $callback_url, $credentials = false) {
49-
49+
5050
if (!isset($hub_url))
5151
throw new Exception('Please specify a hub url');
52-
53-
if (!preg_match("|^https?://|i",$hub_url))
52+
53+
if (!preg_match("|^https?://|i",$hub_url))
5454
throw new Exception('The specified hub url does not appear to be valid: '.$hub_url);
55-
55+
5656
if (!isset($callback_url))
5757
throw new Exception('Please specify a callback');
58-
58+
5959
$this->hub_url = $hub_url;
6060
$this->callback_url = $callback_url;
6161
$this->credentials = $credentials;
6262
}
63-
63+
6464
/**
6565
* $use_regexp lets you choose whether to use google AJAX feed api (faster, but cached) or a regexp to read from site
66-
*
66+
*
6767
* @param string $url
6868
* @param callable $http_function
6969
* @return string
7070
*/
7171
public function find_feed($url, $http_function = false) {
7272
// using google feed API
7373
$url = "http://ajax.googleapis.com/ajax/services/feed/lookup?key={$this->google_key}&v=1.0&q=".urlencode($url);
74-
// fetch the content
74+
// fetch the content
7575
if ($http_function)
7676
$response = $http_function($url);
7777
else
@@ -81,7 +81,7 @@ public function find_feed($url, $http_function = false) {
8181
$rss_url = $result['responseData']['url'];
8282
return $rss_url;
8383
}
84-
84+
8585
/**
8686
* @param string $topic_url
8787
* @param callable $http_function
@@ -90,7 +90,7 @@ public function find_feed($url, $http_function = false) {
9090
public function subscribe($topic_url, $http_function = false) {
9191
return $this->change_subscription("subscribe", $topic_url, $http_function = false);
9292
}
93-
93+
9494
/**
9595
* @param string $topic_url
9696
* @param callable $http_function
@@ -102,7 +102,7 @@ public function unsubscribe($topic_url, $http_function = false) {
102102

103103
/**
104104
* helper function since sub/unsub are handled the same way
105-
*
105+
*
106106
* @param string $mode
107107
* @param string $topic_url
108108
* @param callable $http_function
@@ -111,61 +111,61 @@ public function unsubscribe($topic_url, $http_function = false) {
111111
private function change_subscription($mode, $topic_url, $http_function = false) {
112112
if (!isset($topic_url))
113113
throw new Exception('Please specify a topic url');
114-
115-
// lightweight check that we're actually working w/ a valid url
116-
if (!preg_match("|^https?://|i",$topic_url))
114+
115+
// lightweight check that we're actually working w/ a valid url
116+
if (!preg_match("|^https?://|i",$topic_url))
117117
throw new Exception('The specified topic url does not appear to be valid: '.$topic_url);
118-
118+
119119
// set the mode subscribe/unsubscribe
120120
$post_string = "hub.mode=".$mode;
121121
$post_string .= "&hub.callback=".urlencode($this->callback_url);
122122
$post_string .= "&hub.verify=".$this->verify;
123123
$post_string .= "&hub.verify_token=".$this->verify_token;
124124
$post_string .= "&hub.lease_seconds=".$this->lease_seconds;
125-
125+
126126
// append the topic url parameters
127127
$post_string .= "&hub.topic=".urlencode($topic_url);
128-
128+
129129
// make the http post request and return true/false
130130
// easy to over-write to use your own http function
131131
if ($http_function)
132132
return $http_function($this->hub_url,$post_string);
133133
else
134134
return $this->http($this->hub_url,$post_string);
135135
}
136-
136+
137137
/**
138138
* default http function that uses curl to post to the hub endpoint
139-
*
139+
*
140140
* @param string $url
141141
* @param string $post_string
142142
* @return mixed
143143
*/
144144
private function http($url, $post_string) {
145-
145+
146146
// add any additional curl options here
147147
$options = array(CURLOPT_URL => $url,
148-
CURLOPT_USERAGENT => "PubSubHubbub-Subscriber-PHP/1.0",
149-
CURLOPT_RETURNTRANSFER => true);
150-
148+
CURLOPT_USERAGENT => "PubSubHubbub-Subscriber-PHP/1.0",
149+
CURLOPT_RETURNTRANSFER => true);
150+
151151
if ($post_string) {
152152
$options[CURLOPT_POST] = true;
153153
$options[CURLOPT_POSTFIELDS] = $post_string;
154154
}
155-
155+
156156
if ($this->credentials)
157157
$options[CURLOPT_USERPWD] = $this->credentials;
158158

159-
$ch = curl_init();
160-
curl_setopt_array($ch, $options);
159+
$ch = curl_init();
160+
curl_setopt_array($ch, $options);
161161

162162
$response = curl_exec($ch);
163163
$info = curl_getinfo($ch);
164-
165-
// all good -- anything in the 200 range
164+
165+
// all good -- anything in the 200 range
166166
if (substr($info['http_code'],0,1) == "2") {
167167
return $response;
168168
}
169-
return false;
169+
return false;
170170
}
171171
}

0 commit comments

Comments
 (0)