Huwebes, Hulyo 19, 2012

“Viral Lock PHP CODE” To Make your Site Go VIRAL!!


“Viral Lock PHP” Documentation by “WESMASHED.IT” v1.1


“Viral Lock PHP”

Created: 21/02/2012
Created: 24/04/2012
By: WESMASHED.IT 

"Do not let what you cannot do interfere with what you can do."
-Unknown 

Viral Lock is also available for WordPress!

Table of Contents

  1. Basic usage
  2. Using the plugin
  3. Cookies
  4. Customizing the code

A) Basic usage - top

The easiest way to get started is to copy paste the code below (or copy paste the code from the included example.php), insert it into any PHP file and replace the lorem ipsum with your contetnt, code, script or whatever it is that you want to lock.
  • Replace URL with the link you wan't your users to share. This parameter is optional and if you delete the line the page URL will be used automatically.
  • NEW IN v. 1.1: Replace TURL with the link you wan't your users to share on Twitter. This parameter is optional and if you delete the line the gobal URL paramter will be used instead. Of none of these are defined then the page URL will be used.
  • NEW IN v. 1.1: Replace GURL with the link you wan't your users to share on Google+. This parameter is optional and if you delete the line the gobal URL paramter will be used instead. Of none of these are defined then the page URL will be used.
  • NEW IN v. 1.1: Replace FURL with the link you wan't your users to share on Facebook. This parameter is optional and if you delete the line the gobal URL paramter will be used instead. Of none of these are defined then the page URL will be used.
  • Replace MESSAGE with the message you wan't to display before the content is unlocked. This paramter is optinal and if you delete the line the default message will be shown instead.
  • Replace MY_ID with any unique string our number to identify this lock. This is to stop all of the locks to open if you unlock one lock. This paramter is required.
  • Replace TWEET with the message you want to send to twitter along with your link. This paramter is optinal, if you delete the line the default tweet message defined in viral-lock.class.php will be used.
<!-- Start: Viral Lock Script to hide premium content -->
<?php
/** Incude the Viral Locker Class **/
require_once( 'viral-lock.class.php' );
/** New Viral Object **/
$virallocker = new virallocker_class();
/** Get the default array **/
$defArr = $virallocker->default_vl_array();
/** Define the specific page VL fields if you want to **/
$pageVLArr = array(
'URL' => 'http://WESMASHED.IT',
'TURL' => 'http://www.twitter.com',
'GURL' => 'http://www.google.com',
'FURL' => 'http://www.facebook.com',
'MESSAGE' => 'Like or Tweet about this page to reveal the content.',
'MY_ID' => 'myid123',
'TWEET' => 'Check out this great script!'
);
/** 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>
<strong>Lorem Ipsum</strong> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
</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 -->

B) Customizing the Class - top

The "viral-lock.class.php" is the file that includes all the functions of the script. Here is what you need to know to customize this file.
Change the default settings
Between line 86-91 you can find the following code:
/** 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'
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.

Localizing

To change the language of the Facebook like button find line 75 of viral-lock.class.php:
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.

To change the language of the Tweet button find line on your page (line 61 in example.php)
<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.
To change the Google+ language add the following in the <head> part of your site.
<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>
Chage the cookie time
You can change how long the cookies are saved on the users computer (=how long the lock remains open) by editing line 104 of viral-lock.class.php:
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".


C) Cookies top

Please note that this script tries to place a cookie on the users computer so that the user doesen't have to like or share the post again to view the content. In some countries you have to inform your visitors that your site uses cookies.
You can read more about cookies here:

If you wan't to change the style of your Viral Lock box then you wan either edit the default styles in viral-lock.class.php or create a separate stylsheet.
.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.

 

KIND REGARDS
WESMASHED.IT