2014-05-26 00:30:46 +02:00
|
|
|
<?php
|
2017-02-11 16:16:56 +01:00
|
|
|
class TwitterBridge extends BridgeAbstract {
|
|
|
|
const NAME = 'Twitter Bridge';
|
|
|
|
const URI = 'https://twitter.com/';
|
|
|
|
const CACHE_TIMEOUT = 300; // 5min
|
|
|
|
const DESCRIPTION = 'returns tweets';
|
2016-12-17 16:43:47 +01:00
|
|
|
const MAINTAINER = 'pmaziere';
|
2017-02-11 16:16:56 +01:00
|
|
|
const PARAMETERS = array(
|
|
|
|
'global' => array(
|
|
|
|
'nopic' => array(
|
|
|
|
'name' => 'Hide profile pictures',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'title' => 'Activate to hide profile pictures in content'
|
2017-04-22 15:36:25 +02:00
|
|
|
),
|
|
|
|
'noimg' => array(
|
|
|
|
'name' => 'Hide images in tweets',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'title' => 'Activate to hide images in tweets'
|
2018-12-12 16:56:36 +01:00
|
|
|
),
|
|
|
|
'noimgscaling' => array(
|
|
|
|
'name' => 'Disable image scaling',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'title' => 'Activate to disable image scaling in tweets (keeps original image)'
|
2017-02-11 16:16:56 +01:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'By keyword or hashtag' => array(
|
|
|
|
'q' => array(
|
|
|
|
'name' => 'Keyword or #hashtag',
|
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'rss-bridge, #rss-bridge',
|
2019-06-11 21:51:10 +02:00
|
|
|
'title' => <<<EOD
|
|
|
|
* To search for multiple words (must contain all of these words), put a space between them.
|
|
|
|
|
|
|
|
Example: `rss-bridge release`.
|
|
|
|
|
|
|
|
* To search for multiple words (contains any of these words), put "OR" between them.
|
|
|
|
|
|
|
|
Example: `rss-bridge OR rssbridge`.
|
|
|
|
|
|
|
|
* To search for an exact phrase (including whitespace), put double-quotes around them.
|
|
|
|
|
|
|
|
Example: `"rss-bridge release"`
|
|
|
|
|
|
|
|
* If you want to search for anything **but** a specific word, put a hyphen before it.
|
|
|
|
|
|
|
|
Example: `rss-bridge -release` (ignores "release")
|
|
|
|
|
|
|
|
* Of course, this also works for hashtags.
|
|
|
|
|
|
|
|
Example: `#rss-bridge OR #rssbridge`
|
|
|
|
|
|
|
|
* And you can combine them in any shape or form you like.
|
|
|
|
|
|
|
|
Example: `#rss-bridge OR #rssbridge -release`
|
|
|
|
EOD
|
2017-02-11 16:16:56 +01:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'By username' => array(
|
|
|
|
'u' => array(
|
|
|
|
'name' => 'username',
|
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'sebsauvage',
|
|
|
|
'title' => 'Insert a user name'
|
|
|
|
),
|
|
|
|
'norep' => array(
|
|
|
|
'name' => 'Without replies',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'title' => 'Only return initial tweets'
|
2017-03-17 18:41:35 +01:00
|
|
|
),
|
|
|
|
'noretweet' => array(
|
|
|
|
'name' => 'Without retweets',
|
|
|
|
'required' => false,
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'title' => 'Hide retweets'
|
2017-02-11 16:16:56 +01:00
|
|
|
)
|
2017-09-24 16:59:45 +02:00
|
|
|
),
|
|
|
|
'By list' => array(
|
|
|
|
'user' => array(
|
|
|
|
'name' => 'User',
|
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'sebsauvage',
|
|
|
|
'title' => 'Insert a user name'
|
|
|
|
),
|
|
|
|
'list' => array(
|
|
|
|
'name' => 'List',
|
|
|
|
'required' => true,
|
|
|
|
'title' => 'Insert the list name'
|
|
|
|
),
|
|
|
|
'filter' => array(
|
|
|
|
'name' => 'Filter',
|
|
|
|
'exampleValue' => '#rss-bridge',
|
|
|
|
'required' => false,
|
|
|
|
'title' => 'Specify term to search for'
|
|
|
|
)
|
2017-02-11 16:16:56 +01:00
|
|
|
)
|
|
|
|
);
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2018-11-26 18:05:41 +01:00
|
|
|
public function detectParameters($url){
|
|
|
|
$params = array();
|
|
|
|
|
|
|
|
// By keyword or hashtag (search)
|
|
|
|
$regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/search.*(\?|&)q=([^\/&?\n]+)/';
|
|
|
|
if(preg_match($regex, $url, $matches) > 0) {
|
|
|
|
$params['q'] = urldecode($matches[4]);
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
// By hashtag
|
|
|
|
$regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/hashtag\/([^\/?\n]+)/';
|
|
|
|
if(preg_match($regex, $url, $matches) > 0) {
|
|
|
|
$params['q'] = urldecode($matches[3]);
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
// By list
|
|
|
|
$regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/([^\/?\n]+)\/lists\/([^\/?\n]+)/';
|
|
|
|
if(preg_match($regex, $url, $matches) > 0) {
|
|
|
|
$params['user'] = urldecode($matches[3]);
|
|
|
|
$params['list'] = urldecode($matches[4]);
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
// By username
|
|
|
|
$regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/([^\/?\n]+)/';
|
|
|
|
if(preg_match($regex, $url, $matches) > 0) {
|
|
|
|
$params['u'] = urldecode($matches[3]);
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
public function getName(){
|
2017-07-29 19:28:00 +02:00
|
|
|
switch($this->queriedContext) {
|
2017-02-11 16:16:56 +01:00
|
|
|
case 'By keyword or hashtag':
|
|
|
|
$specific = 'search ';
|
|
|
|
$param = 'q';
|
|
|
|
break;
|
|
|
|
case 'By username':
|
|
|
|
$specific = '@';
|
|
|
|
$param = 'u';
|
|
|
|
break;
|
2017-09-24 16:59:45 +02:00
|
|
|
case 'By list':
|
2018-01-12 13:07:40 +01:00
|
|
|
return $this->getInput('list') . ' - Twitter list by ' . $this->getInput('user');
|
2017-02-14 22:20:55 +01:00
|
|
|
default: return parent::getName();
|
2017-02-11 16:16:56 +01:00
|
|
|
}
|
|
|
|
return 'Twitter ' . $specific . $this->getInput($param);
|
|
|
|
}
|
2016-08-25 01:49:30 +02:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
public function getURI(){
|
2017-07-29 19:28:00 +02:00
|
|
|
switch($this->queriedContext) {
|
2017-02-11 16:16:56 +01:00
|
|
|
case 'By keyword or hashtag':
|
|
|
|
return self::URI
|
|
|
|
. 'search?q='
|
|
|
|
. urlencode($this->getInput('q'))
|
|
|
|
. '&f=tweets';
|
|
|
|
case 'By username':
|
|
|
|
return self::URI
|
2017-07-03 19:52:56 +02:00
|
|
|
. urlencode($this->getInput('u'));
|
|
|
|
// Always return without replies!
|
|
|
|
// . ($this->getInput('norep') ? '' : '/with_replies');
|
2017-09-24 16:59:45 +02:00
|
|
|
case 'By list':
|
|
|
|
return self::URI
|
|
|
|
. urlencode($this->getInput('user'))
|
|
|
|
. '/lists/'
|
|
|
|
. str_replace(' ', '-', strtolower($this->getInput('list')));
|
2017-02-14 22:36:33 +01:00
|
|
|
default: return parent::getURI();
|
2017-02-11 16:16:56 +01:00
|
|
|
}
|
|
|
|
}
|
2016-08-25 01:49:30 +02:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-07-08 19:06:35 +02:00
|
|
|
$html = '';
|
2019-07-26 10:36:59 +02:00
|
|
|
$page = $this->getURI();
|
2016-08-28 00:01:42 +02:00
|
|
|
|
2020-01-31 14:36:25 +01:00
|
|
|
$header = array(
|
|
|
|
'User-Agent: Mozilla/5.0 (Windows NT 9.0; WOW64; Trident/7.0; rv:11.0) like Gecko'
|
|
|
|
);
|
|
|
|
|
2019-09-12 16:14:48 +02:00
|
|
|
if(php_sapi_name() === 'cli' && empty(ini_get('curl.cainfo'))) {
|
|
|
|
$cookies = $this->getCookies($page);
|
2020-01-31 14:36:25 +01:00
|
|
|
$html = getSimpleHTMLDOM($page, array_merge($header, array("Cookie: $cookies")));
|
2019-09-12 16:14:48 +02:00
|
|
|
} else {
|
2020-01-31 14:36:25 +01:00
|
|
|
$html = getSimpleHTMLDOM($page, $header, array(CURLOPT_COOKIEFILE => ''));
|
2019-09-12 16:14:48 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
if(!$html) {
|
|
|
|
switch($this->queriedContext) {
|
2016-08-28 00:01:42 +02:00
|
|
|
case 'By keyword or hashtag':
|
2016-09-25 23:22:33 +02:00
|
|
|
returnServerError('No results for this query.');
|
2016-08-28 00:01:42 +02:00
|
|
|
case 'By username':
|
2016-09-25 23:22:33 +02:00
|
|
|
returnServerError('Requested username can\'t be found.');
|
2017-09-24 16:59:45 +02:00
|
|
|
case 'By list':
|
|
|
|
returnServerError('Requested username or list can\'t be found');
|
2016-08-28 00:01:42 +02:00
|
|
|
}
|
2014-05-26 00:30:46 +02:00
|
|
|
}
|
|
|
|
|
2016-08-28 01:25:33 +02:00
|
|
|
$hidePictures = $this->getInput('nopic');
|
2016-08-10 10:44:23 +02:00
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach($html->find('div.js-stream-tweet') as $tweet) {
|
2017-03-17 18:41:35 +01:00
|
|
|
|
|
|
|
// Skip retweets?
|
|
|
|
if($this->getInput('noretweet')
|
2019-06-12 18:25:48 +02:00
|
|
|
&& $tweet->find('div.context span.js-retweet-text a', 0)) {
|
2017-03-17 18:41:35 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-06-18 23:18:41 +02:00
|
|
|
// remove 'invisible' content
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach($tweet->find('.invisible') as $invisible) {
|
2019-06-02 13:03:26 +02:00
|
|
|
$invisible->outertext = '';
|
2017-06-18 23:18:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-03 00:26:32 +02:00
|
|
|
// Skip protmoted tweets
|
2017-08-03 17:56:39 +02:00
|
|
|
$heading = $tweet->previousSibling();
|
2017-08-03 00:26:32 +02:00
|
|
|
if(!is_null($heading) &&
|
2017-08-03 17:56:39 +02:00
|
|
|
$heading->getAttribute('class') === 'promoted-tweet-heading'
|
|
|
|
) {
|
2017-08-03 00:26:32 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
2014-05-26 00:30:46 +02:00
|
|
|
// extract username and sanitize
|
2018-11-15 22:00:01 +01:00
|
|
|
$item['username'] = htmlspecialchars_decode($tweet->getAttribute('data-screen-name'), ENT_QUOTES);
|
2014-05-26 00:30:46 +02:00
|
|
|
// extract fullname (pseudonym)
|
2018-11-15 22:00:01 +01:00
|
|
|
$item['fullname'] = htmlspecialchars_decode($tweet->getAttribute('data-name'), ENT_QUOTES);
|
2016-08-10 10:26:29 +02:00
|
|
|
// get author
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['author'] = $item['fullname'] . ' (@' . $item['username'] . ')';
|
2019-06-12 18:25:48 +02:00
|
|
|
if($rt = $tweet->find('div.context span.js-retweet-text a', 0)) {
|
|
|
|
$item['author'] .= ' RT: @' . $rt->plaintext;
|
2019-02-04 14:56:07 +01:00
|
|
|
}
|
2014-05-26 00:30:46 +02:00
|
|
|
// get avatar link
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['avatar'] = $tweet->find('img', 0)->src;
|
2014-05-26 00:30:46 +02:00
|
|
|
// get TweetID
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['id'] = $tweet->getAttribute('data-tweet-id');
|
2016-07-08 19:06:35 +02:00
|
|
|
// get tweet link
|
2017-06-19 00:19:52 +02:00
|
|
|
$item['uri'] = self::URI . substr($tweet->find('a.js-permalink', 0)->getAttribute('href'), 1);
|
2014-05-26 00:30:46 +02:00
|
|
|
// extract tweet timestamp
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['timestamp'] = $tweet->find('span.js-short-timestamp', 0)->getAttribute('data-time');
|
2016-08-10 10:26:29 +02:00
|
|
|
// generate the title
|
2018-11-15 22:00:01 +01:00
|
|
|
$item['title'] = strip_tags($this->fixAnchorSpacing(htmlspecialchars_decode(
|
|
|
|
$tweet->find('p.js-tweet-text', 0), ENT_QUOTES), '<a>'));
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2017-09-24 16:59:45 +02:00
|
|
|
switch($this->queriedContext) {
|
|
|
|
case 'By list':
|
|
|
|
// Check if filter applies to list (using raw content)
|
2018-01-12 13:07:40 +01:00
|
|
|
if($this->getInput('filter')) {
|
2017-09-24 16:59:45 +02:00
|
|
|
if(stripos($tweet->find('p.js-tweet-text', 0)->plaintext, $this->getInput('filter')) === false) {
|
|
|
|
continue 2; // switch + for-loop!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2017-04-22 15:36:25 +02:00
|
|
|
$this->processContentLinks($tweet);
|
|
|
|
$this->processEmojis($tweet);
|
2016-08-09 21:47:29 +02:00
|
|
|
|
2016-08-09 21:59:55 +02:00
|
|
|
// get tweet text
|
2017-02-11 16:16:56 +01:00
|
|
|
$cleanedTweet = str_replace(
|
|
|
|
'href="/',
|
|
|
|
'href="' . self::URI,
|
|
|
|
$tweet->find('p.js-tweet-text', 0)->innertext
|
|
|
|
);
|
2016-08-09 21:47:29 +02:00
|
|
|
|
2017-06-18 23:18:41 +02:00
|
|
|
// fix anchors missing spaces in-between
|
|
|
|
$cleanedTweet = $this->fixAnchorSpacing($cleanedTweet);
|
|
|
|
|
2016-08-10 10:44:23 +02:00
|
|
|
// Add picture to content
|
|
|
|
$picture_html = '';
|
2017-07-29 19:28:00 +02:00
|
|
|
if(!$hidePictures) {
|
2016-08-10 10:44:23 +02:00
|
|
|
$picture_html = <<<EOD
|
2017-02-11 16:16:56 +01:00
|
|
|
<a href="https://twitter.com/{$item['username']}">
|
|
|
|
<img
|
2017-04-22 15:36:25 +02:00
|
|
|
style="align:top; width:75px; border:1px solid black;"
|
2017-02-11 16:16:56 +01:00
|
|
|
alt="{$item['username']}"
|
|
|
|
src="{$item['avatar']}"
|
|
|
|
title="{$item['fullname']}" />
|
|
|
|
</a>
|
2016-08-10 10:44:23 +02:00
|
|
|
EOD;
|
|
|
|
}
|
|
|
|
|
2017-04-22 15:36:25 +02:00
|
|
|
// Add embeded image to content
|
|
|
|
$image_html = '';
|
2019-06-09 17:24:40 +02:00
|
|
|
$images = $this->getImageURI($tweet);
|
|
|
|
if(!$this->getInput('noimg') && !is_null($images)) {
|
2018-12-12 16:56:36 +01:00
|
|
|
|
2019-06-09 17:24:40 +02:00
|
|
|
foreach ($images as $image) {
|
2017-04-22 15:36:25 +02:00
|
|
|
|
2019-06-09 17:24:40 +02:00
|
|
|
// Set image scaling
|
|
|
|
$image_orig = $this->getInput('noimgscaling') ? $image : $image . ':orig';
|
|
|
|
$image_thumb = $this->getInput('noimgscaling') ? $image : $image . ':thumb';
|
|
|
|
|
|
|
|
// add enclosures
|
|
|
|
$item['enclosures'][] = $image_orig;
|
|
|
|
|
|
|
|
$image_html .= <<<EOD
|
2018-12-12 16:56:36 +01:00
|
|
|
<a href="{$image_orig}">
|
2017-04-22 15:36:25 +02:00
|
|
|
<img
|
|
|
|
style="align:top; max-width:558px; border:1px solid black;"
|
2018-12-12 16:56:36 +01:00
|
|
|
src="{$image_thumb}" />
|
2017-04-22 15:36:25 +02:00
|
|
|
</a>
|
|
|
|
EOD;
|
2019-06-09 17:24:40 +02:00
|
|
|
}
|
2017-04-22 15:36:25 +02:00
|
|
|
}
|
|
|
|
|
2016-08-10 10:44:23 +02:00
|
|
|
// add content
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] = <<<EOD
|
2016-08-09 22:05:42 +02:00
|
|
|
<div style="display: inline-block; vertical-align: top;">
|
2016-08-10 10:44:23 +02:00
|
|
|
{$picture_html}
|
2016-08-09 22:05:42 +02:00
|
|
|
</div>
|
|
|
|
<div style="display: inline-block; vertical-align: top;">
|
|
|
|
<blockquote>{$cleanedTweet}</blockquote>
|
|
|
|
</div>
|
2017-04-22 15:36:25 +02:00
|
|
|
<div style="display: block; vertical-align: top;">
|
|
|
|
<blockquote>{$image_html}</blockquote>
|
|
|
|
</div>
|
|
|
|
EOD;
|
|
|
|
|
|
|
|
// add quoted tweet
|
|
|
|
$quotedTweet = $tweet->find('div.QuoteTweet', 0);
|
2017-07-29 19:28:00 +02:00
|
|
|
if($quotedTweet) {
|
2017-04-22 15:36:25 +02:00
|
|
|
// get tweet text
|
|
|
|
$cleanedQuotedTweet = str_replace(
|
|
|
|
'href="/',
|
|
|
|
'href="' . self::URI,
|
|
|
|
$quotedTweet->find('div.tweet-text', 0)->innertext
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->processContentLinks($quotedTweet);
|
|
|
|
$this->processEmojis($quotedTweet);
|
|
|
|
|
|
|
|
// Add embeded image to content
|
|
|
|
$quotedImage_html = '';
|
2019-06-09 17:24:40 +02:00
|
|
|
$quotedImages = $this->getQuotedImageURI($tweet);
|
2018-12-12 16:56:36 +01:00
|
|
|
|
2019-06-09 17:24:40 +02:00
|
|
|
if(!$this->getInput('noimg') && !is_null($quotedImages)) {
|
|
|
|
|
|
|
|
foreach ($quotedImages as $image) {
|
|
|
|
|
|
|
|
// Set image scaling
|
|
|
|
$image_orig = $this->getInput('noimgscaling') ? $image : $image . ':orig';
|
|
|
|
$image_thumb = $this->getInput('noimgscaling') ? $image : $image . ':thumb';
|
2017-04-22 15:36:25 +02:00
|
|
|
|
2019-06-09 17:24:40 +02:00
|
|
|
// add enclosures
|
|
|
|
$item['enclosures'][] = $image_orig;
|
|
|
|
|
|
|
|
$quotedImage_html .= <<<EOD
|
|
|
|
<a href="{$image_orig}">
|
2017-04-22 15:36:25 +02:00
|
|
|
<img
|
|
|
|
style="align:top; max-width:558px; border:1px solid black;"
|
2019-06-09 17:24:40 +02:00
|
|
|
src="{$image_thumb}" />
|
2017-04-22 15:36:25 +02:00
|
|
|
</a>
|
|
|
|
EOD;
|
2019-06-09 17:24:40 +02:00
|
|
|
}
|
2017-04-22 15:36:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$item['content'] = <<<EOD
|
2018-11-12 19:59:46 +01:00
|
|
|
{$item['content']}
|
|
|
|
<hr>
|
2017-04-22 15:36:25 +02:00
|
|
|
<div style="display: inline-block; vertical-align: top;">
|
|
|
|
<blockquote>{$cleanedQuotedTweet}</blockquote>
|
|
|
|
</div>
|
|
|
|
<div style="display: block; vertical-align: top;">
|
|
|
|
<blockquote>{$quotedImage_html}</blockquote>
|
|
|
|
</div>
|
2016-08-09 21:47:29 +02:00
|
|
|
EOD;
|
2017-04-22 15:36:25 +02:00
|
|
|
}
|
2018-11-15 22:00:01 +01:00
|
|
|
$item['content'] = htmlspecialchars_decode($item['content'], ENT_QUOTES);
|
2016-08-09 21:47:29 +02:00
|
|
|
|
2014-05-26 00:30:46 +02:00
|
|
|
// put out
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2017-04-22 15:36:25 +02:00
|
|
|
|
|
|
|
private function processEmojis($tweet){
|
|
|
|
// process emojis (reduce size)
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach($tweet->find('img.Emoji') as $img) {
|
2017-04-22 15:36:25 +02:00
|
|
|
$img->style .= ' height: 1em;';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function processContentLinks($tweet){
|
|
|
|
// processing content links
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach($tweet->find('a') as $link) {
|
|
|
|
if($link->hasAttribute('data-expanded-url')) {
|
2017-04-22 15:36:25 +02:00
|
|
|
$link->href = $link->getAttribute('data-expanded-url');
|
|
|
|
}
|
|
|
|
$link->removeAttribute('data-expanded-url');
|
|
|
|
$link->removeAttribute('data-query-source');
|
|
|
|
$link->removeAttribute('rel');
|
|
|
|
$link->removeAttribute('class');
|
|
|
|
$link->removeAttribute('target');
|
|
|
|
$link->removeAttribute('title');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-18 23:18:41 +02:00
|
|
|
private function fixAnchorSpacing($content){
|
|
|
|
// fix anchors missing spaces in-between
|
|
|
|
return str_replace(
|
|
|
|
'<a',
|
|
|
|
' <a',
|
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-22 15:36:25 +02:00
|
|
|
private function getImageURI($tweet){
|
|
|
|
// Find media in tweet
|
2019-06-09 17:24:40 +02:00
|
|
|
$images = array();
|
|
|
|
|
2017-04-22 15:36:25 +02:00
|
|
|
$container = $tweet->find('div.AdaptiveMedia-container', 0);
|
2019-06-09 17:24:40 +02:00
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
if($container && $container->find('img', 0)) {
|
2019-06-09 17:24:40 +02:00
|
|
|
foreach ($container->find('img') as $img) {
|
|
|
|
$images[] = $img->src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($images)) {
|
|
|
|
return $images;
|
2017-04-22 15:36:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getQuotedImageURI($tweet){
|
|
|
|
// Find media in tweet
|
2019-06-09 17:24:40 +02:00
|
|
|
$images = array();
|
|
|
|
|
2017-04-22 15:36:25 +02:00
|
|
|
$container = $tweet->find('div.QuoteMedia-container', 0);
|
2019-06-09 17:24:40 +02:00
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
if($container && $container->find('img', 0)) {
|
2019-06-09 17:24:40 +02:00
|
|
|
foreach ($container->find('img') as $img) {
|
|
|
|
$images[] = $img->src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($images)) {
|
|
|
|
return $images;
|
2017-04-22 15:36:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2019-07-26 10:36:59 +02:00
|
|
|
|
|
|
|
private function getCookies($pageURL){
|
|
|
|
|
|
|
|
$ctx = stream_context_create(array(
|
|
|
|
'http' => array(
|
|
|
|
'follow_location' => false
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$a = file_get_contents($pageURL, 0, $ctx);
|
|
|
|
|
|
|
|
//First request to get the cookie
|
|
|
|
$cookies = '';
|
|
|
|
foreach($http_response_header as $hdr) {
|
|
|
|
if(stripos($hdr, 'Set-Cookie') !== false) {
|
|
|
|
$cLine = explode(':', $hdr)[1];
|
|
|
|
$cLine = explode(';', $cLine)[0];
|
|
|
|
$cookies .= ';' . $cLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return substr($cookies, 2);
|
|
|
|
}
|
2014-05-26 00:30:46 +02:00
|
|
|
}
|