array( ), 'Clearance' => array( 'ready_made' => array( 'name' => 'Ready Made', 'type' => 'checkbox' ), 'flop' => array( 'name' => 'Flops', 'type' => 'checkbox' ), 'skus' => array( 'name' => 'Products', 'exampleValue' => 'chanceflared, crackers', 'title' => 'Comma separated list of product SKUs' ), 'onesize' => array( 'name' => 'One-Size', 'type' => 'checkbox' ), 'mini' => array( 'name' => 'Mini', 'type' => 'checkbox' ), 'small' => array( 'name' => 'Small', 'type' => 'checkbox' ), 'medium' => array( 'name' => 'Medium', 'type' => 'checkbox' ), 'large' => array( 'name' => 'Large', 'type' => 'checkbox' ), 'extralarge' => array( 'name' => 'Extra Large', 'type' => 'checkbox' ), 'category' => array( 'name' => 'Category', 'type' => 'list', 'values' => array( 'All' => 'all', 'Accessories' => 'accessories', 'Merchandise' => 'merchandise', 'Dildos' => 'insertable', 'Masturbators' => 'penetrable', 'Packers' => 'packer', 'Lil\' Squirts' => 'shooter', 'Lil\' Vibes' => 'vibrator', 'Wearables' => 'wearable' ), 'defaultValue' => 'all', ), 'soft' => array( 'name' => 'Soft Firmness', 'type' => 'checkbox' ), 'med_firm' => array( 'name' => 'Medium Firmness', 'type' => 'checkbox' ), 'firm' => array( 'name' => 'Firm', 'type' => 'checkbox' ), 'split' => array( 'name' => 'Split Firmness', 'type' => 'checkbox' ), 'maxprice' => array( 'name' => 'Max Price', 'type' => 'number', 'required' => true, 'defaultValue' => 300 ), 'minprice' => array( 'name' => 'Min Price', 'type' => 'number', 'defaultValue' => 0 ), 'cumtube' => array( 'name' => 'Cumtube', 'type' => 'checkbox' ), 'suctionCup' => array( 'name' => 'Suction Cup', 'type' => 'checkbox' ), 'noAccessories' => array( 'name' => 'No Accessories', 'type' => 'checkbox' ) ) ); /* * This sets index $strFrom (or $strTo if set) in $outArr to 'on' if * $inArr[$param] contains $strFrom. * It is used for translating BD's shop filter URLs into something we can use. * * For the query '?type[]=ready_made&type[]=flop' we would have an array like: * Array ( * [type] => Array ( * [0] => ready_made * [1] => flop * ) * ) * which could be translated into: * Array ( * [ready_made] => on * [flop] => on * ) * */ private function setParam($inArr, &$outArr, $param, $strFrom, $strTo = null) { if(isset($inArr[$param]) && in_array($strFrom, $inArr[$param])) { $outArr[($strTo ?: $strFrom)] = 'on'; } } public function detectParameters($url) { $params = array(); // Sale $regex = '/^(https?:\/\/)?bad-dragon\.com\/sales/'; if(preg_match($regex, $url, $matches) > 0) { return $params; } // Clearance $regex = '/^(https?:\/\/)?bad-dragon\.com\/shop\/clearance/'; if(preg_match($regex, $url, $matches) > 0) { parse_str(parse_url($url, PHP_URL_QUERY), $urlParams); $this->setParam($urlParams, $params, 'type', 'ready_made'); $this->setParam($urlParams, $params, 'type', 'flop'); if(isset($urlParams['skus'])) { $skus = array(); foreach($urlParams['skus'] as $sku) { is_string($sku) && $skus[] = $sku; is_array($sku) && $skus[] = $sku[0]; } $params['skus'] = implode(',', $skus); } $this->setParam($urlParams, $params, 'sizes', 'onesize'); $this->setParam($urlParams, $params, 'sizes', 'mini'); $this->setParam($urlParams, $params, 'sizes', 'small'); $this->setParam($urlParams, $params, 'sizes', 'medium'); $this->setParam($urlParams, $params, 'sizes', 'large'); $this->setParam($urlParams, $params, 'sizes', 'extralarge'); if(isset($urlParams['category'])) { $params['category'] = strtolower($urlParams['category']); } else{ $params['category'] = 'all'; } $this->setParam($urlParams, $params, 'firmnessValues', 'soft'); $this->setParam($urlParams, $params, 'firmnessValues', 'medium', 'med_firm'); $this->setParam($urlParams, $params, 'firmnessValues', 'firm'); $this->setParam($urlParams, $params, 'firmnessValues', 'split'); if(isset($urlParams['price'])) { isset($urlParams['price']['max']) && $params['maxprice'] = $urlParams['price']['max']; isset($urlParams['price']['min']) && $params['minprice'] = $urlParams['price']['min']; } isset($urlParams['cumtube']) && $urlParams['cumtube'] === '1' && $params['cumtube'] = 'on'; isset($urlParams['suctionCup']) && $urlParams['suctionCup'] === '1' && $params['suctionCup'] = 'on'; isset($urlParams['noAccessories']) && $urlParams['noAccessories'] === '1' && $params['noAccessories'] = 'on'; return $params; } return null; } public function getName() { switch($this->queriedContext) { case 'Sales': return 'Bad Dragon Sales'; case 'Clearance': return 'Bad Dragon Clearance Search'; default: return parent::getName(); } } public function getURI() { switch($this->queriedContext) { case 'Sales': return self::URI . 'sales'; case 'Clearance': return $this->inputToURL(); default: return parent::getURI(); } } public function collectData() { switch($this->queriedContext) { case 'Sales': $sales = json_decode(getContents(self::URI . 'api/sales')); foreach($sales as $sale) { $item = array(); $item['title'] = $sale->title; $item['timestamp'] = strtotime($sale->startDate); $item['uri'] = $this->getURI() . '/' . $sale->slug; $contentHTML = '
'; if(isset($sale->endDate)) { $contentHTML .= 'This promotion ends on ' . gmdate('M j, Y \a\t g:i A T', strtotime($sale->endDate)) . '
'; } else { $contentHTML .= 'This promotion never ends
'; } $ul = false; $content = json_decode($sale->content); foreach($content->blocks as $block) { switch($block->type) { case 'header-one': $contentHTML .= '' . $block->text . '
'; break; } } $item['content'] = $contentHTML; $this->items[] = $item; } break; case 'Clearance': $toyData = json_decode(getContents($this->inputToURL(true))); $productList = json_decode(getContents(self::URI . 'api/inventory-toy/product-list')); foreach($toyData->toys as $toy) { $item = array(); $item['uri'] = $this->getURI() . '#' . $toy->id; $item['timestamp'] = strtotime($toy->created); foreach($productList as $product) { if($product->sku == $toy->sku) { $item['title'] = $product->name; break; } } // images $content = ''; foreach($toy->images as $image) { $content .= ''; } // price $content .= '
Price: $'
. $toy->price
// size
. '
Size: '
. $toy->size
// color
. '
Color: '
. $toy->color
// features
. '
Features: '
. ($toy->suction_cup ? 'Suction cup' : '')
. ($toy->suction_cup && $toy->cumtube ? ', ' : '')
. ($toy->cumtube ? 'Cumtube' : '')
. ($toy->suction_cup || $toy->cumtube ? '' : 'None');
// firmness
$firmnessTexts = array(
'2' => 'Extra soft',
'3' => 'Soft',
'5' => 'Medium',
'8' => 'Firm'
);
$firmnesses = explode('/', $toy->firmness);
if(count($firmnesses) === 2) {
$content .= '
Firmness: '
. $firmnessTexts[$firmnesses[0]]
. ', '
. $firmnessTexts[$firmnesses[1]];
} else{
$content .= '
Firmness: '
. $firmnessTexts[$firmnesses[0]];
}
// flop
if($toy->type === 'flop') {
$content .= '
Flop reason: '
. $toy->flop_reason;
}
$content .= '