-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GoogleGroupsBridge] Add new bridge for Google Groups #2451
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
afab728
[GoogleGroupsBridge] Add new bridge for Google Groups
yamanq 185fa07
Use defaultLinkTo to account for base href
yamanq 8c2b6ba
Remove newline
yamanq 7d9cef5
Add Newline
yamanq 85e65a7
Use # delimiter
yamanq 09d0aba
Fix detectParameters bug
yamanq 3ba0db1
Fix for automated testing
yamanq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
class GoogleGroupsBridge extends XPathAbstract { | ||
const NAME = 'Google Groups Bridge'; | ||
const DESCRIPTION = 'Returns the latest posts on a Google Group'; | ||
const URI = 'https://groups.google.com'; | ||
const MAINTAINER = 'Yaman Qalieh'; | ||
const PARAMETERS = array( array( | ||
'group' => array( | ||
'name' => 'Group id', | ||
'title' => 'The string that follows /g/ in the URL', | ||
'exampleValue' => 'governance', | ||
'required' => true | ||
), | ||
'account' => array( | ||
'name' => 'Account id', | ||
'title' => 'Some Google groups have an additional id following /a/ in the URL', | ||
'exampleValue' => 'mozilla.org', | ||
'required' => false | ||
) | ||
)); | ||
const CACHE_TIMEOUT = 3600; | ||
|
||
const TEST_DETECT_PARAMETERS = array( | ||
'https://groups.google.com/a/mozilla.org/g/announce' => array( | ||
'account' => 'mozilla.org', 'group' => 'announce' | ||
), | ||
'https://groups.google.com/g/ansible-project' => array( | ||
'account' => null, 'group' => 'ansible-project' | ||
), | ||
); | ||
|
||
const XPATH_EXPRESSION_ITEM = '//div[@class="yhgbKd"]'; | ||
const XPATH_EXPRESSION_ITEM_TITLE = './/span[@class="o1DPKc"]'; | ||
const XPATH_EXPRESSION_ITEM_CONTENT = './/span[@class="WzoK"]'; | ||
const XPATH_EXPRESSION_ITEM_URI = './/a[@class="ZLl54"]/@href'; | ||
const XPATH_EXPRESSION_ITEM_AUTHOR = './/span[@class="z0zUgf"][last()]'; | ||
const XPATH_EXPRESSION_ITEM_TIMESTAMP = './/div[@class="tRlaM"]'; | ||
const XPATH_EXPRESSION_ITEM_ENCLOSURES = ''; | ||
const XPATH_EXPRESSION_ITEM_CATEGORIES = ''; | ||
const SETTING_FIX_ENCODING = true; | ||
|
||
protected function getSourceUrl() { | ||
$source = self::URI; | ||
|
||
$account = $this->getInput('account'); | ||
if($account) { | ||
$source = $source . '/a/' . $account; | ||
} | ||
return $source . '/g/' . $this->getInput('group'); | ||
} | ||
|
||
protected function provideWebsiteContent() { | ||
return defaultLinkTo(getContents($this->getSourceUrl()), self::URI); | ||
} | ||
|
||
const URL_REGEX = '#^https://groups.google.com(?:/a/(?<account>\S+))?(?:/g/(?<group>\S+))#'; | ||
|
||
public function detectParameters($url) { | ||
$params = array(); | ||
if(preg_match(self::URL_REGEX, $url, $matches)) { | ||
$params['group'] = $matches['group']; | ||
$params['account'] = $matches['account']; | ||
return $params; | ||
} | ||
return null; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why this is necessary is because Google groups defines the base as the root (
<base href="https://groups.google.com/">
) while XPathAbstract uses the source url as the base (for examplehttps://groups.google.com/a/mozilla.org/g/announce
), which leads to duplication ofa/mozilla.org/g
in all the relative urls used in the document if this is not used to correctly convert the relative links first.