count_posts = wp_count_posts("post"); // Replace these with your meta_key and meta_value $meta_key = '_rpuplugin_enabled'; $meta_value = 'yes'; $sql = "SELECT count(DISTINCT pm.post_id) FROM $wpdb->postmeta pm JOIN $wpdb->posts p ON (p.ID = pm.post_id) WHERE pm.meta_key = '$meta_key' AND pm.meta_value = '$meta_value' AND p.post_type = 'post' AND p.post_status = 'publish' "; $rpustats->enabled = $wpdb->get_var($sql); $meta_value = 'no'; $sql = "SELECT count(DISTINCT pm.post_id) FROM $wpdb->postmeta pm JOIN $wpdb->posts p ON (p.ID = pm.post_id) WHERE pm.meta_key = '$meta_key' AND pm.meta_value = '$meta_value' AND p.post_type = 'post' AND p.post_status = 'publish' "; $rpustats->disabled = $wpdb->get_var($sql); //Handle a regression bug where we screwed up the meaning of this option $synall = get_option('rpuplugin_individual_post'); if($synall == "on" || empty($synall)) { //Update old "on" value to new "Yes" value update_option('rpuplugin_individual_post', 'yes'); } elseif($synall == "off") { //or the old "off" to the new "no update_option('rpuplugin_individual_post', 'no'); } // HTML for Repost Settings plugin page //Set values for javascript to pickup ?>

Repost Settings

Your content, everywhere.
With Repost, you can instantly share your content with other publishers, bloggers, and websites. Learn how it works.

Important: It looks like you have a cache plugin installed. Repost is compatible with most cache plugins, however you must empty the cache after installing or updating the settings to allow the changes to be picked up.

API Key

Select where the Repost button will appear on your posts:





Choose the type of button(s) that will appear on your site:

Single Post Blog Page
/> />
/> />
/>
None
Optional Features

/> Include a syndicated byline

Default byline: "By: display_name ); ?>" (the name will be the display name of the post author)

Custom byline:

You may prefer to not include articles posted before a certain date.

'> '> '> (Note: YYYY-MM-DD)

/> Automatically create a "Featured Image" from the embedded article when publishing a new post.

/> Make all posts available for syndication by default
/> Do not make all posts available for syndication by default

- posts are syndicated / - posts are not syndicated

(To override the default for an individual post, check or uncheck "Syndicate this article" when adding or editing a post.)

The following user(s) are currently able to repost articles from the Article Recommendation widget:

/> Administrator
/> Editor
/> Author
/> Contributor


API Key Not Installed
Settings'; array_unshift($links, $settings_link); } else { $settings_link = 'API Key Installed ✓
Settings'; array_unshift($links, $settings_link); } if (!preg_match("/yes|no/",get_option('rpuplugin_individual_post'))) { $settings_link = 'Default Not Set'; array_unshift($links, $settings_link); } } return $links; } // Create Syndication Enable/Disable Meta Box function rpuplugin_meta_box() { add_meta_box('rpuplugin_enabled_meta', 'Repost', 'rpuplugin_meta_content', 'post', 'side', 'default'); } // Meta Box Title and Contents function rpuplugin_meta_content() { global $post; // Nonce Name to Verify Data Origination echo ''; // Get Existing Data if Available $rpuplugin_enabled = get_post_meta($post->ID, '_rpuplugin_enabled', true); // If it's not set to a valid value use the system default if(!preg_match("/yes|no/",$rpuplugin_enabled)) { $defval = get_option('rpuplugin_individual_post'); if(empty($defval) || $defval == "yes" || $defval == "on") { update_post_meta($post->ID, '_rpuplugin_enabled', 'yes',true); $rpuplugin_enabled = "yes"; } else { update_post_meta($post->ID, '_rpuplugin_enabled', 'no',true); $rpuplugin_enabled = "no"; } } // Echo Meta Box Contents echo ' Syndicate this article.'; } // Save Metadata from Meta Box function rpuplugin_save_meta($post_id, $post) { //Can we even be here // Post Editing Verification if (!current_user_can('edit_post', $post->ID)) return $post->ID; // Authentication Via Nonce if (!wp_verify_nonce($_POST['rpuplugin_meta_noncename'], 'repostus')) { return $post->ID; } // Put options nto Array - only 1 for now $rpuplugin_meta['_rpuplugin_enabled'] = $_POST['_rpuplugin_enabled']; /** * Auto thumbnail * If the post is an embed and if it doesn't have a thumbnail make one an add it to the post if enabled **/ if( get_option( 'rpuplugin_featured_image' ) == "on" && current_user_can('upload_files') && function_exists("has_post_thumbnail") ) { //If it's a revision we need to see if the parent has a thumb because it will inherit it. if(wp_is_post_revision($post_id) !== false) { $pid = wp_is_post_revision($post_id); } else { $pid = $post_id; } if (!has_post_thumbnail($pid)) { if(preg_match("@rp-api\.com/thumb/(\w*)|\[repostus[^\]]*thumb=(\w*)@",$post->post_content,$matches)) { //OK it's a repost.us embed and it doesn't have a thumbnail - grab an image $key = max(intval($matches[1]),intval($matches[2])); //Only one will match the other will be zero //See if we already have this attachment and if so use it. $attach = get_page_by_title("repost-us-image-$key","OBJECT","attachment"); if(!empty($attach)) { set_post_thumbnail($post_id, $attach->ID); //Use the one we have } elseif (preg_match("@rpuRepost-(\w*)-top|\[repostus.*hash=(\w*)@s",$post->post_content, $hashMatches)) { $hash = sanitize_key($hashMatches[1].$hashMatches[2]); //One string will be empty $response = wp_remote_get("http://1.rp-api.com/thumb/$key/0/0"); $the_body = wp_remote_retrieve_body($response); $headers = wp_remote_retrieve_headers($response); if(strlen($hash) == 32 && !empty($key) && !empty($the_body) && preg_match("/^image/",$headers['content-type'])) { $file = wp_upload_bits("repost-us-". $key . ".jpg",null,$the_body); if(is_array($file) && empty($file['error'])) { $filename = $file['file']; $wp_filetype = wp_check_filetype(basename($filename), null ); $wp_upload_dir = wp_upload_dir(); $attachment = array( 'guid' => "repost-us-image-$key", 'post_mime_type' => $wp_filetype['type'], 'post_title' => "repost-us-image-$key", 'post_content' => "Copyright Image - this image may only be used with\nhttp://www.repost.us/article-preview/#!hash=".$hash . ", all other rights reserved.", 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $filename, $post_id ); // You must first include the image.php file // for the function wp_generate_attachment_metadata() to work require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data ); set_post_thumbnail($post_id, $attach_id); } } } } } } // Add Values of $rpuplugin_meta as Custom Fields foreach ($rpuplugin_meta as $key => $value) { // Loop Through $rpuplugin_meta Array $key = sanitize_text_field($key); //paranoia - it's a good thing $value = sanitize_text_field($value); if ($post->post_type == 'revision') return; // Check Against Duplicated Data Storage $value = implode(',', (array)$value); // If $value is in an Array, Make it a CSV if (empty($value)) $value = 'no'; if (get_post_meta($post->ID, $key, FALSE)) { // If Field Already Has a Value update_post_meta($post->ID, $key, $value); } else { // If Field Does Not Have a Value add_post_meta($post->ID, $key, $value); } } return $post->ID; } //code to make managing syndication for many posts less of a PITA add_filter('manage_posts_columns', 'rpuplugin_columns'); function rpuplugin_columns($defaults) { $defaults['rpupluginsyndicate'] = __('Syndicated'); return $defaults; } add_action('manage_posts_custom_column', 'rpuplugin_custom_column', 10, 2); function rpuplugin_custom_column($column_name, $id) { if( $column_name == 'rpupluginsyndicate' ) { // Get Existing Data if Available $rpuplugin_enabled = get_post_meta($id, '_rpuplugin_enabled', true); // If it's not set to a valid value use the system default if(!preg_match("/yes|no/",$rpuplugin_enabled)) { $rpuplugin_enabled = get_option('rpuplugin_individual_post'); } print $rpuplugin_enabled; } } //Place Embed Code into Header function rpuplugin_header_code() { //Only output headers if the user has set an apikey, this stops us having a bad apikey when they have activated the plugin but not configured it $apikey = get_option('rpuplugin_apikey'); if (strlen($apikey) == 32) { echo "\n\n\n"; } } //Byline Contents function rpuplugin_byline_content() { if (get_option('rpuplugin_byline') == 'byline_startup') { //Initial Startup Setting return ""; } elseif (get_option('rpuplugin_byline') == '') { //Default Byline Content Setting return "By: ".get_the_author().""; } else { return str_replace("\"", "'", get_option('rpuplugin_byline')); //Fixes Quotes if URL is Included in Byline Content } } //Byline Inclusion function rpuplugin_byline_inclusion() { if (get_option('rpuplugin_include_byline') == 1) { return rpuplugin_byline_content(); } else { return ''; } } //Exclude Post by Date function rpuplugin_exclude_date() { $mo = (int) get_option('rpuplugin_exclude_month',01); if($mo < 1 || $mo > 12) $mo = 1; $dy = (int) get_option('rpuplugin_exclude_day',01); if($dy < 1 || $dy > 31) $dy = 1; $yr = (int) get_option('rpuplugin_exclude_year',2000); if($yr < 2000) $yr = 2000; return mktime(0,0,0,$mo,$dy,$yr); } function rpuplugin_make_button($type) { $buttonjs = "onclick: return(false);"; $buttontitle = "title='Repost may need more time to index your page. If issue persists, contact us at support@repost.us'"; if (get_option($type) != 'repostus_bttn_text') { // Button $buttonCode = ""; } else { // Text, $buttonCode = "". " " . strip_tags(get_option('rpuplugin_button_custom')) . ""; } return $buttonCode; } function rpuplugin_add_button($content,$location,$type) { if(get_option($type) == "none") { return $content; } $apikey = get_option('rpuplugin_apikey'); if (strlen($apikey) != 32) { return $content; } $buttonCode = rpuplugin_make_button($type); switch($location) { case 0: //top return "
" . $buttonCode . "
\n" . $content; case 1: //bottom return $content ."\n
" .$buttonCode . "
\n"; case 2: //custom return $content; case 3: //auto - addthis //Add this glue magic return $content . "\n
" . $buttonCode . "
\n" . ""; default: return $content; } } //Single Post Button Placement function rpuplugin_post_button_location($content) { if (rpuplugin_can_syndicate()) { if (is_single()) { $content = rpuplugin_add_button($content,get_option("rpuplugin_post_button_location"),"rpuplugin_post_button_type") ; } elseif(!is_page() && !is_feed()) { //On blog pages allow butto nat bottom or in add this or custom but don't allow on top $pos = max(get_option("rpuplugin_post_button_location"),1); $content = rpuplugin_add_button($content,$pos,"rpuplugin_blog_button_type") ; } return $content; } else { return $content; } } //Can we syndicate the current post? function rpuplugin_can_syndicate() { return (!is_feed() && ( (get_option('rpuplugin_individual_post') == 'yes' && get_post_meta(get_the_id(), '_rpuplugin_enabled', true) != "no") || (get_option('rpuplugin_individual_post') == 'no' && get_post_meta(get_the_id(), '_rpuplugin_enabled', true) == "yes") ) && get_the_date('U') > rpuplugin_exclude_date() ) ; } //Single Post Button Placement Using Shortcode //rpuplugin_individual_post function rpuplugin_shortcode($content) { $apikey = get_option('rpuplugin_apikey'); if (strlen($apikey) != 32) { return $content; } is_single() ? $type = "rpuplugin_post_button_type" : $type = "rpuplugin_blog_button_type"; if (rpuplugin_can_syndicate() && get_option("rpuplugin_post_button_location") == 2) { return rpuplugin_make_button($type); } else { return false; } } //Custom Button Contents function rpuplugin_button_content() { if (get_option('rpuplugin_button_custom') == 'rpuplugin_button_custom') { //Initial Startup Setting return ""; } else { return str_replace("\"", "'", get_option('rpuplugin_button_custom')); } } /** * We get content using our feed type 'rpujson' or new with 2.8 our /rpujson endpoint * The new endpoint method is prefered because it's less vulnerable to other plugins messing with it, however we'll support both for a while * to allows us a fallback if one or others is broken by another plugin. * * Note: all sanitizing of this output is done server side, we don't trues what we're sent so there is little point in sanitizing it here where it can be * subverted easily. **/ function rpuplugin_json_feed() { $_SERVER['HTTP_USER_AGENT'] = "Bloglines"; //Fool jetpack into expanding youtube $output = array(); while (have_posts()) { global $pages,$post; $images = array(); the_post(); $post_id = get_the_ID(); function_exists("get_post_thumbnail_id") ? $featured = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'single-post-thumbnail' ) : $featured = ""; $pages = array(implode($pages)); //unpaginate //We put begin / end markers on the content before we let other plugins process it then rip off the markers and //and content before or after the markers - this deals with all the social bookmark and related articles lint that //accumulates on content while still allowing in article content expansion like video embeds. //NB. This may lead to broken tags- we fix that server side. $content = apply_filters('the_content',"".get_the_content().""); // Use get_the_content() to because it does the password check $content = preg_replace("@.*\'; $rep .= '
'; $rep .= $thumb; $rep .= $fallback; $rep .= "
"; if(!empty($jump)) { $rep .= ''; } if($more || empty($jump)) { $rep .= ''; } // Set the search bait keywords if needed if(isset($atts['keywords'])) { $rep .= '"; } $rep .= ''; } return $rep; } /* Add our new feed type and endpoint - we're moving to the endpoint model because other peoples feed wrappers don't screw with it. Feed support is retaiend as a fallback */ function rpuplugin_json_init() { add_feed('rpujson','rpuplugin_json_feed'); add_rewrite_endpoint( 'rpujson', EP_PERMALINK | EP_PAGES ); //Also in _install } /** * Endpoint code based on https://gist.github.com/2891111 **/ /* Template redirect */ function rpuplugin_template_redirect() { global $wp_query; // if this is not a request for rpujson or it's not a singular object then bail if ( ! isset( $wp_query->query_vars['rpujson'] ) || ! is_singular() ) return; //Call common backend. rpuplugin_json_feed(); exit; } /** * Hook a few things so WordPress knows what to do with us **/ //Actions add_action( 'template_redirect', 'rpuplugin_template_redirect' ); add_action('init','rpuplugin_json_init'); add_action('wp_head', 'rpuplugin_header_code', 1); add_action('admin_menu','rpuplugin_admin_menu'); add_action('admin_init','rpuplugin_admin_init'); add_action('add_meta_boxes', 'rpuplugin_meta_box'); add_action('save_post', 'rpuplugin_save_meta', 1, 2); //add_action('admin_enqueue_scripts', 'rpuplugin_add_jquery', 1); add_action('wp_dashboard_setup', 'rpuplugin_add_dashboard_widgets'); //Filters add_filter('plugin_action_links', 'rpuplugin_action_links', 10, 2); add_filter('the_content', 'rpuplugin_post_button_location'); add_filter('pre_kses', 'repostus_embed_to_short_code'); //Shortcodes add_shortcode('rpuplugin', 'rpuplugin_shortcode'); add_shortcode('repostus', 'repostus_shortcode'); ?>