Skip to content
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 7 commits into from
Mar 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions bridges/GoogleGroupsBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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' => 'announce',
'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');
}

public function collectData() {
parent::collectData();

# There is duplication in the original item url, so this fixes that
$replace_len = strlen(self::getSourceUrl()) - strlen($this->getInput('group')) - 1;
foreach ($this->items as $item) {
$item->setURI(substr_replace($item->getURI(), self::URI, 0, $replace_len));
}
}

const URL_REGEX = '/^https:\/\/groups.google.com(?:\/a\/(?<account>\S+))?(?:\/g\/(?<group>\S+))/';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use # as delimiter instead of /


public function detectParameters($url) {
$params = array();
if(preg_match(self::URL_REGEX, $url, $matches)) {
$params['group'] = $matches['group'];
$params['account'] = $matches['account'];
}
return $params;
}
}