[ ], 'Clearance' => [ 'ready_made' => [ 'name' => 'Ready Made', 'type' => 'checkbox' ], 'flop' => [ 'name' => 'Flops', 'type' => 'checkbox' ], 'skus' => [ 'name' => 'Products', 'exampleValue' => 'chanceflared, crackers', 'title' => 'Comma separated list of product SKUs' ], 'onesize' => [ 'name' => 'One-Size', 'type' => 'checkbox' ], 'mini' => [ 'name' => 'Mini', 'type' => 'checkbox' ], 'small' => [ 'name' => 'Small', 'type' => 'checkbox' ], 'medium' => [ 'name' => 'Medium', 'type' => 'checkbox' ], 'large' => [ 'name' => 'Large', 'type' => 'checkbox' ], 'extralarge' => [ 'name' => 'Extra Large', 'type' => 'checkbox' ], 'category' => [ 'name' => 'Category', 'type' => 'list', 'values' => [ 'All' => 'all', 'Accessories' => 'accessories', 'Merchandise' => 'merchandise', 'Dildos' => 'insertable', 'Masturbators' => 'penetrable', 'Packers' => 'packer', 'Lil\' Squirts' => 'shooter', 'Lil\' Vibes' => 'vibrator', 'Wearables' => 'wearable' ], 'defaultValue' => 'all', ], 'soft' => [ 'name' => 'Soft Firmness', 'type' => 'checkbox' ], 'med_firm' => [ 'name' => 'Medium Firmness', 'type' => 'checkbox' ], 'firm' => [ 'name' => 'Firm', 'type' => 'checkbox' ], 'split' => [ 'name' => 'Split Firmness', 'type' => 'checkbox' ], 'maxprice' => [ 'name' => 'Max Price', 'type' => 'number', 'required' => true, 'defaultValue' => 300 ], 'minprice' => [ 'name' => 'Min Price', 'type' => 'number', 'defaultValue' => 0 ], 'cumtube' => [ 'name' => 'Cumtube', 'type' => 'checkbox' ], 'suctionCup' => [ 'name' => 'Suction Cup', 'type' => 'checkbox' ], 'noAccessories' => [ '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 = []; // Sale $regex = '/^(https?:\/\/)?bad-dragon\.com\/sales/'; if (preg_match($regex, $url, $matches) > 0) { $params['context'] = 'Sales'; 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 = []; 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'; $params['context'] = 'Clearance'; 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 = []; $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 = []; $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 = [
'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 .= '