Feed re-enabled

Removed custom feed generation in favor of WPs integrated post_type/taxonomy feed functionality.
This commit is contained in:
Stefan Kalscheuer 2017-12-10 15:19:11 +01:00
parent f10e9c63e0
commit 7b0a512c2b
5 changed files with 72 additions and 111 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -93,6 +93,14 @@ class WPLiveticker2_Admin extends WPLiveticker2 {
'wplt2-settings-page', 'wplt2-settings-page',
'wplt2_settings_general' 'wplt2_settings_general'
); );
add_settings_field(
'show_feed',
__( 'Show RSS feed', 'wplt2' ),
array( 'WPLiveticker2_Admin', 'settings_show_feed_field' ),
'wplt2-settings-page',
'wplt2_settings_general'
);
} }
/** /**
@ -111,21 +119,6 @@ class WPLiveticker2_Admin extends WPLiveticker2 {
public static function settings_uninstall_section() { public static function settings_uninstall_section() {
} }
/**
* Render enable css field.
*
* @return void
*/
public static function settings_enable_css_field() {
$checked = self::$_options['enable_css'];
echo '<label for="' . esc_attr( self::OPTION ) . '[enable_css]">';
echo '<input type="checkbox" name="' . esc_attr( self::OPTION ) . '[enable_css]" value="1" ' . checked( $checked, 1, false ) . ' /> ';
esc_html_e( 'Enable', 'wplt2' );
echo '</label>';
echo '<p class="description">' . esc_html__( 'Disable this option to remove the default styling CSS file.', 'wplt2' ) . '</p>';
}
/** /**
* Render enable AJAX field. * Render enable AJAX field.
* *
@ -156,22 +149,35 @@ class WPLiveticker2_Admin extends WPLiveticker2 {
echo '<p class="description">' . esc_html__( 'Interval (in seconds) to update ticker if AJAX is enabled.', 'wplt2' ) . '</p>'; echo '<p class="description">' . esc_html__( 'Interval (in seconds) to update ticker if AJAX is enabled.', 'wplt2' ) . '</p>';
} }
/** /**
* Render default style field. * Render enable css field.
* *
* @return void * @return void
*/ */
public static function settings_default_style_field() { public static function settings_enable_css_field() {
$styles = wplt_get_shortcode_styles(); $checked = self::$_options['enable_css'];
$default_style = self::$_options['default_style'];
echo '<select name="simple-downloads[default_style]">'; echo '<label for="' . esc_attr( self::OPTION ) . '[enable_css]">';
foreach ( $styles as $key => $value ) { echo '<input type="checkbox" name="' . esc_attr( self::OPTION ) . '[enable_css]" value="1" ' . checked( $checked, 1, false ) . ' /> ';
$selected = ( $default_style === $key ? ' selected="selected"' : '' ); esc_html_e( 'Enable', 'wplt2' );
echo '<option value="' . esc_attr( $key ) . '" ' . esc_attr( $selected ) . '>' . esc_html( $value ) . '</option>'; echo '</label>';
echo '<p class="description">' . esc_html__( 'Disable this option to remove the default styling CSS file.', 'wplt2' ) . '</p>';
} }
echo '</select>';
echo '<p class="description">' . esc_html__( 'The default display style.', 'wplt2' ) . '</p>'; /**
* Render enable css field.
*
* @return void
*/
public static function settings_show_feed_field() {
$checked = self::$_options['show_feed'];
echo '<label for="' . esc_attr( self::OPTION ) . '[show_feed]">';
echo '<input type="checkbox" name="' . esc_attr( self::OPTION ) . '[show_feed]" value="1" ' . checked( $checked, 1, false ) . ' /> ';
esc_html_e( 'Enable', 'wplt2' );
echo '</label>';
echo '<p class="description">' . esc_html__( 'Can be overwritten in shortcode.', 'wplt2' ) . '</p>';
} }
/** /**

View File

@ -144,12 +144,14 @@ class WPLiveticker2 {
'menu_name' => __( 'Liveticker', 'wplt2' ), 'menu_name' => __( 'Liveticker', 'wplt2' ),
), ),
'public' => false, 'public' => false,
'publicly_queryable' => true,
'show_ui' => true, 'show_ui' => true,
'show_in_menu' => true, 'show_in_menu' => true,
'menu_icon' => 'dashicons-rss', 'menu_icon' => 'dashicons-rss',
'capability_type' => 'post', 'capability_type' => 'post',
'supports' => array( 'title', 'editor', 'author' ), 'supports' => array( 'title', 'editor', 'author' ),
'taxonomies' => array( 'wplt2_ticker' ), 'taxonomies' => array( 'wplt2_ticker' ),
'has_archive' => true,
); );
register_post_type( 'wplt2_tick', $args ); register_post_type( 'wplt2_tick', $args );
@ -170,29 +172,39 @@ class WPLiveticker2 {
$output = ''; $output = '';
// Check if first attribute is filled. // Check if first attribute is filled.
if ( $atts['ticker'] ) { if ( ! empty( $atts['ticker'] ) ) {
$ticker = sanitize_text_field( $atts['ticker'] );
// Set limit to infinite, if not set explicitly. // Set limit to infinite, if not set explicitly.
if ( ! isset( $atts['limit'] ) ) { if ( ! isset( $atts['limit'] ) ) {
$atts['limit'] = - 1; $atts['limit'] = - 1;
} }
$limit = intval( $atts['limit'] );
// Determine if feed link should be shown.
if ( isset( $atts['feed'] ) ) {
$show_feed = 'true' === strtolower( $atts['feed'] ) || '1' === $atts['feed'];
} else {
$show_feed = 1 === self::$_options['show_feed'];
}
$output = '<ul class="wplt2-ticker'; $output = '<ul class="wplt2-ticker';
if ( 1 === self::$_options['enable_ajax'] ) { if ( 1 === self::$_options['enable_ajax'] ) {
$output .= ' wplt2-ticker-ajax" ' $output .= ' wplt2-ticker-ajax" '
. 'data-wplt2-ticker="' . $atts['ticker'] . '" ' . 'data-wplt2-ticker="' . $ticker . '" '
. 'data-wplt2-limit="' . $atts['limit'] . '" ' . 'data-wplt2-limit="' . $limit . '" '
. 'data-wplt2-last="' . time(); . 'data-wplt2-last="' . time();
} }
$output .= '">'; $output .= '">';
$args = array( $args = array(
'post_type' => 'wplt2_tick', 'post_type' => 'wplt2_tick',
'posts_per_page' => $atts['limit'], 'posts_per_page' => $limit,
'tax_query' => array( 'tax_query' => array(
array( array(
'taxonomy' => 'wplt2_ticker', 'taxonomy' => 'wplt2_ticker',
'field' => 'slug', 'field' => 'slug',
'terms' => $atts['ticker'], 'terms' => $ticker,
), ),
), ),
); );
@ -207,9 +219,15 @@ class WPLiveticker2 {
$output .= '</ul>'; $output .= '</ul>';
// Show RSS feed link, if configured. // Show RSS feed link, if configured.
if ( 1 === self::$_options['show_feed'] ) { if ( $show_feed ) {
// TODO. // TODO: For some reason get_term_feed_link() does not give the desired result...
$output .= '<a href="/feed/liveticker/' . esc_html( $atts['ticker'] ) . '"><img class="wplt2_rss" src="/wp-content/plugins/wp-liveticker2/images/rss.jpg" alt="RSS" /></a>'; $feed_link = get_post_type_archive_feed_link( 'wplt2_tick' ) . '';
if ( false === strpos( $feed_link, '&' ) ) {
$feed_link .= '?wplt2_ticker=' . $ticker;
} else {
$feed_link .= '&wplt2_ticker=' . $ticker;
}
$output .= '<a href="' . esc_attr( $feed_link ) . '">Feed</a>';
} }
}// End if(). }// End if().
@ -239,7 +257,8 @@ class WPLiveticker2 {
'wplt2-js', 'wplt2-js',
WPLT2_BASE . 'scripts/wp-liveticker2.js', WPLT2_BASE . 'scripts/wp-liveticker2.js',
array( 'jquery' ), array( 'jquery' ),
self::VERSION self::VERSION,
true
); );
// Add endpoint to script. // Add endpoint to script.
@ -266,9 +285,10 @@ class WPLiveticker2 {
// Extract update requests. // Extract update requests.
if ( isset( $_POST['update'] ) && is_array( $_POST['update'] ) ) { if ( isset( $_POST['update'] ) && is_array( $_POST['update'] ) ) {
$res = array(); $res = array();
// @codingStandardsIgnoreLine Sanitization of arrayhandled on field level.
foreach ( wp_unslash( $_POST['update'] ) as $update_req ) { foreach ( wp_unslash( $_POST['update'] ) as $update_req ) {
if ( isset( $update_req['s'] ) ) { if ( is_array( $update_req ) && isset( $update_req['s'] ) ) {
$slug = $update_req['s']; $slug = sanitize_text_field( $update_req['s'] );
$limit = ( isset( $update_req['l'] ) ) ? intval( $update_req['l'] ) : - 1; $limit = ( isset( $update_req['l'] ) ) ? intval( $update_req['l'] ) : - 1;
$last_poll = ( isset( $update_req['t'] ) ) ? intval( $update_req['t'] ) : 0; $last_poll = ( isset( $update_req['t'] ) ) ? intval( $update_req['t'] ) : 0;
@ -343,7 +363,7 @@ class WPLiveticker2 {
* @param string $title Tick title. * @param string $title Tick title.
* @param string $content Tick content. * @param string $content Tick content.
*/ */
public static function tick_html( $time, $title, $content = null ) { private static function tick_html( $time, $title, $content = null ) {
return '<li class="wplt2-tick">' return '<li class="wplt2-tick">'
. '<p><span class="wplt2-tick_time">' . esc_html( $time ) . '</span>' . '<p><span class="wplt2-tick_time">' . esc_html( $time ) . '</span>'
. '<span class="wplt2-tick-title">' . esc_html( $title ) . '</span></p>' . '<span class="wplt2-tick-title">' . esc_html( $title ) . '</span></p>'

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,65 +0,0 @@
<?php
/**
* @package Scripts
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Hook RSS function
* @return void
*/
if (strpos($_SERVER['REQUEST_URI'], '/feed/liveticker/') !== false) {
$args = array();
$args['ticker_slug'] = substr($_SERVER['SCRIPT_NAME'], 1);
wplt_print_feed($args);
exit;
}
function wplt_print_feed( $arguments ) {
$args = array( 'post_type' => 'wplt_tick',
'tax_query' => array(
array( 'taxonomy' => 'wplt_ticker',
'field' => 'slug',
'terms' => $arguments['ticker_slug']
)
)
);
global $wpdb;
$sql = "SELECT `ID`, DATE_FORMAT(`post_date`,'%a, %d %b %Y %T') AS `post_date_rfc`, `post_content`, `post_title` FROM `".$wpdb->prefix."posts` WHERE `post_type` = 'wplt_tick' AND `post_status` = 'publish' ORDER BY `post_date` DESC;";
$entries = $wpdb->get_results($sql);
date_default_timezone_set("Europe/Berlin");
// modify header information
header("Content-Type: application/rss+xml; charset=UTF-8");
// generate file head
$rss = '<?xml version="1.0" encoding="UTF-8"?>';
$rss .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
$rss .= '<channel><title>Lager Live</title>';
$rss .= '<link>http://'.$_SERVER['SERVER_NAME'].'/lagerticker</link>';
$rss .= '<atom:link href="http://'.$_SERVER['SERVER_NAME'].''.$_SERVER['REQUEST_URI'].'" rel="self" type="application/rss+xml" />';
$rss .= '<description></description>';
$rss .= '<language>de-de</language>';
$rss .= '<pubDate>'.date("r").'</pubDate>';
// build entries
foreach ( $entries as $entry ) {
//print_r($entry);
$rss .= '<item><title>'.$entry->post_title.'</title>';
$rss .= '<link>http://www.dpsg-hardenberg.org/lagerticker</link>';
$rss .= '<pubDate>'.$entry->post_date_rfc.' '.date('O').'</pubDate>';
$rss .= '<description><![CDATA['.$entry->post_content.']]></description></item>';
}
// generate document foot
$rss .= '</channel></rss>';
print $rss;
}