Ejemplo n.º 1
0
function bio_read($bio_owner, $which = 'both', $edit = FALSE)
{
    include_once 'plan_read.php';
    if (strpos($bio_owner, '@dl') || strpos($bio_owner, '@diaryland')) {
        $bio = bio_read_diaryland($bio_owner);
    }
    if (strpos($bio_owner, '@lj') || strpos($bio_owner, '@livejournal')) {
        $bio = bio_read_livejournal($bio_owner);
    }
    if (strpos($bio_owner, '@dj') || strpos($bio_owner, '@deadjournal')) {
        $bio = bio_read_livejournal($bio_owner, 'dead');
    }
    $bio_fn = "{$_SERVER['PWUSERS_DIR']}/{$bio_owner}/bio.txt";
    $bio_p_fn = $bio_fn . ".p";
    if (file_exists($bio_fn) && ($which == 'public' || $which == 'both')) {
        $bio = plan_add_user_links(stripslashes(stripslashes(file_get_contents($bio_fn))));
    }
    if (file_exists($bio_p_fn) && ($which == 'private' || $which == 'both') && user_is_authorized($bio_owner, $_SERVER['USER'])) {
        $bio_p = plan_add_user_links(stripslashes(stripslashes(file_get_contents($bio_p_fn))));
    }
    if ($bio != $bio_p && $which == 'both' && !$edit) {
        $bio .= "\n<br />\n" . $bio_p;
    }
    if ($which == 'private') {
        $bio = $bio_p;
    }
    if (!$bio) {
        $bio = '';
    }
    //	if($bio_owner==$_SERVER['USER'] && !$edit) $bio.="$bio_owner $_SERVER[USER] <br clear='all' /><a class='bigbutton' href='/write/bio'>&#x270e; edit your bio</a>";
    return $bio;
}
Ejemplo n.º 2
0
function help_display($helpname = FALSE)
{
    include_once 'plan_read.php';
    include_once 'markdown.php';
    include_once 'smartypants.php';
    if ($helpname) {
        if (file_exists("{$_SERVER['HELP_ROOT']}/{$helpname}.help")) {
            include_once "{$_SERVER['HELP_ROOT']}/{$helpname}.help";
        } else {
            $filelist = files_list("{$_SERVER['HELP_ROOT']}/", "*{$helpname}*.help");
            if ($filelist) {
                include_once "{$_SERVER['HELP_ROOT']}/{$filelist['0']}";
                $helpname = str_replace('.help', '', $filelist[0]);
            } else {
                return FALSE;
            }
        }
    }
    if (user_is_valid($_SERVER['USERINFO_ARRAY']['username'], $_SERVER['USERINFO_ARRAY']['userpass'])) {
        $editlink = "<a style='font-size: 9pt; font-family: sans-serif; background: #eec; padding: 2px; border: thin solid #eee;' href='{$_SERVER['WEB_ROOT']}/help/edit/{$helpname}'>edit</a>";
    } else {
        $editlink = '';
    }
    $content = Smartypants(Markdown(plan_process_directives(plan_add_user_links(plan_process_smileys("<h1><a href='/help'><img src='{$GLOBALS['helpicon']}' /></a> {$title} {$editlink}</h1>\n\n{$body}")))));
    if ($title || $body) {
        return $content;
    } else {
        return FALSE;
    }
}
Ejemplo n.º 3
0
                file_put_contents("{$_SERVER['FILE_ROOT']}/temp/draft...{$_POST['writer']}...{$_POST['edit']}...{$_POST['private']}...{$_POST['nolinebreaks']}...txt", $_POST['newplan']);
                echo "Sending entry to full-page editor...";
                break;
            case 'Delete Draft Ajax':
                $draft_filename = "{$_SERVER['USER_ROOT']}/plan/draft.{$_POST['draft_time']}.txt";
                unlink($draft_filename);
                echo plan_list_drafts();
                break;
            case 'Update Journaling Plan Ajax':
                $_SERVER['AJAX_POST'] = TRUE;
                $return = plan_write_journaling($_POST['edit'], $_POST['newplan'], $_POST['private'], $_POST['nolinebreaks'], $_POST['writer']);
                $return = stripslashes(stripslashes($return));
                if ($_POST['nolinebreaks'] != 1) {
                    $return = nl2br($return);
                }
                $return = plan_process_directives(plan_add_user_links(plan_add_alias_links($return, $_POST['writer'])));
                echo $return;
                break;
            case 'Update Nonjournaling Plan':
                plan_write_traditional($_POST['newplan'], $_POST['writer']);
                break;
            default:
                echo "ERROR: no valid action selected.";
                print_r($_POST);
        }
    }
} else {
    echo "invalid user {$_POST['writer']}";
    exit;
}
//redirect("/");
Ejemplo n.º 4
0
function plan_read_local($planowner, $threshhold = FALSE, $begindate = '', $source = FALSE)
{
    $prl_rand = rand();
    profile("plan_read_local_{$prl_rand}");
    profile('plan_read_local_head');
    $reader = $_SERVER['USER'];
    if (!$threshhold) {
        $threshhold = $_SERVER['PLANOWNER_INFO_ARRAY']['defaultdays'] . 'd';
    }
    // this also appears in caching
    if (user_is_authorized($planowner, $reader)) {
        $private = "*";
        $private_cache_fn = 'private';
    }
    // css has to be here so it can be placed properly even when the plan is cached.
    // this is especially important for offnode readers for some reason.
    $css_filename = "{$_SERVER['PLANOWNER_ROOT']}/plan/plancss.txt";
    if (file_exists($css_filename)) {
        $plan_dressing['css'] = stripslashes(file_get_contents($css_filename));
        $plan_dressing['css'] = str_replace(array("\r", "\n"), " ", $plan_dressing['css']);
        $plan_dressing['css'] = str_replace(array("\r", "\n"), " ", $plan_dressing['css']);
        $plan_dressing['css'] = str_replace(array("\r", "\n"), " ", $plan_dressing['css']);
        $_SERVER['PLANOWNER_INFO']['css'] = strip_tags(trim($plan_dressing['css']));
    }
    //		if ($_SERVER['USER']=='jwdavidson') return "got css $css_filename $plan_dressing[css]";
    // CACHING
    // this tests to see if there's a cached version. if not, it will write
    // one when it's done getting the plan together.
    //----------------------------------------------
    // first figure out the appropriate cache filename
    if ($_SERVER['OUTPUT_MODE'] == 'RSS') {
        $feed = 'feed';
    }
    if ($_SERVER['OUTPUT_MODE'] == 'ATOM') {
        $feed = 'atomfeed';
    }
    if ($_SERVER['OUTPUT_MODE'] == 'ATOM_PRIVATE') {
        $feed = rand(100, 999);
    }
    if ($_SERVER['OUTPUT_MODE'] == 'IPHONE') {
        $feed = 'phonefeed';
    }
    profile('plan_read_local_uia');
    if (user_is_authorized($planowner, $reader)) {
        $private = "*";
        $private_cache_fn = 'private';
    }
    profile('plan_read_local_uia');
    profile('plan_read_local_utp');
    if (!plan_test_privacy($reader, $planowner)) {
        $blocked_cache_fn = 'blocked';
    }
    profile('plan_read_local_utp');
    $fn_username = base64_encode($planowner);
    if ($planowner == $reader) {
        $self = 'self';
    }
    if ($remoteuser == 'rss reader') {
        $feed = 'feed';
    }
    if ($source) {
        $source = "source";
    }
    $cache_fn = "{$_SERVER['FILE_ROOT']}/temp/{$_SERVER['PLANOWNER_INFO_ARRAY']['salt']}.{$self}{$private_cache_fn}{$blocked_cache_fn}{$remote}{$feed}.{$threshhold}.{$begindate}.{$source}.cache";
    // then, if the file exists, read it
    if (file_exists($cache_fn) && plan_get_last_update($planowner) < filemtime($cache_fn) && filesize($cache_fn) > 256) {
        profile('plan_read_local_pis');
        if (plan_is_local($reader)) {
            user_update_lastread($planowner);
        }
        profile('plan_read_local_pis');
        return file_get_contents($cache_fn);
    }
    // END CACHING
    // if no valid cache is found, on with the show
    if ($threshhold[0] != '.') {
        if (strstr($threshhold, 'r')) {
            $threshhold = str_replace('r', '', $threshhold);
            $reverse = 1;
        }
        $threshhold = time_calculate_threshhold($threshhold);
        $threshhold = time() - $threshhold;
        if (!$begindate || $begindate < 100) {
            $begindate = $threshhold;
            $enddate = time();
            $default_view = TRUE;
        } else {
            $enddate = $begindate + (time() - $threshhold);
        }
    }
    profile('plan_read_local_head');
    profile('plan_read_local_styles');
    // if the user has local pref stuff, read it in
    if ($_SERVER['USER_ROOT']) {
        $styles_fn = "{$_SERVER['USER_ROOT']}/styles.txt";
        $skin_fn = "{$_SERVER['USER_ROOT']}/skin.txt";
        $colors_fn = "{$_SERVER['USER_ROOT']}/colors.txt";
        $fonts_fn = "{$_SERVER['USER_ROOT']}/fonts.txt";
        $css_fn = "{$_SERVER['USER_ROOT']}/user_css.txt";
        if (file_exists($styles_fn) && !file_exists($skin_fn) && !file_exists($colors_fn)) {
            parse_str(file_get_contents($styles_fn));
            if ($skin && file_exists("{$_SERVER['FILE_ROOT']}/resources/skins/{$skin}")) {
                @(include $skin);
            }
        }
        if (file_exists($skin_fn)) {
            parse_str(file_get_contents($skin_fn));
            if ($skin) {
                include $skin;
            }
        }
        if (file_exists($colors_fn)) {
            parse_str(file_get_contents($colors_fn));
        }
        if (file_exists($fonts_fn)) {
            parse_str(file_get_contents($fonts_fn));
        }
        if (file_exists($css_fn)) {
            eval(file_get_contents($css_fn));
        }
    }
    profile('plan_read_local_styles');
    // screen out blocked readers, readers that fall below
    // privacy levels set by planowner
    if (!plan_test_privacy($reader, $planowner)) {
        $blocked_fn = "{$_SERVER['PLANOWNER_ROOT']}/blockedmessage.txt";
        if (file_exists($blocked_fn)) {
            $plan = stripslashes(file_get_contents($blocked_fn));
            $plan = str_replace('MYUSER', $planowner, $plan);
            $plan = str_replace('READER', $reader, $plan);
            $plan .= " <!--planowner: {$planowner} | reader: {$reader}-->";
        } else {
            $plan = "{$planowner} has no plan... <!-- reader: {$reader} --- planowner: {$planowner} -->";
        }
    } else {
        // if there's a series of entries listed, break out that list
        if (strstr($threshhold, ',')) {
            $threshhold_array = explode(',', $threshhold);
        } else {
            $threshhold_array = array($threshhold);
        }
        $plan_array = array();
        // this either reads in all the files from the list of entries passed
        // OR it just gets a list of all the entries that pass privacy muster
        foreach ($threshhold_array as $threshholdline) {
            // if the first character of the threshhold is a '.' we
            // want to show the entry indicated by the remainder of the line
            if ($threshholdline[0] == '.') {
                $limiter = $threshholdline;
            } else {
                $limiter = '.';
            }
            //sets dir for reading
            $plan_dir = "{$_SERVER['PLANOWNER_ROOT']}/plan/";
            // gets the entries indicated by $limiter
            // if $limiter is unset, fills the array with all available entries
            $plan_array = array_merge($plan_array, files_list($plan_dir, "plan{$limiter}*.txt{$private}"));
            if (is_array($plan_array) && $threshholdline[0] == '.') {
                $begindate = 1;
                $enddate = time() + 1;
            }
        }
        // get all the plan 'dressing' -- sidebars, header, footer, etc.
        /* CSS taken care of outside of caching.
        		$css_filename="$_SERVER[PLANOWNER_ROOT]/plan/plancss.txt";
        		if (file_exists($css_filename))
        		{
        			$plan_dressing['css']=stripslashes(file_get_contents($css_filename));
        			$plan_dressing['css']=str_replace(array("\r","\n")," ",$plan_dressing['css']);
        			$plan_dressing['css']=str_replace(array("\r","\n")," ",$plan_dressing['css']);
        			$plan_dressing['css']=str_replace(array("\r","\n")," ",$plan_dressing['css']);
        			$_SERVER['PLANOWNER_INFO']['css']=strip_tags(trim($plan_dressing['css']));
        		}
        */
        $header_filename = "{$_SERVER['PLANOWNER_ROOT']}/plan/planheader.txt";
        if (file_exists($header_filename)) {
            $plan_dressing['header'] = stripslashes(file_get_contents($header_filename));
            if (strstr($plan_dressing['header'], 'nolinebreaks')) {
                $plan_dressing['header'] = str_replace(array("\r", "\n"), "", $plan_dressing['header']);
                $plan_dressing['header'] = str_replace(array("\r", "\n"), "", $plan_dressing['header']);
                $plan_dressing['header'] = str_replace(array("\r", "\n"), "", $plan_dressing['header']);
            }
            if (strpos($plan_dressing['header'], '<!--markdown-->')) {
                include_once 'markdown.php';
                $plan_dressing['header'] = Markdown(str_replace('<!--markdown-->', '', $plan_dressing['header']));
            }
            $plan_dressing['header'] = "<div id='plan_header_{$_SERVER['PLANOWNER']}' class='plan_header'>{$plan_dressing['header']}</div>";
        }
        $footer_filename = "{$_SERVER['PLANOWNER_ROOT']}/plan/planfooter.txt";
        if (file_exists($footer_filename)) {
            $plan_dressing['footer'] = stripslashes(file_get_contents($footer_filename));
            if (strstr($plan_dressing['footer'], 'nolinebreaks')) {
                $plan_dressing['footer'] = str_replace(array("\r", "\n"), "", $plan_dressing['footer']);
                $plan_dressing['footer'] = str_replace(array("\r", "\n"), "", $plan_dressing['footer']);
                $plan_dressing['footer'] = str_replace(array("\r", "\n"), "", $plan_dressing['footer']);
            }
            if (strpos($plan_dressing['footer'], '<!--markdown-->')) {
                include_once 'markdown.php';
                $plan_dressing['footer'] = Markdown($plan_dressing['footer']);
            }
            $plan_dressing['footer'] = "<div id='plan_footer_{$_SERVER['PLANOWNER']}' class='plan_footer'>{$plan_dressing['footer']}</div>";
        }
        $divider_filename = "{$_SERVER['PLANOWNER_ROOT']}/plan/plandivider.txt";
        if (file_exists($divider_filename)) {
            $plan_dressing['divider'] = stripslashes(file_get_contents($divider_filename));
        }
        if ($plan_dressing) {
            foreach ($plan_dressing as $area => $content) {
                $content = stripslashes($content);
                if (strpos($content, 'nolinebreaks') !== FALSE) {
                    $content = str_replace('#nolinebreaks#', '', $content);
                } else {
                    $content = smart_nl2br($content);
                }
                $plan_dressing[$area] = $content;
            }
        }
        if (plan_is_journaling($planowner)) {
            $plan_array[] = "plan.{$begindate}.fake";
            $plan_array[] = "plan.{$enddate}.fake";
            sort($plan_array);
            $plan_array = array_values($plan_array);
            // extract the update time for all the plan entries
            foreach ($plan_array as $z => $planfn) {
                $planfn_a = explode(".", $planfn);
                $nextplanfn_a = explode(".", $plan_array[$z + 1]);
                $lastplanfn_a = explode(".", $plan_array[$z - 1]);
                if (($planfn_a[1] >= $begindate && $planfn_a[1] <= $enddate || $nextplanfn_a[1] >= $begindate && $nextplanfn_a[1] <= $enddate || $lastplanfn_a[1] >= $begindate && $lastplanfn_a[1] <= $enddate) && !strstr($planfn, 'fake')) {
                    $plan_index_array[$planfn_a[1]] = $planfn;
                }
            }
            // if we don't have any entries, give up now
            if (!is_array($plan_index_array)) {
                return "no plan entries found.";
            }
            // sort the plan list in order of update time newest to oldest.
            // we'll account for $reverse later, when we're
            // actually writing the entries to strings.
            krsort($plan_index_array);
            foreach ($plan_index_array as $entry_timecode => $entry_filename) {
                if ($entry_timecode >= $begindate && $entry_timecode <= $enddate) {
                    $entry_filename = "{$_SERVER['PLANOWNER_ROOT']}/plan/{$entry_filename}";
                    if (file_exists($entry_filename)) {
                        $plan_entries[$entry_timecode] = file_get_contents($entry_filename);
                    }
                }
            }
            // if there were no entries within the threshhold
            // and the threshhold was near now, show the most recent entry
            if (!is_array($plan_entries) && $enddate > time() - 15) {
                // the most recent entry will be just after the beginning of the array
                // because the first two entries will be the $enddate test entry
                reset($plan_index_array);
                while (strpos(current($plan_index_array), 'FAKE')) {
                    next($plan_index_array);
                }
                $entry_filename = "{$_SERVER['PLANOWNER_ROOT']}/plan/" . current($plan_index_array);
                $entry_timecode = key($plan_index_array);
                if (file_exists($entry_filename)) {
                    $plan_entries[$entry_timecode] = file_get_contents($entry_filename);
                }
            }
            // if there's still no plan, and we're considering an archival view
            // find the nearest-neighbor plan entry
            if (!is_array($plan_entries) && $enddate < time() - 15) {
                // get the distance to the prev entry
                array_set_current($plan_index_array, $enddate);
                $previous_entry_filename = "{$_SERVER['PLANOWNER_ROOT']}/plan/" . prev($plan_index_array);
                $previous_entry_timecode = key($plan_index_array);
                if (file_exists($previous_entry_filename)) {
                    $plan_entries[$previous_entry_timecode] = file_get_contents($previous_entry_filename);
                }
                // get the distance to the next entry
                array_set_current($plan_index_array, $begindate);
                $next_entry_filename = "{$_SERVER['PLANOWNER_ROOT']}/plan/" . next($plan_index_array);
                $next_entry_timecode = key($plan_index_array);
                if (file_exists($next_entry_filename)) {
                    $plan_entries[$next_entry_timecode] = file_get_contents($next_entry_filename);
                }
                $plan_entries[1000000000000000] = "Nothing In Range";
            }
            if ($reverse) {
                ksort($plan_entries);
            } else {
                krsort($plan_entries);
            }
            // if we're ouputting to HTML, put it all together in tasty DIVs.
            if ($_SERVER['OUTPUT_MODE'] == 'HTML' || $_SERVER['OUTPUT_MODE'] == 'IPHONE' || $_SERVER['OUTPUT_MODE'] == 'MOBILE' || $_SERVER['OUTPUT_MODE'] == 'AJAX') {
                foreach ($plan_entries as $entry_time => $entry_text) {
                    $entry_text = trim(stripslashes($entry_text));
                    if (strpos($entry_text, 'nolinebreaks') || strpos($entry_text, '<!--markdown-->')) {
                        $entry_nolinebreaks = 1;
                        $entry_text = str_replace('#nolinebreaks#', '', $entry_text);
                    } else {
                        $entry_nolinebreaks = '';
                        $entry_text = smart_nl2br($entry_text);
                    }
                    if (strpos($entry_text, '<!--markdown-->')) {
                        include_once 'markdown.php';
                        $entry_text = Markdown(str_replace('<!--markdown-->', '', $entry_text));
                    }
                    // pretty up the divider (erm... entry header)
                    $entry_header = plan_prepare_divider($planowner, $reader, $plan_dressing['divider'], $entry_time, $plan_index_array[$entry_time], $entry_text, $entry_nolinebreaks);
                    $plan_content .= plan_prepare_entry($entry_time, $entry_header, $entry_text);
                }
                $plan .= $plan_dressing['header'] . "\n{$new_entry_link}\n<div class='plan_body' id='plan_body_{$_SERVER['PLANOWNER']}'>\n{$plan_content}\n</div>" . $plan_dressing['footer'];
            }
            // if we're building a feed, we want to do valid XML goodness
            if ($_SERVER['OUTPUT_MODE'] == 'RSS') {
                foreach ($plan_entries as $entry_time => $entry_text) {
                    $entry_text = trim(stripslashes($entry_text));
                    if (strpos($entry_text, 'nolinebreaks')) {
                        $entry_text = str_replace('#nolinebreaks#', '', $entry_text);
                    } else {
                        $entry_text = smart_nl2br($entry_text);
                    }
                    $rss_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['WEB_ROOT']}/read/{$planowner}";
                    $entry_text = plan_add_user_links(plan_add_alias_links($entry_text, $planowner));
                    list($entry, $li) = plan_encapsulate_rss($planowner, $entry_time, $entry_text);
                    $plan .= $entry;
                    $items .= $li;
                }
                $plan = "{$items}\n<!-- FEED_DIVIDER -->\n{$plan}";
            }
            if (strstr($_SERVER['OUTPUT_MODE'], 'ATOM')) {
                foreach ($plan_entries as $entry_time => $entry_text) {
                    $entry_text = trim(stripslashes($entry_text));
                    if (strpos($entry_text, 'nolinebreaks')) {
                        $entry_text = str_replace('#nolinebreaks#', '', $entry_text);
                    } else {
                        $entry_text = smart_nl2br($entry_text);
                    }
                    $rss_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['WEB_ROOT']}/read/{$planowner}";
                    $entry_text = plan_add_user_links(plan_add_alias_links($entry_text, $planowner));
                    $entry = plan_encapsulate_atom($planowner, $entry_time, $entry_text);
                    $plan .= $entry;
                }
                $plan = "{$items}\n<!-- FEED_DIVIDER -->\n{$plan}";
            }
        } else {
            // TODO:(v4.5) RSS for traditional plans
            //if ($_SERVER['USER']=='dskatz04') echo "$threshhold ".(time()-21*24*3600)." this is a traditional plan\n<br />";
            if (strlen($threshhold) < 9) {
                $threshhold = '';
            } elseif (strpos($threshhold, ',')) {
                $threshhold_array = explode(',', $threshhold);
            } else {
                $threshhold_array = array($threshhold);
            }
            if (is_array($threshhold_array)) {
                $threshhold_array = array_reverse($threshhold_array);
            } else {
                $threshhold_array = array("1" => "");
            }
            foreach ($threshhold_array as $z => $threshhold) {
                if ($threshhold != time() - $_SERVER['PLANOWNER_INFO_ARRAY']['defaultdays'] * 24 * 3600) {
                    $plan_filenames = files_list("{$_SERVER['PLANOWNER_ROOT']}/plan", "*{$threshhold}*");
                } else {
                    $plan_filenames = array('plan.txt');
                }
                $entry_time = $threshhold;
                if (count($threshhold_array) > 1) {
                    $plan .= "<hr/>" . date('F jS Y, g:ia', $threshhold_array[$z]) . "<hr/>";
                    $entry_header = plan_prepare_divider($planowner, $reader, $plan_dressing['divider'], $entry_time, $plan_filenames[0], $entry_text, $entry_nolinebreaks);
                }
                if (is_array($plan_filenames)) {
                    foreach ($plan_filenames as $filename) {
                        if (file_exists("{$_SERVER['PLANOWNER_ROOT']}/plan/{$filename}")) {
                            if (strstr($filename, '.gz')) {
                                $plan .= stripslashes(file_get_contents("compress.zlib://{$_SERVER['PLANOWNER_ROOT']}/plan/" . basename($filename)));
                            } else {
                                $plan .= stripslashes(file_get_contents("{$_SERVER['PLANOWNER_ROOT']}/plan/" . basename($filename)));
                            }
                        }
                    }
                }
            }
            if (strlen(trim($plan)) > 10) {
                if (!strstr($plan, 'nolinebreaks')) {
                    $plan = smart_nl2br($plan);
                }
                $plan = "{$plan_dressing['header']}<div class='plan_body' id='plan_body_{$_SERVER['PLANOWNER']}'>{$plan}</div>\n{$plan_dressing['footer']}";
            }
        }
    }
    // MORE CACHING
    if (!file_exists($cache_fn) || plan_get_last_update($planowner) > filemtime($cache_fn) && $remoteuser != 'rss reader') {
        file_put_contents($cache_fn, $plan);
    }
    profile("plan_read_local_{$prl_rand}");
    return "<!-- since " . formattime($threshhold) . " " . formattime($begindate) . " -->\n" . $plan;
}