Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @package YD_feedwordpress_content_filter
- * @author Yann Dubois
- * @version 0.2.0
- */
- /*
- Plugin Name: YD Feedwordpress content filter
- Plugin URI: http://www.yann.com/en/wp-plugins/yd-feedwordpress-content-filter
- Description: Automatically filters the content of syndicated posts. | Funded by <a href="http://www.abc.fr">ABC.fr</a>
- Version: 0.2.0
- Author: Yann Dubois
- Author URI: http://www.yann.com/
- License: GPL2
- */
- /**
- * @copyright 2010 Yann Dubois ( email : yann _at_ abc.fr )
- *
- * Original development of this plugin was kindly funded by http://www.abc.fr
- *
- * Additional developments kindly provided by Alessandro Nuzzo ( http://www.e-one.it )
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
- /**
- Revision 0.1.0:
- - Original beta release
- Revision 0.2.0:
- - Refactored using the YD Plugins Framework
- - Added some options
- - Added image attachment hack contributed by Alessandro Nuzzo
- - Added redirected URL resolution
- - Got rid of unused code
- - Small bug fixes
- */
- include_once( 'inc/yd-widget-framework.inc.php' );
- $junk = new YD_Plugin(
- array(
- 'name' => 'YD Feedwordpress Content Filter',
- 'version' => '0.2.0',
- 'has_option_page' => true,
- 'has_shortcode' => false,
- 'has_widget' => false,
- 'widget_class' => '',
- 'has_cron' => false,
- 'crontab' => array(
- 'daily' => array( 'yd_fwp_filter', 'daily_update' ),
- 'hourly' => array( 'yd_fwp_filter', 'hourly_update' )
- ),
- 'has_stylesheet' => false,
- 'stylesheet_file' => 'css/yd.css',
- 'has_translation' => false,
- 'translation_domain'=> '', // must be copied in the widget class!!!
- 'translations' => array(
- array( 'English', 'Yann Dubois', 'http://www.yann.com/' )
- ),
- 'initial_funding' => array( 'Yann.com', 'http://www.yann.com' ),
- 'additional_funding'=> array(),
- 'form_blocks' => array(
- 'Main options' => array(
- 'google_filter' => 'bool',
- 'yahoo_filter' => 'bool',
- 'wikio_filter' => 'bool',
- 'local_images' => 'bool',
- 'fix_attach' => 'bool',
- 'fix_first' => 'bool',
- 'fix_redirect' => 'bool',
- 'hash_to_tags' => 'bool' // Hashtag
- )
- ),
- 'option_field_labels'=>array(
- 'google_filter' => 'Apply Google News item filter',
- 'yahoo_filter' => 'Apply Yahoo News item filter',
- 'wikio_filter' => 'Apply Wikio News item filter',
- 'local_images' => 'Import images as local attachments',
- 'fix_attach' => 'Fix attachment IDs',
- 'fix_first' => 'Fix repeated title on first line',
- 'fix_redirect' => 'Resolve redirected source URL',
- 'hash_to_tags' => 'Twitter Hashtags to tags' // Hashtag
- ),
- 'option_defaults' => array(
- 'google_filter' => 1,
- 'yahoo_filter' => 1,
- 'wikio_filter' => 1,
- 'local_images' => 1,
- 'fix_attach' => 1,
- 'fix_first' => 1,
- 'fix_redirect' => 1,
- 'hash_to_tags' => 1, // Hashtag
- ),
- 'form_add_actions' => array(
- // no custom actions
- ),
- 'has_cache' => false,
- 'option_page_text' => '',
- 'backlinkware_text' => 'Featuring YD Feedwordpress Content Filter Plugin',
- 'plugin_file' => __FILE__
- )
- );
- class yd_fwp_filter {
- const option_key = 'yd-feedwordpress-content-filter';
- function __construct() {
- $this->yd_fwp_filter();
- }
- function yd_fwp_filter() {
- $options = get_option( self::option_key );
- add_action( 'syndicated_post', array( &$this, 'filter' ), 10, 1 );
- if( $options['fix_attach'] ) {
- add_action( 'post_syndicated_item', array( &$this, 'fixAttach' ), 20, 1 );
- add_action( 'update_syndicated_item', array( &$this, 'fixAttach' ), 20, 1 );
- }
- }
- function filter( $post ) {
- if( !$post ) return $post;
- $options = get_option( self::option_key );
- $content = $post['post_content'];
- $title = $post['post_title'];
- $stripped_content = strip_tags( $content, '<i><sup><sub><strong><u><br><p><img>' ); //<b><em>
- $stripped_content = preg_replace( '|^(<[^>]*>)*(<br\s*\/?>)+|i', "$1", $stripped_content ); // no <br> at beginning (Google)
- $stripped_content = preg_replace( '|<img[^src]+>|i', '', $stripped_content ); // no sourceless <img> (Google)
- $stripped_content = preg_replace( '|(<p\s*>)*\s*et plus encore »\s*(</p\s*>)*|ims', '', $stripped_content );
- // Hashtag
- if( $options['hash_to_tags'] ) {
- // find hashtags
- preg_match_all( '/\B#(\w*[a-zA-Z-]+\w*)/', $content, $matches );
- $hashtags = $matches[0]; // #bleh
- $tags = $matches[1]; // bleh
- unset( $matches );
- global $id;
- wp_set_post_tags( $id, implode( ', ', $tags ) );
- }
- // i nice try ^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement