Dynamically Generating Webpages – Insert Video

This is just a teaser for a series of articles on dynamically creating webpages on the fly based on keywords. Whether it’s based on a list of related keywords to your target set or simply based on what a user is searching for, the more content that you can provide related to the term, the better off your chances of it being ranked well in the serps (not to mention will provide a better user experience).

Here’s an easy one for you, it will pull a youtube video based on whatever keyword you give it. For use in a wordpress installation, make sure to enable the Exec-PHP plugin before inserting the code.

There are two parts to this, the youtube class and then the actual code to call it and display the video. This was taken long ago from a post on WF, though has been slightly modded. I forget who originally provided it but thanks. 🙂

Instead of having one huge php file with all the various functions, I’ve found it easier to separate each task into separate class files, that way on the actual page I only need to use the include() function and call up the script using my keyword.

Create a file called youtube_class.php and insert the following code:

<?php 

class youtube{ 
     
    function get_youtubevideo($theproduct){                 
        ///do youtube stuff     
        $theproductencoded=urlencode($theproduct);         
        $apicall = "http://gdata.youtube.com/feeds/videos?vq=$theproductencoded&max-results=1";         
        //Initialize the Curl session 
        $ch = curl_init();         
        //Set curl to return the data instead of printing it to the browser. 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);         
        //Set the URL 
        curl_setopt($ch, CURLOPT_URL, $apicall);         
        //Execute the fetch 
        $data = curl_exec($ch);         
        //Close the connection 
        curl_close($ch);                             
        $xml = new SimpleXMLElement($data);                     
        // Check to see if the XML response was loaded, else print an error 
        $contentcenter.="<div class="leftside">";         
        //show the video if a video was found         
        if (!empty($xml->entry)) {             
        $media = $xml->entry->children('http://search.yahoo.com/mrss/');         
        $vidtitle= $media->group->title;         
        $vid= $media->group->content->attributes()->url;             
        $contentcenter.="<h1>Video for " . str_replace("-"," ",ucwords($theproduct)). "</h1>";                     
        $results = '';         
        // If the XML response was loaded, parse it and build links          
        $vid = str_replace("?v=", "v/", $vid);          
        // For each SearchResultItem node, build a link and append it to $results         
        $contentcenter.= "<object width="425" height="355"> 
        <param name="movie" value="$vid"></param> 
        <param name="wmode" value="transparent"></param> 
        <embed src="$vid" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed> 
        </object>";         
        } 
         
        // If there was no XML response, print an error         
        else {             
            //$results = "Dang! Must not have got the XML response!"; 
            $contentcenter .= "<h2>Error: No video found</h2>";                     
        } 
        $contentcenter.="</div>";         
        return $contentcenter;         
    }     
}


?>

Now on whatever page you’d like to display the youtube video, simply insert the following code:

include_once("youtube_class.php");
$theproduct = 'topic';
$videoshow = new youtube();
echo $videoshow->get_youtubevideo($theproduct);

Typically you’ll have the keyword that you’re using to generate the dynamic page already stored as a variable, in which case you can just replace $theproduct = ‘topic’; with your variable(i.e. $searchkeyword).

Cloak And Rotate Your Affiliate Links!

Here’s a simple php script that you can use to not only cloak the referrer information, but also to rotate through your affiliate links so that you can test different offers and/or different advertising networks.

In order to hide your traffic sources you need to send the user through a double-redirect before pushing them along to the advertisers page. This can be done many different ways, but for the sake of this post I’m just going to use a very basic PHP redirect. For this setup, have the offer link on your landing page point to link.php, which will immediately redirect them to offer.php. Once they reach offer.php it will randomly select one of the affiliate links and redirect them on to their final destination. It’s that simple.

link.php

<?php
/* Redirect browser */
header("Location: offer.php");
/* Now the next line just makes sure that code below does not get executed when we redirect. */
exit;
?>

Now here’s the second file – You’ll want to replace the URL’s with YOUR affiliate links. If you’d like to add or remove offers just add or remove one of the “$affiliateoffer[] = ‘http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=1788&t202kw='” lines.

offer.php

<?php
$r = $_GET['sub'];
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=1788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=2788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=3788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=4788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=5788&t202kw=';
srand ((double) microtime() * 1000000);
$random_number = rand(0,count($affiliateoffer)-1);
$dur = ($affiliateoffer[$random_number]);
$moneysite = $dur.$r;
header("Location: $moneysite");
?>

There you go, now you’re safeguarding your leads as well as testing out networks/offers. Remember, the secret to having sustainable campaigns is to always be testing!

Break out of ANY iFrame (Including Google Image Search)

Have a video game portal and you’re tired of folks iframing their own ads around your games? Want to break the google image iframe when it reaches your site? Easy, just copy and paste this code at the top of your file and it’ll break you out of any iframe. For large sites it’s best to put it in an external .js file and just use an include call at the top of each page:

<script type="text/javascript">
	<!--
		if (top.location!= self.location) {
			top.location = self.location.href
		}
	//-->
</script>

Enjoy

Free Greasemonkey Script For Facebook Ad Manager

Facebook Ad Manager Greasemonkey Script

Let’s face it, the UI for the Ad Manager in Facebook is horrible, especially if you’ve got a large set of campaigns & are having to deal w/ the ebb and flow of interns rejecting + accepting ads (not to mention deleting/re-submitting them after they’ve been rejected).

Apparently there are other scripts/add-ons available that make this process a whole lot easier, but as was recently pointed out over on the WickedFire Forums, there’s a guy out there who’s actually trying to sell this script for $99.95 (or if you’re dumb enough to send him $25 now to secure your spot in the ‘pre-order’ the script would only be $85 after his discount). He’s since updated his blog to announce that his program would not be released on time after-all, adding that:

…Some rookie on WF totally stole my steam and posted some FireFox plug-in that works pretty sweet with FB to do lots of stuff I had planned.

Well, that rookie just knocked out a working script in one night (while allegedly drunk) meanwhile you’ve only been talking about the project since November 20th….hope you learned a lesson in being quiet.

Nathan from WF from just released what he claims was a drunken coding effort, but regardless is a great Greasemonkey script that streamlines managing Facebook ads. He even was so kind enough to add in a ‘dickroll’ option allowing you to partake in the kind of entertainment that only makemonies.com can provide.

You’ll need the Greasemonkey Firefox add-on in order to use this, install that first from the mozilla add-on site then, after installing & restarting Firefox, download and open (with Firefox) Nathan’s fbo.user.js script (which should then add it to Greasemonkey). Just head on over to the Facebook Ad Manager and partake in your newly acquired abilities of awesomeness.

Some brief features:
Here’s the old campaign screen, forcing you to click through far too many screens just to perform basic ad management functions:
The old Facebook Campaign Screen Before Installing The Greasemonkey Script

Here’s the improved campaign screen, now with added shortcuts:
Facebook Campaign Screen With Greasemonkey Script Installed

Now this wouldn’t be complete without the MakeMonies shout-out…
The Old Menu Bar:
The Facebook Ad Manager Menu Before Installing The Greasemonkey script

The *New* Menu Bar:
The new Facebook Ad Manager Menu After Installing The Greasemonkey Script

Dynamically Generate Users Location On Landing Pages

What? An offer only available if I live in:

Hey, that’s me…sign me up!

Making a user think they’re looking at a local company or offer is an old trick that typically meant you’d have to download and install a location database and then call it using php/perl. Well, not anymore. Part of Google’s AJAX API is a geolocating service. It loads fast + barely takes up any space….great for testimonials or redirected users to specific pages based on their location. It’s a well established marketing theory that consumers will always feel more secure (i.e. more likely to open their wallets up) with someone they can relate to. What’s an instant way to relate to all your customers regardless of how big of an affiliate scum-bag you are? By making them think you’re both from the same city.

It might be a few miles off for some locations and give you the city next door, but over-all it’s pretty spot on and a great little tool that’s only a few lines of code. Best of all, you don’t need any type of Google developer key as it’s not tied to any specific website (i.e. you don’t need to register the site for it to work). Enjoy

Here you go:

<script type="text/javascript" 
src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
if (typeof(google.loader.ClientLocation.address.city) != null) {
  document.write(google.loader.ClientLocation.address.city
  +", "
  +google.loader.ClientLocation.address.region);
} else {
  document.write("Unknown location")
}
</script>