function change_one_pref($prefname, $newvalue) { if (user_is_valid($_SERVER['USERINFO_ARRAY']['username'], $_SERVER['USERINFO_ARRAY']['userpass'])) { $userinfo = unserialize(file_get_contents("{$_SERVER['USER_ROOT']}/userinfo.dat")); $preferences = unserialize(file_get_contents("{$_SERVER['USER_ROOT']}/preferences.dat")); if (isset($userinfo[$prefname])) { $userinfo[$prefname] = $newvalue; } else { $preferences[$prefname] = $newvalue; } file_put_contents("{$_SERVER['USER_ROOT']}/userinfo.dat", serialize($userinfo)); file_put_contents("{$_SERVER['USER_ROOT']}/preferences.dat", serialize($preferences)); } redirect("/"); }
function list_edit($listname) { if (user_is_valid($_SERVER['USERINFO_ARRAY']['username'], $_SERVER['USERINFO_ARRAY']['userpass'])) { $list_fn = "{$_SERVER['USER_ROOT']}/{$listname}list.txt"; if (file_exists($list_fn)) { $list_array = file($list_fn); } else { $list_array = array(); } if (strstr($list_array[0], 'sort')) { $sb = str_replace('sort by ', '', trim($list_array[0])); $list_array[0] = ''; $sc[$sb] = 'SELECTED'; } else { $sc['none'] == 'SELECTED'; } foreach ($list_array as $i => $listitem) { if (strstr($listitem, '!!!')) { $prune = '!!!'; $prune_visibility = 'visible'; $prune_checked = 'CHECKED'; $list_array[$i] = ''; } if (!$prune) { $prune_visibility = 'hidden'; } if (strstr($listitem, '!prune')) { $prunenum = str_replace('!prune', '', trim($listitem)); if (strstr($prunenum, 's')) { $pn['s'] = 'SELECTED'; } if (strstr($prunenum, 'm')) { $pn['m'] = 'SELECTED'; } if (strstr($prunenum, 'b')) { $pn['b'] = 'SELECTED'; } if (strstr($prunenum, 'h')) { $pn['h'] = 'SELECTED'; } if (strstr($prunenum, 'd')) { $pn['d'] = 'SELECTED'; } if (strstr($prunenum, 'w')) { $pn['w'] = 'SELECTED'; } if (strstr($prunenum, 'n')) { $pn['n'] = 'SELECTED'; } if (strstr($prunenum, 'y')) { $pn['y'] = 'SELECTED'; } if (strstr($prunenum, 'k')) { $pn['k'] = 'SELECTED'; } $prunenum = ereg_replace("[[:alpha:]]", '', $prunenum); $list_array[$i] = ''; } if (strstr($listitem, '!onlynew')) { $onlynew = 'CHECKED'; $list_array[$i] = ''; } if (strstr($listitem, '!alwaysnew')) { $alwaysnew = 'CHECKED'; $list_array[$i] = ''; } } $listcontent = trim(implode('', $list_array)); $content .= "<form action='{$_SERVER['WEB_ROOT']}/scripts/lists.php' method='post' class='edit_links'><br />\n" . "<h1>{$_SERVER['USER']}'s " . ucwords($listname) . " List</h1>\n\t\t\tenter one user per line<br />\n"; $content .= "<br />\n<textarea id='textbox' style='margin-right: 8px;' name='addedlist' wrap='off'>{$listcontent}</textarea>\n<div>\n"; $content .= "<input type='submit' id='submit_button' value='Save Changes' /><br />\n"; if ($listname == 'watched') { $content .= "<a href='{$_SERVER['WEB_ROOT']}/help/watched'>Watched List Help</a>\n\t\t\t<h4 style='margin-bottom: 0px;'>List sorting</h4>\n\t\t\t<select name='sortby'>\n\t\t\t\t<option value='name' {$sc['name']}>by name</option>\n\t\t\t\t<option value='time' {$sc['time']}>by time</option>\n\t\t\t\t<option value='none' {$sc['none']}>unsorted</option>\n\t\t\t</select>\n\t\t\t<h4 style='margin-bottom: 0px;'>Plans to include</h4>\n\t\t\t<input type='checkbox' value='!!!' name='prune' {$prune_checked}\n\t\t\t\tonclick=\"if(this.checked) document.getElementById('prunedetails').style.visibility='visible'; else document.getElementById('prunedetails').style.visibility='hidden';\"/>\n\t\t\tPrune older plans\n\t\t\t<div id='prunedetails' style='visibility: {$prune_visibility};'>\n\t\t\t after\n\t\t\t<input type='text' value='{$prunenum}' name='prunenum' size='3'/>\n\t\t\t<select name='pruneunit'>\n\t\t\t\t<option value=''> </option>\n\t\t\t\t<option value='s' " . $pn['s'] . ">seconds</option>\n\t\t\t\t<option value='m' " . $pn['m'] . ">minutes</option>\n\t\t\t\t<option value='b' " . $pn['b'] . ">beats</option>\n\t\t\t\t<option value='h' " . $pn['h'] . ">hours</option>\n\t\t\t\t<option value='d' " . $pn['d'] . ">days</option>\n\t\t\t\t<option value='w' " . $pn['w'] . ">weeks</option>\n\t\t\t\t<option value='n' " . $pn['n'] . ">months</option>\n\t\t\t\t<option value='y' " . $pn['y'] . ">years</option>\n\t\t\t\t<option value='k' " . $pn['k'] . ">decades</option>\n\t\t\t</select><br/>\n"; $content .= " <input type='checkbox' value='!onlynew' name='onlynew' {$onlynew} /> only show unread plans<br/>\n"; $content .= " <input type='checkbox' value='!alwaysnew' name='alwaysnew' {$alwaysnew} /> always show unread plans</div>\n"; } $content .= "\n\t\t<input type='hidden' name='listname' value='{$listname}'/><input type='hidden' name='username' value='{$_SERVER['USER']}'/>\n\t\t</form>\n\t\t</div>\n"; } else { $content = "<div class='alert'>Your attempt failed because you do not have permission\n\tto edit the {$listname} list. If you feel this is an error, send\n\t<a href='mailto:help@planwatch.org'>help@planwatch.org</a> an email.</div>\n"; } return $content; }
function output_build_reader_toolbar_mobile($content) { if ($_SERVER['URL_ARRAY'][3] == 'bio') { $is_bio = TRUE; } elseif ($_SERVER['URL_ARRAY'][1] == 'send') { $is_send = TRUE; } elseif (in_array('archives', $_SERVER['URL_ARRAY'])) { $is_archives = TRUE; } else { $is_plan = TRUE; } $planwatchlist = file_get_contents("{$_SERVER['USER_ROOT']}/watchedlist.txt"); if ($is_send) { $_SERVER['PLANOWNER'] = $_SERVER['URL_ARRAY'][2]; plan_get_owner_info($_SERVER['PLANOWNER']); } if (user_is_valid($_SERVER['USERINFO_ARRAY']['username'], $_SERVER['USERINFO_ARRAY']['userpass']) && $_SERVER['PLANOWNER'] && !strstr($content, '<h1>Plan Read Failed</h1>')) { profile('reader_toolbar', 'begin'); if ($is_plan || $is_bio || $is_archives || $is_send && $_SERVER['URL_ARRAY'][2]) { // bio if ((file_exists("{$_SERVER['PWUSERS_DIR']}/{$_SERVER['PLANOWNER']}/bio.txt") || (strpos($_SERVER['PLANOWNER_REAL_LOCATION'], 'diaryland') || strpos($_SERVER['PLANOWNER_REAL_LOCATION'], 'livejournal'))) && !$is_bio) { $readertoolbar[] = "<a href='{$_SERVER['WEB_ROOT']}/read/{$_SERVER['PLANOWNER_REAL_LOCATION']}/bio'>bio</a>"; } // send if ((strpos($_SERVER['PLANOWNER_REAL_LOCATION'], 'planworld.net') || strpos($_SERVER['PLANOWNER_REAL_LOCATION'], 'amherst.edu') || plan_is_local($_SERVER['PLANOWNER'])) && $_SERVER['PLANOWNER'] != $_SERVER['USER'] && !$is_send) { $send_files = files_list("{$_SERVER['USER_ROOT']}/sends", files_encode_safe_name("{$_SERVER['PLANOWNER']}") . "*"); if (is_array($send_files)) { $lastsend = formattime(filemtime("{$_SERVER['USER_ROOT']}/sends/" . end($send_files))); if (strstr(end($send_files), '.new')) { $lastsend .= " <b>NEW</b>"; } $lastsend = "({$lastsend})"; } $readertoolbar[] = "<a href='{$_SERVER['WEB_ROOT']}/send/{$_SERVER['PLANOWNER_REAL_LOCATION']}/'>send</a>"; } // planread if ($is_send || $is_bio) { $readertoolbar[] = "<a href='{$_SERVER['WEB_ROOT']}/read/{$_SERVER['PLANOWNER_REAL_LOCATION']}/'>plan</a>"; } // archives if (plan_has_archives($_SERVER['PLANOWNER_REAL_LOCATION'])) { if (!$is_archives) { $readertoolbar[] = "<a href='{$_SERVER['WEB_ROOT']}/read/{$_SERVER['PLANOWNER']}/archives' >archives</a>"; } else { $readertoolbar[] = "<a href='{$_SERVER['WEB_ROOT']}/read/{$_SERVER['PLANOWNER']}' >plan</a>"; } } // If the reader isn't watching the writer, offer the option if (!stristr($planwatchlist, $_SERVER['PLANOWNER']) && $is_plan) { $readertoolbar[] = "<span id='watch_link'><a href=\"javascript:loadXMLDoc('{$_SERVER['WEB_ROOT']}/lists/add_ajax/watched/!{$_SERVER['PLANOWNER_REAL_LOCATION']}:{$_SERVER['PLANOWNER_DISPLAY_NAME']}!',null,'planwatch');void(null);\" title='add {$_SERVER['PLANOWNER_DISPLAY_NAME']} to your watched list' >watch</a></span>"; } // if writer isn't a blog or the same as reader, offer the option of // blocking, unblocking, allowing, or disallowing access to reader's plan if ($_SERVER['PLANOWNER'] != $_SERVER['USER'] && !strpos($_SERVER['PLANOWNER'], '://')) { // offer administrators a link to masquerade as writer // this is so it's easy to follow up on plan-reported bugs if (user_is_administrator() && file_exists("{$_SERVER['PWUSERS_DIR']}/{$_SERVER['PLANOWNER']}/userinfo.dat")) { $readertoolbar[] = "<a href='{$_SERVER['WEB_ROOT']}/masq/on/{$_SERVER['PLANOWNER']}'>masq</a>"; } if ($is_plan) { $readertoolbar[] = "<a href='/lists/unread/{$_SERVER['PLANOWNER']}'>unread</a>"; } if ($is_send) { $readertoolbar[] = "<a href='/send/{$_SERVER['PLANOWNER']}/unread'>unread</a>"; } } // make the links into a string for output. $readertoolbar = "<li class='toolbutton'>" . implode("</li><li class='toolbutton'>", $readertoolbar) . "</li>\n"; $readertoolbar = str_replace("<li class='toolbutton'></li>", "", $readertoolbar); if (($lasttime = plan_get_last_update($_SERVER['PLANOWNER'])) && $is_plan) { $readertoolbar = "<li class='plan_data_block'>Last Update: " . formattime($lasttime) . "</li>" . $readertoolbar; } if ($lastlogin = plan_get_last_login($_SERVER['PLANOWNER'])) { if ($lastlogin > 1) { $readertoolbar = "<li class='plan_data_block' id='lastaction'>Last Action: " . formattime($lastlogin) . "</li>" . $readertoolbar; } } } profile('reader_toolbar', 'end'); } return $readertoolbar; }
function bio_write() { if (user_is_valid($_SERVER['USERINFO_ARRAY']['username'], $_SERVER['USERINFO_ARRAY']['userpass'])) { if ($_POST['bio']) { $bio_fn = "{$_SERVER['USER_ROOT']}/bio.txt"; file_put_contents($bio_fn, stripslashes(trim($_POST['bio']))); } if ($_POST['bio_p']) { $bio_p_fn = "{$_SERVER['USER_ROOT']}/bio.txt.p"; file_put_contents($bio_p_fn, stripslashes(trim($_POST['bio_p']))); } } redirect("/read/{$_SERVER['USER']}/bio"); }
function login($user, $pass, $remember = 0, $prevpage = '/', $newuser = FALSE) { // only go further if the user exists and has given us a valid password if (file_exists("{$_SERVER['PWUSERS_DIR']}/{$user}/userinfo.dat") && user_is_valid($user, $pass)) { parse_str(user_read_info($user)); // sets the expiry of the cookie to 3 hours from now, or 5 years if ($remember) { $time = time() + 86400 * 365 * 5; } else { $time = 0; } $cookie_name = $_SERVER['AUTH_COOKIE']; $cookie_data = user_get_fingerprint($user, $pass); $cookie_host = $_SERVER['HTTP_HOST']; if (substr_count($cookie_host, '.') < 2) { $cookie_host = ".{$cookie_host}"; } $cookie_host = str_replace('www', '', $cookie_host); setcookie($cookie_name, $cookie_data, $time, $_SERVER['WEB_ROOT'] . "/", $cookie_host); setcookie('remember', "remember={$remember}", time() + 86400 * 365 * 5, $_SERVER['WEB_ROOT'] . "/", $cookie_host); if ($prevpage === FALSE) { $prevpage = '/'; } Header("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['WEB_ROOT']}/scripts/cookie-test.php?fingerprint_v4={$cookie_data}&newuser={$newuser}&redirect_page={$prevpage}"); } else { redirect("/failed"); /* echo "<div class='alert'><h1>Login failed for $user.</h1> Double check the username and password you provided, and try again. If you keep getting this message and you shouldn't, email <a href='mailto:help@planwatch.org'>help@planwatch.org</a></div> <form action='/scripts/form_shim.php' method='post' name='loginForm'> user <input id='login_username' type='text' name='user' size='10' /> pass <input id='login_userpass' type='password' name='pass' size='6' /> <input type='checkbox' name='remember' id='remember' value='1' /> <label for='remember'>remember me</label> <input type='hidden' name='action' value='login'/> <input type='submit' name='action' value='login' onclick='document.forms.loginForm.submit();' /> <input type='hidden' name='prevpage' value=''/> </form>"*/ } }
function user_is_administrator() { if (user_is_valid($_SERVER['USERINFO_ARRAY']['username'], $_SERVER['USERINFO_ARRAY']['userpass']) && ($_SERVER['USERINFO_ARRAY']['username'] == 'jwdavidson' || $_SERVER['USERINFO_ARRAY']['username'] == 'madvani' || $_SERVER['USERINFO_ARRAY']['username'] == 'system')) { return TRUE; } else { return FALSE; } }
function blogger_getUserInfo($m) { $appkey = $m->getParam(0); // discarded $username = $m->getParam(1); $password = $m->getParam(2); unset($appkey); // this is just to drive the point home that we aren't using appkey. // i suppose we could log the appkeys just for the heck of it. $username = $username->scalarval(); $password = $password->scalarval(); if (user_is_valid($username, $password)) { parse_str(user_read_info($username), $userinfo); } list($firstname, $lastname) = explode(' ', $userinfo['real_name']); $returnlist['nickname'] = new xmlrpcval($username, 'string'); $returnlist['userid'] = new xmlrpcval($username, 'string'); $returnlist['firstname'] = new xmlrpcval($firstname, 'string'); $returnlist['lastname'] = new xmlrpcval($lastname, 'string'); $returnlist['nickname'] = new xmlrpcval($userinfo['email'], 'string'); $returnlist['url'] = new xmlrpcval("http://planwatch.org/read/{$username}", 'string'); $xmlarray = new xmlrpcval(array(xmlrpc_encode($returnlist)), 'array'); $returnval = new xmlrpcresp($xmlarray); // if we generated an error, create an error return response if ($err) { return new xmlrpcresp(0, $xmlrpcerruser, $err); } else { // otherwise, we create the right response return $returnval; } }
function getfeatures($threshhold = '2d', $sortby = FALSE, $sortdir = FALSE, $searchterm = FALSE) { if (!$searchterm) { exec("ls {$_SERVER['FILE_ROOT']}/features/*.feature", $featurelist); } else { exec("grep -il '{$searchterm}' {$_SERVER['FILE_ROOT']}/features/*.feature", $featurelist); } if (!$threshhold) { $threshhold = '2w'; } $thresh_url = $threshhold; if (strstr($threshhold, 'r')) { $threshhold = str_replace('r', '', $threshhold); $reverse = 1; } if (strstr($threshhold, 'w')) { $threshhold = time() - 604800 * str_replace('w', '', $threshhold); } if (strstr($threshhold, 'd')) { $threshhold = time() - 86400 * str_replace('d', '', $threshhold); } if (strstr($threshhold, 'h')) { $threshhold = time() - 3600 * str_replace('h', '', $threshhold); } if (strstr($threshhold, 'm')) { $threshhold = time() - 60 * str_replace('m', '', $threshhold); } if (!$sortby) { $sortby = 'featuretime'; } if (!$sortdir) { $sortdir = 'down'; } if (user_is_valid($_SERVER['USERINFO_ARRAY']['username'], $_SERVER['USERINFO_ARRAY']['userpass'])) { $watch_link = "[ <a href='{$_SERVER['WEB_ROOT']}/lists/add/watched/!http://{$_SERVER['HTTP_HOST']}{$_SERVER['WEB_ROOT']}/feature/atom:planbugs!'>add to your watched list</a> ]"; } $content .= stripslashes("\n\n<div align='center'>\n<h1>Planwatch.org Bugs</h1>\n<a style=' width: 250px; margin: auto; margin-bottom: 20px; display: block; background: #293; font-size: 20px; font-weight: bold; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-left: 2px solid rgba(255,255,255,0.5); border-top: 2px solid rgba(255,255,255,0.5); border-right: 2px solid rgba(0,0,0,0.5); border-bottom: 2px solid rgba(0,0,0,0.5); color: white;' href='{$_SERVER['WEB_ROOT']}/feature/new'>Report a Bug!<br /><span style='font-size: 12px; font-weight: normal;'>(or request a feature)</span></a>\n\n<style type='text/css'>\n\tul { list-style: none; margin: 0px; padding: 0px; }\n\tli { text-align: left; margin-bottom: 5px; background: {$GLOBALS['listsbgcolor']}; color: {$GLOBALS['navtextcolor']}; }\n\tli h1 { font-size: 22px; margin: 0px; }\n\tli.fixed { opacity: 0.5; }\n\tli.fixed h1 { font-size: 14px; }\n\tli.testing { opacity: 0.7; background-color: {$GLOBALS['navtextcolor']}; color: {$GLOBALS['listsbgcolor']}; }\n\tli.testing a { color: {$GLOBALS['listsbgcolor']}; }\n\tli.testing h1 { font-size: 18px; }\n\tli.progress { opacity: 0.9; background-color: {$GLOBALS['navlinkcolor']}; color: {$GLOBALS['listsbgcolor']}; }\n\tli.progress a { color: {$GLOBALS['listsbgcolor']}; }\n\tli.progress h1 { font-size: 20px; }\n</style>\n<ul>"); if ($featurelist) { foreach ($featurelist as $i => $feature) { $feature = trim($feature); parse_str(file_get_contents($feature), $feature_array[$i]); $feature_array[$i]['featuretime'] = filemtime($feature); $feature_array[$i]['url_feature'] = basename($feature); $sort_array[$i] = $feature_array[$i][$sortby]; } if ($sortdir == 'down') { array_multisort($sort_array, SORT_DESC, $feature_array); } else { array_multisort($sort_array, SORT_ASC, $feature_array); } foreach ($feature_array as $i => $feature) { if ($feature['featuretime'] > $threshhold || $feature['status'] != "Verified Fixed" && stripslashes($feature['status']) != "Won't Fix" && $feature['status'] != "On Hold") { $somefeature = TRUE; if (!$feature['latest_responder']) { $feature['latest_responder'] = $feature['submitter']; } $lastresponse = "\n\t\t" . formattime($feature['featuretime']) . " by {$feature['latest_responder']} \n\t\t"; $class = ''; if ($feature['status'] == 'Verified Fixed') { $class = 'fixed'; } if ($feature['status'] == 'Testing') { $class = 'testing'; } if ($feature['status'] == 'In Progress') { $class = 'progress'; } $content .= "<li class='{$class}'><div style='float: right; width: 140px; text-align: right;'>{$feature['priority']}<br />{$feature['status']}</div><h1><a href='{$_SERVER['WEB_ROOT']}/feature/description/{$feature['url_feature']}'>{$feature['title']}</a></h1>from {$feature['submitter']} ∗ {$lastresponse}</li>"; } } } $content .= "<input type='search' id='searchinput' placeholder='search' style='width: 90%; font-size: 16px;' />"; $content .= "</ul>"; return $content; }
function format_watched_list_iphone() { // WATCHED LIST //------------------------------------------------------------------------------ if (!user_is_valid($_SERVER['USERINFO_ARRAY']['username'], $_SERVER['USERINFO_ARRAY']['userpass'])) { return ""; } else { $_SERVER['STOPWATCH']['watched_begin'] = array_sum(explode(' ', microtime())); $planwatchlist .= "<option value='/watched'>watched</option>"; $planwatchlist .= list_format_iphone(); } return $planwatchlist; }
function help_edit($helpname = FALSE) { if (!user_is_valid($_SERVER['USERINFO_ARRAY']['username'], $_SERVER['USERINFO_ARRAY']['userpass'])) { redirect(); exit; } if ($helpname && $helpname != 'new') { include_once "{$_SERVER['HELP_ROOT']}/{$helpname}.help"; } else { include_once "{$_SERVER['HELP_ROOT']}/empty.help.template"; } $body = preg_replace("|&(\\S+);|", "&\\1;", $body); $helpnum = substr($helpname, 0, strpos($helpname, '.')); $helpname = substr($helpname, strpos($helpname, '.')); if ($helpname[0] == '.') { $helpname = substr($helpname, 1); } $content = "\n\t<form action='{$_SERVER['WEB_ROOT']}/scripts/help.php' method='post'>\n\n\t<input type='hidden' name='oldhelpname' value='{$helpname}'/>\n\t<input type='hidden' name='oldhelpnum' value='{$helpnum}'/>\n\n\t<h1><img src='{$GLOBALS['helpicon']}' />Edit \"{$title}\"</h1>\n\n\t<strong>Title:</strong>\n\t <input type='text' style='border: none; background: #ffe; font-size: 20px; width: 90%;' name='helptitle' value='{$title}'/><br />\n\t <em style='opacity: 0.5'>a descriptive title or the question you're answering.</em><br /><br />\n\n\t<strong>Link:</strong>\n\t <u>http://{$_SERVER['HTTP_HOST']}{$_SERVER['WEB_ROOT']}/help/</u>\n\t <input type='text' style='border: none; font-size: {$GLOBALS['pfsize']}; font-family: {$GLOBALS['pfonts']}; background: #ffe;' name='helpname' value='{$helpname}'/>\n\t <em style='opacity: 0.5'>one short word, letters and dashes.</em><br />\n\n\t<strong>Index #</strong>\n\t<input type='text' style='border: none; font-size: {$GLOBALS['pfsize']}; font-family: {$GLOBALS['pfonts']}; background: #ffe;' name='helpnum' value='{$helpnum}'/>\n\t<em style='opacity: 0.5'>how the help list is sorted</em>\n\n\t<textarea name='body' id='textbox'>{$body}</textarea>\n\n\t<input type='hidden' name='action' value='write help'/>\n\n\t<br /><br />\n\t<input type='submit' id='submit_button' name='write help file' value='write help file'/>\n\t</form>\n"; output("editing help for {$helpname}", $content); }
function get_recent($params) { global $xmlrpcerruser; global $SYSTEM; $blogid = $params->getParam(0); $username = $params->getParam(1); $password = $params->getParam(2); $numposts = $params->getParam(3); $uid = $username->scalarval(); $pwd = $password->scalarval(); $usr = NewUser($uid); # Again, let's just skip the permissions check since this information is # public anyway. user_verify_fingerprint(user_get_fingerprint($username->scalarval(), $password->scalarval())); if (user_is_valid($username->scalarval(), $password->scalarval())) { $plan_array = array_merge($plan_array, files_list($plan_dir, "plan{$limiter}*.txt{$private}")); rsort($plan_array); $arr = array(); for ($i = 0; $i < $numposts->scalarval(); $i++) { } $arr[] = entry_to_struct($plan_array[$i]); $ret = new xmlrpcresp(new xmlrpcval($arr, 'array')); } else { $ret = new xmlrpcresp(0, $xmlrpcerruser + 3, "Invalid login"); } return $ret; }
function plan_write_journaling($edit, $plandata, $private, $nolinebreaks = FALSE, $writer = FALSE) { include_once 'plan_read.php'; include_once 'snoop.php'; include_once 'spiel.php'; include_once 'send.php'; $planowner = $writer; // make sure all the timecodes are the same $time = time(); // find the character encoding of the plan entry, convert it to something // more universal mb_detect_order("UTF-8, UTF-8, Windows-1252"); if (mb_detect_encoding($plandata) == "Windows-1252") { $plandata = mb_convert_encoding($plandata, UTF - 8, Windows - 1252); } // make sure no one can post an update to someone else's plan // this will need to be smarter if we ever implement group plans // but probably we won't, so no biggie. if ($planowner != $_SERVER['USER'] && !user_is_administrator()) { $planowner = $_SERVER['USER']; } $plan_dir = "{$_SERVER['PWUSERS_DIR']}/{$planowner}/plan"; // Find the old snoops. We have to masquerade briefly as 'cacheuser' to do // this without leaving a spurious snitch or getting private entries. // We remain 'cacheuser' until after snoop_add() below. $_SERVER['USER'] = '******'; // find old snoops, for later clearing $old_snoop_array = snoop_find(plan_read_local($planowner, $_SERVER['USERINFO_ARRAY']['defaultdays'] + 3 . 'd'), $planowner); // delete the (now-invalid) cache files cache_clear($planowner); // leave a reminder to plan_read_local to ignore linebreaks. if ($nolinebreaks) { $plandata .= "<!--nolinebreaks-->"; } if ($_POST['title']) { $plandata .= "<!--title {$_POST['title']} -->"; } if ($_POST['tags']) { $plandata .= "<!--tags {$_POST['tags']} -->"; } // if we weren't editing an existing (already-posted) entry, set the filename for the current time. if (!$_POST['edit'] || $_POST['edit'] == $_POST['draft_edit']) { $_POST['edit'] = ".{$time}"; } $plan_fn = "{$plan_dir}/plan{$_POST['edit']}.txt{$_POST['private']}"; if (!file_exists($plan_fn)) { file_put_contents("{$_SERVER['PWUSERS_DIR']}/{$planowner}/stats/lastupdate", $time); } if ($_FILES['attached_file']['tmp_name']) { rename("{$_FILES['attached_file']['tmp_name']}", "{$_SERVER['USER_ROOT']}/files/{$_FILES['attached_file']['name']}"); if (strstr($_FILES['attached_file']['name'], 'jpg') || strstr($_FILES['attached_file']['name'], 'gif') || strstr($_FILES['attached_file']['name'], 'png')) { $plandata .= "<img src='/userfiles/view/{$writer}/{$_FILES['attached_file']['name']}' />"; } else { $plandata .= "\n<a href='/userfiles/view/{$writer}/{$_FILES['attached_file']['name']}'>{$_FILES['attached_file']['name']}</a>"; } } // else trigger_error("No Files Uploaded"); $plandata .= $_POST['markdown']; $plandata .= $_POST['nofeed']; // save old headers and footers. if (strstr($plan_fn, 'header') || strstr($plan_fn, 'footer')) { exec("mv {$plan_fn} {$plan_fn}.{$time}"); } // write the update to disk. file_put_contents($plan_fn, $plandata); // new feature: SPIEL // here's the part where spiels are found // TODO(v4.5): replace spiel syntax with hashtags if (!$private && !$edit) { spiel_find($plandata, $planowner, $time); } // here's the part where sends are found if (!$private && !$edit) { send_find($plandata, $planowner, $time); } if (file_exists($plan_fn)) { if ($private && file_exists("{$plan_dir}/plan{$edit}.txt")) { exec("mv {$plan_dir}/plan{$edit}.txt {$plan_dir}/rem.plan{$edit}.txt"); } if (!$private && file_exists("{$plan_dir}/plan{$edit}.txt.p")) { exec("mv {$plan_dir}/plan{$edit}.txt.p {$plan_dir}/rem.plan{$edit}.txt.p"); } if ($_POST['draft_edit'] && file_exists("{$plan_dir}/draft{$_POST['draft_edit']}.txt")) { unlink("{$plan_dir}/draft{$_POST['draft_edit']}.txt"); } // clean up old drafts if ($drafts = files_list("{$plan_dir}/", "draft*.txt")) { foreach ($drafts as $draft) { if (filemtime("{$plan_dir}/{$draft}") < time() - 7 * 24 * 3600) { unlink("{$plan_dir}/{$draft}"); } } } } @chmod($plan_fn, 0755); // clean old snoops and add new ones $new_snoop_array = snoop_find(plan_read_local($planowner), $planowner); $snoops_to_remove = array_unique(array_diff($old_snoop_array, $new_snoop_array)); $snoops_to_set = array_unique(array_diff($new_snoop_array, $old_snoop_array)); $remove_status = snoop_clean($snoops_to_remove, $planowner); $add_status = snoop_add($snoops_to_set, $planowner); $_SERVER['USER'] = $_SERVER['USERINFO_ARRAY']['username']; // done masquerading // report the good news if we wrote the post to disk. if (file_exists($plan_fn)) { if ($_SERVER['AJAX_POST']) { return $plandata; } if (!$_SERVER['BLOGPOST']) { if ($_COOKIE[$_SERVER['AUTH_COOKIE']]) { if ($_SERVER['AJAX_POST']) { return $plandata; } else { redirect("/read/{$planowner}"); } } elseif (user_is_valid($_SERVER['USERINFO_ARRAY']['username'], $_SERVER['USERINFO_ARRAY']['userpass'])) { if ($_POST['mailpost']) { echo "posted"; exit; } else { // If the writer's cookie expired while updating, log her back in. login($_SERVER['USERINFO_ARRAY']['username'], $_SERVER['USERINFO_ARRAY']['userpass'], 0, "/read/{$planowner}"); exit; } } } else { return ".{$time}"; } } else { if ($_SERVER['BLOGPOST']) { return FALSE; } else { output('Error Updating', "<div class='alert'>There was an error writing {$_SERVER['USER']}'s plan entry to {$plan_fn} {$edit}. <a href='{$_SERVER['WEB_ROOT']}/feature'>File a bug</a> so we know about this problem. Here's your plan text for safekeeping:<br /><br />{$plandata}</div>", '', ' had an error'); } } }