2016-08-11 00:18:35 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 20:11:09 +03:00
|
|
|
class KununuBridge extends BridgeAbstract
|
|
|
|
{
|
2017-02-11 18:16:56 +03:00
|
|
|
const MAINTAINER = 'logmanoriginal';
|
|
|
|
const NAME = 'Kununu Bridge';
|
|
|
|
const URI = 'https://www.kununu.com/';
|
2016-09-25 18:04:28 +03:00
|
|
|
const CACHE_TIMEOUT = 86400; // 24h
|
2017-02-11 18:16:56 +03:00
|
|
|
const DESCRIPTION = 'Returns the latest reviews for a company and site of your choice.';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-17 19:11:58 +03:00
|
|
|
const PARAMETERS = [
|
|
|
|
'global' => [
|
2017-02-11 18:16:56 +03:00
|
|
|
'site' => [
|
|
|
|
'name' => 'Site',
|
|
|
|
'type' => 'list',
|
|
|
|
'title' => 'Select your site',
|
|
|
|
'values' => [
|
|
|
|
'Austria' => 'at',
|
|
|
|
'Germany' => 'de',
|
2022-06-14 16:45:01 +03:00
|
|
|
'Switzerland' => 'ch'
|
2022-04-13 00:37:30 +03:00
|
|
|
],
|
|
|
|
'exampleValue' => 'de',
|
2017-02-11 18:16:56 +03:00
|
|
|
],
|
2019-06-21 01:00:44 +03:00
|
|
|
'include_ratings' => [
|
|
|
|
'name' => 'Include ratings',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'title' => 'Activate to include ratings in the feed'
|
|
|
|
],
|
2019-11-01 17:27:35 +03:00
|
|
|
'limit' => [
|
|
|
|
'name' => 'Limit',
|
|
|
|
'type' => 'number',
|
|
|
|
'defaultValue' => 3,
|
|
|
|
'title' => "Maximum number of items to return in the feed.\n0 = unlimited"
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2016-12-17 19:11:58 +03:00
|
|
|
],
|
2022-07-01 16:10:30 +03:00
|
|
|
[
|
2017-02-11 18:16:56 +03:00
|
|
|
'company' => [
|
|
|
|
'name' => 'Company',
|
|
|
|
'required' => true,
|
2022-06-14 16:45:01 +03:00
|
|
|
'exampleValue' => 'kununu',
|
|
|
|
'title' => 'Insert company name (i.e. Kununu) or URI path (i.e. kununu)'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2016-12-17 19:11:58 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-17 20:04:21 +03:00
|
|
|
private $companyName = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-06-14 16:45:01 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
2017-07-29 20:28:00 +03:00
|
|
|
if (!is_null($this->getInput('company')) && !is_null($this->getInput('site'))) {
|
2017-02-11 18:16:56 +03:00
|
|
|
$company = $this->fixCompanyName($this->getInput('company'));
|
2016-12-17 20:04:21 +03:00
|
|
|
$site = $this->getInput('site');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-06-14 16:45:01 +03:00
|
|
|
return sprintf('%s%s/%s', self::URI, $site, $company);
|
2016-12-17 19:11:58 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-17 20:04:21 +03:00
|
|
|
return parent::getURI();
|
2016-12-17 19:11:58 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-06-14 16:45:01 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
2017-07-29 20:28:00 +03:00
|
|
|
if (!is_null($this->getInput('company'))) {
|
2017-02-11 18:16:56 +03:00
|
|
|
$company = $this->fixCompanyName($this->getInput('company'));
|
|
|
|
return ($this->companyName ?: $company) . ' - ' . self::NAME;
|
2016-12-17 20:04:21 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-02-15 00:20:55 +03:00
|
|
|
return parent::getName();
|
2016-12-17 19:11:58 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-09-16 10:55:35 +03:00
|
|
|
public function getIcon()
|
|
|
|
{
|
|
|
|
return 'https://www.kununu.com/favicon-196x196.png';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-08-29 13:20:18 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2016-12-17 19:11:58 +03:00
|
|
|
$full = $this->getInput('full');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-08-11 00:18:35 +03:00
|
|
|
// Load page
|
2022-06-14 16:45:01 +03:00
|
|
|
$json = json_decode(getContents($this->getAPI()), true);
|
|
|
|
$this->companyName = $json['common']['name'];
|
|
|
|
$baseURI = $this->getURI() . '/bewertung/';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-11-01 17:27:35 +03:00
|
|
|
$limit = $this->getInput('limit') ?: 0;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-08-11 00:18:35 +03:00
|
|
|
// Go through all articles
|
2022-06-14 16:45:01 +03:00
|
|
|
foreach ($json['reviews'] as $review) {
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = [];
|
2022-06-14 16:45:01 +03:00
|
|
|
$item['author'] = $review['position'] . ' / ' . $review['department'];
|
|
|
|
$item['timestamp'] = $review['createdAt'];
|
|
|
|
$item['title'] = $review['roundedScore'] . ' : ' . $review['title'];
|
|
|
|
$item['uri'] = $baseURI . $review['uuid'];
|
|
|
|
$item['content'] = $this->extractArticleDescription($review);
|
2016-08-11 00:18:35 +03:00
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-11-01 17:27:35 +03:00
|
|
|
if ($limit > 0 && count($this->items) >= $limit) {
|
|
|
|
break;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2018-09-16 10:55:35 +03:00
|
|
|
}
|
2016-08-11 00:18:35 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-06-14 16:45:01 +03:00
|
|
|
/**
|
|
|
|
* Returns JSON API url
|
|
|
|
*/
|
|
|
|
private function getAPI()
|
|
|
|
{
|
|
|
|
$company = $this->fixCompanyName($this->getInput('company'));
|
|
|
|
$site = $this->getInput('site');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-06-14 16:45:01 +03:00
|
|
|
return self::URI . 'middlewares/profiles/' .
|
|
|
|
$site . '/' . $company .
|
|
|
|
'/reviews?reviewType=employees&urlParams=sort=newest&sort=newest&page=1';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-17 20:04:21 +03:00
|
|
|
/*
|
|
|
|
* Returns a fixed version of the provided company name
|
|
|
|
*/
|
2017-02-11 18:16:56 +03:00
|
|
|
private function fixCompanyName($company)
|
|
|
|
{
|
2016-12-17 20:04:21 +03:00
|
|
|
$company = trim($company);
|
|
|
|
$company = str_replace(' ', '-', $company);
|
|
|
|
$company = strtolower($company);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-06-30 00:55:33 +03:00
|
|
|
$umlauts = ['/ä/','/ö/','/ü/','/Ä/','/Ö/','/Ü/','/ß/'];
|
|
|
|
$replace = ['ae','oe','ue','Ae','Oe','Ue','ss'];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-09-16 10:55:35 +03:00
|
|
|
return preg_replace($umlauts, $replace, $company);
|
2016-08-11 00:18:35 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-08-11 00:18:35 +03:00
|
|
|
/**
|
|
|
|
* Returns the description from a given article
|
|
|
|
*/
|
2022-06-14 16:45:01 +03:00
|
|
|
private function extractArticleDescription($json)
|
|
|
|
{
|
|
|
|
$retVal = '';
|
|
|
|
foreach ($json['texts'] as $text) {
|
|
|
|
$retVal .= '<h4>' . $text['id'] . '</h4><p>' . $text['text'] . '</p>';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-06-14 16:45:01 +03:00
|
|
|
if ($this->getInput('include_ratings') && !empty($json['ratings'])) {
|
2019-06-21 01:00:44 +03:00
|
|
|
$retVal .= (empty($retVal) ? '' : '<hr>') . '<table>';
|
2022-06-14 16:45:01 +03:00
|
|
|
foreach ($json['ratings'] as $rating) {
|
2019-06-21 01:00:44 +03:00
|
|
|
$retVal .= <<<EOD
|
|
|
|
<tr>
|
2022-06-14 16:45:01 +03:00
|
|
|
<td>{$rating['id']}
|
|
|
|
<td>{$rating['roundedScore']}
|
|
|
|
<td>{$rating['text']}
|
2019-06-21 01:00:44 +03:00
|
|
|
</tr>
|
|
|
|
EOD;
|
|
|
|
}
|
|
|
|
$retVal .= '</table>';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retVal;
|
2016-08-11 00:18:35 +03:00
|
|
|
}
|
|
|
|
}
|