| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 |
|
| 5 |
global $my_link_library_plugin; |
| 6 |
|
| 7 |
function link_library_generate_rss_feed () { |
| 8 |
|
| 9 |
require_once plugin_dir_path( __FILE__ ) . 'rss.genesis.php'; |
| 10 |
|
| 11 |
if ( isset( $_GET['settingsset'] ) && !empty( $_GET['settingsset'] ) ) { |
| 12 |
$settingsetid = intval( $_GET['settingsset'] ); |
| 13 |
} else { |
| 14 |
$settingsetid = 1; |
| 15 |
} |
| 16 |
|
| 17 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 18 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 19 |
|
| 20 |
$settingsname = 'LinkLibraryPP' . $settingsetid; |
| 21 |
$options = get_option( $settingsname ); |
| 22 |
|
| 23 |
$rss = new rssGenesis(); |
| 24 |
|
| 25 |
$feedtitle = ($options['rssfeedtitle'] == "" ? "Link Library Generated Feed" : $options['rssfeedtitle']); |
| 26 |
$feeddescription = ($options['rssfeeddescription'] == "" ? "Link Library Generated Feed Description" : $options['rssfeeddescription']); |
| 27 |
|
| 28 |
// CHANNEL |
| 29 |
$rss->setChannel ( |
| 30 |
$feedtitle, // Title |
| 31 |
home_url () . '/feed/linklibraryfeed?settingsset=' . $settingsetid, // Link |
| 32 |
$feeddescription, // Description |
| 33 |
null, // Language |
| 34 |
null, // Copyright |
| 35 |
null, // Managing Editor |
| 36 |
null, // WebMaster |
| 37 |
null, // Rating |
| 38 |
"auto", // PubDate |
| 39 |
"auto", // Last Build Date |
| 40 |
"Link Library Links", // Category |
| 41 |
null, // Docs |
| 42 |
null, // Time to Live |
| 43 |
null, // Skip Days |
| 44 |
null // Skip Hours |
| 45 |
); |
| 46 |
|
| 47 |
$link_query_args = array( 'post_type' => 'link_library_links', 'posts_per_page' => $options['numberofrssitems'], 'post_status' => 'publish', 'order' => 'DESC' ); |
| 48 |
|
| 49 |
if ( 'updated_date' == $options['rss_item_date_source'] ) { |
| 50 |
$link_query_args['orderby'] = 'meta_value_num'; |
| 51 |
$link_query_args['meta_key'] = 'link_updated'; |
| 52 |
} elseif( 'pub_date' == $options['rss_item_date_source'] ) { |
| 53 |
$link_query_args['orderby'] = 'date'; |
| 54 |
} |
| 55 |
|
| 56 |
if ( $options['showinvisible'] == true ) { |
| 57 |
$link_query_args['post_status'] = array( 'publish', 'private' ); |
| 58 |
} |
| 59 |
|
| 60 |
if ( !empty( $options['categorylist_cpt'] ) ) { |
| 61 |
$link_query_args['tax_query'] = array( |
| 62 |
array( |
| 63 |
'taxonomy' => $genoptions['cattaxonomy'], |
| 64 |
'field' => 'term_id', |
| 65 |
'terms' => explode( ',', $options['categorylist_cpt'] ), |
| 66 |
'operator' => 'IN', |
| 67 |
), |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
if ( !empty( $options['excludecategorylist_cpt'] ) ) { |
| 72 |
if ( !empty( $options['categorylist_cpt'] ) ) { |
| 73 |
$link_query_args['tax_query']['relation'] = 'AND'; |
| 74 |
} |
| 75 |
|
| 76 |
$link_query_args['tax_query'][] = array( |
| 77 |
'taxonomy' => $genoptions['cattaxonomy'], |
| 78 |
'field' => 'term_id', |
| 79 |
'terms' => explode( ',', $options['excludecategorylist_cpt'] ), |
| 80 |
'operator' => 'NOT IN', |
| 81 |
); |
| 82 |
} |
| 83 |
|
| 84 |
$the_link_query = new WP_Query( $link_query_args ); |
| 85 |
|
| 86 |
if ( $the_link_query->have_posts() ) { |
| 87 |
while ( $the_link_query->have_posts() ) { |
| 88 |
$the_link_query->the_post(); |
| 89 |
|
| 90 |
$link_url = get_post_meta( get_the_ID(), 'link_url', true ); |
| 91 |
$link_description = get_post_meta( get_the_ID(), 'link_description', true ); |
| 92 |
|
| 93 |
if ( 'updated_date' == $options['rss_item_date_source'] ) { |
| 94 |
$link_updated = get_post_meta( get_the_ID(), 'link_updated', true ); |
| 95 |
} elseif( 'pub_date' == $options['rss_item_date_source'] ) { |
| 96 |
$link_updated = get_post_time(); |
| 97 |
} |
| 98 |
|
| 99 |
$human_date = date( "Y-m-d H:i", $link_updated ); |
| 100 |
|
| 101 |
$link_categories = wp_get_post_terms( get_the_ID(), $genoptions['cattaxonomy'] ); |
| 102 |
|
| 103 |
$cat_names = ''; |
| 104 |
if ( $link_categories ) { |
| 105 |
$countcats = 0; |
| 106 |
foreach ( $link_categories as $link_category ) { |
| 107 |
if ( $countcats >= 1 ) { |
| 108 |
$cat_names .= ', '; |
| 109 |
} |
| 110 |
$cat_names .= $link_category->name; |
| 111 |
$countcats++; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
if ( !empty( $link_url ) ) { |
| 116 |
// ITEM |
| 117 |
$rss->addItem ( |
| 118 |
get_the_title(), // Title |
| 119 |
$link_url, // Link |
| 120 |
$link_description, // Description |
| 121 |
$human_date, //Publication Date |
| 122 |
$cat_names // Category |
| 123 |
); |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
wp_reset_postdata(); |
| 129 |
|
| 130 |
if ( $options['publishrssfeed'] ) { |
| 131 |
header( 'Content-Type: '. feed_content_type('rss') . '; charset=' . get_option('blog_charset') ); |
| 132 |
print( $rss->getFeed() ); |
| 133 |
} else { |
| 134 |
header( 'Location: ' . home_url() ); |
| 135 |
} |
| 136 |
exit; |
| 137 |
} |