<?php $action = $_GET['action']; switch ($action) { case 'getcat': $toreturn = getAllSubCategories(); break; case 'searchproducts': $toreturn = searchProducts($_GET['value']); break; case 'searchsubcat': $toreturn = searchSubCategories($_GET['value']); break; case 'searchproductcheap': $toreturn = searchProductCheap($_GET['value']); break; case 'searchproductname': $toreturn = searchProductName($_GET['value']); break; case 'getcarts': $toreturn = getAllCarts($_GET['value']); break; case 'getcartcontent': $toreturn = getCartContent($_GET['value']); break; case 'savecarts': $toreturn = saveCart($_GET['name'], $_GET['user'], $_GET['value']); break; default: $toreturn = array("status" => 0, "title" => "Forbidden", "msg" => "Forbidden attempt at backend functionallity."); break;
<?php require_once dirname(__FILE__) . '/../vendor/phpQuery.php'; $deparments_path = dirname(__FILE__) . '/walmart-departments.txt'; if (!file_exists($deparments_path)) { echo "---- exec getAllDeparments() ----\n\r"; getAllDepartments($deparments_path); } else { getAllSubCategories($deparments_path); } function getAllDepartments($filename) { echo "---- run getAllDeparments() ----\n\r"; $doc = phpQuery::newDocumentHTML(file_get_contents(dirname(__FILE__) . '/deparments.html')); phpQuery::selectDocument($doc); echo "---- loading dom html ----\n\r"; $categories = array(); foreach (pq('.accordion div') as $el) { echo "---- reading a deparment and childrens ----\n\r"; $link = pq($el)->find('h4 a:last-child')->attr('href'); $name = pq($el)->find('h4 a:last-child span')->text(); foreach (pq($el)->find('li') as $ele) { echo "---- reading a deparment's children ----\n\r"; $subcategories[] = array('link' => pq($ele)->find('a')->attr('href'), 'name' => pq($ele)->find('a')->text()); } echo "---- wrapping deparments ----\n\r"; $categories[] = array('name' => $name, 'link' => $link, 'childrens' => $subcategories); } echo "---- creating deparment file ----\n\r"; $file = fopen($filename, 'a+'); echo "---- writing deparment file ----\n\r";