How Random Babbling Becomes Corporate Policy (t3knomanser) wrote in component_help,
How Random Babbling Becomes Corporate Policy
t3knomanser
component_help

Full Update Page (More Query Handling)

During my fit of insomnia last night, I decided that I wanted to cull my collection of components, but I wanted to keep the functionality- specifically the update component. Which is huge and takes up a fantastic amount of space, and is kinda hard to use being a sidebar component. So I decided to create a full-update page in my journal style.


We accomplish this by overriding the print_my_entries function.

function print_my_entries(Page p, string title) {

var flatbox f = new flatbox;  #This tutorial requires the flatbox class..
#if you remove any lines referring to $f it'll work, but be ugly.
if ($p.args{"mode"} == "update") {
####################################################################################
#Begin update component                                                            #
####################################################################################
if(true) {

########################
# USER SETTINGS

# set this to your time zone difference
var int time_difference = -5; #this one you'll have to change

# Set to true for commmunity journal, false for personal journal
var bool community = false;

# Set to true to show all features of the full update page.
var bool show_all = true;

# Set to true to show the date options, false otherwise.
var bool show_date = false;

# set this to the header of the component
var string update_title = "Update"; #this isn't used anymore

#No need to change these values, unless you want to have it default to someone elses username.
# set this to the journal you want it to post to
var string defaultjournal = "$p.journal.username";

#set this to the default username you want displayed
var string defaultuser = "$p.journal.username";


#########################
# DON'T need to mess with anything below (until we reach the end of the update component)

var int year = $p.time.year;
var int day = $p.time.day;
var int hour = $p.time.hour + $time_difference;
var int month = $p.time.month;

# figure out days in month
var int mondays = 31;
if($month == 4 or $month == 6 or $month == 9 or $month == 11) {
$mondays = 30;
} elseif($month == 2) {
$mondays = ($year % 4 == 0) ? 29 : 28;
}

if($hour > 24) { # if your timezone is the day after system...
$hour = $hour - 24; # figure out new hour value
$day = $day + 1; # make sure to change day value
if($day > $mondays) { # if your day is in the next month...
$day = $day - $mondays; # figure out the new day
$month = $month + 1; # change the month value
if($month > 12) { # if your month is in the next year...
$month = 1; # change the month value and
$year = $year + 1; # change the year value
}
}
} elseif($hour < 0) { # otherwise, if your day is the day before...
$hour = 24 + $hour; # change the hour and
$day = $day - 1; # change the day value
if($day < 1) { # if that puts you in the previous month...
$month = $month - 1; # decrement the month value
if($month < 1) { # if that puts you in the previous year...
$month = 12; # set the new month value and
$year = $year - 1; # decrement the year value
}
$mondays = 31; # figure out how many days are in this new month
if($month == 4 or $month == 6 or $month == 9 or $month == 11) {
$mondays = 30;
} elseif($month == 2) {
$mondays = ($year % 4) == 0 ? 29 : 28;
}
$day = $mondays; # and change your day value to that.
}
}
#print_comp_header($update_title);
"""<td valign="top">""";
"""<div align="center"><table><tr><td>""";
$f->flatbox_header();
"""
<form method="post" action="http://www.livejournal.com/update.bml" name="updateForm">
<label for="user">Username:</label><input type="text" name="user" value="$defaultuser">
<label for="password">Password:</label><input type="password" name="password"><br/>
<label for="usejournal">Journal:</label><input type="text" name="usejournal" value="$defaultjournal">
""";
$f->flatbox_footer();


if($show_date) {
$f->flatbox_header();
"""
<p><input type="text" maxlength="4" size="5" value="$year" name="year" />-<input type="text" maxlength="2" size="3" value="$month" name="mon" />-<input type="text" maxlength="2" size="3" value="$day" name="day" /><i>(yyyy-mm-dd)</i></p>
<p><input type="text" maxlength="2" size="3" value="$hour" name="hour" />:<input type="text" maxlength="2" size="3" value="$p.time.min" name="min" /> <i>(24 hour time)</i></p>
""";
$f->flatbox_footer();
} else {
$f->flatbox_header();
"""
<input type="hidden" value="$year" name="year" />
<input type="hidden" value="$month" name="mon" />
<input type="hidden" value="$day" name="day" />
<input type="hidden" value="$hour" name="hour" />
<input type="hidden" value="$p.time.min" name="min" />
<input type="hidden" value="1" name="altlogin" />
""";
$f->flatbox_footer();
}
$f->flatbox_header();
"""
<p><b>Subject:</b> <i>(Optional)</i><br /><input type="text" maxlength="100" style="width: 99%" size="12" value="" name="subject" /></p>

<p><b>Event:</b><br /><textarea style="width: 99%" wrap="soft" cols="24" rows="10" name="event"></textarea>
""";
$f->flatbox_footer();
if($show_all) {
$f->flatbox_header();
"""
<p><input type='checkbox' id="do_spellcheck" name="do_spellcheck" /><label for='do_spellcheck'>Spell Check Before Posting</label></p>
<p><b>Security Level:</b> <select onchange="customboxes()" name="security"><option value="public">Public</option><option value="private">Private</option><option value="friends">Friends</option><option value="custom">Custom...</option></select></p>
<p><b><label for='prop_opt_backdated'>Backdate Entry:</label></b> <input type='checkbox' id="prop_opt_backdated" name="prop_opt_backdated" />
<b><b><label for='prop_opt_preformatted'><p><b>Don't Auto-Format:</label></b> <input type='checkbox' id="prop_opt_preformatted" name="prop_opt_preformatted" /></a></p>
<p><b><label for='prop_opt_nocomments'>Disallow Comments:</label></b> <input type='checkbox' id="prop_opt_nocomments" name="prop_opt_nocomments" /> <br />
<b><b><label for='prop_opt_noemail'>Don't E-Mail Comments:</label></b> <input type='checkbox' id="prop_opt_noemail" name="prop_opt_noemail" />
<p><b>Current <a href="/moodlist.bml">Mood</a>:</b></b></b></b><br /><select name="prop_current_moodid"><option value="" selected='selected'>None, or other:</option><option value="90">accomplished</option><option value="1">aggravated</option><option value="44">amused</option><option value="2">angry</option><option value="3">annoyed</option><option value="4">anxious</option><option value="114">apathetic</option><option value="108">artistic</option><option value="87">awake</option><option value="110">bitchy</option><option value="92">blah</option><option value="113">blank</option><option value="5">bored</option><option value="59">bouncy</option><option value="91">busy</option><option value="68">calm</option><option value="125">cheerful</option><option value="99">chipper</option><option value="84">cold</option><option value="63">complacent</option><option value="6">confused</option><option value="101">contemplative</option><option value="64">content</option><option value="8">cranky</option><option value="7">crappy</option><option value="106">crazy</option><option value="107">creative</option><option value="129">crushed</option><option value="56">curious</option><option value="104">cynical</option><option value="9">depressed</option><option value="45">determined</option><option value="130">devious</option><option value="119">dirty</option><option value="55">disappointed</option><option value="10">discontent</option><option value="127">distressed</option><option value="35">ditzy</option><option value="115">dorky</option><option value="40">drained</option><option value="34">drunk</option><option value="98">ecstatic</option><option value="79">embarrassed</option><option value="11">energetic</option><option value="12">enraged</option><option value="13">enthralled</option><option value="80">envious</option><option value="78">exanimate</option><option value="41">excited</option><option value="14">exhausted</option><option value="67">flirty</option><option value="47">frustrated</option><option value="93">full</option><option value="103">geeky</option><option value="120">giddy</option><option value="72">giggly</option><option value="38">gloomy</option><option value="126">good</option><option value="132">grateful</option><option value="51">groggy</option><option value="95">grumpy</option><option value="111">guilty</option><option value="15">happy</option><option value="16">high</option><option value="43">hopeful</option><option value="17">horny</option><option value="83">hot</option><option value="18">hungry</option><option value="52">hyper</option><option value="116">impressed</option><option value="48">indescribable</option><option value="65">indifferent</option><option value="19">infuriated</option><option value="128">intimidated</option><option value="20">irate</option><option value="112">irritated</option><option value="133">jealous</option><option value="21">jubilant</option><option value="33">lazy</option><option value="75">lethargic</option><option value="76">listless</option><option value="22">lonely</option><option value="86">loved</option><option value="39">melancholy</option><option value="57">mellow</option><option value="36">mischievous</option><option value="23">moody</option><option value="37">morose</option><option value="117">naughty</option><option value="97">nauseated</option><option value="102">nerdy</option><option value="134">nervous</option><option value="60">nostalgic</option><option value="124">numb</option><option value="61">okay</option><option value="70">optimistic</option><option value="58">peaceful</option><option value="73">pensive</option><option value="71">pessimistic</option><option value="24">pissed off</option><option value="109">pleased</option><option value="118">predatory</option><option value="89">productive</option><option value="105">quixotic</option><option value="77">recumbent</option><option value="69">refreshed</option><option value="123">rejected</option><option value="62">rejuvenated</option><option value="53">relaxed</option><option value="42">relieved</option><option value="54">restless</option><option value="100">rushed</option><option value="25">sad</option><option value="26">satisfied</option><option value="46">scared</option><option value="122">shocked</option><option value="82">sick</option><option value="66">silly</option><option value="49">sleepy</option><option value="27">sore</option><option value="28">stressed</option><option value="121">surprised</option><option value="81">sympathetic</option><option value="131">thankful</option><option value="29">thirsty</option><option value="30">thoughtful</option><option value="31">tired</option><option value="32">touched</option><option value="74">uncomfortable</option><option value="96">weird</option><option value="88">working</option><option value="85">worried</option></select><br \>Other: <br \><input type="text" maxlength="30" size="15" value="" name="prop_current_mood" /></p>
<p><b>Current Music:</b><br /><input type="text" maxlength="40" size="30" value="" name="prop_current_music" /></p>
""";
$f->flatbox_footer();
}
$f->flatbox_header();
"""
<p><input type="submit" value="Update Journal" /></p>""";
$f->flatbox_footer();
"""
</form>
""";

if($community) {
"""<p>If not a member, you must <a href="http://www.livejournal.com/community/join.bml?comm=$defaultjournal">join</a> first.</p>""";
}
#############################################################################################
#                        End Update Component                                               #
#############################################################################################
"""</td></tr></table></div>""";
#print_comp_footer();
"""</td>""";
}

} else {

    #other code to print your page For one example, see the tutorial on custom titlebar components.
}

}
#####################################
#    END print_my_entries           #
#####################################



Now, once that's done, you have a full update page at the address: http://www.livejournal.com/users/your_lj_name/?.mode=update (ie. http://www.livejournal.com/users/t3knomanser/?.mode=update). Using this basic idea, you could add more if/then/else clauses and have any number of custom pages to print out. And I swear I'll do the tutorial on the flat-box-border entries, but the code's kinda messed up, so I'm putting it off.
Tags: admin: deprecated, user: t3knomanser
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 7 comments