diff options
Diffstat (limited to 'bridges/PepperBridgeAbstract.php')
-rw-r--r-- | bridges/PepperBridgeAbstract.php | 67 |
1 files changed, 51 insertions, 16 deletions
diff --git a/bridges/PepperBridgeAbstract.php b/bridges/PepperBridgeAbstract.php index 4e9ab0b5..43dbe829 100644 --- a/bridges/PepperBridgeAbstract.php +++ b/bridges/PepperBridgeAbstract.php @@ -62,7 +62,7 @@ class PepperBridgeAbstract extends BridgeAbstract foreach ($list as $deal) { // Get the JSON Data stored as vue $jsonDealData = $this->getDealJsonData($deal); - $dealMeta = Json::decode($deal->find('div[class=threadGrid-headerMeta]', 0)->find('div[class=js-vue2]', 1)->getAttribute('data-vue2')); + $dealMeta = Json::decode($deal->find('div[class=js-vue2]', 1)->getAttribute('data-vue2')); $item = []; $item['uri'] = $this->getDealURI($jsonDealData); @@ -80,7 +80,7 @@ class PepperBridgeAbstract extends BridgeAbstract . $this->getShipsFrom($dealMeta) . $this->getShippingCost($jsonDealData) . $this->getSource($jsonDealData) - . $this->getDealLocation($dealMeta) + . $this->getDealLocation($jsonDealData) . $deal->find('div[class*=' . $selectorDescription . ']', 0)->innertext . '</td><td>' . $this->getTemperature($jsonDealData) @@ -263,12 +263,41 @@ HEREDOC; */ private function getTalkTitle() { - $html = getSimpleHTMLDOMCached($this->getInput('url')); - $title = $html->find('title', 0)->plaintext; + $cacheKey = $this->getInput('url') . 'TITLE'; + $title = $this->loadCacheValue($cacheKey); + // The cache does not contain the title of the bridge, we must get it and save it in the cache + if ($title === null) { + $html = getSimpleHTMLDOMCached($this->getInput('url')); + $title = $html->find('title', 0)->plaintext; + // Save the value in the cache for the next 15 days + $this->saveCacheValue($cacheKey, $title, 86400 * 15); + } return $title; } /** + * Get the Title from a Group if it exists + * @return string String of the Talk title + */ + private function getGroupTitle() + { + $cacheKey = $this->getInput('group') . 'TITLE'; + $title = $this->loadCacheValue($cacheKey); + // The cache does not contain the title of the bridge, we must get it and save it in the cache + if ($title == null) { + $html = getSimpleHTMLDOMCached($this->getGroupURI()); + // Search the title in the javascript mess + preg_match('/threadGroupName":"([^"]*)","threadGroupUrlName":"' . $this->getInput('group') . '"/m', $html, $matches); + $title = $matches[1]; + // Save the value in the cache for the next 15 days + $this->saveCacheValue($cacheKey, $title, 86400 * 15); + } + + $order = $this->getKey('order'); + return $title . ' - ' . $order; + } + + /** * Get the HTML Title code from an item * @return string String of the deal title */ @@ -373,14 +402,9 @@ HEREDOC; * Get the Deal location if it exists * @return string String of the deal location */ - private function getDealLocation($dealMeta) + private function getDealLocation($jsonDealData) { - $ribbons = $dealMeta['props']['metaRibbons']; - $isLocal = false; - foreach ($ribbons as $ribbon) { - $isLocal |= ($ribbon['type'] == 'local'); - } - if ($isLocal) { + if ($jsonDealData['props']['thread']['isLocal']) { $content = '<div>' . $this->i8n('deal-type') . ' : ' . $this->i8n('localdeal') . '</div>'; } else { $content = ''; @@ -395,8 +419,11 @@ HEREDOC; private function getImage($deal) { // Get thread Image JSON content - $content = Json::decode($deal->find('div[class*=threadGrid-image]', 0)->find('div[class=js-vue2]', 0)->getAttribute('data-vue2')); - return '<img src="' . $content['props']['threadImageUrl'] . '"/>'; + $content = Json::decode($deal->find('div[class=js-vue2]', 0)->getAttribute('data-vue2')); + //return '<img src="' . $content['props']['threadImageUrl'] . '"/>'; + return '<img src="' . $this->i8n('image-host') . $content['props']['thread']['mainImage']['path'] . '/' + . $content['props']['thread']['mainImage']['name'] . '/re/202x202/qt/70/' + . $content['props']['thread']['mainImage']['uid'] . '"/>'; } /** @@ -405,7 +432,7 @@ HEREDOC; */ private function getShipsFrom($dealMeta) { - $metas = $dealMeta['props']['metaRibbons']; + $metas = $dealMeta['props']['metaRibbons'] ?? []; $shipsFrom = null; foreach ($metas as $meta) { if ($meta['type'] == 'dispatched-from') { @@ -429,7 +456,7 @@ HEREDOC; return $this->i8n('bridge-name') . ' - ' . $this->i8n('title-keyword') . ' : ' . $this->getInput('q'); break; case $this->i8n('context-group'): - return $this->i8n('bridge-name') . ' - ' . $this->i8n('title-group') . ' : ' . $this->getKey('group'); + return $this->i8n('bridge-name') . ' - ' . $this->i8n('title-group') . ' : ' . $this->getGroupTitle(); break; case $this->i8n('context-talk'): return $this->i8n('bridge-name') . ' - ' . $this->i8n('title-talk') . ' : ' . $this->getTalkTitle(); @@ -495,9 +522,17 @@ HEREDOC; { $group = $this->getInput('group'); $order = $this->getInput('order'); + $subgroups = $this->getInput('subgroups'); + + // This permit to keep the existing Feed to work + if ($order == $this->i8n('context-hot')) { + $sortBy = 'temp'; + } else if ($order == $this->i8n('context-new')) { + $sortBy = 'new'; + } $url = $this->i8n('bridge-uri') - . $this->i8n('uri-group') . $group . $order; + . $this->i8n('uri-group') . $group . '?sortBy=' . $sortBy . '&groups=' . $subgroups; return $url; } |