<?php

/**
 * https://blog.shahednasser.com/how-to-easily-add-share-links-for-each-social-media-platform/#facebook
 */

// system links
// - home page
add_shortcode('dragblock.home.url', 'dragblock_shortcode_home_url');
function dragblock_shortcode_home_url($attrs = array())
{
	return get_home_url();
}
add_shortcode('dragblock.theme.url', 'dragblock_shortcode_theme_url');
function dragblock_shortcode_theme_url($attrs = array())
{
	return get_stylesheet_directory_uri();
}

// - latest posts
add_shortcode('dragblock.blog.url', 'dragblock_shortcode_blog_url');
function dragblock_shortcode_blog_url($attrs = array())
{
	$link = add_query_arg(array(
		's' => '',
		'post_type' => 'post'
	), get_home_url());

	// Get the blog page ID from the WordPress reading settings
	$blog_page_id = get_option('page_for_posts');

	// Check if a static page is set as the blog page
	if ($blog_page_id) {
		// Get the blog page URL
		$blog_page_url = get_permalink($blog_page_id);

		$link = $blog_page_url;
	}
	return $link;
}




// - login page
add_shortcode('dragblock.login.url', 'dragblock_shortcode_login_url');
function dragblock_shortcode_login_url($attrs = array())
{
	return wp_login_url();
}


function dragblock_current_url()
{
	global $wp;
	return home_url(add_query_arg($_GET, $wp->request));
}

//  twitter
add_shortcode('dragblock.share.url.twitter', 'dragblock_shortcode_share_url_twitter');
function dragblock_shortcode_share_url_twitter($attrs = array())
{
	return 'https://twitter.com/intent/tweet?text=' . dragblock_current_url();
}

// facebook
add_shortcode('dragblock.share.url.facebook', 'dragblock_shortcode_share_url_facebook');
function dragblock_shortcode_share_url_facebook($attrs = array())
{
	return 'https://www.facebook.com/sharer/sharer.php?u=' . dragblock_current_url();
}

// whatsapp
add_shortcode('dragblock.share.url.whatsapp', 'dragblock_shortcode_share_url_whatsapp');
function dragblock_shortcode_share_url_whatsapp($attrs = array())
{
	return 'https://wa.me/?text=' . dragblock_current_url();
}

// telegram
add_shortcode('dragblock.share.url.telegram', 'dragblock_shortcode_share_url_telegram');
function dragblock_shortcode_share_url_telegram($attrs = array())
{
	return 'https://t.me/share/url?url=' . dragblock_current_url();
}

// tumblr
add_shortcode('dragblock.share.url.tumblr', 'dragblock_shortcode_share_url_tumblr');
function dragblock_shortcode_share_url_tumblr($attrs = array())
{
	return 'https://www.tumblr.com/widgets/share/tool?canonicalUrl=' . dragblock_current_url();
}

// reddit
add_shortcode('dragblock.share.url.reddit', 'dragblock_shortcode_share_url_reddit');
function dragblock_shortcode_share_url_reddit($attrs = array())
{
	return 'https://www.reddit.com/submit?url=' . dragblock_current_url();
}

// linkedin
add_shortcode('dragblock.share.url.linkedin', 'dragblock_shortcode_share_url_linkedin');
function dragblock_shortcode_share_url_linkedin($attrs = array())
{
	return 'https://www.linkedin.com/sharing/share-offsite/?url=' . dragblock_current_url();
}

// gmail
add_shortcode('dragblock.share.url.gmail', 'dragblock_shortcode_share_url_gmail');
function dragblock_shortcode_share_url_gmail($attrs = array())
{
	return 'https://mail.google.com/mail/u/0/?view=cm&fs=1&tf=1&body=' . dragblock_current_url();
}

// email
add_shortcode('dragblock.share.url.email', 'dragblock_shortcode_share_url_email');
function dragblock_shortcode_share_url_email($attrs = array())
{
	return 'mailto:?body=' . dragblock_current_url();
}

// NAVIGATOR (for mobile devices)
add_shortcode('dragblock.share.url.navigator', 'dragblock_shortcode_share_url_navigator');
function dragblock_shortcode_share_url_navigator($attrs = array())
{
	return 'javascript:navigator.share?navigator.share({url:location.href}):null';
}
