2021-07-20 11:06:56 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-07-20 11:06:56 +03:00
|
|
|
class PicukiBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const MAINTAINER = 'marcus-at-localhost';
|
|
|
|
const NAME = 'Picuki Bridge';
|
|
|
|
const URI = 'https://www.picuki.com/';
|
|
|
|
const CACHE_TIMEOUT = 3600; // 1h
|
|
|
|
const DESCRIPTION = 'Returns Picuki posts by user and by hashtag';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-07-20 11:06:56 +03:00
|
|
|
const PARAMETERS = [
|
|
|
|
'Username' => [
|
|
|
|
'u' => [
|
|
|
|
'name' => 'username',
|
2022-03-24 13:59:34 +03:00
|
|
|
'exampleValue' => 'aesoprockwins',
|
2021-07-20 11:06:56 +03:00
|
|
|
'required' => true,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'Hashtag' => [
|
|
|
|
'h' => [
|
|
|
|
'name' => 'hashtag',
|
2022-03-24 13:59:34 +03:00
|
|
|
'exampleValue' => 'beautifulday',
|
2021-07-20 11:06:56 +03:00
|
|
|
'required' => true,
|
|
|
|
],
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2021-07-20 11:06:56 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-07-20 11:06:56 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
if (!is_null($this->getInput('u'))) {
|
|
|
|
return urljoin(self::URI, '/profile/' . $this->getInput('u'));
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-07-20 11:06:56 +03:00
|
|
|
if (!is_null($this->getInput('h'))) {
|
|
|
|
return urljoin(self::URI, '/tag/' . trim($this->getInput('h'), '#'));
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-07-20 11:06:56 +03:00
|
|
|
return parent::getURI();
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-07-20 11:06:56 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2023-02-19 03:35:28 +03:00
|
|
|
$re = '#let short_code = "(.*?)";\s*$#m';
|
2021-07-20 11:06:56 +03:00
|
|
|
$html = getSimpleHTMLDOM($this->getURI());
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-07-20 11:06:56 +03:00
|
|
|
foreach ($html->find('.box-photos .box-photo') as $element) {
|
2022-05-10 20:53:29 +03:00
|
|
|
// skip ad items
|
2021-07-20 11:06:56 +03:00
|
|
|
if (in_array('adv', explode(' ', $element->class))) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-10 20:53:29 +03:00
|
|
|
$url = urljoin(self::URI, $element->find('a', 0)->href);
|
2023-02-19 03:35:28 +03:00
|
|
|
$html = getSimpleHTMLDOMCached($url);
|
|
|
|
$sourceUrl = null;
|
|
|
|
if (preg_match($re, $html, $matches) > 0) {
|
|
|
|
$sourceUrl = 'https://instagram.com/p/' . $matches[1];
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-10 20:53:29 +03:00
|
|
|
$author = trim($element->find('.user-nickname', 0)->plaintext);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-10 20:53:29 +03:00
|
|
|
$date = date_create();
|
|
|
|
$relativeDate = str_replace(' ago', '', $element->find('.time', 0)->plaintext);
|
|
|
|
date_sub($date, date_interval_create_from_date_string($relativeDate));
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-04-10 19:54:48 +03:00
|
|
|
$description = trim($element->find('.photo-description', 0)->plaintext);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-10 20:53:29 +03:00
|
|
|
$isVideo = (bool) $element->find('.video-icon', 0);
|
|
|
|
$videoNote = $isVideo ? '<p><i>(video)</i></p>' : '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-10 20:53:29 +03:00
|
|
|
$imageUrl = $element->find('.post-image', 0)->src;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-10 20:53:29 +03:00
|
|
|
// the last path segment needs to be encoded, because it contains special characters like + or |
|
|
|
|
$imageUrlParts = explode('/', $imageUrl);
|
|
|
|
$imageUrlParts[count($imageUrlParts) - 1] = urlencode($imageUrlParts[count($imageUrlParts) - 1]);
|
|
|
|
$imageUrl = implode('/', $imageUrlParts);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-10 20:53:29 +03:00
|
|
|
// add fake file extension for it to be recognized as image/jpeg instead of application/octet-stream
|
|
|
|
$imageUrl = $imageUrl . '#.jpg';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-10 20:53:29 +03:00
|
|
|
$this->items[] = [
|
|
|
|
'uri' => $url,
|
|
|
|
'author' => $author,
|
|
|
|
'timestamp' => date_format($date, 'r'),
|
|
|
|
'title' => strlen($description) > 60 ? mb_substr($description, 0, 57) . '...' : $description,
|
|
|
|
'thumbnail' => $imageUrl,
|
2023-02-19 03:35:28 +03:00
|
|
|
'source' => $sourceUrl,
|
2022-05-10 20:53:29 +03:00
|
|
|
'enclosures' => [$imageUrl],
|
|
|
|
'content' => <<<HTML
|
|
|
|
<a href="{$url}">
|
|
|
|
<img loading="lazy" src="{$imageUrl}" />
|
|
|
|
</a>
|
2023-02-19 03:35:28 +03:00
|
|
|
<a href="{$sourceUrl}">{$sourceUrl}</a>
|
2022-05-10 20:53:29 +03:00
|
|
|
{$videoNote}
|
|
|
|
<p>{$description}<p>
|
|
|
|
HTML
|
|
|
|
];
|
2021-07-20 11:06:56 +03:00
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-07-20 11:06:56 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
if (!is_null($this->getInput('u'))) {
|
|
|
|
return $this->getInput('u') . ' - Picuki Bridge';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-07-20 11:06:56 +03:00
|
|
|
if (!is_null($this->getInput('h'))) {
|
|
|
|
return $this->getInput('h') . ' - Picuki Bridge';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-07-20 11:06:56 +03:00
|
|
|
return parent::getName();
|
|
|
|
}
|
|
|
|
}
|