Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-22-2017, 03:57 AM
scottkoz20 scottkoz20 is offline
 
Join Date: Dec 2015
Location: Lewiston, NY
Posts: 344
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default ok - what did I do wrong

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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:04 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06846 seconds
  • Memory Usage 2,301KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete