Esempio n. 1
0
function plan_write_traditional($newplan, $planowner)
{
    include_once 'plan_read.php';
    include_once 'snoop.php';
    include_once 'spiel.php';
    include_once 'send.php';
    mb_detect_order("UTF-8, windows-1252");
    if (mb_detect_encoding($newplan) == "Windows-1252") {
        $newplan = mb_convert_encoding($newplan, UTF - 8, Windows - 1252);
    }
    $oldplan_fn = "{$_SERVER['PWUSERS_DIR']}/{$planowner}/plan/plan.txt";
    // current oldplan name
    $oldplan_fn_moved = $oldplan_fn . "." . filectime($oldplan_fn);
    // archival oldplan name
    $oldplan_array = explode("\n", $oldplan);
    $_SERVER['USER'] = '******';
    $old_snoop_array = snoop_find(plan_read_local($planowner), $planowner);
    exec("mv {$oldplan_fn} {$oldplan_fn_moved}");
    exec("gzip {$oldplan_fn_moved}");
    exec("rm -f {$_SERVER['FILE_ROOT']}/temp/{$planowner}*.cache");
    $oldplan_fn_moved .= ".gz";
    $newplan .= $_POST['nolinebreaks'];
    $newplan .= $_POST['markdown'];
    $newplan .= $_POST['nofeed'];
    if ($_POST['title']) {
        $newplan .= "<!--title {$_POST['title']}-->";
    }
    if ($_POST['tags']) {
        $newplan .= "<!--tags {$_POST['tags']}-->";
    }
    $newplan_fn = $oldplan_fn;
    $newplan_file = fopen($newplan_fn, 'w');
    fwrite($newplan_file, $newplan);
    fclose($newplan_file);
    $newplan_array = explode("\n", $newplan);
    $diffplan = implode('', array_diff($newplan_array, $oldplan_array));
    spiel_find($diffplan, $planowner, time());
    $new_snoop_array = snoop_find(plan_read_local($planowner), $planowner);
    snoop_clean(array_unique($old_snoop_array), $planowner);
    snoop_add(array_unique($new_snoop_array), $planowner);
    touch("{$_SERVER['PWUSERS_DIR']}/{$planowner}/stats/lastupdate");
    if (file_exists($newplan_fn) && (file_exists($oldplan_fn_moved) || !file_exists($oldplan_fn))) {
        redirect("/read/{$planowner}");
    } else {
        output("Error updating", "<div class='alert'>Your plan update failed:<br/><br/>{$newplan}</div>");
    }
}
Esempio n. 2
0
function plan_read($planowner, $threshhold = FALSE, $begindate = FALSE, $unformatted = FALSE, $remotesnitch = FALSE)
{
    if ($planowner == 'invite' || $planowner == '*****@*****.**') {
        return plan_read_invite($reader);
    }
    if ($planowner == 'backup' || $planowner == '*****@*****.**') {
        return plan_read_backup($reader);
    }
    if ($planowner == 'backup_archives' || $planowner == '*****@*****.**') {
        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;
}