function user_read_info($user, $publish = FALSE)
{
    $_SERVER['STOPWATCH']['readuser_begin'] = array_sum(explode(' ', microtime()));
    if ($user && $user != 'guest') {
        $user = plan_repair_local_name($user);
        if (file_exists("{$_SERVER['PWUSERS_DIR']}/{$user}/userinfo.dat")) {
            $readuser_info = unserialize(@file_get_contents("{$_SERVER['PWUSERS_DIR']}/{$user}/userinfo.dat"));
        }
        if (file_exists("{$_SERVER['PWUSERS_DIR']}/{$user}/preferences.dat")) {
            $readuser_prefs = unserialize(@file_get_contents("{$_SERVER['PWUSERS_DIR']}/{$user}/preferences.dat"));
        } else {
            $readuser_prefs = unserialize(@file_get_contents("{$_SERVER['FILE_ROOT']}/resources/defaults/preferences.dat"));
        }
        $readuser_all = array_merge($readuser_info, $readuser_prefs);
        if ($publish) {
            $_SERVER['USERINFO_ARRAY'] = $readuser_all;
            $_SERVER['USER'] = $user;
        }
        foreach ($readuser_all as $key => $value) {
            $userdata_string .= "&{$key}={$value}";
        }
        $userdata_string = substr($userdata_string, 1);
    }
    $_SERVER['STOPWATCH']['readuser_end'] = array_sum(explode(' ', microtime()));
    return $userdata_string;
}
Exemplo n.º 2
0
function snoop_remove_local($oldsnoop, $remote = 0)
{
    if ($remote == FALSE) {
        $snoop_setter = $_SERVER['USER'];
    } else {
        $snoop_setter = $remote;
    }
    $oldsnoop = str_replace('@planwatch.org', '', $oldsnoop);
    $oldsnoop = plan_repair_local_name($oldsnoop);
    $oldsnoop_fn = "{$_SERVER['PWUSERS_DIR']}/{$oldsnoop}/stats/snoop.txt";
    if (file_exists("{$_SERVER['PWUSERS_DIR']}/{$oldsnoop}/userinfo.dat")) {
        $success = TRUE;
    } else {
        $success = FALSE;
    }
    if (file_exists($oldsnoop_fn)) {
        $oldsnoop_a = file($oldsnoop_fn);
        foreach ($oldsnoop_a as $i => $snoopitem) {
            if (strpos($snoopitem, $snoop_setter) !== FALSE) {
                $oldsnoop_a[$i] = '';
            }
        }
        $oldsnoop_a = array_unique(array_values($oldsnoop_a));
        sort($oldsnoop_a);
        file_put_contents($oldsnoop_fn, str_replace("\n\n", "\n", implode("\n", $oldsnoop_a)));
    }
    return $success;
}
function plan_is_local($planowner)
{
    $valid = 0;
    $planowner = trim($planowner);
    parse_str(user_read_info(plan_repair_local_name($planowner)));
    if (strpos($plantype, 'local') !== FALSE) {
        $valid = 1;
    }
    if (strpos($plantype, 'planwatch') !== FALSE) {
        $valid = 1;
    }
    if ($plantype == '' && file_exists("{$_SERVER['PWUSERS_DIR']}/{$planowner}/userinfo.dat")) {
        $valid = 1;
    }
    return $valid;
}
Exemplo n.º 4
0
function plan_read($planowner, $threshhold = FALSE, $begindate = FALSE, $unformatted = FALSE, $remotesnitch = FALSE)
{
    if ($planowner == 'invite' || $planowner == 'invite@planwatch.org') {
        return plan_read_invite($reader);
    }
    if ($planowner == 'backup' || $planowner == 'backup@planwatch.org') {
        return plan_read_backup($reader);
    }
    if ($planowner == 'backup_archives' || $planowner == 'backup_archives@planwatch.org') {
        return plan_read_backup($reader, "archives");
    }
    $reader = $_SERVER['USER'];
    if ($reader == 'cacheuser') {
        $utility = 1;
    }
    $plan_read_rand = rand();
    if (!isset($_SERVER['PLANOWNER_INFO_ARRAY']) || $_SERVER['PLANOWNER'] != $planowner) {
        plan_get_owner_info($planowner);
    }
    profile("plan_read_{$plan_read_rand}");
    profile("plan_read_head_{$plan_read_rand}");
    if (plan_is_local($planowner)) {
        $islocal = TRUE;
        $planowner = plan_repair_local_name($planowner);
    } else {
        if (user_is_local($planowner)) {
            $localusernotplan = TRUE;
            $localusername = $planowner;
        }
    }
    include_once 'snitch.php';
    include_once 'spiel.php';
    if ($_SERVER['REMOTENODE']) {
        if (isset($_SERVER['PLANOWNER_INFO_ARRAY']['fingerpref']) && $_SERVER['PLANOWNER_INFO_ARRAY']['fingerpref'] == 0) {
            snitch_write($reader, $planowner, ' failed');
            return "{$planowner}'s plan is not available for reading outside planwatch.org.";
        }
    }
    // tests the user against the planowner's privacy settings,
    // blocked list, and allowed list
    $plan_test_privacy = plan_test_privacy($reader, $planowner, $remotesnitch);
    $authorized = user_is_authorized($planowner, $reader);
    if (!$_SERVER['PLANOWNER_REAL_LOCATION']) {
        plan_get_owner_info($planowner);
    }
    if (user_is_local($planowner) && !plan_is_local($planowner)) {
        $localplan = plan_read_local($planowner, $threshhold, $begindate, $unformatted);
    }
    if ($_SERVER['PLANOWNER_REAL_LOCATION']) {
        $planowner = $_SERVER['PLANOWNER_REAL_LOCATION'];
    }
    profile("plan_read_head_{$plan_read_rand}");
    // on with the show
    if ($plan_test_privacy) {
        if ($islocal) {
            $plan = plan_read_local($planowner, $threshhold, $begindate, $unformatted);
        }
        //		elseif($localusernotplan) $localplan=plan_read_local($localusername,$threshhold,$begindate,$unformatted);
        if (strpos($planowner, '@') !== FALSE && !strpos($planowner, '://') && !$plan) {
            // if it comes from another planworld node (we used to fingertest in here too)
            list($xmlrpc_username, $xmlrpc_node) = explode('@', $planowner);
            $plan = plan_read_xmlrpc($xmlrpc_username, $xmlrpc_node);
        }
        if (strpos($planowner, '://') && !$plan) {
            // if it's a URL call plan_read_web()
            // plan_read_web passes it on to plan_read_rss_simplepie if necessary.
            $url = $planowner;
            $plan = plan_read_web($url);
        }
        // Valid snitches only get set here
        if ((!$threshhold || $threshhold == '2d' || $threshhold == $_SERVER['PLANOWNER_INFO_ARRAY']['defaultdays'] . "d") && !$begindate) {
            snitch_write($reader, $planowner);
        } else {
            snitch_write($reader, $planowner, " archives ( {$threshhold} {$_SERVER['PLANOWNER_INFO_ARRAY']['defaultdays']}{$begindate} )");
        }
        if (file_exists("{$_SERVER['PWUSERS_DIR']}/{$_SERVER['USER']}/userinfo.dat")) {
            user_update_lastread($planowner);
        }
        $plan = trim($localplan) . $plan;
    } else {
        // if the privacy test didn't check out, display the blocked message
        $blocked_fn = "{$_SERVER['PWUSERS_DIR']}/{$planowner}/blockedmessage.txt";
        if (file_exists($blocked_fn)) {
            $plan = stripslashes(stripslashes(file_get_contents($blocked_fn)));
            $plan = str_replace('MYUSER', $planowner, $plan);
            $plan = str_replace('READER', $reader, $plan);
        } else {
            if ($_SERVER['whitelist_passed'] === FALSE) {
                $plan = "<h1>Security Error</h1>Unverified readers from planworld.net are not allowed to read protected planwatch.org plans without\n\t\t\t\tspecific permission from the author. Please send the owner of this plan, or email <a href='mailto:help@planwatch.org'>help@planwatch.org</a>\n\t\t\t\tto be added to the list of verified readers. ";
            } else {
                $plan = "<h1>Error: No Such User</h1>No user found by that name. Please try again, {$reader}.";
            }
        }
        snitch_write($reader, $planowner, ' failed');
        if (file_exists("{$_SERVER['PWUSERS_DIR']}/{$_SERVER['USER']}/userinfo.dat")) {
            user_update_lastread($planowner);
        }
    }
    profile("plan_format_{$plan_read_rand}");
    if (!$utility && !$unformatted) {
        profile("plan_read_tail_{$plan_read_rand}");
        $plan = plan_add_alias_links($plan, $planowner);
        if (!$_SERVER['REMOTENODE']) {
            $plan = spiel_format($plan, $planowner);
            $plan = plan_add_user_links($plan);
        } else {
            preg_replace("|!sp[ie][ie]l:(.*):(.*)!|", "<a href='http://{$_SERVER['HTTP_HOST']}{$_SERVER['WEB_ROOT']}/spiel/view/\\1'>\\2</a>", $plan);
            preg_replace("|!sp[ei][ie]l:(.*)!|", "<a href='http://{$_SERVER['HTTP_HOST']}{$_SERVER['WEB_ROOT']}/spiel/view/\\1'>\\1</a>", $plan);
            $plan = plan_process_directives($plan, TRUE);
            // turn on remotepatch to avoid processing directives other nodes will handle
            if (strstr($plan, "aside")) {
                $plan = "<style>aside.sidebar { float: right; width: 200px; margin-left: 20px; }</style>{$plan}";
            }
        }
        if (strstr($plan, 'http://')) {
            $plan = plan_match_embed_urls($plan);
        }
        $plan = plan_embed_player($plan);
        $plan = str_replace(array("id=\"content\"", "id='content'"), "id='content2'", $plan);
        $plan = str_replace("#content", "#content2", $plan);
        $plan = str_replace("font-color:", "color:", $plan);
        $plan = str_replace("position: absolute", "position: relative;", $plan);
        $plan = hyperlink($plan);
        if (strpos($plan, "/read/{$_SERVER['USER']}")) {
            $plan = str_replace("<a target='_self' href='/read/{$_SERVER['USER']}'", "<a target='_self' id='snoop' href='/read/{$_SERVER['USER']}'", $plan);
        }
        $plan = str_replace("@note", "@amherst.edu", $plan);
        $plan = str_replace("@pwn", "@planworld.net", $plan);
        $remoteuser = str_replace($_SERVER['REMOTENODE'], "", $_SERVER['USER']);
        if (strpos($plan, "?id={$remoteuser}")) {
            $plan = str_replace("<a href='?id={$remoteuser}", "<a id='snoop' href='?id={$remoteuser}", $plan);
        }
        if (strpos($plan, "!{$_SERVER['USER']}")) {
            $plan = preg_replace("/!{$_SERVER['USER']}:([^!]+)!/", "<a id='snoop' href='?id={$remoteuser}'>\\1</a>", $plan);
            $plan = preg_replace("/!{$_SERVER['USER']}!/", "<a id='snoop' href='?id={$remoteuser}'>{$_SERVER['USER']}</a>", $plan);
        }
        if (strpos($plan, "id='snoop'")) {
            if ($_SERVER['OUTPUT_MODE'] == 'HTML') {
                $plan = "<a href='#snoop'>Find My Snoop</a><br />\n{$plan}";
            }
            if ($_SERVER['OUTPUT_MODE'] == 'IPHONE' || $_SERVER['OUTPUT_MODE'] == 'MOBILE') {
                $plan = "<a href='javascript:alert(getRealTop(\"snoop\"));'>Find My Snoop</a><br />\n{$plan}";
            }
        }
        if ($_SERVER['USERINFO_ARRAY']['strip_css'] == 1) {
            $plan = plan_strip_css($plan);
        }
        if ($_SERVER['USERINFO_ARRAY']['strip_css'] == 2) {
            $plan = plan_confine_css($plan);
        }
    }
    profile('encoding');
    if (!$url) {
        $encoding = mb_detect_encoding($plan, 'UTF-8, ISO-8859-1');
        if ($encoding !== 'UTF-8') {
            $plan = mb_convert_encoding($plan, 'UTF-8', $encoding);
        }
    }
    profile('encoding');
    profile("plan_read_tail_{$plan_read_rand}");
    profile("plan_read_{$plan_read_rand}");
    profile("plan_format_{$plan_read_rand}");
    return $plan;
}