Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 62 lines (50 sloc) 2.392 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
<?php
/**
* A quick-and-dirty proxy to make FetLife.com pages accessible to everyone.
*/

// Library.
require_once(dirname(__FILE__) . '/lib/FetLife.php');

// Grab the BugMeNot.com account credential listing for FetLife.com.
$ch = curl_init('http://www.bugmenot.com/view/fetlife.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
curl_close($ch);

// Create HTML DOM from the BugMeNot.com account page.
$bugmenot = new DOMDocument();
$bugmenot->loadHTML($html);
$divs = $bugmenot->getElementsByTagName('div');

$accts = array();
$i = 0;
foreach ($divs as $div) {
    if ('account' === $div->getAttribute('class')) {
        $accts[$i]['nickname'] = $div->getElementsByTagName('td')->item(0)->nodeValue;
        $accts[$i]['password'] = $div->getElementsByTagName('td')->item(1)->nodeValue;
        $accts[$i]['hit_rate'] = $div->getElementsByTagName('td')->item(3)->nodeValue;
        $i++;
    }
}
// BugMeNot.com already sorts accounts based on reported success rate. Just use those.

// Augment list of accounts with any additional credentials in `fetlife-accounts.php`.
include_once('fetlife-accounts.php');
if (!empty($my_FetLife_accounts)) {
    $accts = array_merge($my_FetLife_accounts, $accts);
}

// Find a working login and use it.
for ($i = 0; $i < count($accts); $i++) {
    $FL = new FetLifeUser($accts[$i]['nickname'], $accts[$i]['password']);
    if ($FL->logIn()) {
        break; // exit loop, we've got a functional login to FetLife!
    }
}

$conn = new FetLifeConnection($FL);

if (isset($_GET['page'])) {
    $response = $conn->doHttpGet(urldecode($_GET['page']));
} else {
    $response = $conn->doHttpGet('/home');
}

$html_out = preg_replace('/href="\//', 'href="' . $_SERVER['PHP_SELF'] . '?page=/', $response['body']);
$html_out = preg_replace('/href="https:\/\/fetlife.com/', 'href="' . $_SERVER['PHP_SELF'] . '?page=', $html_out);

// Replace CSS with our own.
$html_out = preg_replace('/<link href="https:\/\/flassets.a.ssl.fastly.net\/stylesheets\/(std2\/std|base_packaged).css/', '<link href="' . dirname($_SERVER['PHP_SELF']) . '/vendor/stylesheets/base_packaged.css', $html_out);
$html_out = preg_replace('/<link href="https:\/\/flassets.a.ssl.fastly.net\/stylesheets\/(std2\/scratch|print_packaged).css/', '<link href="' . dirname($_SERVER['PHP_SELF']) . '/vendor/stylesheets/base_packaged.css', $html_out);

print $html_out;
Something went wrong with that request. Please try again.