mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-23 06:56:53 +00:00
Merge 536b27dfc7
into 2500d0df93
This commit is contained in:
commit
8d39944733
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require __DIR__ . '/../lib/contents_curl.php';
|
||||||
class FacebookBridge extends BridgeAbstract {
|
class FacebookBridge extends BridgeAbstract {
|
||||||
|
|
||||||
const MAINTAINER = 'teromene';
|
const MAINTAINER = 'teromene';
|
||||||
@ -87,6 +88,7 @@ class FacebookBridge extends BridgeAbstract {
|
|||||||
$captcha_action = $_SESSION['captcha_action'];
|
$captcha_action = $_SESSION['captcha_action'];
|
||||||
$captcha_fields = $_SESSION['captcha_fields'];
|
$captcha_fields = $_SESSION['captcha_fields'];
|
||||||
$captcha_fields['captcha_response'] = preg_replace("/[^a-zA-Z0-9]+/", "", $_POST['captcha_response']);
|
$captcha_fields['captcha_response'] = preg_replace("/[^a-zA-Z0-9]+/", "", $_POST['captcha_response']);
|
||||||
|
/*
|
||||||
$http_options = array(
|
$http_options = array(
|
||||||
'http' => array(
|
'http' => array(
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
@ -98,10 +100,11 @@ class FacebookBridge extends BridgeAbstract {
|
|||||||
);
|
);
|
||||||
$context = stream_context_create($http_options);
|
$context = stream_context_create($http_options);
|
||||||
$html = getContents($captcha_action, false, $context);
|
$html = getContents($captcha_action, false, $context);
|
||||||
|
*/
|
||||||
|
list($html, $info, $res_header, $proxy) = curlgetContents($captcha_action, $captcha_fields, true);
|
||||||
|
if ( $info['http_code'] != 200 )
|
||||||
|
returnServerError('Error '.$info['http_code'].$captcha_action."\nReq:\n".$res_header."\nResp:\n".$info['request_header']."\nProxy:\n".$proxy);
|
||||||
|
|
||||||
if($html === false){
|
|
||||||
returnServerError('Failed to submit captcha response back to Facebook');
|
|
||||||
}
|
|
||||||
unset($_SESSION['captcha_fields']);
|
unset($_SESSION['captcha_fields']);
|
||||||
$html = str_get_html($html);
|
$html = str_get_html($html);
|
||||||
}
|
}
|
||||||
@ -109,14 +112,17 @@ class FacebookBridge extends BridgeAbstract {
|
|||||||
unset($_SESSION['captcha_action']);
|
unset($_SESSION['captcha_action']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$res_header = '';
|
||||||
|
$proxy = '';
|
||||||
//Retrieve page contents
|
//Retrieve page contents
|
||||||
if(is_null($html)){
|
if (is_null($html)) {
|
||||||
if(!strpos($this->getInput('u'), "/")){
|
if (!strpos($this->getInput('u'), "/")) {
|
||||||
$html = getSimpleHTMLDOM(self::URI . urlencode($this->getInput('u')) . '?_fb_noscript=1')
|
list($html, $info, $res_header, $proxy) = curlgetSimpleHTMLDOM(self::URI.urlencode($this->getInput('u')).'?_fb_noscript=1');
|
||||||
or returnServerError('No results for this query.');
|
if ( $info['http_code'] != 200 )
|
||||||
|
returnServerError('Error '.print_r($info, true)."\nResp:\n".$res_header."\nReq:\n".$info['request_header']."\nProxy:\n".$proxy);
|
||||||
} else {
|
} else {
|
||||||
$html = getSimpleHTMLDOM(self::URI . 'pages/' . $this->getInput('u') . '?_fb_noscript=1')
|
list($html, $info) = curlgetSimpleHTMLDOM(self::URI.'pages/'.$this->getInput('u').'?_fb_noscript=1');
|
||||||
or returnServerError('No results for this query.');
|
if ( $info['http_code'] != 200 ) returnServerError('No results for this query.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,6 +151,8 @@ class FacebookBridge extends BridgeAbstract {
|
|||||||
<p><img src="data:image/png;base64,{$img}" /></p>
|
<p><img src="data:image/png;base64,{$img}" /></p>
|
||||||
<p><b>Response:</b> <input name="captcha_response" placeholder="please fill in" />
|
<p><b>Response:</b> <input name="captcha_response" placeholder="please fill in" />
|
||||||
<input type="submit" value="Submit!" /></p>
|
<input type="submit" value="Submit!" /></p>
|
||||||
|
<pre>{$res_header}</pre>
|
||||||
|
<p>Proxy: <pre>{$proxy}</pre></p>
|
||||||
</form>
|
</form>
|
||||||
EOD;
|
EOD;
|
||||||
die($message);
|
die($message);
|
||||||
@ -172,6 +180,18 @@ EOD;
|
|||||||
// Ignore summary posts
|
// Ignore summary posts
|
||||||
if(strpos($post->class, '_3xaf') !== false) continue;
|
if(strpos($post->class, '_3xaf') !== false) continue;
|
||||||
|
|
||||||
|
// Determine post attachments
|
||||||
|
/*
|
||||||
|
$attachment_wrapper = $post->find('._3x-2')[0];// search for attachment
|
||||||
|
if ( isset($attachment_wrapper) ) {
|
||||||
|
$attachment = $attachment_wrapper->find('.mtm')[0]->children(0);
|
||||||
|
if ( strpos($attachment->class, '_2a2q') !== false ) {
|
||||||
|
// photos
|
||||||
|
} elseif ( strpos($attachment->class, '_6m2') !== false ) {
|
||||||
|
// link
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
$item = array();
|
$item = array();
|
||||||
|
|
||||||
if(count($post->find('abbr')) > 0){
|
if(count($post->find('abbr')) > 0){
|
||||||
@ -236,13 +256,8 @@ EOD;
|
|||||||
$date = 0;
|
$date = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Build title from username and content
|
//Build title from content
|
||||||
$title = $author;
|
$title = mb_substr(strip_tags($post->find('.userContent > p')[0]->innertext), 0, 20).'...';
|
||||||
if(strlen($title) > 24)
|
|
||||||
$title = substr($title, 0, strpos(wordwrap($title, 24), "\n")) . '...';
|
|
||||||
$title = $title . ' | ' . strip_tags($content);
|
|
||||||
if(strlen($title) > 64)
|
|
||||||
$title = substr($title, 0, strpos(wordwrap($title, 64), "\n")) . '...';
|
|
||||||
|
|
||||||
//Build and add final item
|
//Build and add final item
|
||||||
$item['uri'] = self::URI . $post->find('abbr')[0]->parent()->getAttribute('href');
|
$item['uri'] = self::URI . $post->find('abbr')[0]->parent()->getAttribute('href');
|
||||||
@ -257,11 +272,6 @@ EOD;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getName(){
|
public function getName(){
|
||||||
if(!empty($this->authorName)){
|
return isset($this->extraInfos['name']) ? $this->extraInfos['name'] : $this->authorName.' - Facebook Bridge';
|
||||||
return isset($this->extraInfos['name']) ? $this->extraInfos['name'] : $this->authorName
|
|
||||||
. ' - Facebook Bridge';
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getName();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
79
lib/contents_curl.php
Normal file
79
lib/contents_curl.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
function curlgetContents( $url, $params, $post=false){
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $post ? $url : $url.'?'.http_build_query($params) );
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
|
||||||
|
#curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/rssbridge-fb-cookies.txt');
|
||||||
|
#curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/rssbridge-fb-cookies.txt');
|
||||||
|
$files = array_diff(scandir(__DIR__.'/../proxylist/'), array('.', '..'));
|
||||||
|
$proxies = [];
|
||||||
|
foreach($files as $file) {
|
||||||
|
$proxies_str = file_get_contents(__DIR__.'/../proxylist/'.$file);
|
||||||
|
$proxies = array_merge($proxies, explode("\n", $proxies_str, -1));
|
||||||
|
}
|
||||||
|
$proxy = $proxies[array_rand($proxies)];
|
||||||
|
curl_setopt($ch, CURLOPT_PROXY, $proxy);
|
||||||
|
$proxy_d = print_r($proxy, true);
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_VERBOSE, 1);
|
||||||
|
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
|
||||||
|
|
||||||
|
if ( $post ) {
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||||
|
'Content-Type: application/x-www-form-urlencoded',
|
||||||
|
'User-Agent: '.ini_get('user_agent'),
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||||
|
'User-Agent: '.ini_get('user_agent'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
$info = curl_getinfo($ch);
|
||||||
|
|
||||||
|
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||||
|
$header = substr($response, 0, $header_size);
|
||||||
|
$body = substr($response, $header_size);
|
||||||
|
|
||||||
|
if($errno = curl_errno($ch)) {
|
||||||
|
$error_message = curl_strerror($errno);
|
||||||
|
$info = "cURL error ({$errno}):\n {$error_message}";
|
||||||
|
}
|
||||||
|
curl_close($ch);
|
||||||
|
#file_put_contents(__DIR__.'/../debug/D'.date('H-i-s').'.html', $body);
|
||||||
|
|
||||||
|
rewind($verbose);
|
||||||
|
$verboseLog = stream_get_contents($verbose);
|
||||||
|
|
||||||
|
return array($body, $info, $header, $proxy_d);
|
||||||
|
|
||||||
|
}
|
||||||
|
function curlgetSimpleHTMLDOM($url
|
||||||
|
, $use_include_path = false
|
||||||
|
, $context = null
|
||||||
|
, $offset = 0
|
||||||
|
, $maxLen = null
|
||||||
|
, $lowercase = true
|
||||||
|
, $forceTagsClosed = true
|
||||||
|
, $target_charset = DEFAULT_TARGET_CHARSET
|
||||||
|
, $stripRN = true
|
||||||
|
, $defaultBRText = DEFAULT_BR_TEXT
|
||||||
|
, $defaultSpanText = DEFAULT_SPAN_TEXT
|
||||||
|
){
|
||||||
|
list($body, $info, $header, $proxy) = curlgetContents($url, $use_include_path, $context, $offset, $maxLen);
|
||||||
|
return array(str_get_html($body
|
||||||
|
, $lowercase
|
||||||
|
, $forceTagsClosed
|
||||||
|
, $target_charset
|
||||||
|
, $stripRN
|
||||||
|
, $defaultBRText
|
||||||
|
, $defaultSpanText),
|
||||||
|
$info, $header, $proxy);
|
||||||
|
}
|
||||||
|
?>
|
0
proxylist/.gitkeep
Normal file
0
proxylist/.gitkeep
Normal file
Loading…
Reference in New Issue
Block a user