Jump to content

WordPress custom php for a script


Recommended Posts

Hello there,
 
I am trying to recreate a HTML website on a WordPress website. On the current website we pull a php file from the directory that lists brands for different catrogies.
 
http://www.nongmosho...d-and-seed.html
 
We use the following script
 

<!--?php <br ?--> <?php include('../lib/IphoneDataRenderer.php');?>
<?php echo $IphoneDataRenderer->getAdsForBrandId();?>

<!--?php } ?-->
<?php $IphoneDataRenderer listBrandsForCategory(); ?>
 
and it works fine for the website above. However, when I add this code within our WP website we don't get any information (I did add the /lib/iphoneDataRenderer.php files and folders).
 
Please message me your rate and any questions you have and I'll be in touch.
 
The php file I am pulling contains the following code:
 
<?php

include('../lib/IphoneService.php');
include('../brands/config.php');

define('AD_FOLDER', $_SERVER['DOCUMENT_ROOT'] . "/brands/logos/" );

class IphoneDataRenderer {

    private $showOnlyVerified = true;
    
    public $categoryIdByPageArray;

    public function IphoneDataRenderer() {
        /*
            $categoryArray = array();
            $categories = $service->getProdCategories();
            foreach ($categories as $category) {
            $categoryArray[$category->id] = $category->name;
         */
        $this->categoryIdByPageArray = array(
            '/brands/alternative-dairy-products.html' => 1,
            '/brands/baby-food-and-infant-formula.html' => 2,
            '/brands/beverages.html' => 3,
            '/brands/body-care-products.html' => 4,
            '/brands/breads-and-baked-good.html' => 5,
            '/brands/candy-chocolate-and-sweeteners.html' => 6,
            '/brands/cereal-and-breakfast-foods.html' => 7,
            '/brands/condiments-oils-dressings-and-spreads.html' => 8,
            '/brands/dairy-products.html' => 9,
            '/brands/feed-and-seed.html' => 10,
            '/brands/fruits-and-vegetables.html' => 13,
            '/brands/grains-beans-and-flour.html' => 15,
            '/brands/herbs-spices-and-other-ingredients.html' => 16,
            '/brands/meat-fish-and-eggs.html' => 17,
            '/brands/mercantile.html' => 18,
            '/brands/packaged-frozen-meals.html' => 19,
            '/brands/pasta.html' => 20,
            '/brands/pet-products.html' => 21,
            '/brands/snack-foods-and-bars.html' => 22,
            '/brands/soups-and-sauces.html' => 23,
            '/brands/tofu-tempeh-and-alternative-meat-products.html' => 24,
            '/brands/vitamins-and-supplements.html' => 25,
            '/brands/wholesale-ingredients.html' => 26
        );

    }

    private function stripUnverified($productList) {
        $returnArray = array();
        foreach($productList as $product) {
            if ($product->pVerified == 1) array_push($returnArray, $product);
        }
        return $returnArray;
    }
    
    public function getAllProductsForBrandId() {
        $service = new IphoneService();
        if (isset($_GET['bid'])) {
            $brandId = $_GET['bid'];
            $productList = $service->GetProducts('', $brandId);
            if ($this->showOnlyVerified) $productList = $this->stripUnverified($productList);
            return $productList;
        } else {
            return array();
        }
    }
    /*
     * This function determines the proper category by looking at the name of
     * the file that is including it. A little brittle, but better than having to
     * change 20 files each time.
     */
    public function listBrandsForCategory() {
        $service = new IphoneService();
        if (isset($this->categoryIdByPageArray[$_SERVER['PHP_SELF']])) {
            $categoryId = $this->categoryIdByPageArray[$_SERVER['PHP_SELF']];
            if (isset($_GET['bid']) && is_numeric($_GET['bid'])) {
                $brandId = $_GET['bid'];
                $productList = $service->GetProducts($categoryId, $brandId);
                // the service appears to do an "or" rather than an "and".
                $resultList = array();
                foreach($productList as $product) {
                    if (($product->brandID == $brandId) && ($product->catID == $categoryId))
                        array_push($resultList, $product);
                }
               $this->renderProductList($resultList, true);
            } else {
                $productsByCatId = $service->GetProducts($categoryId);
                $brandArray = array();
                foreach($productsByCatId as $product) {
                    if (!isset($brandArray[$product->brandID])) {
                        $brandArray[$product->brandID] = new Brand($product->brandID, $product->brandName, $product->brandLogo, $product->catID);
                    }
                }
                // we're going to assume that there's a "sort by name" on the remote service.
                $this->renderBrandList($brandArray);
            }
            
        } else {
            echo "<!-- I don't know what category to display. Please see /lib/IphoneDataRenderer.php. -->";
        }
        
    }
    
    public function getAdsForBrandId($brandId = '', $brandName = '') {
        if ($brandId == '') {
            // then get from GET parameter
            if (isset($_GET['bid']) && is_numeric($_GET['bid'])) {
                $brandId = $_GET['bid'];
            }
        }
        global $brandLinkArray;
        $logoLink = '';
        if (isset($brandLinkArray[$brandId])) {
            $logoLink = $brandLinkArray[$brandId];
            $logoFile = AD_FOLDER . "$brandId.jpg";
            if (file_exists($logoFile)) {
                return "<a href='$logoLink' title='$brandName' target='_new'><img src='/brands/logos/$brandId.jpg' alt='$brandName' style='margin-top: 8px;' border='0' /></a>";
            }
        }
    }

    public function renderProductList($products, $limitByCat = false) {
        global $brandLinkArray;
        if (count($products) < 1) {
            echo "No products for this brand and category.";
            return;
        }
        $sample = $products[0];
        if ($limitByCat) {
            $linkToProductPage = "/brands/all-products-for-brand.html?bid={$sample->brandID}";
            $logoLink = $linkToProductPage;
            if (isset($brandLinkArray[$sample->brandID])) {
                $logoLink = $brandLinkArray[$sample->brandID];
            }
            echo "<a href='$logoLink' title='{$sample->brandName}' target='_new'>";
            echo "<img src='{$sample->brandLogo}' alt='{$sample->brandName}' width='130' border='0' style='float: left; margin-right: 15px;'>";
            echo "</a>";
            echo "<h2 style='margin: 0; color: #414F26;'>$sample->brandName</h2>";
            echo "<h3 style='margin:5px 0 0 0;'><a href='$linkToProductPage' title='{$sample->brandName}'>Show all products from ";
            echo "{$sample->brandName}</a></h3>";
            echo "« <a href='javascript: history.back();'>Back</a></h3><br/>";
        } else {
           echo "<h3 style='margin: 0; color: #414F26;'>Showing all products</h3>";
           echo "<h3 style='margin:5px 0 0 0;'>« <a href='javascript: history.back();'>Back</a></h3>";
        }
        
        echo "<ul class='prodlist' style='list-style: none; clear: both;'>";
        $i = 0;
        foreach($products as $product) {
            if (!$this->showOnlyVerified || ($product->pVerified == 1)) {
                $i++;
                echo "<li style='line-height: 24px; vertical-align: middle; margin-bottom: 4px;'>";
                if ($product->pVerified == 1) echo "<a href='http://www.nongmoproject.org/consumers/understanding-our-seal/' title='This product has been verified. Click for more information.'><img src='/images/bullet-verified.gif' alt='Verified' style='vertical-align: top; margin-right: 5px;' border='0'/></a>";
                echo $product->name;
                echo "</li>";
            }
        }
        if ($i == 0) echo "<li>There are no products that have been verified at this time, though some products are enrolled in the Product Verification Program and may be verified soon. Please check back!</li>";
        echo "</ul>";
    }
    
    public function renderBrandList($brands) {
        if (count($brands) < 1) {
            echo "No brands for this category.";
            return;
        }
       //echo "<table cellpadding=10>";
       echo "<ul>";
        foreach($brands as $brand) {
            $link = "?bid={$brand->id}";
            echo "<li>";
            echo "<a href='$link' title='See all products for this brand'>{$brand->name}</a>";
            echo "</li>";
            //echo "<tr>";
            //echo "<td><a href='$link' title='See all products for this brand'><img src='{$brand->logo}' alt='{$brand->name}' border='0' /></a></td>";
            //echo "<td><a href='$link' title='See all products for this brand'>{$brand->name}</a></td>";
            //echo "</tr>";
        }
        //echo "</table>";
        echo "</ul>";
    }

    public function showDescription() {
        if (isset($_GET['bid']) && is_numeric($_GET['bid'])) {
            return false;
        } else {
            return true;
        }
            
    }
    
    public function renderKey() {
        if (isset($_GET['bid']) && is_numeric($_GET['bid'])) { ?>
            <img src="/images/bullet-verified.gif"> Indicates that the product has been verified as fully compliant to the Non-GMO Project Standard. For more information please  <a href="../non-gmo-project-seal.html">click here.</a>
            <p>If a product you like is not listed here, feel free to  <a href="http://www.nongmoproject.org/take-action/make-a-product-verification-request/" target="_blank">request product verification</a>.  Your request will be sent to the company to let them know you would like to see that product verified as Non-GMO.
               </p>
        <?php } else { ?>
            The brands featured above are enrolled in the the Non-GMO Project Standard. <br />
              For more information please <a href="../non-gmo-project-enrollment.html" >click here.</a>
            <p>If a product you like is not listed here, feel free to  <a href="http://www.nongmoproject.org/take-action/make-a-product-verification-request/" target="_blank">request product verification</a>.  Your request will be sent to the company to let them know you would like to see that product verified as Non-GMO.
               </p>
        <?php }
    }
}

class Brand {

    public $id;
    public $name;
    public $logo;
    public $catId;

    public function Brand($id, $name, $logo, $catId) {
        $this->id = $id;
        $this->name = $name;
        $this->logo = $logo;
        // possibly not really needed
        $this->catId = $catId;
    }
}

$IphoneDataRenderer = new IphoneDataRenderer();

?>
Edited by Zane
Link to comment
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.