I was trying to build the 1st of several pages that I want to use to show the Most Watched eBay items in a certain category and I have a blunder somewhere and I'm too novice to figure this out
Here is the page
https://www.sportscardforum.com/ebay_bkb.php
The PHP code itself from eBay appears to be working right but where I am having the issue is getting the code into the template that I built
Here is the php
PHP Code:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'ebay_bkb');
define('CSRF_PROTECTION', true);
// change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('ebay_bkb',
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
$navbits = construct_navbits(array('' => 'Top 20 Most Watched Basketball Cards on eBay'));
$navbar = render_navbar_template($navbits);
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'Top 20 Most Watched Basketball Cards on eBay';
// Turn on all errors, warnings and notices for easier PHP debugging
error_reporting(E_ALL);
// Define global variables
$s_endpoint = "http://open.api.ebay.com/shopping?"; // Shopping URL to call
$cellColor = "bgcolor=\"#dfefff\""; // Light blue background used for selected items
$m_endpoint = 'http://svcs.ebay.com/MerchandisingService?'; // Merchandising URL to call
$appid = 'ScottKoz-Top25Mos-PRD-95d705b3d-e9d9a81d'; // You will need to supply your own AppID
$responseEncoding = 'XML'; // Type of response we want back
// Create a function for the getMostWatchedItems call
function getMostWatchedItemsResults ($selectedItemID = '', $cellColor = '') {
global $m_endpoint;
global $appid;
global $responseEncoding;
// Construct getMostWatchedItems call with maxResults and categoryId as input
$apicalla = "$m_endpoint";
$apicalla .= "OPERATION-NAME=getMostWatchedItems";
$apicalla .= "&SERVICE-VERSION=1.0.0";
$apicalla .= "&CONSUMER-ID=$appid";
$apicalla .= "&RESPONSE-DATA-FORMAT=$responseEncoding";
$apicalla .= "&maxResults=2";
$apicalla .= "&categoryId=215";
// Load the call and capture the document returned by eBay API
$resp = simplexml_load_file($apicalla);
// Check to see if the response was loaded, else print an error
if ($resp) {
// Set return value for the function to null
$retna = '';
// Verify whether call was successful
if ($resp->ack == "Success") {
// If there were no errors, build the return response for the function
// Build a table for the 20 most watched items
$retna .= "<!-- start table in getMostWatchedItemsResults --> \n";
$retna .= "<table width=\"75%\" cellpadding=\"10\" border=\"0\"><tr> \n";
// For each item node, build a table cell and append it to $retna
foreach($resp->itemRecommendations->item as $item) {
// Set the cell color blue for the selected most watched item
if ($selectedItemID == $item->itemId) {
$thisCellColor = $cellColor;
} else {
$thisCellColor = '';
}
// Determine which price to display
if ($item->currentPrice) {
$price = $item->currentPrice;
} else {
$price = $item->buyItNowPrice;
}
// For each item, create a cell with imageURL, viewItemURL, watchCount, currentPrice
$retna .= "<TR><TD><img src=\"$item->imageURL\"> \n<BR><BR></TD>";
$retna .= "<TD><STRONG><p><a href=\"" . $item->viewItemURL . "\">" . $item->title . "</a></p>\n</STRONG>";
$retna .= 'Time Remaining: <b>' . getPrettyTimeFromEbayTime($item->timeLeft). "</b><br> \n";
$retna .= 'Number of Watchers: <b>' . $item->watchCount . "</b><br> \n";
$retna .= 'Current Price: <b>$' . $price . "</b><br> \n</TD></TR>";
}
$retna .= "</tr></table> \n<!-- finish table in getMostWatchedItemsResults --> \n";
} else {
// If there were errors, print an error
$retna = "The response contains errors<br>";
$retna .= "Call used was: $apicalla";
} // if errors
} else {
// If there was no response, print an error
$retna = "Dang! Must not have got the getMostWatchedItems response!<br>";
$retna .= "Call used was: $apicalla";
} // End if response exists
// Return the function's value
return $retna;
$return_value = $retna;
} // End of getMostWatchedItemsResults function
function pluralS($intIn) {
// if $intIn > 1 return an 's', else return null string
if ($intIn > 1) {
return 's';
} else {
return '';
}
} // function
// Make returned eBay times pretty
function getPrettyTimeFromEbayTime($eBayTimeString){
// Input is of form 'PT12M25S'
$matchAry = array(); // null out array which will be filled
$pattern = "#P([0-9]{0,3}D)?T([0-9]?[0-9]H)?([0-9]?[0-9]M)?([0-9]?[0-9]S)#msiU";
preg_match($pattern, $eBayTimeString, $matchAry);
$days = (int) $matchAry[1];
$hours = (int) $matchAry[2];
$min = (int) $matchAry[3]; // $matchAry[3] is of form 55M - cast to int
$sec = (int) $matchAry[4];
$retnStr = '';
if ($days) { $retnStr .= " $days day" . pluralS($days); }
if ($hours) { $retnStr .= " $hours hour" . pluralS($hours); }
if ($min) { $retnStr .= " $min minute" . pluralS($min); }
if ($sec) { $retnStr .= " $sec second" . pluralS($sec); }
return $retnStr;
} // function
// Display the response data
// If button clicked for most watched item, display details and related category items
if (isset($_POST['Selection'])) {
$selectedItemID = $_POST['Selection'];
print getMostWatchedItemsResults($selectedItemID, $cellColor);
} else {
// If button not clicked, show only most watched items
print getMostWatchedItemsResults('', '');
}
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('ebay_bkb');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
$templater->register('return_value', $return_value);
print_output($templater->render());
?>
Here is the template Code and this is what is giving me fits
Code:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
<title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
{vb:raw headinclude}
{vb:raw headinclude_bottom}
</head>
<body>
{vb:raw header}
{vb:raw navbar}
<BR>
<h2 class="blockhead">{vb:raw pagetitle}</h2>
<div class="blockbody">
<div class="blockrow">
{vb:raw return_value}
</div>
</div>
{vb:raw footer}
</body>
</html>
my guess is that I am not setting the output correctly for the template to pick it up, but I don't know what I'd need to do with it.
once I have this one built, I have several more pages to create using the same structure.
Any direction would be welcome
Thanks,
Scott
--------------- Added [DATE]1511369262[/DATE] at [TIME]1511369262[/TIME] ---------------
Ok - I am pretty sure that it's the return that is causing the output to render at the top of the page.
And I did change the {vb:raw retna} in the template to a different name as I am trying to pass the result of retna to that variable.
Hoping that I'm getting close