/** * Checks if the feed source uses the force full content option or meta option, and * returns the fulltextrss url if so. * * @since 1.0 */ public static function check_force_full_content( $feed_url, $feed_ID ) { if ( wprss_ftp_using_feed_items( $feed_ID ) ) { return $feed_url; } // Get the computed settings / meta options for the feed source $options = WPRSS_FTP_Settings::get_instance()->get_computed_options( $feed_ID ); // If using force full content option / meta if ( WPRSS_FTP_Utils::multiboolean( $options['force_full_content'] ) === TRUE ) { $service = WPRSS_FTP_Settings::get_instance()->get('full_text_rss_service'); $service = apply_filters( 'wprss_ftp_service_before_full_text_feed_url', $service ); switch( $service ) { case 'free': $key = WPRSS_FTP_FULL_TEXT_RSS_KEY; $API_HASH = sha1( $key . $feed_url ); $encoded_url = urlencode( $feed_url ); // Prepare the fulltext sources $full_text_sources = apply_filters( 'wprss_ftp_full_text_sources', array( "http://fulltext.wprssaggregator.com/makefulltextfeed.php?key=1&hash=$API_HASH&links=preserve&exc=1&url=", "http://ftr-premium.fivefilters.org/makefulltextfeed.php?key=1920&hash=$API_HASH&max=10&links=preserve&exc=1&url=", ) ); // Start with no feed to use $feed_url_to_use = NULL; // Load SimplePie require_once ( ABSPATH . WPINC . '/class-feed.php' ); // For each source ... foreach ( $full_text_sources as $full_text_source ) { // Prepare the feed $full_text_feed_url = $full_text_source . $encoded_url; $feed = wprss_fetch_feed( $full_text_feed_url, $feed_ID ); // If the feed has no errors, the we will use this feed if ( !is_wp_error( $feed ) && !$feed->error() ) { $feed_url_to_use = $full_text_source . $encoded_url; break; } } // If after trying all the sources, the feed to use is still NULL, then no source was valid. // Return the same url passed as parameter, Otherwise, return the full text rss feed url if ( $feed_url_to_use === NULL ) { WPRSS_FTP_Utils::log( __( 'Failed to find a working full text rss service.', WPRSS_TEXT_DOMAIN ), 'check_force_full_content' ); } return ( $feed_url_to_use === NULL )? $feed_url : $feed_url_to_use; case 'feeds_api': $api_key = WPRSS_FTP_Settings::get_instance()->get( 'feeds_api_key' ); $encoded_url = urlencode( $feed_url ); $feeds_api_feed_url = WPRSS_FTP_Utils::template( WPRSS_FTP_FEEDS_API_REQUEST_FORMAT, array( 'url' => $encoded_url, 'key' => $api_key, ) ); // Attempt to fetch the feed $feed = wprss_fetch_feed( $feeds_api_feed_url, $feed_ID ); // If an error was encountered if ( is_wp_error( $feed ) || $feed->error() ) { // Request the error message and log it $response = wp_remote_get( $feeds_api_feed_url ); WPRSS_FTP_Utils::log( "FeedsAPI failed to return a feed, and responded with: \"{$response['body']}\"" ); // Return the original parameter url return $feed_url; } // Return the feeds api if no error was encountered. return $feeds_api_feed_url; // For other services default: return apply_filters( 'wprss_ftp_misc_full_text_url', $feed_url, $feed_ID, $service ); } } // Otherwise, return back the given url else return $feed_url; }
/** * Renders the custom fields mapping option * * @since 2.8 */ public function render_custom_fields( $post, $field_id, $field, $meta ) { $META_PREFIX = self::META_PREFIX; $id = $META_PREFIX . $field_id; // Get the RSS tags, RSS namespaces options and the custom fields //$saved_namespaces = WPRSS_FTP_Settings::get_instance()->get( 'user_feed_namespaces' ); $saved_namespaces = WPRSS_FTP_Settings::get_instance()->get_namespaces(); ?> <p> <?php _e( 'This allows you to retrieve data from any RSS tag in feed items, then store it in a custom meta field in imported posts.', WPRSS_TEXT_DOMAIN ); ?> </p> <?php // If there are no saved namespaces, show a message and exit function if ( !is_array( $saved_namespaces ) || count( $saved_namespaces ) === 0 ) { ?> <p> <?php $link_attrs = 'href="' . admin_url( 'edit.php?post_type=wprss_feed&page=wprss-aggregator-settings&tab=ftp_settings#wprss-ftp-add-namespace' ) . '" target="wprss_ftp_settings"'; printf( __( 'To use this option, you first need to add the namespaces that you want to use in the <a %s>Feed to Post settings page</a>.', WPRSS_TEXT_DOMAIN ), $link_attrs ); ?> </p> <?php return; } // Get the meta values $rss_namespaces = $this->get_meta( $post->ID, 'rss_namespaces' ); $rss_namespaces = ( $rss_namespaces === '' )? array() : $rss_namespaces; $rss_tags = $this->get_meta( $post->ID, 'rss_tags' ); $rss_tags = ( $rss_tags === '' )? array() : $rss_tags; $custom_fields = $this->get_meta( $post->ID, 'custom_fields' ); $custom_fields = ( $custom_fields === '' )? array() : $custom_fields; // Prepare the array of namespaces // Add an entry to selected a namespace // And make each entry use the name as both value and label $namespaces_array = array_merge( array( '' => __( 'Choose a namespace', WPRSS_TEXT_DOMAIN ) ), array_combine( $saved_namespaces['names'], $saved_namespaces['names'] ) ); // Generate field templates to use in loop below and in JS $namespace_dropdown_template = array( 'options' => $namespaces_array, 'attributes' => array( 'name' => self::META_PREFIX . 'rss_namespaces[]', 'selected' => '' ) ); $rss_tag_placeholder = __( 'RSS Tag', WPRSS_TEXT_DOMAIN ); $rss_tag_field = "<input type='text' name='{$META_PREFIX}rss_tags[]' value='{{value}}' placeholder='$rss_tag_placeholder' />"; $custom_field_placeholder = __( 'Meta field name', WPRSS_TEXT_DOMAIN ); $custom_field_field = "<input type='text' name='{$META_PREFIX}custom_fields[]' value='{{value}}' placeholder='custom_field_placeholder' />"; $section_class = "wprss-ftp-custom-fields-section"; $remove_btn_title_text = __( 'Remove', WPRSS_TEXT_DOMAIN ); $remove_btn = '<button type="button" class="button-secondary wprss-ftp-remove-custom-mapping" title="'.$remove_btn_title_text.'"><i class="fa fa-trash-o"></i></button>'; ob_start(); // Print a section for each for ( $i = 0; $i < count( $rss_namespaces ); $i++ ) { // Get the data for the current custom field entry $namespace = $rss_namespaces[$i]; $tag = $rss_tags[$i]; $custom_field = $custom_fields[$i]; // Prepare the dropdown $namespace_dropdown = $namespace_dropdown_template; $namespace_dropdown['attributes']['selected'] = $namespace; echo "<div class='$section_class'>"; echo WPRSS_FTP_Utils::array_to_select( $namespace_dropdown['options'], $namespace_dropdown['attributes'] ); echo WPRSS_FTP_Utils::template( $rss_tag_field, array( 'value' => $tag ) ); echo WPRSS_FTP_Utils::template( $custom_field_field, array( 'value' => $custom_field ) ); echo $remove_btn; echo "</div>"; } $saved_custom_mappings = ob_get_clean(); // Prepare the dropdown template for JS $namespace_dropdown_template = WPRSS_FTP_Utils::array_to_select( $namespace_dropdown_template['options'], $namespace_dropdown_template['attributes'] ); // Show the field row, with the prepare input fields for the extraction rules ob_start(); ?> <tr> <th><label for="<?php echo $id; ?>"><?php echo $field['label']; ?></label></th> <td> <?php echo $saved_custom_mappings; ?> <span id="wprss-ftp-custom-fields-marker"></span> <button type="button" id="wprss-ftp-add-custom-mapping" class="button-primary"> <i class="fa fa-plus"></i> <?php _e( 'Add New', WPRSS_TEXT_DOMAIN ); ?> </button> <?php echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.$field_id ); ?> <br/> <p> <?php $settings_link_attrs = 'href="' . admin_url( 'edit.php?post_type=wprss_feed&page=wprss-aggregator-settings&tab=ftp_settings#wprss-ftp-add-namespace' ) . '" target="wprss_ftp_settings"'; printf( __( 'You can add and change your namespaces from the <a %s>Feed to Post settings page</a>.', WPRSS_TEXT_DOMAIN ), $settings_link_attrs ); ?> </p> <script type="text/javascript"> var wprss_ftp_custom_mappings_section_class = "<?php echo addslashes( $section_class ); ?>"; var wprss_ftp_namespaces_dropdown = "<?php echo addslashes( $namespace_dropdown_template ); ?>"; var wprss_ftp_rss_tag_field = "<?php echo addslashes( $rss_tag_field ); ?>"; var wprss_ftp_custom_field_field = "<?php echo addslashes( $custom_field_field ); ?>"; var wprss_ftp_remove_custom_mapping = "<?php echo addslashes( $remove_btn ); ?>"; </script> </td> </tr> <tr> <th> <label for="wprss-ftp-namespace-detector-refresh"> <?php _e( 'Namespace Detector' ); ?> </label> </th> <td> <button type="button" id="wprss-ftp-namespace-detector-refresh" class="button-secondary"> <i class="fa fa-search"></i> <?php _e( 'Detect namespaces in Feed Source' ); ?> </button> <?php if ( class_exists( 'WPRSS_Help' ) ) : ?> <?php echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.'namespace_detector' ); ?> <?php else: ?> <br/> <label class="description" for="wprss-ftp-namespace-detector-refresh"> <?php _e('Use this button to detect the namespaces being used by this feed source.', WPRSS_TEXT_DOMAIN); ?> </label> <?php endif; ?> <div id="wprss-ftp-namespace-detector-results"></div> </td> </tr> <?php return ob_get_clean(); }