" . __("Your theme needs to be fixed. To fix your theme, use the Theme Editor to insert <?php wp_footer(); ?> just before the </body> line of your theme's footer.php file.") . "
";
}
// If header.php exists in the current theme, scan for "wp_head"
$file = $template_directory . '/header.php';
if (is_file($file)) {
$search_string = "wp_head";
$file_lines = @file($file);
foreach ($file_lines as $line) {
$searchCount = substr_count($line, $search_string);
if ($searchCount > 0) {
return true;
}
}
// wp_footer() not found:
echo "
" . __("Your theme needs to be fixed. To fix your theme, use the Theme Editor to insert <?php wp_head(); ?> just before the </head> line of your theme's header.php file.") . "
";
}
}
function A2A_SHARE_SAVE_auto_placement($title) {
global $A2A_SHARE_SAVE_auto_placement_ready;
$A2A_SHARE_SAVE_auto_placement_ready = true;
return $title;
}
/**
* Remove the_content filter and add it for next time
*/
function A2A_SHARE_SAVE_remove_from_content($content) {
remove_filter('the_content', 'A2A_SHARE_SAVE_add_to_content', 98);
add_filter('the_content', 'A2A_SHARE_SAVE_add_to_content_next_time', 98);
return $content;
}
/**
* Apply the_content filter "next time"
*/
function A2A_SHARE_SAVE_add_to_content_next_time($content) {
add_filter('the_content', 'A2A_SHARE_SAVE_add_to_content', 98);
return $content;
}
function A2A_SHARE_SAVE_add_to_content($content) {
global $A2A_SHARE_SAVE_auto_placement_ready;
$is_feed = is_feed();
$options = get_option('addtoany_options');
$sharing_disabled = get_post_meta( get_the_ID(), 'sharing_disabled', true );
if( ! $A2A_SHARE_SAVE_auto_placement_ready)
return $content;
if (get_post_status(get_the_ID()) == 'private')
return $content;
// Disabled for this post?
if ( ! empty( $sharing_disabled ) )
return $content;
if (
(
// Legacy tags
// tag
strpos($content, '')===false ||
// tag
strpos($content, '')!==false
) &&
(
// Posts
// All posts
( ! is_page() && $options['display_in_posts']=='-1' ) ||
// Front page posts
( is_home() && $options['display_in_posts_on_front_page']=='-1' ) ||
// Archive page posts (Category, Tag, Author and Date pages)
( is_archive() && $options['display_in_posts_on_archive_pages']=='-1' ) ||
// Search results posts (same as Archive page posts option)
( is_search() && $options['display_in_posts_on_archive_pages']=='-1' ) ||
// Posts in feed
( $is_feed && ($options['display_in_feed']=='-1' ) ||
// Pages
// Individual pages
( is_page() && $options['display_in_pages']=='-1' ) ||
// legacy tag
( (strpos($content, '')!==false) )
)
)
)
return $content;
$kit_args = array(
"output_later" => true,
"is_kit" => ($is_feed) ? FALSE : TRUE,
);
if ( ! $is_feed ) {
$container_wrap_open = '
';
$container_wrap_close = '
';
} else { // Is feed
$container_wrap_open = '
';
$container_wrap_close = '
';
$kit_args['html_container_open'] = '';
$kit_args['html_container_close'] = '';
$kit_args['html_wrap_open'] = '';
$kit_args['html_wrap_close'] = '';
}
$options['position'] = isset($options['position']) ? $options['position'] : 'bottom';
if ($options['position'] == 'both' || $options['position'] == 'top') {
// Prepend to content
$content = $container_wrap_open.ADDTOANY_SHARE_SAVE_KIT($kit_args) . $container_wrap_close . $content;
}
if ( $options['position'] == 'bottom' || $options['position'] == 'both') {
// Append to content
$content .= $container_wrap_open.ADDTOANY_SHARE_SAVE_KIT($kit_args) . $container_wrap_close;
}
return $content;
}
// Only automatically output button code after the_title has been called - to avoid premature calling from misc. the_content filters (especially meta description)
add_filter('the_title', 'A2A_SHARE_SAVE_auto_placement', 9);
add_filter('the_content', 'A2A_SHARE_SAVE_add_to_content', 98);
// [addtoany url="http://example.com/page.html" title="Some Example Page"]
function A2A_SHARE_SAVE_shortcode( $attributes ) {
extract( shortcode_atts( array(
'url' => 'something',
'title' => 'something else',
), $attributes ) );
$linkname = (isset($attributes['title'])) ? $attributes['title'] : FALSE;
$linkurl = (isset($attributes['url'])) ? $attributes['url'] : FALSE;
$output_later = TRUE;
return ADDTOANY_SHARE_SAVE_KIT( compact('linkname', 'linkurl', 'output_later') );
}
add_shortcode( 'addtoany', 'A2A_SHARE_SAVE_shortcode' );
function A2A_SHARE_SAVE_stylesheet() {
global $A2A_SHARE_SAVE_options, $A2A_SHARE_SAVE_plugin_url_path;
// Use stylesheet?
if ($A2A_SHARE_SAVE_options['inline_css'] != '-1' && ! is_admin()) {
wp_enqueue_style('A2A_SHARE_SAVE', $A2A_SHARE_SAVE_plugin_url_path . '/addtoany.min.css', false, '1.5');
}
}
add_action('wp_print_styles', 'A2A_SHARE_SAVE_stylesheet');
/*****************************
CACHE ADDTOANY
******************************/
function A2A_SHARE_SAVE_refresh_cache() {
$contents = wp_remote_fopen("http://www.addtoany.com/ext/updater/files_list/");
$file_urls = explode("\n", $contents, 20);
$upload_dir = wp_upload_dir();
// Make directory if needed
if ( ! wp_mkdir_p( dirname( $upload_dir['basedir'] . '/addtoany/foo' ) ) ) {
$message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), dirname( $new_file ) );
return array( 'error' => $message );
}
if (count($file_urls) > 0) {
for ($i = 0; $i < count($file_urls); $i++) {
// Download files
$file_url = $file_urls[$i];
$file_name = substr(strrchr($file_url, '/'), 1, 99);
// Place files in uploads/addtoany directory
wp_get_http($file_url, $upload_dir['basedir'] . '/addtoany/' . $file_name);
}
}
}
function A2A_SHARE_SAVE_schedule_cache() {
// WP "Cron" requires WP version 2.1
$timestamp = wp_next_scheduled('A2A_SHARE_SAVE_refresh_cache');
if ( ! $timestamp) {
// Only schedule if currently unscheduled
wp_schedule_event(time(), 'daily', 'A2A_SHARE_SAVE_refresh_cache');
}
}
function A2A_SHARE_SAVE_unschedule_cache() {
$timestamp = wp_next_scheduled('A2A_SHARE_SAVE_refresh_cache');
wp_unschedule_event($timestamp, 'A2A_SHARE_SAVE_refresh_cache');
}
/*****************************
OPTIONS
******************************/
// Post Options
function A2A_SHARE_SAVE_add_meta_box() {
// get_post_types() only included in WP 2.9/3.0
$post_types = ( function_exists( 'get_post_types' ) ) ? get_post_types( array( 'public' => true ) ) : array( 'post', 'page' ) ;
$title = apply_filters( 'A2A_SHARE_SAVE_meta_box_title', __( 'AddToAny', 'add-to-any' ) );
foreach( $post_types as $post_type ) {
add_meta_box( 'A2A_SHARE_SAVE_meta', $title, 'A2A_SHARE_SAVE_meta_box_content', $post_type, 'advanced', 'high' );
}
}
function A2A_SHARE_SAVE_meta_box_content( $post ) {
do_action( 'start_A2A_SHARE_SAVE_meta_box_content', $post );
$disabled = get_post_meta( $post->ID, 'sharing_disabled', true ); ?>