From 012ecf8e525bbce4ad090353c3182c05f404803b Mon Sep 17 00:00:00 2001 From: Yaman Qalieh Date: Fri, 25 Mar 2022 20:09:33 -0400 Subject: [PATCH] [GoogleGroupsBridge] Add new bridge for Google Groups (#2451) --- bridges/GoogleGroupsBridge.php | 68 ++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 bridges/GoogleGroupsBridge.php diff --git a/bridges/GoogleGroupsBridge.php b/bridges/GoogleGroupsBridge.php new file mode 100644 index 00000000..6a1ff841 --- /dev/null +++ b/bridges/GoogleGroupsBridge.php @@ -0,0 +1,68 @@ + 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/(?\S+))?(?:/g/(?\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; + } +}