MyBB Community Forums

Full Version: How to make this code snippet work for MyBB?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Locking content until shared incorporated into any MyCode??? How to?
Here's the coding (I purchased the license for this, and for others.. if you haven't purchased the license you can do so here):
PHP file 1:
<?php 
/*
Script Name: Viral Lock PHP
Description: Viral Lock let's you hide premium content from your users until they Like, Google+1 or Tweet about the page.
Version: 1.1
Author: WESMASHED.IT
*/
ob_start();
class virallocker_class {
	
	function __construct() 
	{
		$this->add_header();
	}

	/** Function to Get the Current URL **/
	function curPageURL() 
	{
		$pageURL = 'http';
		if (isset($_SERVER["HTTPS"]) && ( $_SERVER["HTTPS"] == "on" ) ) {$pageURL .= "s";}
		$pageURL .= "://";
		if ($_SERVER["SERVER_PORT"] != "80") {
		$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
		} else {
		$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
		}
		return $pageURL;
	}

	function virallocker_handler( $my_id, $pageVLArr ) 
	{
		echo '
		<script type="text/javascript">
			var virallocker_use = true;
			function virallocker_plusone(plusone) {
				if (plusone.state == "on") {
					var data = { action: "virallocker", myID: "'.$my_id.'"};
					jQuery.post("viral-lock.class.php", data, function(response) {
						if (virallocker_use) location.reload();					
					});
				}
			}
			FB.init();
			jQuery(document).ready(function() {
				FB.Event.subscribe("edge.create", function(href) { 
					var data = { action: "virallocker", myID: "'.$my_id.'"};
					jQuery.post("viral-lock.class.php", data, function(response) {
						if (virallocker_use) location.reload();					
					});
					
				});
				twttr.ready(function (twttr) {
					twttr.events.bind("tweet", function(event) {
						var data = { action: "virallocker", myID: "'.$my_id.'"};
						jQuery.post("viral-lock.class.php", data, function(response) {
						if (virallocker_use) location.reload();					
					});
					});
				});
			});
		</script>';
	}
	
	/** Function to add the required styles and scripts **/
	function add_header() 
	{
	    /** Include the required styles and scripts for the VL script **/
		echo '<style type="text/css">
		.virallocker-box {background-color: #E0ECEF;border: 1px dashed #3B5998;padding: 10px 20px;	color: #000;text-align: left; margin-top: 5px; margin-bottom: 5px;border-radius: 5px;-moz-border-radius: 5px; font-weight: bold; font-family: Helvetica, Verdana, Arial, sans-serif;}
		.virallocker-box  div {margin-top: 5px;}
		.fb_edge_widget_with_comment span.fb_edge_comment_widget iframe.fb_ltr {display: none !important;}
		.virallocker-box iframe {max-width: 600px !important;}
		</style>';
		echo '<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>';
		echo '<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>';
		echo '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';
		echo '<script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script>';
		echo '<div id="fb-root"></div><script type="text/javascript">FB.XFBML.parse();</script>';
	}

	/** Function to define the defaut Viral Lock fields **/
	function default_vl_array()
	{
		/** Get the current URL **/
		$currentUrl = $this->curPageURL();
		/** Define the default VL fields **/
		$defaultVLArr = array( 
								'VIRALLOCKER_DEFAULTMESSAGE' => 'Like or Tweet about this page to reveal the content.',
								'VIRALLOCKER_COOKIEVALUE' => '0001',
								'URL' => $currentUrl,
								'TWEET' => 'Check out this link'
							);	
		return $defaultVLArr;
	}
}

/** Intiate object **/
$virallocker = new virallocker_class();
/** set cookie on ajax call and return true to show the locked content **/
if( isset( $_POST['action'] ) && ( $_POST['action'] == 'virallocker' ) )
{
	$my_id = $_POST['myID'];
	$myArr = $virallocker->default_vl_array();
	setcookie("virallock_".$my_id, $myArr['VIRALLOCKER_COOKIEVALUE'], time()+60*60*24*365*10);
	echo true;
	exit;
}
?>


Codes to add theme or alter for MyCode:
<?php 
/*
Script Name: Viral Lock PHP
Description: Viral Lock let's you hide premium content from your users until they Like, Google+1 or Tweet about the page.
Version: 1.1
Author: WESMASHED.IT
*/
ob_start();
class virallocker_class {
	
	function __construct() 
	{
		$this->add_header();
	}

	/** Function to Get the Current URL **/
	function curPageURL() 
	{
		$pageURL = 'http';
		if (isset($_SERVER["HTTPS"]) && ( $_SERVER["HTTPS"] == "on" ) ) {$pageURL .= "s";}
		$pageURL .= "://";
		if ($_SERVER["SERVER_PORT"] != "80") {
		$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
		} else {
		$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
		}
		return $pageURL;
	}

	function virallocker_handler( $my_id, $pageVLArr ) 
	{
		echo '
		<script type="text/javascript">
			var virallocker_use = true;
			function virallocker_plusone(plusone) {
				if (plusone.state == "on") {
					var data = { action: "virallocker", myID: "'.$my_id.'"};
					jQuery.post("viral-lock.class.php", data, function(response) {
						if (virallocker_use) location.reload();					
					});
				}
			}
			FB.init();
			jQuery(document).ready(function() {
				FB.Event.subscribe("edge.create", function(href) { 
					var data = { action: "virallocker", myID: "'.$my_id.'"};
					jQuery.post("viral-lock.class.php", data, function(response) {
						if (virallocker_use) location.reload();					
					});
					
				});
				twttr.ready(function (twttr) {
					twttr.events.bind("tweet", function(event) {
						var data = { action: "virallocker", myID: "'.$my_id.'"};
						jQuery.post("viral-lock.class.php", data, function(response) {
						if (virallocker_use) location.reload();					
					});
					});
				});
			});
		</script>';
	}
	
	/** Function to add the required styles and scripts **/
	function add_header() 
	{
	    /** Include the required styles and scripts for the VL script **/
		echo '<style type="text/css">
		.virallocker-box {background-color: #E0ECEF;border: 1px dashed #3B5998;padding: 10px 20px;	color: #000;text-align: left; margin-top: 5px; margin-bottom: 5px;border-radius: 5px;-moz-border-radius: 5px; font-weight: bold; font-family: Helvetica, Verdana, Arial, sans-serif;}
		.virallocker-box  div {margin-top: 5px;}
		.fb_edge_widget_with_comment span.fb_edge_comment_widget iframe.fb_ltr {display: none !important;}
		.virallocker-box iframe {max-width: 600px !important;}
		</style>';
		echo '<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>';
		echo '<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>';
		echo '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';
		echo '<script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script>';
		echo '<div id="fb-root"></div><script type="text/javascript">FB.XFBML.parse();</script>';
	}

	/** Function to define the defaut Viral Lock fields **/
	function default_vl_array()
	{
		/** Get the current URL **/
		$currentUrl = $this->curPageURL();
		/** Define the default VL fields **/
		$defaultVLArr = array( 
								'VIRALLOCKER_DEFAULTMESSAGE' => 'Like or Tweet about this page to reveal the content.',
								'VIRALLOCKER_COOKIEVALUE' => '0001',
								'URL' => $currentUrl,
								'TWEET' => 'Check out this link'
							);	
		return $defaultVLArr;
	}
}

/** Intiate object **/
$virallocker = new virallocker_class();
/** set cookie on ajax call and return true to show the locked content **/
if( isset( $_POST['action'] ) && ( $_POST['action'] == 'virallocker' ) )
{
	$my_id = $_POST['myID'];
	$myArr = $virallocker->default_vl_array();
	setcookie("virallock_".$my_id, $myArr['VIRALLOCKER_COOKIEVALUE'], time()+60*60*24*365*10);
	echo true;
	exit;
}
?>
/** Set the VL fields **/
if (isset($pageVLArr["MY_ID"]) && !empty($pageVLArr["MY_ID"])) $my_id = $pageVLArr["MY_ID"];
if (isset($pageVLArr["TWEET"]) && !empty($pageVLArr["TWEET"])) $tweet = $pageVLArr["TWEET"];
else $tweet = $defArr["TWEET"];
if (isset($pageVLArr["URL"]) && !empty($pageVLArr["URL"])) $my_url = $pageVLArr["URL"];
else $my_url = $defArr["URL"];
if (isset($pageVLArr["MESSAGE"]) && !empty($pageVLArr["MESSAGE"])) $message = $pageVLArr["MESSAGE"];
else $message = $defArr["VIRALLOCKER_DEFAULTMESSAGE"];
/** Check if viral lock is active or not to show/hide the content accordingly **/
if( isset( $_COOKIE["virallock_".$my_id] ) )
$cookie_value = $_COOKIE["virallock_".$my_id];
if( !empty( $cookie_value ) && $cookie_value == $defArr['VIRALLOCKER_COOKIEVALUE'] )
{
?>
<!-- Content that needs to be hidden -->
<p>
CONTENT TO BLOCK GOES HERE
</p>
<?php
}
else
{
echo '
<script type="text/javascript">
virallocker_use = true;
</script>
<div class="virallocker-box">
'.$message.'
<div><a data-related="webtemplates" href="http://twitter.com/share" class="twitter-share-button" data-text="'.$tweet.'" data-url="'.$my_url.'" data-count="horizontal">Tweet</a></div>
<div><g:plusone size="medium" annotation="inline" callback="virallocker_plusone" href="'.$my_url.'"></g:plusone></div>
<div><fb:like id="fbLikeButton" href="'.$my_url.'" show_faces="false" width="450"></fb:like></div>
</div>';
}
/** Include the required fb div and short code handler **/
$virallocker->virallocker_handler( $my_id, $pageVLArr );
?>
<!-- End: Viral Lock Script to hide premium content -->

To change Default settings:
VIRALLOCKER_DEFAULTMESSAGE = This is the default message that is shown before content is unlocked. Replace the message with your own default message if you want to.

VIRALLOCKER_COOKIEVALUE = This is part of the cookie that is stored on the users computer. Usually you don't need to touch this but if you use the script on several sites it can be good to change it to another random value to not unlock any locks on several sites. This would required the MY_ID of the lock to be the same on both pages so usually this would not happen even if you use the script on several sites.

URL = This gets the current page URL if no URL is defined on the page where you use the lock. If you have another URL that you wan't to use as default Like url you can change the paramter (don't forget the single quotes 'http://wesmashed.it').

TWEET = Defines the default message that is sent to twitter. Your ofcourse free to change this to whatever you like, but remember to keep it short.
To change language of network share buttons:
Facebook:
echo '<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>';

Replace en_US with your country and language code. Example: de_DE for Germany.
_____________________________________________________
Twitter:
<div><a data-related="webtemplates" href="http://twitter.com/share" class="twitter-share-button" data-text="'.$tweet.'" data-url="'.$my_url.'" data-count="horizontal" data-lang="en">Tweet</a></div>

Replace data-lang="en" with your own language code. Example: data-lang="de" for german. Then on the same line replace "Tweet" with the translated version.
_____________________________________________________
Google+:
<script type="text/javascript">
window.___gcfg = {
lang: 'zh-CN'
};(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
To change cookie time:
setcookie("virallock_".$my_id, $myArr['VIRALLOCKER_COOKIEVALUE'], time()+60*60*24*365*10);

By default this is set to 10 years but you are free to change it to what fits your purpose best. Change "60*60*24*365*10". The format is 60s*60min*24h*365days*10years. So if you wan it to be saved for 90 days then change to it"60*60*24*90".

For styling:
.virallocker-box is the class you should apply your styles to.

You can also edit the default styles from line 69 of viral-lock.class.php.

Note to script author if author finds this thread, this is not intented to facilate or intended to be any form of rights infringement, every user has the responsibility to pay you for license to use your code if required by law. This thread is for recieving possible support to implement this script for use in MyBB powered forums and that is all.


Ok with the notification aside... how do I implement this into MyBB? Thanks a billion in advanced!