-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PicukiBridge] Displays Instagram Posts #2183
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
class PicukiBridge extends BridgeAbstract | ||
{ | ||
|
||
const MAINTAINER = 'marcus-at-localhost'; | ||
const NAME = 'Picuki Bridge'; | ||
const URI = 'https://www.picuki.com/'; | ||
const CACHE_TIMEOUT = 21600; // 6h | ||
const DESCRIPTION = 'Returns Picuki posts by users and by hashtag'; | ||
|
||
const PARAMETERS = [ | ||
'Username' => [ | ||
'u' => [ | ||
'name' => 'username', | ||
'required' => true, | ||
], | ||
], | ||
'Hashtag' => [ | ||
'h' => [ | ||
'name' => 'hashtag', | ||
'required' => true, | ||
], | ||
] | ||
]; | ||
|
||
public function getURI() | ||
{ | ||
if (!is_null($this->getInput('u'))) { | ||
return trim(self::URI, '/') . '/profile/' . $this->getInput('u'); | ||
} | ||
|
||
if (!is_null($this->getInput('h'))) { | ||
return trim(self::URI, '/') . '/tag/' . $this->getInput('h'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same about urljoin There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be nice, if |
||
} | ||
|
||
return parent::getURI(); | ||
} | ||
|
||
public function collectData() | ||
{ | ||
$html = getSimpleHTMLDOM($this->getURI()) | ||
or returnServerError('Could not request Picuki.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need this. getSimpleHTMLDom will throw exception. |
||
|
||
foreach ($html->find('.box-photos .box-photo') as $element) { | ||
|
||
// check if item is an ad. | ||
if (in_array('adv', explode(' ', $element->class))) { | ||
continue; | ||
} | ||
|
||
$item = []; | ||
|
||
$date = date_create(); | ||
$relative_date = str_replace(' ago', '', $element->find('.time', 0)->plaintext); | ||
date_sub($date, date_interval_create_from_date_string($relative_date)); | ||
$item['timestamp'] = date_format($date, 'r'); | ||
|
||
|
||
$item['uri'] = self::URI . $element->find('a', 0)->href; | ||
|
||
$item['title'] = $element->find('.photo-description', 0)->plaintext; | ||
|
||
$is_video = (bool) $element->find('.video-icon', 0); | ||
$item['content'] = ($is_video) ? '(video) ' : ''; | ||
$item['content'] .= str_replace( | ||
'src="', | ||
'src="' . trim(self::URI, '/'), | ||
$element->find('.photo', 0)->outertext | ||
); | ||
|
||
$item['enclosures'] = [ | ||
// just add `.jpg` extension to get the correct mime type. All Instagram posts are JPG | ||
trim(self::URI, '/') . $element->find('.post-image', 0)->src . '.jpg' | ||
]; | ||
|
||
$item['thumbnail'] = trim(self::URI, '/') . $element->find('.post-image', 0)->src; | ||
|
||
$this->items[] = $item; | ||
} | ||
} | ||
|
||
|
||
public function getName() | ||
{ | ||
if (!is_null($this->getInput('u'))) { | ||
return $this->getInput('u') . ' - Picuki Bridge'; | ||
} | ||
|
||
return parent::getName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing for hashtag?) |
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have
urljoin