Commit 105ecaf4 authored by Dave Lane's avatar Dave Lane
Browse files

fixed problem with sometimes not finding feeds in 'common places' - mostly...

fixed problem with sometimes not finding feeds in 'common places' - mostly because I'd forgot to finish implementing it. Also addressed #2, I think, and a problem where the URL sometimes had a final / and sometimes not.
parent 61bdc2a7
......@@ -7,7 +7,7 @@ Plugin Name: Blog Feed Finder
Plugin URI: https://github.com/oeru/bff
Description: Provides a widget that helps a user figure out the valid URL for
their personal course blog feed
Version: 1.0.0
Version: 1.0.1
Author: Dave Lane
Author URI: https://oeru.org, http://WikiEducator.org/User:Davelane
License: AGPLv3 or later
......@@ -30,7 +30,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
define( 'BFF_VERSION', '1.0.0' );
define( 'BFF_VERSION', '1.0.1' );
// plugin computer name
define('BFF_NAME', 'BFF');
// current version
......
......@@ -32,17 +32,22 @@ abstract class BFFFeed extends BFFResponse {
// construct the array that gets sent back to the user
public function ajaxfeeds() {
if (count($this->feeds)) {
$this->response['feeds'] = $this->feeds;
$this->response['feed_types'] = $this->feed_types;
$this->response['feed_classes'] = $this->feed_classes;
//$this->response['feeds_msg'] = $this->list_feeds();
if (count($this->feeds) == 1) {
$this->response['feed_selected'] = true;
if (is_array($this->feeds)) {
if (count($this->feeds)) {
$this->response['feeds'] = $this->feeds;
$this->response['feed_types'] = $this->feed_types;
$this->response['feed_classes'] = $this->feed_classes;
//$this->response['feeds_msg'] = $this->list_feeds();
if (count($this->feeds) == 1) {
$this->response['feed_selected'] = true;
}
$this->response['feed_found'] = true;
} else {
$this->log('no feeds found!');
$this->response['feed_found'] = false;
}
$this->response['feed_found'] = true;
} else {
$this->response['feed_found'] = false;
$this->log('nothing found, feed-wise!');
}
// add the response object details
$this->ajaxresponse();
......
......@@ -211,9 +211,35 @@ abstract class BFFFinder extends BFFFeed {
// check and see if there are any references to feeds in the content of the page
public function find_feed_in_usual_places($url) {
$this->log('checking the page of '.$url.' to look for feed references.');
$this->log('checking "usual places" under '.$url.' to look for feed references.');
foreach($this->usual_places as $place) {
$this->log('testing '.$url.'/'.$place.' for a valid feed');
// make sure the url ends with exactly one / - if not add one)
$url = $path = rtrim($url, '/') . '/';
// create the full url with path
$full_url = $url.$place;
$this->log('testing '.$full_url.' for a valid feed');
$headers = @get_headers($full_url);
if ($headers){
$this->log('looks like we found something! Returns: '.
print_r($headers, true));
$this->set_content_type($headers);
switch ($headers[0]) {
case 'HTTP/1.0 200 OK':
case 'HTTP/1.1 200 OK':
$this->log('Yay! Found a valid url: '.$full_url.'... now, to find out what type...');
// now check the type
if ($type = $this->test_feed($full_url)) {
$this->log('The feed at '.$full_url.' is of type '.$type);
$this->set_response(true, $url, $place, '200', '', 'Yay! We found a feed of type '.$type.' in one of the usual places feeds are found!',
'"'.$full_url.'" found. It is a valid address and a valid feed of type '.$type.'!', 'good');
$this->add_feed($full_url, $type);
return true;
}
break;
}
} else {
$this->log('no headers returned');
}
}
return false;
}
......@@ -272,6 +298,7 @@ abstract class BFFFinder extends BFFFeed {
$this->add_message('We completed your address by adding http:// to the front.','We\'ve added an http:// \'scheme\' to your address - a valid scheme is a necessary part of a web address', 'neutral');
//$parts = parse_url('http://'.$parts['host'].$parts['path']);
$url = 'http://'.$orig;
$this->log('the new url = '.$url);
$parts = parse_url(strtolower(trim($url)));
$this->log('re-checking blog_url: '. print_r($parts, true));
} else {
......@@ -307,8 +334,9 @@ abstract class BFFFinder extends BFFFeed {
case 'HTTP/1.0 200 OK':
case 'HTTP/1.1 200 OK':
$this->log('Yay! Returning valid url: '.$url);
$this->set_response(true, $orig, $path, '200', '', 'Ok, we\'ve verified the web address you entered points to a real site.',
'"'.$orig.'" found. It is a valid address!', 'good');
$redirect = ($url != $orig) ? $url : '';
$this->set_response(true, $url, $path, '200', $redirect, 'Ok, we\'ve verified the web address you entered points to a real site.',
'"'.$url.'" found. It is a valid address!', 'good');
break;
case 'HTTP/1.0 301 Moved Permanently':
case 'HTTP/1.1 301 Moved Permanently':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment