From 7b0a512c2beff392ff85a9f3cb8de129468fed79 Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Sun, 10 Dec 2017 15:19:11 +0100 Subject: [PATCH] Feed re-enabled Removed custom feed generation in favor of WPs integrated post_type/taxonomy feed functionality. --- images/rss.jpg | Bin 1073 -> 0 bytes includes/class-wpliveticker2-admin.php | 58 ++++++++++++---------- includes/class-wpliveticker2.php | 60 +++++++++++++++-------- includes/images/rss.jpg | Bin 1073 -> 0 bytes includes/rss.php | 65 ------------------------- 5 files changed, 72 insertions(+), 111 deletions(-) delete mode 100644 images/rss.jpg delete mode 100644 includes/images/rss.jpg delete mode 100644 includes/rss.php diff --git a/images/rss.jpg b/images/rss.jpg deleted file mode 100644 index 78cfa7f6d3b2aebb8fc01a591e924efb72c685b7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1073 zcmex=Lf83h@b1R0qH8UG()Sj@l(1VGor0Shw|8&HH9MUa`1i4~}qiHR9SH6s(V zprVj4i-;i5_e`uT%y3f}83dUWg$x4|jhG7?m4qiATqMN641`EPK*5l~F;N(3C=)Zt zWT+I-b&7_Lfr*WU3nw1j`0(TZTMRrv$1n*p3j)LVb zbdWE%?x!=xI(=>KZa#D7gJqaOG81JdUA#DX;+wA9hb=9w+#y<+*zB2Z?sSiaC-0diT^YZ=2gxJmDGoRfI4ms~L?Pj&(n^OTjs{7tq z)hsk*iZFjV!RX<{2@J6TnX6`e5ubb4X3NFc#Pn2%fy|8dira-e_pqM}Sg*^*(Y{K| z=vcp+kF~O!Yj4uSfc&X*OVWdOe}C|^VX=z;20?p{7fqT!XKXkrn7-JLX~qsuHSdL| zU3?S*CLHa%c5b?Di1L)@5Kn*%K4aHnI8D`go@a2^#cnzdR zB_Lj)ZMuL|=g}jXE=|8$8C8-VbsnGI} z77d>#9BE|RZ@`#qoij`NOw_`F6U+&W1snpeWVHhl<%IwAE!f-%_lSU4e#+na0IMSh zE1MG}f2HMRG4K8Q^pJW{q-*)TWgq4kN!5u991+Y)eEyD?@&4^b0Z$*nAhAD=Dh'; - echo ' '; - esc_html_e( 'Enable', 'wplt2' ); - echo ''; - echo '

' . esc_html__( 'Disable this option to remove the default styling CSS file.', 'wplt2' ) . '

'; - } - /** * Render enable AJAX field. * @@ -156,22 +149,35 @@ class WPLiveticker2_Admin extends WPLiveticker2 { echo '

' . esc_html__( 'Interval (in seconds) to update ticker if AJAX is enabled.', 'wplt2' ) . '

'; } + /** - * Render default style field. + * Render enable css field. * * @return void */ - public static function settings_default_style_field() { - $styles = wplt_get_shortcode_styles(); - $default_style = self::$_options['default_style']; + public static function settings_enable_css_field() { + $checked = self::$_options['enable_css']; - echo ''; - echo '

' . esc_html__( 'The default display style.', 'wplt2' ) . '

'; + echo ''; + echo '

' . esc_html__( 'Disable this option to remove the default styling CSS file.', 'wplt2' ) . '

'; + } + + /** + * Render enable css field. + * + * @return void + */ + public static function settings_show_feed_field() { + $checked = self::$_options['show_feed']; + + echo ''; + echo '

' . esc_html__( 'Can be overwritten in shortcode.', 'wplt2' ) . '

'; } /** diff --git a/includes/class-wpliveticker2.php b/includes/class-wpliveticker2.php index 9eba7ae..0135bad 100644 --- a/includes/class-wpliveticker2.php +++ b/includes/class-wpliveticker2.php @@ -128,7 +128,7 @@ class WPLiveticker2 { // Post type arguments. $args = array( - 'labels' => array( + 'labels' => array( 'name' => __( 'Ticks', 'wplt2' ), 'singular_name' => __( 'Tick', 'wplt2' ), 'add_new' => __( 'Add New', 'wplt2' ), @@ -143,13 +143,15 @@ class WPLiveticker2 { 'parent_item_colon' => '', 'menu_name' => __( 'Liveticker', 'wplt2' ), ), - 'public' => false, - 'show_ui' => true, - 'show_in_menu' => true, - 'menu_icon' => 'dashicons-rss', - 'capability_type' => 'post', - 'supports' => array( 'title', 'editor', 'author' ), - 'taxonomies' => array( 'wplt2_ticker' ), + 'public' => false, + 'publicly_queryable' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'menu_icon' => 'dashicons-rss', + 'capability_type' => 'post', + 'supports' => array( 'title', 'editor', 'author' ), + 'taxonomies' => array( 'wplt2_ticker' ), + 'has_archive' => true, ); register_post_type( 'wplt2_tick', $args ); @@ -170,29 +172,39 @@ class WPLiveticker2 { $output = ''; // 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. if ( ! isset( $atts['limit'] ) ) { $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 = '
    '; $args = array( 'post_type' => 'wplt2_tick', - 'posts_per_page' => $atts['limit'], + 'posts_per_page' => $limit, 'tax_query' => array( array( 'taxonomy' => 'wplt2_ticker', 'field' => 'slug', - 'terms' => $atts['ticker'], + 'terms' => $ticker, ), ), ); @@ -207,9 +219,15 @@ class WPLiveticker2 { $output .= '
'; // Show RSS feed link, if configured. - if ( 1 === self::$_options['show_feed'] ) { - // TODO. - $output .= 'RSS'; + if ( $show_feed ) { + // TODO: For some reason get_term_feed_link() does not give the desired result... + $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 .= 'Feed'; } }// End if(). @@ -239,7 +257,8 @@ class WPLiveticker2 { 'wplt2-js', WPLT2_BASE . 'scripts/wp-liveticker2.js', array( 'jquery' ), - self::VERSION + self::VERSION, + true ); // Add endpoint to script. @@ -266,9 +285,10 @@ class WPLiveticker2 { // Extract update requests. if ( isset( $_POST['update'] ) && is_array( $_POST['update'] ) ) { $res = array(); + // @codingStandardsIgnoreLine Sanitization of arrayhandled on field level. foreach ( wp_unslash( $_POST['update'] ) as $update_req ) { - if ( isset( $update_req['s'] ) ) { - $slug = $update_req['s']; + if ( is_array( $update_req ) && isset( $update_req['s'] ) ) { + $slug = sanitize_text_field( $update_req['s'] ); $limit = ( isset( $update_req['l'] ) ) ? intval( $update_req['l'] ) : - 1; $last_poll = ( isset( $update_req['t'] ) ) ? intval( $update_req['t'] ) : 0; @@ -343,7 +363,7 @@ class WPLiveticker2 { * @param string $title Tick title. * @param string $content Tick content. */ - public static function tick_html( $time, $title, $content = null ) { + private static function tick_html( $time, $title, $content = null ) { return '
  • ' . '

    ' . esc_html( $time ) . '' . '' . esc_html( $title ) . '

    ' diff --git a/includes/images/rss.jpg b/includes/images/rss.jpg deleted file mode 100644 index 78cfa7f6d3b2aebb8fc01a591e924efb72c685b7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1073 zcmex=Lf83h@b1R0qH8UG()Sj@l(1VGor0Shw|8&HH9MUa`1i4~}qiHR9SH6s(V zprVj4i-;i5_e`uT%y3f}83dUWg$x4|jhG7?m4qiATqMN641`EPK*5l~F;N(3C=)Zt zWT+I-b&7_Lfr*WU3nw1j`0(TZTMRrv$1n*p3j)LVb zbdWE%?x!=xI(=>KZa#D7gJqaOG81JdUA#DX;+wA9hb=9w+#y<+*zB2Z?sSiaC-0diT^YZ=2gxJmDGoRfI4ms~L?Pj&(n^OTjs{7tq z)hsk*iZFjV!RX<{2@J6TnX6`e5ubb4X3NFc#Pn2%fy|8dira-e_pqM}Sg*^*(Y{K| z=vcp+kF~O!Yj4uSfc&X*OVWdOe}C|^VX=z;20?p{7fqT!XKXkrn7-JLX~qsuHSdL| zU3?S*CLHa%c5b?Di1L)@5Kn*%K4aHnI8D`go@a2^#cnzdR zB_Lj)ZMuL|=g}jXE=|8$8C8-VbsnGI} z77d>#9BE|RZ@`#qoij`NOw_`F6U+&W1snpeWVHhl<%IwAE!f-%_lSU4e#+na0IMSh zE1MG}f2HMRG4K8Q^pJW{q-*)TWgq4kN!5u991+Y)eEyD?@&4^b0Z$*nAhAD=Dh '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 = ''; - $rss .= ''; - $rss .= 'Lager Live'; - $rss .= 'http://'.$_SERVER['SERVER_NAME'].'/lagerticker'; - $rss .= ''; - $rss .= ''; - $rss .= 'de-de'; - $rss .= ''.date("r").''; - - // build entries - foreach ( $entries as $entry ) { - //print_r($entry); - $rss .= ''.$entry->post_title.''; - $rss .= 'http://www.dpsg-hardenberg.org/lagerticker'; - $rss .= ''.$entry->post_date_rfc.' '.date('O').''; - $rss .= 'post_content.']]>'; - } - - // generate document foot - $rss .= ''; - - print $rss; -} \ No newline at end of file