PHP Social Media vbulletin plugin

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,073
78,998
2,371
Hello friends, I've been learning PHP and creating my first plugin the past few days and I'm looking for constructive criticism on my code. I'm using Nexia's OpenGraph Protocol Inserts as a basis for my project, so many thanks and credits for his great modification.

The plugin accomplishes this so far:
  • Adds Open Graph and Twitter Card meta tags to pages for better sharing
  • Includes code linking Facebook Domain and app insights to your page
  • vbAdvanced Support (the main reason I started modifying this)
  • Picks an image from the content with priority being video, then hot linked image, then attached image.
  • Grabs thumbnail from youtube video and drives traffic from your social share to your page instead of youtube
  • Grabs highest quality thumbnail available for the particular video
  • Defaults to a vboptions defined image if no image is found, no more social shares without images or badly resized images
  • Tells twitter the aspect ratio of the image for better resizing

This is what it dynamically adds to the HTML of everypage.
C++:
<meta property="og:description" content="Long tutorial here, gonna upload it in 4 seperate parts!  It is 1.5 hours long and will explain everything you need to know to get started using IDA Pro!
Requirements: Intermediate Knowledge of C++ and x86 Assembly"/>
<meta property="og:site_name" content="GuidedHacking How to Hack Games"/>
<meta property="og:title" content="How to Reverse Engineer with IDA Pro Disassembler"/>
<meta property="og:type" content="article"/>
<meta property="fb:app_id" content="1755543248015018"/>
<meta property="fb:admins" content="100009786466728"/>
<meta property="og:url" content="https://guidedhacking.com/showthread.php?7914-How-to-Reverse-Engineer-with-IDA-Pro-Disassembler"/>
<meta property="og:image" content="https://img.youtube.com/vi/fgMl0Uqiey8/maxresdefault.jpg"/>
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:site" content="@guidedhacking"/>
<meta name="twitter:image:width" content="1280"/>
<meta name="twitter:image:height" content="720"/>
Now the share looks like this:

Instead of:


Combining this with some simple social share buttons makes my social marketing campaign much sexier.

C++:
<?
			
global $vbulletin, $threadinfo, $bloginfo, $pagetitle;

$og_array = [
    'og:description'=>	$vbulletin->options['description'],
	'og:site_name'	=>	$vbulletin->options['bbtitle'],
	'og:title'		=>	$pagetitle,
	'og:type'		=>	'website'
	];

$tc_array = [
    'twitter:card'  => 'summary_large_image'
    ];


if (isset($vbulletin->options['gh_socialmeta_fbapp_id']))
{
    $og_array['fb:app_id'] = $vbulletin->options['gh_socialmeta_fbapp_id'];
}

if (isset($vbulletin->options['gh_socialmeta_fbadmin']))
{
    $og_array['fb:admins'] = $vbulletin->options['gh_socialmeta_fbadmin'];
}

if (isset($vbulletin->options['gh_socialmeta_twitter']))
{
    $tc_array['twitter:site'] = $vbulletin->options['gh_socialmeta_twitter'];
}

//if vbadvanced portal, use default image and description but grab vbAdvanced title
if (THIS_SCRIPT == 'adv_index')
{
	$og_array['og:title']          =   $pagetitle;
	$og_array['og:description']    =   $vbulletin->options['description'];
    $og_array['og:image']          =   $vbulletin->options['gh_socialmeta_image'];
    $og_array['og:url']            =   $vbulletin->options['bburl'];
    
}	

//if not the vbAdvanced portal
else if (THIS_SCRIPT == 'showthread' || THIS_SCRIPT == 'showpost')
{
	$og_array['og:url'] = create_full_url(fetch_seo_url('thread|js|nosession', $threadinfo, null, null, null, true));
	$og_array['og:title'] = $threadinfo['title'];
    $tc_array['twitter:card'] = 'summary';

	if (isset($GLOBALS['threadinfo']['description']) && !empty($GLOBALS['threadinfo']['description']))
	{
        $string = $GLOBALS['threadinfo']['description'];
		$og_array['og:description'] = substr($string, 0, 300);

        //if a video
        if (stripos($string, 'youtu'))
        {
            $regex = '/https?:\/\/((.+\.youtube\.com\/watch\?v=)|(youtu\.be\/))([a-zA-Z0-9-_]+)/';
            //$regex = '/((http(s)?:\/\/)?)(www\.)?((youtube\.com\/)|(youtu.be\/))[\S]+/'; //new shit gotta change code tho
            preg_match_all($regex, $string, $matches);
            if (!empty($matches))
            {
                //drive traffic to your URL, not youtube
                foreach ($matches[4] as $row)
                {
                    //for you bastards that might try to exploit this
                    if (strlen($row) == 11)
                    {
                        $h = get_headers('https://img.youtube.com/vi/' . $row . '/maxresdefault.jpg');

                        if (stripos($h[0], '404') == false)
                        {
                            $og_array['og:image'] = 'https://img.youtube.com/vi/' . $row . '/maxresdefault.jpg';
                            break;
                        }

                        else
                        {
                            $og_array['og:image'] = 'https://img.youtube.com/vi/' . $row . '/0.jpg';
                            break;
                        }
                    }
                }
                $tc_array['twitter:card'] = 'summary_large_image';
            }
        }

        //If a hot-linked image
		else if (stripos($string, '[/img]') !== false)
		{
			$regex = '#\[img\]\s*(https?://([^*\r\n]+|[a-z0-9/\\._\- !]+))\[/img\]#iUe';
			preg_match_all($regex, $string, $matches);
			if (!empty($matches))
			{
				$og_array['og:image'] = 'https://' . $matches[2][0];
			}
		}

		else if (stripos($string, '[/attach]') !== false)
		{
			$regex = '#\[attach(?:=(right|left|config))?\](\d+)\[/attach\]#i';
			preg_match_all($regex, $string, $matches);

			if (!empty($matches) && isset($matches[2]) && is_array($matches[2]))
			{
				foreach ($matches[2] as $attach_id)
				{
					$og_array['og:image'] = $vbulletin->options['bburl'] . '/attachment.php?attachmentid=' . $attach_id;
				}
			}
		}

        //otherwise use default image and summary_large_image
		else
		{
			$og_array['og:image'] = $vbulletin->options['gh_socialmeta_image'];
            $tc_array['twitter:card'] = 'summary_large_image';
		}
	}

	else if (THIS_SCRIPT == 'entry')
	{
		$og_array['og:url'] = create_full_url(fetch_seo_url('entry|js|nosession', $bloginfo, null, null, null, true));
		$og_array['og:title'] = $bloginfo['title'];
	}

	else if (THIS_SCRIPT == 'vbcms' && isset($vbulletin->vbcms['content_type']) && $vbulletin->vbcms['content_type'] =='Article')
	{
		$og_array['og:url'] = isset($vbulletin->vbcms['page_url']) ? $vbulletin->vbcms['page_url'] : $og_array['og:url'];
		$og_array['og:title'] = $vbulletin->vbcms['title'];
	}
}

if (THIS_SCRIPT == 'showthread'|| (THIS_SCRIPT == 'showpost') || (THIS_SCRIPT == 'entry') || (THIS_SCRIPT == 'vbcms' && isset($vbulletin->vbcms['content_type']) && $vbulletin->vbcms['content_type'] == 'Article'))
{
	$og_array['og:type'] = 'article';
}

if(!empty($og_array['og:image']))
{
    $data = getimagesize($og_array['og:image']);
    $tc_array['twitter:image:width']     = $data[0];
    $tc_array['twitter:image:height']    = $data[1];
}

$rows = '<html prefix="og: https://ogp.me/ns#">' . "\n";

foreach($og_array AS $key => $value)
{
	$rows .= '<meta property="' . $key . '" content="' . $value . '" />' . "\n";
}

foreach($tc_array AS $key => $value)
{
	$rows .= '<meta name="' . $key . '" content="' . $value . '" />' . "\n";
}

$template_hook['headinclude_bottom_css'] .= $rows;

?>

Thanks to Liam, Amonomen and mambda and the rest of the gang for their assistance!

Let me know if you have any tips!
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Similar threads

Community Mods