2024-01-21 18:26:25 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class BMDSystemhausBlogBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const MAINTAINER = 'cn-tools';
|
|
|
|
const NAME = 'BMD SYSTEMHAUS GesmbH';
|
|
|
|
const CACHE_TIMEOUT = 21600; //6h
|
|
|
|
const URI = 'https://www.bmd.com';
|
2024-02-02 17:33:59 +03:00
|
|
|
const DONATION_URI = 'https://paypal.me/cntools';
|
|
|
|
const DESCRIPTION = 'BMD Systemhaus - We make business easy';
|
2024-08-22 12:36:58 +03:00
|
|
|
const BMD_FAV_ICON = 'https://www.bmd.com/favicon.ico';
|
2024-02-02 17:33:59 +03:00
|
|
|
|
|
|
|
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>',
|
|
|
|
'clir' => '<table width="100%"><tr><td style="vertical-align: top;">{data_content}</td><td style="vertical-align: top;">{data_img}</td></tr></table>',
|
|
|
|
'itcb' => '<div>{data_img}<br />{data_content}</div>',
|
|
|
|
'ctib' => '<div>{data_content}<br />{data_img}</div>',
|
|
|
|
'co' => '{data_content}',
|
|
|
|
'io' => '{data_img}'
|
|
|
|
];
|
2024-01-21 18:26:25 +03:00
|
|
|
|
|
|
|
const PARAMETERS = [
|
|
|
|
'Blog' => [
|
|
|
|
'country' => [
|
|
|
|
'name' => 'Country',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
|
|
|
'Österreich' => 'at',
|
|
|
|
'Deutschland' => 'de',
|
|
|
|
'Schweiz' => 'ch',
|
|
|
|
'Slovensko' => 'sk',
|
|
|
|
'Cesko' => 'cz',
|
2024-02-02 17:33:59 +03:00
|
|
|
'Hungary' => 'hu',
|
|
|
|
],
|
|
|
|
'defaultValue' => 'at',
|
|
|
|
],
|
|
|
|
'style' => [
|
|
|
|
'name' => 'Style',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
|
|
|
'Image left, content right' => 'ilcr',
|
|
|
|
'Content left, image right' => 'clir',
|
|
|
|
'Image top, content bottom' => 'itcb',
|
|
|
|
'Content top, image bottom' => 'ctib',
|
|
|
|
'Content only' => 'co',
|
|
|
|
'Image only' => 'io',
|
|
|
|
],
|
|
|
|
'defaultValue' => 'ilcr',
|
2024-01-21 18:26:25 +03:00
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
public function collectData()
|
|
|
|
{
|
2024-02-02 17:33:59 +03:00
|
|
|
// get website content
|
2024-08-30 05:21:51 +03:00
|
|
|
$html = getSimpleHTMLDOM($this->getURI());
|
2024-02-02 17:33:59 +03:00
|
|
|
|
|
|
|
// Convert relative links in HTML into absolute links
|
|
|
|
$html = defaultLinkTo($html, self::URI);
|
|
|
|
|
|
|
|
// Convert lazy-loading images and frames (video embeds) into static elements
|
|
|
|
$html = convertLazyLoading($html);
|
2024-01-21 18:26:25 +03:00
|
|
|
|
|
|
|
foreach ($html->find('div#bmdNewsList div#bmdNewsList-Item') as $element) {
|
|
|
|
$itemScope = $element->find('div[itemscope=itemscope]', 0);
|
|
|
|
|
|
|
|
$item = [];
|
2024-02-02 17:33:59 +03:00
|
|
|
|
|
|
|
// set base article data
|
2024-01-21 18:26:25 +03:00
|
|
|
$item['title'] = $this->getMetaItemPropContent($itemScope, 'headline');
|
|
|
|
$item['timestamp'] = strtotime($this->getMetaItemPropContent($itemScope, 'datePublished'));
|
|
|
|
$item['author'] = $this->getMetaItemPropContent($itemScope->find('div[itemprop=author]', 0), 'name');
|
|
|
|
|
2024-02-02 17:33:59 +03:00
|
|
|
// find article image
|
|
|
|
$imageTag = '';
|
|
|
|
$image = $element->find('div.mediaelement.mediaelement-image img', 0);
|
|
|
|
if ((!is_null($image)) and ($image->src != '')) {
|
|
|
|
$item['enclosures'] = [$image->src];
|
|
|
|
$imageTag = '<img src="' . $image->src . '"/>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// begin with right style
|
|
|
|
$content = self::ITEMSTYLE[$this->getInput('style')];
|
|
|
|
|
|
|
|
// render placeholder
|
|
|
|
$content = str_replace('{data_content}', $this->getMetaItemPropContent($itemScope, 'description'), $content);
|
|
|
|
$content = str_replace('{data_img}', $imageTag, $content);
|
|
|
|
|
|
|
|
// set finished content
|
|
|
|
$item['content'] = $content;
|
|
|
|
|
|
|
|
// get link to article
|
2024-01-21 18:26:25 +03:00
|
|
|
$link = $element->find('div#bmdNewsList-Text div#bmdNewsList-Title a', 0);
|
|
|
|
if (!is_null($link)) {
|
2024-02-02 17:33:59 +03:00
|
|
|
$item['uri'] = $link->href;
|
2024-01-21 18:26:25 +03:00
|
|
|
}
|
|
|
|
|
2024-02-02 17:33:59 +03:00
|
|
|
// init categories
|
2024-01-21 18:26:25 +03:00
|
|
|
$categories = [];
|
|
|
|
$tmpOne = [];
|
|
|
|
$tmpTwo = [];
|
|
|
|
|
|
|
|
// search first categorie span
|
|
|
|
$catElem = $element->find('div#bmdNewsList-Text div#bmdNewsList-Category span.news-list-category', 0);
|
|
|
|
$txt = trim($catElem->innertext);
|
|
|
|
$tmpOne = explode('/', $txt);
|
|
|
|
|
|
|
|
// split by 2 spaces
|
|
|
|
foreach ($tmpOne as $tmpElem) {
|
|
|
|
$tmpElem = trim($tmpElem);
|
|
|
|
$tmpData = preg_split('/ /', $tmpElem);
|
|
|
|
$tmpTwo = array_merge($tmpTwo, $tmpData);
|
|
|
|
}
|
|
|
|
|
|
|
|
// split by tabulator
|
|
|
|
foreach ($tmpTwo as $tmpElem) {
|
|
|
|
$tmpElem = trim($tmpElem);
|
|
|
|
$tmpData = preg_split('/\t+/', $tmpElem);
|
|
|
|
$categories = array_merge($categories, $tmpData);
|
|
|
|
}
|
|
|
|
|
2024-02-02 17:33:59 +03:00
|
|
|
// trim each categorie entries
|
2024-01-21 18:26:25 +03:00
|
|
|
$categories = array_map('trim', $categories);
|
|
|
|
|
|
|
|
// remove empty entries
|
|
|
|
$categories = array_filter($categories, function ($value) {
|
|
|
|
return !is_null($value) && $value !== '';
|
|
|
|
});
|
|
|
|
|
|
|
|
// set categories
|
|
|
|
if (count($categories) > 0) {
|
|
|
|
$item['categories'] = $categories;
|
|
|
|
}
|
|
|
|
|
2024-02-02 17:33:59 +03:00
|
|
|
// add item
|
2024-01-21 18:26:25 +03:00
|
|
|
if (($item['title'] != '') and ($item['content'] != '') and ($item['uri'] != '')) {
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
public function detectParameters($url)
|
|
|
|
{
|
2024-01-29 23:51:34 +03:00
|
|
|
try {
|
|
|
|
$parsedUrl = Url::fromString($url);
|
|
|
|
} catch (UrlException $e) {
|
2024-01-21 18:26:25 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-08-22 12:36:58 +03:00
|
|
|
if (!in_array($parsedUrl->getHost(), ['www.bmd.com', 'bmd.com'])) {
|
2024-01-29 23:51:34 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-08-22 12:36:58 +03:00
|
|
|
$lang = '';
|
|
|
|
|
|
|
|
// extract language from url
|
2024-01-29 23:51:34 +03:00
|
|
|
$path = explode('/', $parsedUrl->getPath());
|
2024-08-22 12:36:58 +03:00
|
|
|
if (count($path) > 1) {
|
|
|
|
$lang = $path[1];
|
2024-01-21 18:26:25 +03:00
|
|
|
|
2024-08-22 12:36:58 +03:00
|
|
|
// 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';
|
2024-01-21 18:26:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$params = [];
|
2024-08-22 12:36:58 +03:00
|
|
|
$params['country'] = strtolower($lang);
|
|
|
|
|
2024-01-21 18:26:25 +03:00
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
public function getURI()
|
|
|
|
{
|
2024-08-30 05:21:51 +03:00
|
|
|
$country = $this->getInput('country') ?? '';
|
|
|
|
$lURI = $this->getURIbyCountry($country);
|
2024-01-21 18:26:25 +03:00
|
|
|
return $lURI != '' ? $lURI : parent::getURI();
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
public function getIcon()
|
|
|
|
{
|
2024-08-22 12:36:58 +03:00
|
|
|
return self::BMD_FAV_ICON;
|
2024-01-21 18:26:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
private function getMetaItemPropContent($elem, $key)
|
|
|
|
{
|
|
|
|
if (($key != '') and (!is_null($elem))) {
|
|
|
|
$metaElem = $elem->find('meta[itemprop=' . $key . ']', 0);
|
|
|
|
if (!is_null($metaElem)) {
|
|
|
|
return $metaElem->getAttribute('content');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
private function getURIbyCountry($country)
|
|
|
|
{
|
2024-08-22 12:36:58 +03:00
|
|
|
switch (strtolower($country)) {
|
2024-01-21 18:26:25 +03:00
|
|
|
case 'at':
|
|
|
|
return 'https://www.bmd.com/at/ueber-bmd/blog-ohne-filter.html';
|
|
|
|
case 'de':
|
|
|
|
return 'https://www.bmd.com/de/das-ist-bmd/blog.html';
|
|
|
|
case 'ch':
|
|
|
|
return 'https://www.bmd.com/ch/das-ist-bmd/blog.html';
|
|
|
|
case 'sk':
|
|
|
|
return 'https://www.bmd.com/sk/firma/blog.html';
|
|
|
|
case 'cz':
|
|
|
|
return 'https://www.bmd.com/cz/firma/news-blog.html';
|
|
|
|
case 'hu':
|
|
|
|
return 'https://www.bmd.com/hu/rolunk/hirek.html';
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|