Skip to content

Instantly share code, notes, and snippets.

@mkeplinger
Created May 29, 2012 20:31
Show Gist options
  • Save mkeplinger/2830524 to your computer and use it in GitHub Desktop.
Save mkeplinger/2830524 to your computer and use it in GitHub Desktop.
<?php
//include & Initialize the RainTPL class - after this line $tpl should be available to use
include "bootstrap.php";
include "config/products/categories.php"; // Loads $categories @array
include "code/function.getWordpressBlock.php";
include "code/vendors/Rain/RainFramework/helper-functions.php";
// Deconstruct the path of the webpage to determine how to load the page.
$request_uri = explode('?', $_SERVER["REQUEST_URI"]);
$path = explode("/",$request_uri[0]);
$current_page = $_SERVER['SERVER_NAME'].$request_uri[0];
//Get product name from URL (if any)
if(count($path) > 2) $product = $path[2]; else $product = null;
$resize_small = array('w'=>70, 'h'=>100,'crop'=> true,'scale'=>true,'quality'=>100,'cache_http_minutes'=> 60*23);
$resize_normal = array('w'=>238,'h'=>272,'crop'=> true,'scale'=>true,'quality'=>100,'cache_http_minutes'=> 60*23);
//Check to see if there is anything in URL /products/XXXX
if (!empty($product)) {
//remove hyphens from name to name the PHP array
$product_array = str_ireplace("-", "", $product);
if(file_exists("config/products/".$product.".php")) {
// Setup the data and functions used to draw the page.
include_once("config/products/".$product.".php");
$product_data = $$product_array;
// Resize the Image Bottle as needed TODO: Figure out how to make these URLs cleaner. This is sloppy.
$product_image = "templates/ax/img/products/bottle-" . $product .".png"; // TODO: replace with RainTpl global template variable
$normal_bottle = "../".resize($product_image, $resize_normal);
$small_bottle = "../".resize($product_image, $resize_small);
// Loop through the master categories and determine which will be displayed on the product page.
// The 'active-1' will denote which to display. For example "active-2 active-4" will activate categories 2 and 4.
// Build the entire string here instead of the template, then pass string.
$active_list = "";
foreach($categories as $key => &$cat) {
if(array_search($key, $product_data["categories"]) !== false) {
$active_list = $active_list . " active-" . $key;
}
}
// Check for a specific headline name to use. If not present, just use the product name
if (empty($product_data['headline_name'])) {
$headline = $product_data['name'];
}
else {
$headline = $product_data['headline_name'];
}
// Load wordpress articles that are relevant to this product TODO: Figure out how to customize.
$resize_options = array('w'=>100, 'h'=>80, 'scale'=>false, 'crop'=>true);
$tpl->assign( "relevant_articles", getWordpressBlock("http://www.athleticxtreme.com/articles/category/feed", 6, 90, "block-wordpress-product-page", $resize_options));
$tpl->assign( "kb_articles", getWordpressBlock("http://support.athleticxtreme.com/customer/portal/topics/141078-german-creatine/articles.rss", 10, 1000, "block-kb-product-page", $resize_options));
// Assign dynamic data to template.
$tpl->assign( "headline", $headline);
$tpl->assign( "active_list", $active_list);
$tpl->assign( "categories", $categories);
$tpl->assign( "product", $product_data );
$tpl->assign( "current_page", $current_page);
$tpl->assign( "product_code", $product );
$tpl->assign( "normal_bottle", $normal_bottle );
$tpl->assign( "small_bottle", $small_bottle );
// Draw the HTML template
$tpl->draw('product');
exit;
} else {
$tpl->draw('404');
exit;
}
}
// Continue if the page is for the product grid /products and pass all URL parameters
// Prepare products data array using the Grid Array
$product_files = scandir("config/products/");
foreach($product_files as $file) {
if($file == "." || $file == ".." || $file=="categories.php") continue;
$product_code = substr($file, 0, strrpos($file, "."));
include_once("config/products/".$file);
$product_array = str_ireplace("-", "", $product_code);
$product_data = $$product_array;
foreach($product_data["categories"] as $cat) {
$grid[$cat]["products"][$product_code] = $product_data;
}
}
// Load and assign Product Categories data to template (needed for all page loads)
$tpl->assign( "categories", $categories);
$tpl->assign( "grid", $grid);
$tpl->draw('product-grid');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment