dispatch = NULL;
if ( is_null( $filename ) ) :
$this->filename = __FILE__;
else :
$this->filename = $filename;
endif;
} /* FeedWordPressSyndicationPage constructor */
/**
* Stub function to comply with parent class.
*
* @return bool Always returns FALSE in this class.
*/
function has_link()
{
return false;
} /* FeedWordPressSyndicationPage::has_link() */
/** @var array|null List of sources which gets initialised by $this->sources('Y') if it's still NULL */
var $_sources = NULL;
/**
* Builds _sources (list of visible or invisible links to sources of syndicated links)
* or returns existing _sources if it's already built.
*
* @param string $visibility Unknown flag which toggles source visibility
*
* @return array Constructed list of visible/invisible sources
*
* @uses FeedWordPress::syndicated_links()
*
*/
function sources( $visibility = 'Y' )
{
if ( is_null( $this->_sources) ) :
$links = FeedWordPress::syndicated_links( array( "hide_invisible" => false ) );
$this->_sources = array( "Y" => array(), "N" => array() );
foreach ( $links as $link ) :
$this->_sources[$link->link_visible][] = $link;
endforeach;
endif;
$ret = (
array_key_exists( $visibility, $this->_sources )
? $this->_sources[$visibility]
: $this->_sources
);
return $ret;
} /* FeedWordPressSyndicationPage::sources() */
/**
* Toggles source visibility, using the side-effect of pseudo-getter $this->sources(...) method-
*
* @return string
*
* @uses FeedWordPress::param()
*/
function visibility_toggle()
{
$sources = $this->sources( '*' ); // return value unnecessary, it seems the code is just using the side-effect of initialising $this->_sources if it's uninitialised. (gwyneth 20230916)
$defaultVisibility = 'Y';
if ( ( count( $this->sources( 'N' ) ) > 0 )
and ( count( $this->sources( 'Y' ) ) == 0 ) ) :
$defaultVisibility = 'N';
endif;
// this may be output into HTML, and it should really only ever be Y or N...
$sVisibility = FeedWordPress::param( 'visibility', 'REQUEST', $defaultVisibility );
// Ensure $sVisibility is treated as a string
$sVisibility = (string) $sVisibility;
// Apply preg_replace to remove unwanted characters
$visibility = preg_replace('/[^YyNn]+/', '', $sVisibility);
// If preg_replace fails or returns null, ensure $visibility is an empty string
$visibility = $visibility !== null ? $visibility : '';
return ( strlen( $visibility ) > 0 ? $visibility : $defaultVisibility );
} /* FeedWordPressSyndicationPage::visibility_toggle() */
/**
* Shows source feeds that are currently not visible.
*
* @return string
*/
function show_inactive()
{
return ( 'N' == $this->visibility_toggle() );
}
/**
* sanitize_ids: Protect id numbers from untrusted sources (POST array etc.)
* from possibility of SQLi attacks. Runs everything through an intval filter
* and then for good measure through esc_sql()
*
* @param array $link_ids An array of one or more putative link IDs
* @return array
*/
public function sanitize_ids_sql( $link_ids ) {
$link_ids = array_map(
'esc_sql',
array_map(
'intval',
$link_ids
)
);
return $link_ids;
} /* FeedWordPressSyndicationPage::sanitize_ids_sql () */
/**
* requested_link_ids_sql()
*
* @return string An SQL list literal containing the link IDs, sanitized
* and escaped for direct use in MySQL queries.
*
* @uses sanitize_ids_sql()
* @uses sanitize_text_field()
* @uses MyPHP::post()
* @uses MyPHP::request()
* @uses FeedWordPress::post()
*/
public function requested_link_ids_sql()
{
// Multiple link IDs passed in link_ids[]=...
$link_ids = array_map(
'sanitize_text_field',
(array) MyPHP::request( 'link_ids', array() )
);
// Or single in link_id=...
if ( ! is_null( MyPHP::request( 'link_id' ) ) ) :
array_push( $link_ids, sanitize_text_field( MyPHP::request( 'link_id' ) ) );
endif;
// Now use method to sanitize for safe use in MySQL queries.
$link_ids = $this->sanitize_ids_sql( $link_ids );
// Convert to MySQL list literal.
return "('" . implode( "', '", $link_ids ) . "')";
} /* FeedWordPressSyndicationPage::requested_link_ids_sql () */
/**
* Returns the list of requested updates.
*
* @return array List of requested updates
*
* @uses MyPHP::post()
* @uses MyPHP::request()
* @uses FeedWordPress::post()
* @uses FeedWordPressDiagnostic::critical_bug()
*/
function updates_requested()
{
global $wpdb;
if ( FeedWordPress::post( 'update' ) || FeedWordPress::post( 'action' ) || FeedWordPress::post( 'update_uri' ) ) :
// Only do things with side-effects for HTTP POST or command line
$fwp_update_invoke = 'post';
else :
$fwp_update_invoke = 'get';
endif;
$update_set = array();
if ( $fwp_update_invoke != 'get' ) :
if ( is_array( MyPHP::post( 'link_ids' ) )
and ( MyPHP::post( 'action' ) == FWP_UPDATE_CHECKED ) ) :
// Get single link ID or multiple link IDs from REQUEST parameters
// if available. Sanitize values for MySQL.
$link_list = $this->requested_link_ids_sql();
// $link_list has previously been sanitized for html by self::requested_link_ids_sql
$targets = $wpdb->get_results("
SELECT * FROM $wpdb->links
WHERE link_id IN {$link_list}
");
if ( is_array( $targets ) ) :
foreach ($targets as $target) :
$update_set[] = $target->link_rss;
endforeach;
else : // This should never happen
FeedWordPressDiagnostic::critical_bug( 'fwp_syndication_manage_page::targets', $targets, __LINE__, __FILE__ );
endif;
elseif ( !is_null( FeedWordPress::post( 'update_uri' ) ) ) :
$targets = FeedWordPress::post( 'update_uri' );
if ( !is_array( $targets ) ) :
$targets = array( $targets );
endif;
$targets_keys = array_keys( $targets );
$first_key = reset( $targets_keys );
if ( !is_numeric( $first_key) ) : // URLs in keys
$targets = $targets_keys;
endif;
$update_set = $targets;
endif;
endif;
return $update_set;
}
/**
* Cancels the request.
*
* @return bool Success
*
* @uses FeedWordPress::post()
*/
public function cancel_requested()
{
$cancel = FeedWordPress::post( 'cancel' );
return ( $cancel === __( FWP_CANCEL_BUTTON ) );
}
/**
* Adds multiple requests.
*
* @return bool Success
*
* @uses FeedWordPress::post()
*/
public function multiadd_requested()
{
$multiadd = FeedWordPress::post( 'multiadd' );
return ( $multiadd === FWP_SYNDICATE_NEW );
}
/**
* Confirms that multiple requests were added.
*
* @return bool Success
*
* @uses FeedWordPress::post()
*/
public function multiadd_confirm_requested()
{
$confirm = FeedWordPress::post( 'confirm' );
return ( $confirm === 'multiadd' );
}
/**
* Accepts multiple requests that were added.
*
* @return bool Always true
*
* @uses FeedWordPress::post()
* @uses FeedWordPress::syndicate_link()
* @uses FeedWordPressCompatibility::validate_http_request()
*/
function accept_multiadd()
{
if ( $this->cancel_requested() ) :
return true; // Continue ....
endif;
// If this is a POST, validate source and user credentials
FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');
$in = FeedWordPress::post( 'multilookup', '' )
. FeedWordPress::post( 'opml_lookup', '' );
if ( $this->multiadd_confirm_requested() ) :
$chex = FeedWordPress::post( 'multilookup' );
$added = array(); $errors = array();
foreach ( $chex as $feed ) :
if ( isset( $feed['add'] ) and $feed['add'] == 'yes' ) :
// Then, add in the URL.
$link_id = FeedWordPress::syndicate_link(
$feed['title'],
$feed['link'],
$feed['url']
);
if ( !empty( $link_id ) and !is_wp_error( $link_id ) ):
$added[] = $link_id;
else :
$errors[] = array( $feed['url'], $link_id );
endif;
endif;
endforeach;
print "
\n";
print "
Added " . count( $added ) . " new syndicated sources.
";
if ( count( $errors ) > 0 ) :
print "
FeedWordPress encountered errors trying to add the following sources:
\n";
foreach ($errors as $err) :
$url = $err[0];
$short = feedwordpress_display_url($url);
printf(
'%s ',
esc_url( $url ),
esc_html( $short )
);
if ( is_wp_error( $err[1] ) ) :
$error = $err[1];
printf( ' (%s)', esc_html( $error->get_error_messages() ) );
endif;
print " \n";
endforeach;
print " \n";
endif;
print "
\n";
elseif ( is_array( $in ) or strlen( $in ) > 0 ) :
add_meta_box(
/*id=*/ 'feedwordpress_multiadd_box',
/*title=*/ __( 'Add Feeds' ),
/*callback=*/ array( $this, 'multiadd_box' ),
/*page=*/ $this->meta_box_context(),
/*context =*/ $this->meta_box_context()
);
endif;
return true; // Continue...
}
/**
* Emits HTML for multiple added lines.
*
* @param array $line Line item to be displayed.
*/
function display_multiadd_line( $line )
{
$short_feed = feedwordpress_display_url( $line['feed'] );
$feed = $line['feed'];
$link = $line['link'];
$title = $line['title'];
$i = $line['i'];
print " 0 ) :
print ' checked="checked" ';
endif;
print "/> " . esc_html( $title ) . " · " . esc_html( $short_feed ) . " ";
if ( isset( $line['extra']) ) :
print " · " . esc_html( $line['extra'] );
endif;
print
"
\n";
flush();
}
/**
* Emits HTML for the box that allows adding multiple sources.
*
* @param int $page Unknown and unused.
* @param string|null $box Unknown and unused.
*
* @return bool Always true
*
* @uses file_get_contents()
* @uses FeedFinder
* @uses FeedWordPress::fetch()
* @uses FeedWordPress::post()
* @uses FeedWordPressCompatibility::stamp_nonce()
*/
function multiadd_box($page, $box = NULL)
{
$localData = NULL;
if ( isset( $_FILES['opml_upload']['name'] )
and ( strlen( $_FILES['opml_upload']['name'] ) > 0 ) ) :
$in = 'tag:localhost';
/*FIXME: check whether $_FILES['opml_upload']['error'] === UPLOAD_ERR_OK or not...*/
$localData = file_get_contents( $_FILES['opml_upload']['tmp_name'] );
$merge_all = true;
elseif ( ! is_null( FeedWordPress::post( 'multilookup' ) ) ) :
$in = FeedWordPress::post( 'multilookup' );
$merge_all = false;
elseif ( ! is_null( FeedWordPress::post( 'opml_lookup' ) ) ) :
$in = FeedWordPress::post( 'opml_lookup' );
$merge_all = true;
else :
$in = '';
$merge_all = false;
endif;
if ( strlen( $in ) > 0 ) :
$lines = preg_split(
"/\s+/",
$in,
/*no limit soldier*/ -1,
PREG_SPLIT_NO_EMPTY
);
$i = 0;
?>
_sources = NULL; // Force reload of sources list
return true; // Continue
}
/**
* Displays the main syndication page.
*
* @uses FeedWordPress::needs_upgrade()
* @uses FeedWordPress::param()
*/
function display()
{
if ( FeedWordPress::needs_upgrade() ) :
fwp_upgrade_page();
return;
endif;
$cont = true;
$dispatcher = array(
"feedfinder" => 'feedfinder_page',
FWP_SYNDICATE_NEW => 'feedfinder_page',
"switchfeed" => 'switchfeed_page',
FWP_UNSUB_CHECKED => 'multidelete_page',
FWP_DELETE_CHECKED => 'multidelete_page',
'Unsubscribe' => 'multidelete_page',
FWP_RESUB_CHECKED => 'multiundelete_page',
);
$act = FeedWordPress::param( 'action' );
if ( isset( $dispatcher[ $act ] ) ) :
$method = $dispatcher[ $act ];
if ( method_exists( $this, $method ) ) :
$cont = $this->{$method}();
else :
$cont = call_user_func( $method );
endif;
elseif ( $this->multiadd_requested() ) :
$cont = $this->accept_multiadd();
endif;
if ( $cont ) :
$links = $this->sources( 'Y' ); // side-effect of getting _sources instantiated... (gwyneth 20230916)
$potential_updates = ( ! $this->show_inactive() and ( count( $this->sources( 'Y' ) ) > 0 ) );
$this->open_sheet( 'Syndicated Sites' );
?>
updates_requested() ) > 0 ) ) :
add_meta_box(
/*id=*/ 'feedwordpress_update_box',
/*title=*/ __( 'Update feeds now' ),
/*callback=*/ 'fwp_syndication_manage_page_update_box',
/*page=*/ $this->meta_box_context(),
/*context =*/ $this->meta_box_context()
);
endif;
add_meta_box(
/*id=*/ 'feedwordpress_feeds_box',
/*title=*/ __( 'Syndicated sources' ),
/*callback=*/ array( $this, 'syndicated_sources_box' ),
/*page=*/ $this->meta_box_context(),
/*context =*/ $this->meta_box_context()
);
do_action( 'feedwordpress_admin_page_syndication_meta_boxes', $this );
?>
meta_box_context(), $this->meta_box_context(), $this );
?>
close_sheet( /*dispatch=*/ NULL ); ?>
false ) ); // what is $links for? (gwyneth 20230916)
$sources = $this->sources( '*' ); // uses side-effects to initialise _sources (gwyneth 20230916)
/** @var string what is this used for? (gwyneth 20230915) */
$visibility = 'Y';
$hrefPrefix = $this->form_action();
$activeHref = $hrefPrefix . '&visibility=' . $visibility;
$inactiveHref = $hrefPrefix . '&visibility=N';
$lastUpdate = get_option( 'feedwordpress_last_update_all', NULL );
$automatic_updates = get_option( 'feedwordpress_automatic_updates', NULL );
/** @var string default value set here, to avoid having a else clause, but also to init the variable in the right scope. (gwyneth 20230915) */
$update_setting = __( 'using a cron job or manual check-ins' );
if ( 'init' == $automatic_updates ) :
$update_setting = __( 'automatically before page loads' );
elseif ( 'shutdown' == $automatic_updates ) :
$update_setting = __( 'automatically after page loads' );
endif;
// Hey ho, let's go...
?>
FeedWordPress
.
.
false)); // what is $links for? (gwyneth 20230916)
$sources = $this->sources('*');
$visibility = $this->visibility_toggle();
$showInactive = $this->show_inactive();
$hrefPrefix = $this->form_action();
$formHref = sprintf( '%s&visibility=%s', $hrefPrefix, urlencode($visibility) );
?>
0) :
$this->manage_page_links_subsubsub($sources, $showInactive);
endif;
?>
0) :
$this->display_button_bar($showInactive);
else :
$this->manage_page_links_subsubsub($sources, $showInactive);
endif;
fwp_syndication_manage_page_links_table_rows($sources[$visibility], $this, $visibility);
$this->display_button_bar($showInactive);
?>
admin_page_href( "syndication.php" );
$hrefY = sprintf( "%s&visibility=%s", $hrefPrefix, "Y" );
$hrefN = sprintf( "%s&visibility=%s", $hrefPrefix, "N" );
?>
requested_link_ids_sql();
if (MyPHP::post('confirm')=='Delete'):
$actions = array(); // avoids "else" complaint _and_ guarantees that we don't have any scoping issues (gwyneth 20230916)
if ( is_array(MyPHP::post('link_action')) ) :
$actions = MyPHP::post('link_action');
endif;
$do_it = array(
'hide' => array(),
'nuke' => array(),
'delete' => array(),
);
foreach ($actions as $link_id => $what) :
$do_it[$what][] = $link_id;
endforeach;
$alter = array();
if (count($do_it['hide']) > 0) :
$hidem = "(".implode(', ', $do_it['hide']).")";
$alter[] = "
UPDATE $wpdb->links
SET link_visible = 'N'
WHERE link_id IN {$hidem}
";
endif;
if (count($do_it['nuke']) > 0) :
$nukem = "(".implode(', ', $do_it['nuke']).")";
// Make a list of the items syndicated from this feed...
$post_ids = $wpdb->get_col("
SELECT post_id FROM $wpdb->postmeta
WHERE meta_key = 'syndication_feed_id'
AND meta_value IN {$nukem}
");
// ... and kill them all
if (count($post_ids) > 0) :
foreach ($post_ids as $post_id) :
// Force scrubbing of deleted post
// rather than sending to Trashcan
wp_delete_post(
/*postid=*/ $post_id,
/*force_delete=*/ true
);
endforeach;
endif;
$alter[] = "
DELETE FROM $wpdb->links
WHERE link_id IN {$nukem}
";
endif;
if (count($do_it['delete']) > 0) :
$deletem = "(".implode(', ', $do_it['delete']).")";
// Make the items syndicated from this feed appear to be locally-authored
$alter[] = "
DELETE FROM $wpdb->postmeta
WHERE meta_key = 'syndication_feed_id'
AND meta_value IN {$deletem}
";
// ... and delete the links themselves.
$alter[] = "
DELETE FROM $wpdb->links
WHERE link_id IN {$deletem}
";
endif;
$errs = array();
foreach ($alter as $sql) :
$result = $wpdb->query($sql);
if ( ! $result):
$errs[] = $wpdb->last_error;
endif;
endforeach;
if (count($alter) > 0) :
echo "\n";
if (count($errs) > 0) :
echo "There were some problems processing your unsubscribe request. [SQL: ";
$sep = '';
foreach ( $errs as $err ) :
print esc_html($sep);
print esc_html($err);
$sep = '; ';
endforeach;
echo "]";
else :
echo "Your unsubscribe request(s) have been processed.";
endif;
echo "
\n";
endif;
return true; // Continue on to Syndicated Sites listing
else :
// $link_list has previously been sanitized for html by self::requested_link_ids_sql
$targets = $wpdb->get_results("
SELECT * FROM $wpdb->links
WHERE link_id IN {$link_list}
");
?>
requested_link_ids_sql();
if (MyPHP::post('confirm')=='Undelete'):
if ( is_array(MyPHP::post('link_action')) ) :
$actions = MyPHP::post('link_action');
else :
$actions = array();
endif;
$do_it = array(
'unhide' => array(),
);
foreach ($actions as $link_id => $what) :
$do_it[$what][] = $link_id;
endforeach;
$alter = array();
if (count($do_it['unhide']) > 0) :
$unhiddem = "(".implode(', ', $do_it['unhide']).")";
$alter[] = "
UPDATE $wpdb->links
SET link_visible = 'Y'
WHERE link_id IN {$unhiddem}
";
endif;
$errs = array();
foreach ($alter as $sql) :
$result = $wpdb->query($sql);
if ( ! $result):
$errs[] = $wpdb->last_error;
endif;
endforeach;
if (count($alter) > 0) :
echo "\n";
if (count($errs) > 0) :
esc_html_e( 'There were some problems processing your re-subscribe request. ' );
echo esc_html( "[SQL: ".implode('; ', $errs)."]" );
else :
esc_html_e( 'Your re-subscribe request(s) have been processed.' );
endif;
echo "
\n";
endif;
return true; // Continue on to Syndicated Sites listing
else :
// $link_list has previously been sanitized for html by self::requested_link_ids_sql
$targets = $wpdb->get_results("
SELECT * FROM $wpdb->links
WHERE link_id IN {$link_list}
");
?>
admin_page_href( 'feeds-page.php', array( "link_id" => $link_id ) );
?>
set_uri($feed);
if ($changed):
$home = $existingLink->homepage(/*from feed=*/ false);
$name = $existingLink->name(/*from feed=*/ false);
?>
0) and ($auth != '-')) :
$existingLink->update_setting('http auth method', $auth);
$existingLink->update_setting('http username',
FeedWordPress::post('link_rss_username')
);
$existingLink->update_setting('http password',
FeedWordPress::post('link_rss_password')
);
else :
$existingLink->update_setting('http auth method', NULL);
$existingLink->update_setting('http username', NULL);
$existingLink->update_setting('http password', NULL);
endif;
do_action('feedwordpress_admin_switchfeed', FeedWordPress::post( 'feed' ), $existingLink);
$existingLink->save_settings(/*reload=*/ true);
endif;
if ( ! $changed) :
?>
accept_multiadd();
return true;
else :
$post_source = 'feedwordpress_feeds';
// With action=feedfinder, this goes directly to the feedfinder page
include_once(dirname(__FILE__) . '/feeds-page.php');
return false;
endif;
} /* function feedfinder_page () */
} /* class FeedWordPressSyndicationPage */
function fwp_dashboard_update_if_requested ($object) {
global $crash_dt;
$update_set = $object->updates_requested();
if (count($update_set) > 0) :
shuffle($update_set); // randomize order for load balancing purposes...
$feedwordpress = new FeedWordPress;
add_action('feedwordpress_check_feed', 'update_feeds_mention');
add_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3);
$crash_ts = $feedwordpress->crash_ts();
echo "\n";
echo "
\n";
$tdelta = NULL;
foreach ($update_set as $uri) :
if ( !is_null($crash_ts) and (time() > $crash_ts)) :
echo "" . esc_html__( "Further updates postponed:" ) . " "
. esc_html__( "update time limit of " ) . esc_html( $crash_dt ) . esc_html__( " second"
. ( ( 1 == $crash_dt ) ? "" : "s" ) ) . esc_html__( " exceeded." ) . "
";
break;
endif;
if ($uri == '*') : $uri = NULL; endif;
$delta = $feedwordpress->update($uri, $crash_ts);
if ( !is_null($delta)) :
if (is_null($tdelta)) :
$tdelta = $delta;
else :
$tdelta['new'] += $delta['new'];
$tdelta['updated'] += $delta['updated'];
endif;
else :
$display_uri = esc_html(feedwordpress_display_url($uri));
$uri = esc_html($uri);
echo '' . esc_html__( "Error:" ) . " ". esc_html__( 'There was a problem updating ' )
. '' . esc_html( $display_uri ) . '
' . "\n";
endif;
endforeach;
echo " \n";
if ( !is_null($tdelta)) :
echo '
'; esc_html_e( 'Update complete.' ); echo ' '; print esc_html( fwp_update_set_results_message($delta) ); print '
';
echo "\n"; flush();
endif;
echo "
\n";
endif;
}
define('FEEDWORDPRESS_BLEG_MAYBE_LATER_OFFSET', (60 /*sec/min*/ * 60 /*min/hour*/ * 24 /*hour/day*/ * 31 /*days*/));
define('FEEDWORDPRESS_BLEG_ALREADY_PAID_OFFSET', (60 /*sec/min*/ * 60 /*min/hour*/ * 24 /*hour/day*/ * 183 /*days*/));
function fwp_syndication_manage_page_update_box ($object = NULL, $box = NULL) {
$bleg_box_hidden = null;
if ( FeedWordPress::post( 'maybe_later' ) ) :
$bleg_box_hidden = time() + FEEDWORDPRESS_BLEG_MAYBE_LATER_OFFSET;
elseif ( FeedWordPress::post( 'paid' ) ) :
$bleg_box_hidden = time() + FEEDWORDPRESS_BLEG_ALREADY_PAID_OFFSET;
elseif ( FeedWordPress::post( 'go_away' ) ) :
$bleg_box_hidden = 'permanent';
endif;
if ( !is_null($bleg_box_hidden)) :
update_option('feedwordpress_bleg_box_hidden', $bleg_box_hidden);
else :
$bleg_box_hidden = get_option('feedwordpress_bleg_box_hidden');
endif;
?>
bleg_thanks($object, $box);
elseif ($bleg_box_ready || ( FeedWordPress::param( 'test' ) == 'bleg' ) ) :
$object->bleg_box($object, $box);
endif;
?>
off. New posts from your feeds will not be syndicated
until you manually check for them here. You can turn on automatic
updates under' ); ?> .
show_inactive()) : ?>
updates_requested() as $req) : ?>