forked from argoproject/Argo
-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from seamusleahy/feature/feed-consumer
Posts from RSS
- Loading branch information
Showing
8 changed files
with
875 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.