Skip to content

Commit

Permalink
[BMDSystemhausBlogBridge] rework detectParameters (#4138)
Browse files Browse the repository at this point in the history
* bridge BMDSystemhausBlog: rework of detectParameters

* fix lint phpcs error

* Update BMDSystemhausBlogBridge.php

* Update BMDSystemhausBlogBridge.php
  • Loading branch information
cn-tools authored Aug 22, 2024
1 parent 05e2c35 commit b0674d7
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions bridges/BMDSystemhausBlogBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class BMDSystemhausBlogBridge extends BridgeAbstract
const URI = 'https://www.bmd.com';
const DONATION_URI = 'https://paypal.me/cntools';
const DESCRIPTION = 'BMD Systemhaus - We make business easy';
const BMD_FAV_ICON = 'https://www.bmd.com/favicon.ico';

const ITEMSTYLE = [
'ilcr' => '<table width="100%"><tr><td style="vertical-align: top;">{data_img}</td><td style="vertical-align: top;">{data_content}</td></tr></table>',
Expand Down Expand Up @@ -148,18 +149,58 @@ public function detectParameters($url)
return null;
}

if ($parsedUrl->getHost() != 'www.bmd.com') {
if (!in_array($parsedUrl->getHost(), ['www.bmd.com', 'bmd.com'])) {
return null;
}

$lang = '';

// extract language from url
$path = explode('/', $parsedUrl->getPath());
if (count($path) > 1) {
$lang = $path[1];

if ($this->getURIbyCountry($path[1]) == '') {
return null;
// validate data
if ($this->getURIbyCountry($lang) == '') {
$lang = '';
}
}

// if no country available, find language by browser
if ($lang == '') {
$srvLanguages = explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
if (count($srvLanguages) > 0) {
$languages = explode(',', $srvLanguages[0]);
if (count($languages) > 0) {
for ($i = 0; $i < count($languages); $i++) {
$langDetails = explode('-', $languages[$i]);
if (count($langDetails) > 1) {
$lang = $langDetails[1];
} else {
$lang = substr($srvLanguages[0], 0, 2);
}

// validate data
if ($this->getURIbyCountry($lang) == '') {
$lang = '';
}

if ($lang != '') {
break;
}
}
}
}
}

// if no URL found by language, use AT as default
if ($this->getURIbyCountry($lang) == '') {
$lang = 'at';
}

$params = [];
$params['country'] = $path[1];
$params['country'] = strtolower($lang);

return $params;
}

Expand All @@ -173,7 +214,7 @@ public function getURI()
//-----------------------------------------------------
public function getIcon()
{
return 'https://www.bmd.com/favicon.ico';
return self::BMD_FAV_ICON;
}

//-----------------------------------------------------
Expand All @@ -192,7 +233,7 @@ private function getMetaItemPropContent($elem, $key)
//-----------------------------------------------------
private function getURIbyCountry($country)
{
switch ($country) {
switch (strtolower($country)) {
case 'at':
return 'https://www.bmd.com/at/ueber-bmd/blog-ohne-filter.html';
case 'de':
Expand Down

0 comments on commit b0674d7

Please sign in to comment.