Skip to content

Commit

Permalink
Merge pull request #4 from seamusleahy/feature/feed-consumer
Browse files Browse the repository at this point in the history
Posts from RSS
  • Loading branch information
seamusleahy committed Apr 24, 2013
2 parents caa139f + 75b531a commit f785f30
Show file tree
Hide file tree
Showing 8 changed files with 875 additions and 1 deletion.
3 changes: 2 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
'/inc/related-content.php', // functions dealing with related content
'/inc/featured-content.php', // functions dealing with featured content
'/inc/enqueue.php', // enqueue our js and css files
'/inc/post-templates.php' //single post templates
'/inc/post-templates.php', //single post templates
'/inc/feed-input/feed-input.php' // Pull in posts via RSS or Atom feeds
);

// Perform load
Expand Down
28 changes: 28 additions & 0 deletions inc/feed-input/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* The public API functions for Feed Input
*
*/


/**
* Register a feed set to be pulled into
*
* @param string $feed_name - an identify name for the feed set
* @param array $feed_urls - the URLs for the feeds
* @param array $options - the various options for how to handle the feeds
*/
function feedinput_register_feed( $feed_name, $feed_urls, $options=array() ) {
return FeedInput_Manager::register_feed_set( $feed_name, $feed_urls, $options );
}



/**
* Force an update of a feed set instead of waiting for the next cron cycle
*
* @param string $feed_name - the identify name for the feed set
*/
function feedinput_force_update_feed( $feed_name ) {
return FeedInput_Manager::force_update_feedset( $feed_name );
}
21 changes: 21 additions & 0 deletions inc/feed-input/feed-input.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/*
Plugin Name: Feed Input
Plugin URI: http://
Description: Pull RSS and Atom feeds into posts on your WordPress site
Version: 0.1.1
Author: Seamus Leahy
Author URI: http://seamusleahy.com
License: MIT
*/


require_once __DIR__ .'/feedinput_fieldfilters.class.php';
require_once __DIR__ .'/feedinput_feeditem.class.php';
require_once __DIR__ .'/feedinput_feedset.class.php';
require_once __DIR__ .'/feedinput_manager.class.php';
require_once __DIR__ .'/api.php';

require_once __DIR__ . '/feedinput_adminpage.class.php';

//require_once __DIR__ .'/test.php';
125 changes: 125 additions & 0 deletions inc/feed-input/feedinput_adminpage.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php


/**
* Creates the admin UI page
*/
class FeedInput_AdminPage {
var $feed_urls;

function __construct() {
add_action( 'admin_menu', array(&$this, 'admin_menu') );
add_action( 'admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts') );
add_action( 'init', array(&$this, 'register_feedset') );


}


/**
* Add our admin page
*/
function admin_menu() {
$this->hook_suffix = add_options_page('Syndicated Sources','Syndicated Sources','manage_options','syndicated_sources', array($this, 'page_content') );
add_action( 'load-'.$this->hook_suffix, array(&$this, 'process') );
}


/**
* Output the content of the page
*/
function page_content() {
$feed_urls = $this->get_feed_urls();

?>
<div class="wrap">
<h2><?php _e('Syndicated Sources', 'feedinput'); ?></h2>

<form method="POST" action="options-general.php?page=syndicated_sources">
<input type="hidden" name="feedinput" value="1" />
<label for="feed_urls"><?php _e('Feed URLs', 'feedinput'); ?></label>
<p><?php _e('Enter each feed URL on a separate line.', 'feedinput'); ?></p>
<textarea id="feed_urls" name="feed_urls" style="width: 100%" rows="10"><?php echo implode( "\n", $feed_urls ); ?></textarea>

<div>
<button type="submit" class="button-primary"><?php _e('Save'); ?></button>
</div>
</form>
</div>
<?php
}


/**
* Add our JS and CSS for the admin page
*/
function admin_enqueue_scripts( $hook_suffix ) {
if ( $hook_suffix != $this->hook_suffix ) {
return;
}

}


/**
* Attempts to process the form submission
*/
function process() {
$current_screen = get_current_screen();

if ( $current_screen->id == 'settings_page_syndicated_sources' && filter_input(INPUT_POST, 'feedinput', FILTER_VALIDATE_BOOLEAN) ) {
$old_feed_urls = $this->get_feed_urls();

// Get input
$feed_urls_raw = filter_input( INPUT_POST, 'feed_urls', FILTER_SANITIZE_STRING );
$urls = explode( "\n", $feed_urls_raw );
$feed_urls = array();
foreach ( $urls as $url ) {
$url = filter_var( $url, FILTER_SANITIZE_URL );

if ( $url != false ) {
$feed_urls[] = $url;
}
}

// Save the feeds
$this->set_feed_urls( $feed_urls );
$this->register_feedset();

// Check if there are new feeds added, if not then force an initial update
$new_feed_urls = array_diff( $feed_urls, $old_feed_urls );
if ( count( $new_feed_urls ) > 0 ) {
feedinput_force_update_feed( 'feedinput_admin' );
}
}
}


/**
* Init hook
*/
function register_feedset() {
$feed_urls = $this->get_feed_urls();

if ( count( $feed_urls ) > 0 ) {
feedinput_register_feed( 'feedinput_admin', $feed_urls );
}
}


function get_feed_urls() {
if ( !is_array( $this->feed_urls ) ) {
$this->feed_urls = get_option( 'feedinput_feeds', array() );
}
return $this->feed_urls;
}


function set_feed_urls( $feed_urls ) {
$this->feed_urls = $feed_urls;
update_option( 'feedinput_feeds', $feed_urls );
}
}

// Kickoff
new FeedInput_AdminPage;
Loading

0 comments on commit f785f30

Please sign in to comment.