2018-10-01 19:00:50 +03:00
|
|
|
<?php
|
2022-03-31 18:00:14 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
class GlassdoorBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
// Contexts
|
|
|
|
const CONTEXT_BLOG = 'Blogs';
|
|
|
|
const CONTEXT_REVIEW = 'Company Reviews';
|
|
|
|
const CONTEXT_GLOBAL = 'global';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
// Global context parameters
|
|
|
|
const PARAM_LIMIT = 'limit';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
// Blog context parameters
|
|
|
|
const PARAM_BLOG_TYPE = 'blog_type';
|
|
|
|
const PARAM_BLOG_FULL = 'full_article';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
const BLOG_TYPE_HOME = 'Home';
|
|
|
|
const BLOG_TYPE_COMPANIES_HIRING = 'Companies Hiring';
|
|
|
|
const BLOG_TYPE_CAREER_ADVICE = 'Career Advice';
|
|
|
|
const BLOG_TYPE_INTERVIEWS = 'Interviews';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
// Review context parameters
|
|
|
|
const PARAM_REVIEW_COMPANY = 'company';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
const MAINTAINER = 'logmanoriginal';
|
|
|
|
const NAME = 'Glassdoor Bridge';
|
|
|
|
const URI = 'https://www.glassdoor.com/';
|
|
|
|
const DESCRIPTION = 'Returns feeds for blog posts and company reviews';
|
|
|
|
const CACHE_TIMEOUT = 86400; // 24 hours
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
const PARAMETERS = [
|
|
|
|
self::CONTEXT_BLOG => [
|
|
|
|
self::PARAM_BLOG_TYPE => [
|
|
|
|
'name' => 'Blog type',
|
|
|
|
'type' => 'list',
|
|
|
|
'title' => 'Select the blog you want to follow',
|
|
|
|
'values' => [
|
|
|
|
self::BLOG_TYPE_HOME => 'blog/',
|
|
|
|
self::BLOG_TYPE_COMPANIES_HIRING => 'blog/companies-hiring/',
|
|
|
|
self::BLOG_TYPE_CAREER_ADVICE => 'blog/career-advice/',
|
|
|
|
self::BLOG_TYPE_INTERVIEWS => 'blog/interviews/',
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2018-10-01 19:00:50 +03:00
|
|
|
],
|
|
|
|
self::PARAM_BLOG_FULL => [
|
|
|
|
'name' => 'Full article',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'title' => 'Enable to return the full article for each post'
|
2022-07-01 16:10:30 +03:00
|
|
|
],
|
2018-10-01 19:00:50 +03:00
|
|
|
],
|
|
|
|
self::CONTEXT_REVIEW => [
|
|
|
|
self::PARAM_REVIEW_COMPANY => [
|
|
|
|
'name' => 'Company URL',
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
'title' => 'Paste the company review page URL here!',
|
|
|
|
'exampleValue' => 'https://www.glassdoor.com/Reviews/GitHub-Reviews-E671945.htm'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2018-10-01 19:00:50 +03:00
|
|
|
],
|
|
|
|
self::CONTEXT_GLOBAL => [
|
|
|
|
self::PARAM_LIMIT => [
|
|
|
|
'name' => 'Limit',
|
|
|
|
'type' => 'number',
|
|
|
|
'defaultValue' => -1,
|
|
|
|
'title' => 'Specifies the maximum number of items to return (default: All)'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2018-10-01 19:00:50 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case self::CONTEXT_BLOG:
|
|
|
|
return self::URI . $this->getInput(self::PARAM_BLOG_TYPE);
|
|
|
|
case self::CONTEXT_REVIEW:
|
|
|
|
return $this->filterCompanyURI($this->getInput(self::PARAM_REVIEW_COMPANY));
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
return parent::getURI();
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2022-03-31 18:00:14 +03:00
|
|
|
$url = $this->getURI();
|
|
|
|
$html = getSimpleHTMLDOM($url);
|
|
|
|
$html = defaultLinkTo($html, $url);
|
2018-10-01 19:00:50 +03:00
|
|
|
$limit = $this->getInput(self::PARAM_LIMIT);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case self::CONTEXT_BLOG:
|
|
|
|
$this->collectBlogData($html, $limit);
|
|
|
|
break;
|
|
|
|
case self::CONTEXT_REVIEW:
|
|
|
|
$this->collectReviewData($html, $limit);
|
|
|
|
break;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2018-10-01 19:00:50 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
private function collectBlogData($html, $limit)
|
|
|
|
{
|
2022-03-31 18:00:14 +03:00
|
|
|
$posts = $html->find('div.post')
|
2018-10-01 19:00:50 +03:00
|
|
|
or returnServerError('Unable to find blog posts!');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
foreach ($posts as $post) {
|
2022-03-31 18:00:14 +03:00
|
|
|
$item = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-03-31 18:00:14 +03:00
|
|
|
$item['uri'] = $post->find('a', 0)->href;
|
|
|
|
$item['title'] = $post->find('h3', 0)->plaintext;
|
|
|
|
$item['content'] = $post->find('p', 0)->plaintext;
|
|
|
|
$item['author'] = $post->find('p', -2)->plaintext;
|
|
|
|
$item['timestamp'] = strtotime($post->find('p', -1)->plaintext);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-03-31 18:00:14 +03:00
|
|
|
// TODO: fetch entire blog post content
|
2018-10-01 19:00:50 +03:00
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-03-31 18:00:14 +03:00
|
|
|
if ($limit > 0 && count($this->items) >= $limit) {
|
2018-10-01 19:00:50 +03:00
|
|
|
return;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2022-03-31 18:00:14 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
private function collectReviewData($html, $limit)
|
|
|
|
{
|
2019-06-09 20:32:22 +03:00
|
|
|
$reviews = $html->find('#ReviewsFeed li[id^="empReview]')
|
2018-10-01 19:00:50 +03:00
|
|
|
or returnServerError('Unable to find reviews!');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
foreach ($reviews as $review) {
|
2022-03-31 18:00:14 +03:00
|
|
|
$item = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
$item['uri'] = $review->find('a.reviewLink', 0)->href;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-03-31 18:00:14 +03:00
|
|
|
// Not all reviews have a title
|
|
|
|
$item['title'] = $review->find('h2', 0)->plaintext ?? 'Glassdoor review';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-03-31 18:00:14 +03:00
|
|
|
[$date, $author] = explode('-', $review->find('span.authorInfo', 0)->plaintext);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-03-31 18:00:14 +03:00
|
|
|
$item['author'] = trim($author);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-03-31 18:00:14 +03:00
|
|
|
$createdAt = DateTimeImmutable::createFromFormat('F m, Y', trim($date));
|
|
|
|
if ($createdAt) {
|
|
|
|
$item['timestamp'] = $createdAt->getTimestamp();
|
2019-06-09 20:32:22 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-03-31 18:00:14 +03:00
|
|
|
$item['content'] = $review->find('.px-std', 2)->text();
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-03-31 18:00:14 +03:00
|
|
|
if ($limit > 0 && count($this->items) >= $limit) {
|
2018-10-01 19:00:50 +03:00
|
|
|
return;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2022-03-31 18:00:14 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
private function filterCompanyURI($uri)
|
|
|
|
{
|
|
|
|
/* Make sure the URI is a valid review page. Unfortunately there is no
|
|
|
|
* simple way to determine if the URI is valid, because of automagic
|
|
|
|
* redirection and strange naming conventions.
|
|
|
|
*/
|
|
|
|
if (
|
|
|
|
!filter_var(
|
|
|
|
$uri,
|
2018-12-28 18:13:03 +03:00
|
|
|
FILTER_VALIDATE_URL,
|
|
|
|
FILTER_FLAG_PATH_REQUIRED
|
2022-07-01 16:10:30 +03:00
|
|
|
)
|
2018-12-28 18:13:03 +03:00
|
|
|
) {
|
2018-10-01 19:00:50 +03:00
|
|
|
returnClientError('The specified URL is invalid!');
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
$uri = filter_var($uri, FILTER_SANITIZE_URL);
|
|
|
|
$path = parse_url($uri, PHP_URL_PATH);
|
|
|
|
$parts = explode('/', $path);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
$allowed_strings = [
|
|
|
|
'de-DE' => 'Bewertungen',
|
|
|
|
'en-AU' => 'Reviews',
|
|
|
|
'nl-BE' => 'Reviews',
|
|
|
|
'fr-BE' => 'Avis',
|
|
|
|
'en-CA' => 'Reviews',
|
|
|
|
'fr-CA' => 'Avis',
|
|
|
|
'fr-FR' => 'Avis',
|
|
|
|
'en-IN' => 'Reviews',
|
|
|
|
'en-IE' => 'Reviews',
|
|
|
|
'nl-NL' => 'Reviews',
|
|
|
|
'de-AT' => 'Bewertungen',
|
|
|
|
'de-CH' => 'Bewertungen',
|
|
|
|
'fr-CH' => 'Avis',
|
|
|
|
'en-GB' => 'Reviews',
|
|
|
|
'en' => 'Reviews'
|
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
if (!in_array($parts[1], $allowed_strings)) {
|
|
|
|
returnClientError('Please specify a URL pointing to the companies review page!');
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-01 19:00:50 +03:00
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
}
|