/** * Prints the checkbox settings for enabling the legacy feed item. * * @since 2.9.5 */ function wprss_ftp_legacy_enable_option() { $legacy_enabled = WPRSS_FTP_Settings::get_instance()->get('legacy_enabled'); echo WPRSS_FTP_Utils::boolean_to_checkbox( WPRSS_FTP_Utils::multiboolean( $legacy_enabled ), array( 'id' => 'wprss-ftp-legacy-enabled', 'name' => WPRSS_FTP_Settings::OPTIONS_NAME . '[legacy_enabled]', 'value' => 'true', ) ); echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.'legacy_enabled' ); }
/** * Check if the import post is a YouTube, Dailymotion or Vimeo feed item. * * @since 2.8 */ function wprss_ftp_check_yt_feed( $post_id, $source_id ) { // Get the post form the ID $post = get_post( $post_id ); // If the post is null, exit function. if ( $post === NULL ) return; // Get the permalink $permalink = get_post_meta( $post_id, 'wprss_item_permalink', TRUE ); // If the permalink is empty, do not continue. Exit function if ( $permalink === '' ) return; // Get the source options $options = WPRSS_FTP_Settings::get_instance()->get_computed_options( $source_id ); // If embedded content is not allowed, exit function. if ( WPRSS_FTP_Utils::multiboolean( $options['allow_embedded_content'] ) === FALSE ) return; // Search for the video host $found_video_host = preg_match( '/http[s]?:\/\/(www\.)?(youtube|dailymotion|vimeo)\.com\/(.*)/i', $permalink, $matches ); // If video host was found and embedded content is allowed if ( $found_video_host !== 0 && $found_video_host !== FALSE ) { // Determine the embed link $embed = NULL; // Check which video host was found in the URL and prepare the embed link $host = $matches[2]; switch( $host ) { case 'youtube': preg_match( '/(&|\?)v=([^&]+)/', $permalink, $yt_matches ); $embed = 'http://www.youtube.com/embed/' . $yt_matches[2]; $embed = apply_filters( 'wprss_ftp_yt_auto_embed_url', $embed, $post_id, $source_id ); break; case 'vimeo': preg_match( '/(\d*)$/i', $permalink, $vim_matches ); $embed = 'http://player.vimeo.com/video/' . $vim_matches[0]; $embed = apply_filters( 'wprss_ftp_vimeo_auto_embed_url', $embed, $post_id, $source_id ); break; case 'dailymotion': preg_match( '/(\.com\/)(video\/)(.*)/i', $permalink, $dm_matches ); $embed = 'http://www.dailymotion.com/embed/video/' . $dm_matches[3]; $embed = apply_filters( 'wprss_ftp_dm_auto_embed_url', $embed, $post_id, $source_id ); break; } // If the embed link was successfully generated, add it to the post if ( $embed !== NULL ) { $content = $post->post_content; $video_link = apply_filters( 'wprss_ftp_enable_auto_embed_videos', FALSE ) === TRUE ? $embed : $permalink; $new_content = $video_link . "\n\n" . $content; WPRSS_FTP_Utils::update_post_content( $post_id, $new_content ); // YouTube table fix // If the host found is YouTube, and the source is using featured images and removing them from the content // then remove the first column in the table that YouTube puts in the feed if ( $host === 'youtube' && WPRSS_FTP_Utils::multiboolean( $options['use_featured_image'] ) && WPRSS_FTP_Utils::multiboolean( $options['remove_ft_image'] ) ) { // Add a builtin extraction rule add_filter('wprss_ftp_built_in_rules', 'wprss_ftp_yt_table_cleanup'); } } } }
/** * Checks whether a value is considered to be 'true' by this class. * * @since 4.8.1 * @param mixed $value The value to check. * @return bool True if the value is considered by this class to represent 'true'; false otherwise. */ public static function isTrue($value) { return \WPRSS_FTP_Utils::multiboolean($value) || trim($value) === static::getTrueValue(); }
/** * Changes the tags to be stripped from the feed item. * * @since 2.2 */ public static function feed_tags_to_strip( $tags, $source ) { if ( is_null( $source ) ) return $tags; $allow_embedded_content = WPRSS_FTP_Meta::get_instance()->get_meta( $source, 'allow_embedded_content' ); if ( WPRSS_FTP_Utils::multiboolean( $allow_embedded_content ) !== true ) return $tags; // Remove the allowed tags from the list of tags to remove $tags = array_diff( $tags, self::get_allowed_embed_tags() ); $tags = array_values( array_filter( $tags ) ); return $tags; }
/** * Returns whether or not a URL is allowed. * * @since 2.8.6 * @deprecated 3.0 * @param bool $is_allowed Whether or not the request is originally allowed * @param string $host This server's host name * @param string $url URL of the request */ public static function is_allow_local_requests( $is_allowed, $host, $url ) { $allow_local_requests = WPRSS_FTP_Settings::get_instance()->get( 'allow_local_requests' ); if ( true === $allow_local_requests || WPRSS_FTP_Utils::multiboolean( $allow_local_requests ) ) { return true; } return $isAllowed; }
/** * Disables the link to source option for each feed source * * @since 2.4 */ public static function source_link_update() { // Get the meta class instance $meta = WPRSS_FTP_Meta::get_instance(); if ( ! function_exists( "wprss_get_all_feed_sources" ) ) return; // Get all feed sources $feed_sources = wprss_get_all_feed_sources(); // Keep a count of feed sources that got updated $count = 0; // Iterate all feed sources while ( $feed_sources->have_posts() ) { // Prepare loop variables $feed_sources->the_post(); $ID = get_the_ID(); // Get the source link enable and text meta for the feed sources $source_link = $meta->get_meta( $ID, 'source_link' ); $source_link_text = $meta->get_meta( $ID, 'source_link_text' ); // Get the post append text $post_append = $meta->get_meta( $ID, 'post_append' ); // If the post's feed source has source_link enabled ... if ( WPRSS_FTP_Utils::multiboolean( $source_link ) === TRUE ) { // Disable the source link option update_post_meta( $ID, WPRSS_FTP_Meta::META_PREFIX . 'source_link', 'false' ); // Increment the count $count++; // If an asterisk is found in the source link text, use regex to generate the linked phrase if ( stripos( $source_link_text, '*') !== FALSE ) { // Prepare the replacement <a> tag with the placeholder for feed_url $feed_url_link = "<a target=\"_blank\" href=\"{{feed_url}}\">$1</a>"; // Replace the string in double asteriks into the <a> tag $linked_text = preg_replace( '/\*\*(.*?)\*\*/', // The regex pattern to search for $feed_url_link, // The replacement text $source_link_text // The text to which to search in ); // Prepare the replacement <a> tag with the placeholder for post_url $post_url_link = "<a target=\"_blank\" href=\"{{original_post_url}}\">$1</a>"; // Replace the string in single asteriks into the <a> tag $linked_text = preg_replace( '/\*(.*?)\*/', // The regex pattern to search for $post_url_link, // The replacement text $linked_text // The text to which to search in ); // Update the post append text if ( strlen( $post_append ) > 0 ) { $post_append .= '<br/>'; } $post_append .= $linked_text; update_post_meta( $ID, WPRSS_FTP_Meta::META_PREFIX . 'post_append', $post_append ); } } // END OF SOURCLE LINK ENABLED CHECK } // END OF WHILE LOOP if ( $count > 0 ) { set_transient( 'wprss_ftp_admin_notices', array( 'WPRSS_FTP_Utils', 'source_link_update_notice' ), 0 ); } // Restore the $post global to the current post in the main query wp_reset_postdata(); } // END OF source_link_update()
/** * Inserts the terms into a given post, based on their saved meta/ * * This function replaces the old taxonomy code in the converter class, utilizing the new meta data * format used for the taxonomies. The terms for each taxonomy, along with any auto created feed terms * are inserted into the post. * * @since 3.1 * @param int $post_id The ID of the post. * @param int $feed_id The ID of the feed source that imported the post. * @param object $sp_item The SimplePie_Item from which the post was converted. * @return bool TRUE if the terms where inserted successfully, FALSE if the post was not found. */ function wprss_ftp_add_taxonomies_to_post( $post_id, $feed_id, $sp_item ) { // If the post does not exist, stop immediately if ( get_post( $post_id ) === null ) return NULL; // Get the taxonomies meta $meta = WPRSS_FTP_Meta::get_instance()->get( $feed_id, 'taxonomies' ); // If the source has the old meta saved, convert it into the new meta if ( $meta === '' ) { $meta = WPRSS_FTP_Meta::convert_post_taxonomy_meta( $feed_id ); } // Get the settings instance $settings = WPRSS_FTP_Settings::get_instance(); // Get the post type saved in the settings $settings_post_type = $settings->get( 'post_type' ); // If it matches, add the settings taxonomies to the meta taxonomies if ( $settings_post_type === get_post_type( $post_id ) ) { // Get the taxonomies settings, and convert from old format if needed $settings_taxonomies = $settings->get( 'taxonomies' ); if ( $settings_taxonomies === '' ) { $settings_taxonomies = WPRSS_FTP_Settings::convert_post_taxonomy_settings(); } // Add to meta taxonomies $meta = array_merge( (array) $settings_taxonomies, (array) $meta ); } $tax_iterated = array(); // For each entry foreach( $meta as $entry ) { // Check if this taxonomy term should be applied. if ( wprss_ftp_should_apply_taxonomy( $entry, $sp_item ) === FALSE ) { continue; } // Get the data $taxonomy = $entry['taxonomy']; $terms = $entry['terms']; $terms = is_array( $terms ) ? $terms : array(); $auto = WPRSS_FTP_Utils::multiboolean( $entry['auto'] ); $feed_terms = array(); // Repeat the taxonomy slug in an array with the same length as the terms array $taxonomies_array = count( $terms ) > 0 ? array_fill( 0, count($terms), $taxonomy ) : array(); // Run the term slugs through the 'wprss_ftp_create_or_get_term' $terms_to_set = array_map( 'wprss_ftp_create_or_get_term', $terms, $taxonomies_array); // Filter the terms to remove NULL entries (NULL can be returned by 'wprss_ftp_create_or_get_term') $terms_to_set = array_filter( $terms_to_set ); // If auto creation is enabled if ( $auto === TRUE ) { // If auto create is enabled, get the terms from the feed $feed_terms = $sp_item->get_categories(); $feed_terms = is_array( $feed_terms )? $feed_terms : array(); // Map the terms through our preparation function, and filter them for custom user manipulation $feed_terms = array_map( 'wprss_ftp_prepare_auto_created_term', $feed_terms ); $feed_terms = apply_filters( 'wprss_auto_create_terms', $feed_terms, $taxonomy, $feed_id ); // Repeat the taxonomy slug in an array with the same length as the terms array $num_terms = count( $feed_terms ); $taxonomies_array = $num_terms > 0? array_fill( 0, $num_terms, $taxonomy ) : array(); // Run them through the `wprss_ftp_process_auto_created_terms` function for processing $feed_terms = array_map( 'wprss_ftp_process_auto_created_terms', $feed_terms, $taxonomies_array ); // Filter the terms to remove NULL entries (NULL can be returned by 'wprss_ftp_create_or_get_term') $feed_terms = array_filter( $feed_terms ); // Add them to the terms to set $terms_to_set = array_merge( (array) $terms_to_set, (array) $feed_terms ); } // Add the taxonomy to the tax_iterated array if it's not already in the array if ( ! in_array( $taxonomy, $tax_iterated ) ) { $tax_iterated[] = $taxonomy; // Set no terms, and override existing - to remove any default terms, like 'Uncategorized' wp_set_object_terms( $post_id, array(), $taxonomy, FALSE ); } // Insert the terms wp_set_object_terms( $post_id, $terms_to_set, $taxonomy, TRUE ); // clear the cache delete_option($taxonomy."_children"); } return TRUE; }
/** * Renders the meta box specified by the parameter. * The function will use the get_meta_fields function to retrieve the fields for * that particular meta box and render them. * * @since 1.0 */ public function render_metabox( $metabox ) { global $post; $help = class_exists('WPRSS_Help') ? WPRSS_Help::get_instance() : null; # The main metabox template ob_start(); ?> <table class="form-table wprss-form-table"> <tbody> {{fields}} </tbody> </table> <?php $template = ob_get_clean(); # The field template to use for all fields ob_start(); ?> <tr {{hr}}> <th><label for="{{id}}">{{label}}</label></th> <td> {{before}} {{input}} {{after}} {{separator}}<label for="{{id}}"><span class="description">{{desc}}</span></label> </td> </tr> <?php $field_template = ob_get_clean(); # Generate the fields HTML using the template $meta_fields = $this->get_meta_fields( $metabox, $post->ID ); $fields = ''; $options = WPRSS_FTP_Settings::get_instance()->get_computed_options( $post->ID ); # Render each field foreach ( $meta_fields as $field_id => $field ) { if ( isset( $field['ignore']) && $field['ignore'] === TRUE ) { continue; } $hr = ( isset( $field['add_hr'] ) && $field['add_hr'] === TRUE )? 'class="wprss-tr-hr"': ''; $field_html = ''; $id = self::META_PREFIX . $field_id; # Get the meta value for this field, if it exists $nid = substr( $id, strlen( self::META_PREFIX ) ); $meta = $options[ $nid ]; if ( isset( $field['settings'] ) && $field['settings'] === FALSE ) { $meta = get_post_meta( $post->ID, $id, true ); } if ( isset( $field['default'] ) && $meta === '' ) { $meta = $field['default']; } if ( isset( $field['custom_render'] ) && !empty( $field['custom_render'] ) ) { $field_html = call_user_func_array( $field['custom_render'], array( $post, $field_id, $field, $meta ) ); } else { $separator = '<br/>'; $before = ''; $after = ''; # Generate the field input $field_input = ''; $field_type_templates = array( 'text' => '<input type="text" id="{{id}}" name="{{name}}" value="{{value}}" placeholder="{{placeholder}}" {{properties}}/>', 'number' => '<input class="wprss-number-roller" type="number" id="{{id}}" name={{name}} min="0" placeholder="{{placeholder}}" value="{{value}}" {{properties}}/>', 'textarea' => '<textarea id="{{id}}" name="{{name}}" cols="60" rows="4" {{properties}}>{{value}}</textarea>' ); switch( $field['type'] ) { default: case 'text': case 'number': case 'textarea': // If the field is a textarea, and the meta value saved in DB is an array if ( $field['type'] === 'textarea' && is_array( $meta ) ) { // split the array into strings $new_meta = ''; foreach ( $meta as $entry ) { $new_meta .= $entry . "\n"; } $meta = $new_meta; } $substitutions = array( 'id' => $id, 'name' => $id, 'value' => trim( esc_attr( $meta ) ), 'placeholder' => ( isset( $field['placeholder'] )? $field['placeholder'] : 'Default' ), 'properties' => ( isset( $field['properties'] )? $field['properties'] : '' ), ); $field_input = WPRSS_FTP_Utils::template( $field_type_templates[ $field['type'] ], $substitutions ); break; case 'checkbox': $field_input = WPRSS_FTP_Utils::boolean_to_checkbox( WPRSS_FTP_Utils::multiboolean( $meta ), array( 'id' => $id, 'name' => $id, 'class' => 'meta-checkbox', 'value' => 'true', 'disabled' => ( isset( $field['disabled'] )? $field['disabled'] : FALSE ), ) ); $separator = ''; break; case 'msg': $field_input = '<p id="'.$id.'">'.$field['text'].'</p>'; break; case 'dropdown': $choices = $this->resolve_data_source( $field['options'] ); $field_input = WPRSS_FTP_Utils::array_to_select( $choices, array( 'id' => $id, 'name' => $id, 'selected' => $meta, 'disabled' => ( isset( $field['disabled'] )? $field['disabled'] : FALSE ), ) ); break; } if ( $help !== null ) { $after .= $help->do_tooltip( WPRSS_FTP_HELP_PREFIX.$field_id ); } $label = isset( $field['label'] )? $field['label'] : ''; $desc = isset( $field['desc'] )? $field['desc'] : ''; # Finish the field using the template $field_html = WPRSS_FTP_Utils::template( $field_template, array( 'id' => $id, 'input' => $field_input, 'label' => $label, 'desc' => $desc, 'separator' => $separator, 'hr' => $hr, 'before' => $before, 'after' => $after ) ); } // End of if statement that checks if using a custom renderer $fields .= $field_html; } echo str_replace( '{{fields}}', $fields, $template ); echo '<span data-post-id="'.$post->ID.'" id="wprss-ftp-post-id"></span>'; }
/** * Prints the enclosure link in the post content. * * @since 2.8 */ public static function enclosure_link( $content ) { global $post; // Start with the original content $new_content = $content; // check if enclosure is enabled, check filter for before and after (default: before), check filter to modify print // Check if not in the feed and if showing the post, not processing the content if ( is_feed() || !( is_singular() || is_home() || is_front_page() || is_search() || is_preview() ) ) { return $content; } // Get the source meta, if it exists, for this post $source = WPRSS_FTP_Meta::get_instance()->get_meta( $post->ID, 'feed_source' ); // If the meta exists ( i.e. is an imported post ) if ( $source === '' ) { return $content; } // Check if enclosure is enabled $enclosure_enabled = get_post_meta( $source, 'wprss_enclosure', TRUE ); if ( $enclosure_enabled === '' || !WPRSS_FTP_Utils::multiboolean( $enclosure_enabled ) ) { return $content; } // Get the post enclosure link $enclosure_link = WPRSS_FTP_Meta::get_instance()->get_meta( $post->ID, 'enclosure_link' ); // Prepare the default output $enclosure_output = "<a href='$enclosure_link'>$enclosure_link</a>"; // Get the position of the enclosure link. Default: 'before' post content $pos = apply_filters( 'wprss_ftp_enclosure_link_position', 'before' ); // Filter the enclosure output $enclosure_output = apply_filters( 'wprss_ftp_enclosure_output', $enclosure_output, $enclosure_link, $source ); // Show the enclosure link at the appropriate position switch( $pos ) { default: case 'before': $new_content = $enclosure_output . $content; break; case 'after': $new_content = $content . $enclosure_output; break; } // Return the new content return $new_content; }
/** * Checks if the post is to be rejected since no featured image was determined. * * If the 'must_have_ft_image' is enabled for the feed source that imported the post, the * post is deleted. Otherwise no action is taken. * * This function triggers the action 'wprss_ftp_after_post_rejected_no_ft_image' upon * completion. * * @since 3.3 * @param $post_id int The ID of the post. * @param $source_id int The ID of the feed source. */ public function maybe_reject_post( $post_id, $source_id ) { wprss_log( 'Checking if post should be rejected due to lack of a featured image ...', NULL, WPRSS_LOG_LEVEL_SYSTEM ); // Get the meta option value that determines if posts are allowed if they have no featured image $must_have_ft_image = WPRSS_FTP_Meta::get_instance()->get( $source_id, 'must_have_ft_image' ); // Check if the option is enabled $enabled = WPRSS_FTP_Utils::multiboolean( $must_have_ft_image ) === TRUE; if ( $enabled ) { // Filter force deletion. False for sending post to trash $force_delete = apply_filters( 'wprss_ftp_post_rejected_no_ft_image_force_delete', TRUE ); // Delete the post wp_delete_post( $post_id, $force_delete ); // Return null from the convertor add_filter( 'wprss_ftp_converter_return_post_'.$post_id, '__return_false' ); // Logging wprss_log( 'Post rejected.', NULL, WPRSS_LOG_LEVEL_SYSTEM ); } else { // Logging wprss_log( 'Post accepted.', NULL, WPRSS_LOG_LEVEL_SYSTEM ); } // Trigger action. First param: TRUE reject, FALSE accepted. do_action( 'wprss_ftp_after_post_rejected_no_ft_image', $enabled, $source_id ); }
/** * Get the specified feed item's date * @since 3.3.2 */ private function preview_date($item) { $date = $item->get_date( 'U' ); if ( WPRSS_FTP_Utils::multiboolean( $this->params['apply_filters'] ) === TRUE ) { $date = apply_filters( 'wprss_ftp_converter_post_date', $date, 0 ); } if (empty($date)) { $date = $this->format_error_string( __('The item has no date!', WPRSS_TEXT_DOMAIN) ); } else { $date_difference = human_time_diff( $date, current_time('timestamp')); $date = ( $date > current_time('timestamp') ) ? __( 'In', WPRSS_TEXT_DOMAIN ) . ' ' .$date_difference : $date_difference .' '. __( 'ago', WPRSS_TEXT_DOMAIN ); } return $date; }
/** * Renders the checkbox for the option to allow local requests * * @since 2.8.6 * @deprecated 3.0 */ public function render_allow_local_requests( $args ) { $name = 'allow_local_requests'; $id = 'ftp-' . str_replace('_', '-', $name); $allow_local_requests = $this->get( $name ); echo WPRSS_FTP_Utils::boolean_to_checkbox( WPRSS_FTP_Utils::multiboolean( $allow_local_requests ), array( 'id' => $id, 'name' => sprintf('%2$s[%1$s]', $name, self::OPTIONS_NAME), 'value' => 'true' ) ); echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.'allow_local_requests' ); }