mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-03-15 20:04:46 +00:00
[PepperBridge] fix and discussion (#2383)
* [PepperBridge] Fix some Notice for expired items Some expired iteams are not identical to normal items for the title and URI, so they got a special handling to remove PHP Notice. The "most commented" sorting option was removed and show now some forum. So it was removed. With DealabsBridge, MydealsBridge and HotUKDealsBridge, you can monitor a discussion for new comments, excluding or not post without URL
This commit is contained in:
parent
590fdd9f9b
commit
368a198321
3 changed files with 282 additions and 22 deletions
|
@ -1874,12 +1874,30 @@ class DealabsBridge extends PepperBridgeAbstract {
|
|||
'type' => 'list',
|
||||
'title' => 'Ordre de tri des deals',
|
||||
'values' => array(
|
||||
'Du deal le plus Hot au moins Hot' => '',
|
||||
'Du deal le plus Hot au moins Hot' => '-hot',
|
||||
'Du deal le plus récent au plus ancien' => '-nouveaux',
|
||||
'Du deal le plus commentés au moins commentés' => '-commentes'
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
'Surveillance Discussion' => array(
|
||||
'url' => array(
|
||||
'name' => 'URL de la discussion',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'title' => 'URL discussion à surveiller: https://www.dealabs.com/discussions/titre-1234',
|
||||
'exampleValue' => 'https://www.dealabs.com/discussions/titre-1234',
|
||||
),
|
||||
|
||||
'only_with_url' => array(
|
||||
'name' => 'Exclure les commentaires sans URL',
|
||||
'type' => 'checkbox',
|
||||
'title' => 'Exclure les commentaires ne contenant pas d\'URL dans le flux',
|
||||
'defaultValue' => false,
|
||||
)
|
||||
|
||||
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
public $lang = array(
|
||||
|
@ -1887,8 +1905,10 @@ class DealabsBridge extends PepperBridgeAbstract {
|
|||
'bridge-name' => SELF::NAME,
|
||||
'context-keyword' => 'Recherche par Mot(s) clé(s)',
|
||||
'context-group' => 'Deals par groupe',
|
||||
'context-talk' => 'Surveillance Discussion',
|
||||
'uri-group' => 'groupe/',
|
||||
'request-error' => 'Could not request Dealabs',
|
||||
'request-error' => 'Impossible de joindre Dealabs',
|
||||
'thread-error' => 'Impossible de déterminer l\'ID de la discussion. Vérifiez l\'URL que vous avez entré',
|
||||
'no-results' => 'Il n'y a rien à afficher pour le moment :(',
|
||||
'relative-date-indicator' => array(
|
||||
'il y a',
|
||||
|
@ -1899,6 +1919,7 @@ class DealabsBridge extends PepperBridgeAbstract {
|
|||
'discount' => 'Réduction',
|
||||
'title-keyword' => 'Recherche',
|
||||
'title-group' => 'Groupe',
|
||||
'title-talk' => 'Surveillance Discussion',
|
||||
'local-months' => array(
|
||||
'janvier',
|
||||
'février',
|
||||
|
@ -1954,6 +1975,9 @@ class PepperBridgeAbstract extends BridgeAbstract {
|
|||
case $this->i8n('context-group'):
|
||||
return $this->collectDataGroup();
|
||||
break;
|
||||
case $this->i8n('context-talk'):
|
||||
return $this->collectDataTalk();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2039,20 +2063,16 @@ class PepperBridgeAbstract extends BridgeAbstract {
|
|||
} else {
|
||||
foreach ($list as $deal) {
|
||||
$item = array();
|
||||
$item['uri'] = $deal->find('div[class*=threadGrid-title]', 0)->find('a', 0)->href;
|
||||
$item['title'] = $deal->find('a[class*=' . $selectorLink . ']', 0
|
||||
)->plaintext;
|
||||
$item['uri'] = $this->getDealURI($deal);
|
||||
$item['title'] = $this->GetTitle($deal);
|
||||
$item['author'] = $deal->find('span.thread-username', 0)->plaintext;
|
||||
|
||||
$item['content'] = '<table><tr><td><a href="'
|
||||
. $deal->find(
|
||||
'a[class*=' . $selectorImageLink . ']', 0)->href
|
||||
. $item['uri']
|
||||
. '"><img src="'
|
||||
. $this->getImage($deal)
|
||||
. '"/></td><td><h2><a href="'
|
||||
. $deal->find('a[class*=' . $selectorLink . ']', 0)->href
|
||||
. '">'
|
||||
. $deal->find('a[class*=' . $selectorLink . ']', 0)->innertext
|
||||
. '</a></h2>'
|
||||
. '"/></td><td>'
|
||||
. $this->getHTMLTitle($item)
|
||||
. $this->getPrice($deal)
|
||||
. $this->getDiscount($deal)
|
||||
. $this->getShipsFrom($deal)
|
||||
|
@ -2080,6 +2100,127 @@ class PepperBridgeAbstract extends BridgeAbstract {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Talk lastest comments
|
||||
*/
|
||||
protected function collectDataTalk(){
|
||||
$threadURL = $this->getInput('url');
|
||||
$onlyWithUrl = $this->getInput('only_with_url');
|
||||
|
||||
// Get Thread ID from url passed in parameter
|
||||
$threadSearch = preg_match('/-([0-9]{1,20})$/', $threadURL, $matches);
|
||||
|
||||
// Show an error message if we can't find the thread ID in the URL sent by the user
|
||||
if($threadSearch !== 1) {
|
||||
returnClientError($this->i8n('thread-error'));
|
||||
}
|
||||
$threadID = $matches[1];
|
||||
|
||||
$url = $this->i8n('bridge-uri') . 'graphql';
|
||||
|
||||
// Get Cookies header to do the query
|
||||
$cookies = $this->getCookies($url);
|
||||
|
||||
// GraphQL String
|
||||
// This was extracted from https://www.dealabs.com/assets/js/modern/common_211b99.js
|
||||
// This string was extracted during a Website visit, and minified using this neat tool :
|
||||
// https://codepen.io/dangodev/pen/Baoqmoy
|
||||
$graphqlString = <<<'HEREDOC'
|
||||
query comments($filter:CommentFilter!,$limit:Int,$page:Int){comments(filter:$filter,limit:$limit,page:$page){
|
||||
items{...commentFields}pagination{...paginationFields}}}fragment commentFields on Comment{commentId threadId url
|
||||
preparedHtmlContent user{...userMediumAvatarFields...userNameFields...userPersonaFields bestBadge{...badgeFields}}
|
||||
reactionCounts{type count}deletable currentUserReaction{type}reported reportable source status createdAt updatedAt
|
||||
ignored popular deletedBy{username}notes{content createdAt user{username}}lastEdit{reason timeAgo userId}}fragment
|
||||
userMediumAvatarFields on User{userId isDeletedOrPendingDeletion imageUrls(slot:"default",variations:
|
||||
["user_small_avatar"])}fragment userNameFields on User{userId username isUserProfileHidden isDeletedOrPendingDeletion}
|
||||
fragment userPersonaFields on User{persona{type text}}fragment badgeFields on Badge{badgeId level{...badgeLevelFields}}
|
||||
fragment badgeLevelFields on BadgeLevel{key name description}fragment paginationFields on Pagination{count current last
|
||||
next previous size order}
|
||||
HEREDOC;
|
||||
|
||||
// Construct the JSON object to send to the Website
|
||||
$queryArray = array (
|
||||
'query' => $graphqlString,
|
||||
'variables' => array (
|
||||
'filter' => array (
|
||||
'threadId' => array (
|
||||
'eq' => $threadID,
|
||||
),
|
||||
'order' => array (
|
||||
'direction' => 'Descending',
|
||||
),
|
||||
|
||||
),
|
||||
'page' => 1,
|
||||
),
|
||||
);
|
||||
$queryJSON = json_encode($queryArray);
|
||||
|
||||
// HTTP headers
|
||||
$header = array(
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json, text/plain, */*',
|
||||
'X-Pepper-Txn: threads.show',
|
||||
'X-Request-Type: application/vnd.pepper.v1+json',
|
||||
'X-Requested-With: XMLHttpRequest',
|
||||
$cookies,
|
||||
);
|
||||
// CURL Options
|
||||
$opts = array(
|
||||
CURLOPT_POST => 1,
|
||||
CURLOPT_POSTFIELDS => $queryJSON
|
||||
);
|
||||
$json = getContents($url, $header, $opts);
|
||||
$objects = json_decode($json);
|
||||
foreach($objects->data->comments->items as $comment) {
|
||||
$item = array();
|
||||
$item['uri'] = $comment->url;
|
||||
$item['title'] = $comment->user->username . ' - ' . $comment->createdAt;
|
||||
$item['author'] = $comment->user->username;
|
||||
$item['content'] = $comment->preparedHtmlContent;
|
||||
$item['uid'] = $comment->commentId;
|
||||
// Timestamp handling needs a new parsing function
|
||||
if($onlyWithUrl == true) {
|
||||
// Count Links and Quote Links
|
||||
$content = str_get_html($item['content']);
|
||||
$countLinks = count($content->find('a[href]'));
|
||||
$countQuoteLinks = count($content->find('a[href][class=userHtml-quote-source]'));
|
||||
// Only add element if there are Links ans more links tant Quote links
|
||||
if($countLinks > 0 && $countLinks > $countQuoteLinks) {
|
||||
$this->items[] = $item;
|
||||
}
|
||||
} else {
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the cookies obtained from the URL
|
||||
* @return array the array containing the cookies set by the URL
|
||||
*/
|
||||
private function getCookies($url)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
// get headers too with this line
|
||||
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
$result = curl_exec($ch);
|
||||
// get cookie
|
||||
// multi-cookie variant contributed by @Combuster in comments
|
||||
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
|
||||
$cookies = array();
|
||||
foreach($matches[1] as $item) {
|
||||
parse_str($item, $cookie);
|
||||
$cookies = array_merge($cookies, $cookie);
|
||||
}
|
||||
$header = 'Cookie: ';
|
||||
foreach($cookies as $name => $content) {
|
||||
$header .= $name . '=' . $content . '; ';
|
||||
}
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the string $str contains any of the string of the array $arr
|
||||
* @return boolean true if the string matched anything otherwise false
|
||||
|
@ -2112,6 +2253,74 @@ class PepperBridgeAbstract extends BridgeAbstract {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Title from a Deal if it exists
|
||||
* @return string String of the deal title
|
||||
*/
|
||||
private function getTitle($deal)
|
||||
{
|
||||
|
||||
$titleRoot = $deal->find('div[class*=threadGrid-title]', 0);
|
||||
$titleA = $titleRoot->find('a[class*=thread-link]', 0);
|
||||
$titleFirstChild = $titleRoot->first_child();
|
||||
if($titleA !== null) {
|
||||
$title = $titleA->plaintext;
|
||||
} else {
|
||||
// Inb ssome case, expired deals have a different format
|
||||
$title = $titleRoot->find('span', 0)->plaintext;
|
||||
}
|
||||
|
||||
return $title;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Title from a Talk if it exists
|
||||
* @return string String of the Talk title
|
||||
*/
|
||||
private function getTalkTitle()
|
||||
{
|
||||
$html = getSimpleHTMLDOMCached($this->getInput('url'));
|
||||
$title = $html->find('h1[class=thread-title]', 0)->plaintext;
|
||||
return $title;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML Title code from an item
|
||||
* @return string String of the deal title
|
||||
*/
|
||||
private function getHTMLTitle($item)
|
||||
{
|
||||
if($item['uri'] == '') {
|
||||
$html = '<h2>' . $item['title'] . '</h2>';
|
||||
} else {
|
||||
$html = '<h2><a href="' . $item['uri'] . '">'
|
||||
. $item['title'] . '</a></h2>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URI from a Deal if it exists
|
||||
* @return string String of the deal URI
|
||||
*/
|
||||
private function getDealURI($deal)
|
||||
{
|
||||
|
||||
$uriA = $deal->find('div[class*=threadGrid-title]', 0)->find('a[class*=thread-link]', 0);
|
||||
if($uriA === null) {
|
||||
$uri = '';
|
||||
} else {
|
||||
$uri = $uriA->href;
|
||||
}
|
||||
|
||||
return $uri;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Shipping costs from a Deal if it exists
|
||||
* @return string String of the deal shipping Cost
|
||||
|
@ -2342,13 +2551,16 @@ class PepperBridgeAbstract extends BridgeAbstract {
|
|||
$group = array_search($this->getInput('group'), $values);
|
||||
return $this->i8n('bridge-name') . ' - ' . $this->i8n('title-group') . ' : ' . $group;
|
||||
break;
|
||||
case $this->i8n('context-talk'):
|
||||
return $this->i8n('bridge-name') . ' - ' . $this->i8n('title-talk') . ' : ' . $this->getTalkTitle();
|
||||
break;
|
||||
default: // Return default value
|
||||
return static::NAME;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the RSS Feed title according to the parameters
|
||||
* Returns the RSS Feed URI according to the parameters
|
||||
* @return string the RSS feed Title
|
||||
*/
|
||||
public function getURI(){
|
||||
|
@ -2359,6 +2571,9 @@ class PepperBridgeAbstract extends BridgeAbstract {
|
|||
case $this->i8n('context-group'):
|
||||
return $this->getGroupURI();
|
||||
break;
|
||||
case $this->i8n('context-talk'):
|
||||
return $this->getTalkURI();
|
||||
break;
|
||||
default: // Return default value
|
||||
return static::URI;
|
||||
}
|
||||
|
@ -2373,7 +2588,7 @@ class PepperBridgeAbstract extends BridgeAbstract {
|
|||
$hide_expired = $this->getInput('hide_expired');
|
||||
$hide_local = $this->getInput('hide_local');
|
||||
$priceFrom = $this->getInput('priceFrom');
|
||||
$priceTo = $this->getInput('priceFrom');
|
||||
$priceTo = $this->getInput('priceTo');
|
||||
$url = $this->i8n('bridge-uri')
|
||||
. 'search/advanced?q='
|
||||
. urlencode($q)
|
||||
|
@ -2403,6 +2618,15 @@ class PepperBridgeAbstract extends BridgeAbstract {
|
|||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the RSS Feed URI for a Talk Feed
|
||||
* @return string the RSS feed URI
|
||||
*/
|
||||
private function getTalkURI(){
|
||||
$url = $this->getInput('url');
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is some "localisation" function that returns the needed content using
|
||||
* the "$lang" class variable in the local class
|
||||
|
|
|
@ -3243,11 +3243,27 @@ class HotUKDealsBridge extends PepperBridgeAbstract {
|
|||
'title' => 'Sort order of deals',
|
||||
'values' => array(
|
||||
'From the most to the least hot deal' => '-hot',
|
||||
'From the most recent deal to the oldest' => '',
|
||||
'From the most commented deal to the least commented deal' => '-discussed'
|
||||
'From the most recent deal to the oldest' => '-new',
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
'Discussion Monitoring' => array(
|
||||
'url' => array(
|
||||
'name' => 'Discussion URL',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'title' => 'Discussion URL to monitor. Ex: https://www.hotukdeals.com/discussions/the-hukd-lego-thread-3599357',
|
||||
'exampleValue' => 'https://www.hotukdeals.com/discussions/the-hukd-lego-thread-3599357',
|
||||
),
|
||||
'only_with_url' => array(
|
||||
'name' => 'Exclude comments without URL',
|
||||
'type' => 'checkbox',
|
||||
'title' => 'Exclude comments that does not contains URL in the feed',
|
||||
'defaultValue' => false,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
);
|
||||
|
||||
public $lang = array(
|
||||
|
@ -3255,8 +3271,10 @@ class HotUKDealsBridge extends PepperBridgeAbstract {
|
|||
'bridge-name' => SELF::NAME,
|
||||
'context-keyword' => 'Search by keyword(s))',
|
||||
'context-group' => 'Deals per group',
|
||||
'context-talk' => 'Discussion Monitoring',
|
||||
'uri-group' => 'tag/',
|
||||
'request-error' => 'Could not request HotUKDeals',
|
||||
'thread-error' => 'Unable to determine the thread ID. Check the URL you entered',
|
||||
'no-results' => 'Ooops, looks like we could',
|
||||
'relative-date-indicator' => array(
|
||||
'ago',
|
||||
|
@ -3267,6 +3285,7 @@ class HotUKDealsBridge extends PepperBridgeAbstract {
|
|||
'discount' => 'Discount',
|
||||
'title-keyword' => 'Search',
|
||||
'title-group' => 'Group',
|
||||
'title-talk' => 'Discussion Monitoring',
|
||||
'local-months' => array(
|
||||
'Jan',
|
||||
'Feb',
|
||||
|
|
|
@ -1991,12 +1991,26 @@ class MydealsBridge extends PepperBridgeAbstract {
|
|||
'type' => 'list',
|
||||
'title' => 'Sortierung der deals',
|
||||
'values' => array(
|
||||
'Vom heißesten zum kältesten Deal' => '',
|
||||
'Vom heißesten zum kältesten Deal' => '-hot',
|
||||
'Vom jüngsten Deal zum ältesten' => '-new',
|
||||
'Vom am meisten kommentierten Deal zum am wenigsten kommentierten Deal' => '-discussed'
|
||||
)
|
||||
),
|
||||
),
|
||||
'Überwachung Diskussion' => array(
|
||||
'url' => array(
|
||||
'name' => 'URL der Diskussion',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'title' => 'URL-Diskussion zu überwachen: https://www.mydealz.de/diskussion/title-123',
|
||||
'exampleValue' => '://www.mydealz.de/diskussion/title-123',
|
||||
),
|
||||
'only_with_url' => array(
|
||||
'name' => 'Kommentare ohne URL ausschließen',
|
||||
'type' => 'checkbox',
|
||||
'title' => 'Kommentare, die keine URL enthalten, im Feed ausschließen',
|
||||
'defaultValue' => false,
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public $lang = array(
|
||||
|
@ -2004,8 +2018,10 @@ class MydealsBridge extends PepperBridgeAbstract {
|
|||
'bridge-name' => SELF::NAME,
|
||||
'context-keyword' => 'Suche nach Stichworten',
|
||||
'context-group' => 'Deals pro Gruppen',
|
||||
'context-talk' => 'Überwachung Diskussion',
|
||||
'uri-group' => 'gruppe/',
|
||||
'request-error' => 'Could not request mydeals',
|
||||
'thread-error' => 'Die ID der Diskussion kann nicht ermittelt werden. Überprüfen Sie die eingegebene URL',
|
||||
'no-results' => 'Ups, wir konnten keine Deals zu',
|
||||
'relative-date-indicator' => array(
|
||||
'vor',
|
||||
|
@ -2017,6 +2033,7 @@ class MydealsBridge extends PepperBridgeAbstract {
|
|||
'discount' => 'Rabatte',
|
||||
'title-keyword' => 'Suche',
|
||||
'title-group' => 'Gruppe',
|
||||
'title-talk' => 'Überwachung Diskussion',
|
||||
'local-months' => array(
|
||||
'Jan',
|
||||
'Feb',
|
||||
|
|
Loading…
Reference in a new issue