Skip to content

Commit 25e34b3

Browse files
committed
improved logout url search for localization (non-english)
previously it would bug out and not find the logout url on non-english accounts, like Norwegian. now it should work in any language.
1 parent 427b98a commit 25e34b3

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/php/relays/facebook.relay.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,22 @@ function __construct() {
144144
$url = 'https://m.facebook.com' . $InstallFacebookAppRequest->item ( 0 )->getAttribute ( "href" );
145145
$hc->exec ( $url );
146146
$domd = @\DOMDocument::loadHTML ( $hc->getResponseBody () );
147+
$xp = new \DOMXPath ( $domd );
147148
}
148-
unset ( $InstallFacebookAppRequest, $url, $xp );
149-
$logoutUrl = function () use (&$domd, &$hc): string {
150-
foreach ( $domd->getElementsByTagName ( "a" ) as $a ) {
151-
if (strpos ( $a->textContent, 'Logout' ) !== 0) {
152-
continue;
153-
}
154-
$urlinfo = parse_url ( $hc->getinfo ( CURLINFO_EFFECTIVE_URL ) );
155-
$url = $urlinfo ['scheme'] . '://' . $urlinfo ['host'] . $a->getAttribute ( "href" );
156-
return $url;
157-
}
158-
throw new \RuntimeException ( 'failed to login to facebook! apparently... cannot find the logout url!' );
159-
};
160-
$this->logoutUrl = ($logoutUrl = $logoutUrl ()); // IIFE syntax makes eclipse unstable
161-
;
149+
unset ( $InstallFacebookAppRequest, $url );
150+
$urlinfo = parse_url ( $hc->getinfo ( CURLINFO_EFFECTIVE_URL ) );
151+
$a = $xp->query ( '//a[contains(@href,"/logout.php")]' );
152+
if ($a->length < 1) {
153+
$debuginfo = $hc->getStdErr () . $hc->getStdOut ();
154+
$tmp = tmpfile ();
155+
fwrite ( $tmp, $debuginfo );
156+
$debuginfourl = shell_exec ( "cat " . escapeshellarg ( stream_get_meta_data ( $tmp ) ['uri'] . " | pastebinit" ) );
157+
fclose ( $tmp );
158+
throw new \RuntimeException ( 'failed to login to facebook! apparently... cannot find the logout url! debuginfo url: ' . $debuginfourl );
159+
}
160+
$a = $a->item ( 0 );
161+
$url = $urlinfo ['scheme'] . '://' . $urlinfo ['host'] . $a->getAttribute ( "href" );
162+
$this->logoutUrl = $url;
162163
// all initialized, ready to sendMessage();
163164
}
164165
function __destruct() {

0 commit comments

Comments
 (0)