/**
 * Generates an HTML link, using the saved display settings.
 *
 * @param string $link The link URL
 * @param string $text The link text to display
 * @param string $bool Optional boolean. If FALSE, the text is returned unlinked. Default: TRUE.
 * @return string The generated link
 * @since 4.2.4
 */
function wprss_link_display($link, $text, $bool = TRUE)
{
    $display_settings = wprss_get_display_settings(get_option('wprss_settings_general'));
    $a = $bool ? "<a {$display_settings['open']} {$display_settings['follow']} href='{$link}'>{$text}</a>" : $text;
    return $a;
}
Esempio n. 2
0
/**
 * Display feed items on the front end (via shortcode or function)
 *
 * @since 2.0
 */
function wprss_display_feed_items($args = array())
{
    $settings = get_option('wprss_settings_general');
    $display_settings = wprss_get_display_settings($settings);
    $args = wprss_get_shortcode_default_args($args);
    $args = apply_filters('wprss_shortcode_args', $args);
    $query_args = $settings;
    if (isset($args['limit'])) {
        $query_args['feed_limit'] = filter_var($args['limit'], FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'default' => $query_args['feed_limit'])));
    }
    if (isset($args['pagination'])) {
        $query_args['pagination'] = $args['pagination'];
    }
    if (isset($args['source'])) {
        $query_args['source'] = $args['source'];
    } elseif (isset($args['exclude'])) {
        $query_args['exclude'] = $args['exclude'];
    }
    $query_args = apply_filters('wprss_process_shortcode_args', $query_args, $args);
    $feed_items = wprss_get_feed_items_query($query_args);
    do_action('wprss_display_template', $display_settings, $args, $feed_items);
}
	/**
	 * This filter function adds the source link text to the end of the given content, if the 
	 * feed source has source_link enabled. It also checks for phrases wrapped in asteriks, 
	 * and converts them into links.
	 * 
	 * @since 1.0
	 */
	public static function post_content( $content ) {
		global $post;
		$source = WPRSS_FTP_Meta::get_instance()->get_meta( $post->ID, 'feed_source' );

		// IF AN IMPORTED POST
		if ( $source !== '' ) {

			$options = WPRSS_FTP_Settings::get_instance()->get();

			$core_settings = get_option( 'wprss_settings_general' );
			$display_settings = wprss_get_display_settings( $core_settings );

			$link = WPRSS_FTP_Meta::get_instance()->get_meta( $post->ID, 'wprss_item_permalink', false );
			$feed_link = get_post_meta( $source, 'wprss_site_url', true );

			// Check the prepend/append text
			$append = WPRSS_FTP_Meta::get_instance()->get_meta( $source, 'post_append' );
			$prepend = WPRSS_FTP_Meta::get_instance()->get_meta( $source, 'post_prepend' );

			// Add any prepend text
			if ( $prepend !== '' && WPRSS_FTP_Display::show_appended_text('prepend', $source) ) {
				$content = do_shortcode( WPRSS_FTP_Appender::handle_appended_data( $post, $prepend ) ) . $content;
			}
			// Add any append text
			if ( $append !== '' && WPRSS_FTP_Display::show_appended_text('append', $source) ) {
				$content .= do_shortcode( WPRSS_FTP_Appender::handle_appended_data( $post, $append ) );
			}


			// If the post's feed source has source_link enabled ...
			if ( WPRSS_FTP_Display::show_appended_text('source_link', NULL, $options) ) {
				// Prepare to data
				$text = $options['source_link_text'];
				// Search for an asterisk sign
				$search = stripos( $text, '*');

				// If an asterisk is found, use regex to generate the linked phrase
				if ( $search !== FALSE ) {
					$link_open = "<a ${display_settings['open']} ${display_settings['follow']} href=\"";
					$link_close = "</a>";
					$linked_text = preg_replace(
						'/\*\*(.*?)\*\*/',									// The regex pattern to search for
						$link_open . esc_attr( $feed_link ) . "\">$1</a>",	// The replacement text
						$text												// The text to which to search in
					);
					$linked_text = preg_replace(
						'/\*(.*?)\*/',										// The regex pattern to search for
						$link_open . esc_attr( $link ) . "\">$1</a>",		// The replacement text
						$linked_text										// The text to which to search in
					);
				}
				// If no asterisk is found, use as preceding text
				else $linked_text = $text . ' <a href="' . esc_attr( $link ) . '" target="_blank">' . $link . '</a>';
				// Add the generated text to the content
				if ( $linked_text !== '' ) {
                    $linkMethod = apply_filters('wprss_ftp_add_source_link_method', 'before');
                    if( $linkMethod === 'before' ) {
                        $content = $linked_text . '</br>' . $content;
                    }
                    elseif( $linkMethod === 'after' ) {
                        $content = $content . '</br>' . $linked_text;
                    }
                    elseif( is_callable($linkMethod) ) {
                        $content = call_user_func_array($linkMethod, array($content, $linked_text));
                    }
				}
			}

		} // end of imported post check

		return $content;
	}