Add affiliate tracking code to Open Cart? - php

I've recently registered my site at an affiliate network which lets blogs write about me for a fixed price. But I'm having some difficulties adding the code properly.
Here's the code that I'm supposed to add:
<iframe src="http://track.domain.com/?trackID=[CookieID]&orderValue=[orderValue]&orderID=[orderID]&programID=319" scrolling="no" frameborder="0" width="1" height="1"></iframe>
So here's the code I tried to add in the success-page, which is where the code is supposed to be sent to the affiliate network (if the page is accessed through a given link). Notice that I'm trying to send a test order just to make sure it's added to my profile.
<?php
class ControllerCheckoutSuccess extends Controller {
public function index() {
$adrecordPixel = '<iframe src="http://track.adrecord.com/?trackID=' . $_COOKIE['trackID'] . '&orderValue=555555&orderID=5555555&programID=319&test=' . $this->session->data['order_id'] . '" scrolling="no" frameborder="0" width="1" height="1"></iframe>';
And
if ($this->customer->isLogged()) {
$this->data['text_message'] = sprintf($this->language->get('text_customer'), $this->url->link('account/account', '', 'SSL'), $this->url->link('account/order', '', 'SSL'), $this->url->link('account/download', '', 'SSL'), $this->url->link('information/contact'));
$this->data['text_message'] = $adrecordPixel;
But it doesn't work :(
Anyone has any idea on how I can do this?
I will refresh each 5 minutes to check for answers and I will reply asap. If anyone wants to know the URL just ask.
Thanks in advance

Why are you writing over $text_message variable with this line:
$this->data['text_message'] = $adrecordPixel;
Just prepare the html in its own variable in the controller index() function and pass it:
$this->data['pixel'] = '<iframe src="http://track.adrecord.com/?trackID=' . $_COOKIE['trackID'] . '&orderValue=555555&orderID=5555555&programID=319&test=' . $this->session->data['order_id'] . '" scrolling="no" frameborder="0" width="1" height="1"></iframe>';
Then echo $pixel in your view wherever.

Related

Extract part of url in php

I have a url: http://domain.tld/123456789abc.html
My goal is to create an embed code like this:
<iframe src="http://domain.tld/embed-123456789abc-620x360.html" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="620" height="360"></iframe>
But instead of gave me this:
<iframe src="http://domain.tld/embed-123456789abc.html-620x360.html" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="620" height="360"></iframe>
Notice the ".html" included above (123456789abc.html-620x360)?. How can create the code without the ".html" from the source url?
This is the code being used.
elseif (substr_count($link,"domain")){
$video_id = explode("/",$link);
if (isset($video_id[count($video_id)-1])){
$video_id = $video_id[count($video_id)-1];
$embed = '<IFRAME SRC="http://domain.tld/embed-'.$video_id.'-'.$width.'x'.$height.'.html" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="'.$width.'" height="'.$height.'"></iframe>';
}
Appreciate the help. Thank you.
You need to 'clean' $video_id because the ".html" should be contained into the array component you are retrieving.
So instead of
$video_id = $video_id[count($video_id)-1];
try something like this:
$video_id = str_replace('.html', '', $video_id[count($video_id)-1]);
It might be easier to use a regex to match the last part of your
original link, already excluding the .html:
elseif (substr_count($link,"domain")) {
$embed = preg_replace(
'#.+/([^/]+).html$#',
'<iframe src="http://domain.tld/embed-$1-'
. $width . 'x' . $height . '.html"'
. 'frameborder="0" marginwidth="0" marginheight="0" scrolling="no"'
. 'width="' . $width . '" height="' . $height . '"></iframe>',
$link
);
}

php youtube and links regex are combining and in turn rendering useless

i have a posting feature on my site that can embed links and youtube videos. the problem is, that the two clash together, and the youtube iframe ends up being a 404 page on my site. my codes for the youtube videos and links are below, but im not sure how to stop them from combining and ruining it.
by combining, i mean this http://www.youtube.com/watch?v=VhqiT2nWCVU turns to
<iframe src="http://www.youtube.com/watch?v=VhqiT2nWCVU">
which then turns into
<iframe src="">
sorry if i am unclear in any way. my codes are below.
function youtube($string)
{
return preg_replace(
'#(http://(www.)?youtube.com)?/(v/|watch\?v\=)([-|~_0-9A-Za-z]+)&?.*?#i',
'<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/$4?rel=0" frameborder="0" allowfullscreen></iframe>',
$string
);
}
$posted = youtube($posted);
$rexProtocol = '(https?://)?';
$rexDomain = '((?:[-a-zA-Z0-9]{1,63}\.)+[-a-zA-Z0-9]{2,63}|(?:[0-9]{1,3}\.){3}[0-9]{1,3})';
$rexPort = '(:[0-9]{1,5})?';
$rexPath = '(/[!$-/0-9:;=#_\':;!a-zA-Z\x7f-\xff]*?)?';
$rexQuery = '(\?[!$-/0-9:;=#_\':;!a-zA-Z\x7f-\xff]+?)?';
$rexFragment = '(#[!$-/0-9:;=#_\':;!a-zA-Z\x7f-\xff]+?)?';
// Solution 1:
function callback($match)
{
// Prepend http:// if no protocol specified
$completeUrl = $match[1] ? $match[0] : "http://{$match[0]}";
return '<a href="' . $completeUrl . '">'
. $match[2] . $match[3] . $match[4] . '</a>';
}
$posted = preg_replace_callback("&\\b$rexProtocol$rexDomain$rexPort$rexPath$rexQuery$rexFragment(?=[?.!,;:\"]?(\s|$))&",
'callback', $posted);
A popular solution to this problem is to use placeholders. On your first pass you turn all YouTube links into a placeholder, for example:
{{youtube:VhqiT2nWCVU}}
After that you run your normal link converter. And at the end your run yet another regex to turn all your palceholders into youtube embeds.

correct syntax to echo variable inside iframe

I know i am missing something simple. I just want to display this iframe if $video-code exists. Can anyone see what is wrong with this? working in wordpress. error is on the echo line. i've also tried adding .'$video-code'. into the url.
it is displaying the iframe correctly, but the variable is displaying as text in the url. if i call the variable elsewhere in the page without the If statement, it displays correctly.
THANKS for any help!
<?php
$key = 'video-code';
$themeta = get_post_meta($post->ID, $key, TRUE);
if($themeta != '') {
echo '<iframe id="player" width="560" height="315" frameborder="2" src="http://www.youtube.com/embed/$video-code" ></iframe>';
}?>
You can concatenate your $key, like so:
echo '<iframe id="player" width="560" height="315" frameborder="2"
src="http://www.youtube.com/embed/' . $key . '" ></iframe>';

Searching YouTube and displaying first video in PHP, advice needed?

I'm not sure when, but at some point my YouTube searching method stopped working, it has worked for years but both the API and the preferred method of displaying embedded video has changed. I've looked at the official Google docs and I have the option of using Zend or the currently in development Version 3 of the Google API, these are a lot larger codebases than what I was currently using.
I've tried debugging my code and may eventually get it working again, should I just scrap it and integrate the more official PHP codebase into my project. This was is where my method sits, it finds data, but I don't seem to display any videos...
public function embeddableVideoClipFor($searchString)
{
// Previous experience revealed that video search is not perfect, but we're just going to giver and create an embedded player with the
// top result or return NULL
// I used this as a guide to build my embedded player http://code.google.com/apis/youtube/youtube_player_demo.html
$embeddableVideoClipHTML = NULL;
// Further details on searching YouTube http://www.ibm.com/developerworks/xml/library/x-youtubeapi/
// This was working well for over two years but now I'm getting no videos, I may have been throttled or more likely the API has changed...
// Before switching to Zend or going to switch to version 3.0 of Google/YouTube API I should try and debug...
$vq = $searchString;
$vq = preg_replace('/[[:space:]]+/', ' ', trim($vq));
$vq = urlencode($vq);
$feedURL = 'http://gdata.youtube.com/feeds/api/videos?q=' . $vq . '&safeSearch=none&orderby=viewCount&v=2'; // Added version two tag...
print_r($feedURL);
// read feed into SimpleXML object
try
{
$youTubeXML = simplexml_load_file($feedURL);
}
catch(Exception $e)
{
// This rarely throws an error, but when it does, I just want to pretend I can't find a video clip
$youTubeXML = NULL;
}
print("<pre>");
print_r($youTubeXML);
print("</pre>");
if(($youTubeXML != NULL) && ( ! empty($youTubeXML->entry->link[0]['href'])))
{
$videoLink = $youTubeXML->entry->link[0]['href']; // This is not enough, I need to trim the beginning and end off this to just get the video code
$trimedURL = str_replace('http://www.youtube.com/watch?v=', '' , $videoLink);
$videoCode = str_replace('&feature=youtube_gdata', '', $trimedURL);
// $embeddableVideoClipHTML = '<object style="height: 390px; width: 640px"><param name="movie" value="http://www.youtube.com/v/' . $videoCode . '"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/' . $videoCode . '?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object>';
// $embeddableVideoClipHTML = '<iframe id="ytplayer" type="text/html" width="640" height="360" src="https://www.youtube.com/embed/' . $videoCode . '"frameborder="0" allowfullscreen>';
// Version 3
$embeddableVideoClipHTML = '<object width="640" height="360"><param name="movie" value="https://www.youtube.com/v/' . $videoCode . '?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="https://www.youtube.com/v/' . $videoCode . '?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="360"></embed></object>';
}
return $embeddableVideoClipHTML;
}
I'm not sure why, because I did try it, but switching to the iFrame, ie this line of code:
// $embeddableVideoClipHTML = '<iframe id="ytplayer" type="text/html" width="640" height="360" src="https://www.youtube.com/embed/' . $videoCode . '"frameborder="0" allowfullscreen>';
Works now, but I still wonder if I should jump through hoops to use one of the more official PHP frameworks, I really only use this one method to access the Google/YouTube api, it isn't a big part of my mashup, but I like it for movie trailers and song lyric quotations.

youtube autoplay is not working with iframe

i have php function which generate youtube code to display video but auto play is not working properly
function get_youtube_embed($youtube_video_id = 0, $auto = 0) {
$embed_code = "";
if ($auto == 1) {
$embed_code = '<iframe width="589" height="342" src="http://www.youtube.com/embed/' . $youtube_video_id . '?autoplay=1" frameborder="0" allowfullscreen></iframe>';
}
else {
$embed_code = '<iframe width="589" height="342" src="http://www.youtube.com/embed/' . $youtube_video_id . '" frameborder="0" allowfullscreen></iframe>';
}
return $embed_code;
}
Thanks
Your code is alright, try doing it by hand, without Javascript. Most likely that the way to set autoplay is wrong in your code.
It appears that the autoplay does not always work in the newer
At the bottom of the embed option section on the youtube site, there is a checkbox allowing you to use the old code. Use this as your base.
Your code should look something like this:
$embed_code = '<object width="420" height="345"><param name="movie" value="http://www.youtube.com/v/' . $youtube_video_id . '?version=3&hl=en_US&rel=0&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $youtube_video_id . '?version=3&hl=en_US&rel=0&autoplay=1" type="application/x-shockwave-flash" width="420" height="345" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
see: http://www.google.com/support/youtube/bin/answer.py?answer=171780&expand=UseOldEmbedCode#oldcode

Categories