whitespace consistency

This commit is contained in:
Shish 2010-02-18 14:12:52 +00:00
parent d3c921e8f3
commit 7e303dc73d
2 changed files with 135 additions and 135 deletions

View File

@ -20,20 +20,20 @@ class Blotter extends SimpleExtension {
* *
* REMINDER: If I change the database tables, I must change up version by 1. * REMINDER: If I change the database tables, I must change up version by 1.
*/ */
if($version < 1) { if($version < 1) {
/** /**
* Installer * Installer
*/ */
global $database, $config; global $database, $config;
$database->create_table("blotter", $database->create_table("blotter", "
"id SCORE_AIPK id SCORE_AIPK,
, entry_date SCORE_DATETIME DEFAULT SCORE_NOW entry_date SCORE_DATETIME DEFAULT SCORE_NOW,
, entry_text TEXT NOT NULL entry_text TEXT NOT NULL,
, important SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N important SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N
"); ");
// Insert sample data: // Insert sample data:
$database->execute("INSERT INTO blotter (id, entry_date, entry_text, important) VALUES (?, now(), ?, ?)", $database->execute("INSERT INTO blotter (id, entry_date, entry_text, important) VALUES (?, now(), ?, ?)",
array(NULL, "Installed the blotter extension!", "Y")); array(NULL, "Installed the blotter extension!", "Y"));
log_info("blotter", "Installed tables for blotter extension."); log_info("blotter", "Installed tables for blotter extension.");
$config->set_int("blotter_version", 1); $config->set_int("blotter_version", 1);
} }
@ -61,71 +61,73 @@ class Blotter extends SimpleExtension {
if($event->page_matches("blotter")) { if($event->page_matches("blotter")) {
switch($event->get_arg(0)) { switch($event->get_arg(0)) {
case "editor": case "editor":
/** /**
* Displays the blotter editor. * Displays the blotter editor.
*/ */
global $database, $user; global $database, $user;
if(!$user->is_admin()) { if(!$user->is_admin()) {
$this->theme->display_permission_denied($page); $this->theme->display_permission_denied($page);
} else { } else {
$entries = $database->get_all("SELECT * FROM blotter ORDER BY id DESC"); $entries = $database->get_all("SELECT * FROM blotter ORDER BY id DESC");
$this->theme->display_editor($entries); $this->theme->display_editor($entries);
} }
break; break;
case "add": case "add":
/** /**
* Adds an entry * Adds an entry
*/ */
global $page, $database, $user; global $page, $database, $user;
if(!$user->is_admin()) { if(!$user->is_admin()) {
$this->theme->display_permission_denied($page); $this->theme->display_permission_denied($page);
} else { } else {
$entry_text = $_POST['entry_text']; $entry_text = $_POST['entry_text'];
if($entry_text == "") { die("No entry message!"); } if($entry_text == "") { die("No entry message!"); }
if(isset($_POST['important'])) { $important = 'Y'; } else { $important = 'N'; } if(isset($_POST['important'])) { $important = 'Y'; } else { $important = 'N'; }
// Now insert into db: // Now insert into db:
$database->execute("INSERT INTO blotter (id, entry_date, entry_text, important) VALUES (?, now(), ?, ?)", $database->execute("INSERT INTO blotter (id, entry_date, entry_text, important) VALUES (?, now(), ?, ?)",
array(NULL, $entry_text, $important)); array(NULL, $entry_text, $important));
log_info("blotter", "Added Message: $entry_text"); log_info("blotter", "Added Message: $entry_text");
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("blotter/editor")); $page->set_redirect(make_link("blotter/editor"));
} }
break; break;
case "remove": case "remove":
/** /**
* Removes an entry * Removes an entry
*/ */
global $page, $database, $user; global $page, $database, $user;
if(!$user->is_admin()) { if(!$user->is_admin()) {
$this->theme->display_permission_denied($page); $this->theme->display_permission_denied($page);
} else { } else {
$id = $_POST['id']; $id = int_escape($_POST['id']);
if(!isset($id)) { die("No ID!"); } if(!isset($id)) { die("No ID!"); }
$database->Execute("DELETE FROM blotter WHERE id=$id"); $database->Execute("DELETE FROM blotter WHERE id=$id");
log_info("blotter", "Removed Entry #$id"); log_info("blotter", "Removed Entry #$id");
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("blotter/editor")); $page->set_redirect(make_link("blotter/editor"));
} }
break; break;
case "": case "":
/** /**
* Displays all blotter entries * Displays all blotter entries
*/ */
global $database, $user; global $database, $user;
$entries = $database->get_all("SELECT * FROM blotter ORDER BY id DESC"); $entries = $database->get_all("SELECT * FROM blotter ORDER BY id DESC");
$this->theme->display_blotter_page($entries); $this->theme->display_blotter_page($entries);
break; break;
} }
} }
/** /**
* Finally, display the blotter on whatever page we're viewing. * Finally, display the blotter on whatever page we're viewing.
*/ */
$this->display_blotter(); $this->display_blotter();
} }
private function display_blotter() { private function display_blotter() {
global $database, $config; global $database, $config;
$limit = $config->get_int("blotter_recent", 5); $limit = $config->get_int("blotter_recent", 5);
$entries = $database->get_all("SELECT * FROM blotter ORDER BY id DESC LIMIT 0,$limit"); $entries = $database->get_all("SELECT * FROM blotter ORDER BY id DESC LIMIT 0,$limit");
$this->theme->display_blotter($entries); $this->theme->display_blotter($entries);
} }
} }
?>

View File

@ -1,63 +1,63 @@
<? <?php
class BlotterTheme extends Themelet { class BlotterTheme extends Themelet {
public function display_editor($entries) { public function display_editor($entries) {
global $page; global $page;
$html = $this->get_html_for_blotter_editor($entries); $html = $this->get_html_for_blotter_editor($entries);
$page->set_title("Blotter Editor"); $page->set_title("Blotter Editor");
$page->set_heading("Blotter Editor"); $page->set_heading("Blotter Editor");
$page->add_block(new Block("Welcome to the Blotter Editor!", $html, "main", 10)); $page->add_block(new Block("Welcome to the Blotter Editor!", $html, "main", 10));
$page->add_block(new Block("Navigation", "<a href='".make_link()."'>Index</a>", "left", 0)); $page->add_block(new Block("Navigation", "<a href='".make_link()."'>Index</a>", "left", 0));
} }
public function display_blotter_page($entries) { public function display_blotter_page($entries) {
global $page; global $page;
$html = $this->get_html_for_blotter_page($entries); $html = $this->get_html_for_blotter_page($entries);
$page->set_mode("data"); $page->set_mode("data");
$page->set_data($html); $page->set_data($html);
} }
public function display_blotter($entries) { public function display_blotter($entries) {
global $page, $config; global $page, $config;
$html = $this->get_html_for_blotter($entries); $html = $this->get_html_for_blotter($entries);
$position = $config->get_string("blotter_position", "subheading"); $position = $config->get_string("blotter_position", "subheading");
$page->add_block(new Block(null, $html, $position, 20)); $page->add_block(new Block(null, $html, $position, 20));
} }
private function is_odd($number) { private function is_odd($number) {
return $number & 1; // 0 = even, 1 = odd return $number & 1; // 0 = even, 1 = odd
} }
private function get_html_for_blotter_editor($entries) { private function get_html_for_blotter_editor($entries) {
/** /**
* Long function name, but at least I won't confuse it with something else ^_^ * Long function name, but at least I won't confuse it with something else ^_^
*/ */
$html = ""; $html = "";
// Add_new stuff goes here. // Add_new stuff goes here.
$table_header = " $table_header = "
<tr> <tr>
<th>Date</th> <th>Date</th>
<th>Message</th> <th>Message</th>
<th>Important?</th> <th>Important?</th>
<th>Action</th> <th>Action</th>
</tr>"; </tr>";
$add_new = " $add_new = "
<tr class='even'> <tr class='even'>
<form action='".make_link("blotter/add")."' method='POST'> <form action='".make_link("blotter/add")."' method='POST'>
<td colspan='2'><textarea style='text-align:left;' name='entry_text' rows='2' /></textarea></td> <td colspan='2'><textarea style='text-align:left;' name='entry_text' rows='2' /></textarea></td>
<td><input type='checkbox' name='important' /></td> <td><input type='checkbox' name='important' /></td>
<td><input type='submit' value='Add'></td> <td><input type='submit' value='Add'></td>
</form> </form>
</tr>"; </tr>";
// Now, time for entries list. // Now, time for entries list.
$table_rows = ""; $table_rows = "";
for ($i = 0 ; $i < count($entries) ; $i++) for ($i = 0 ; $i < count($entries) ; $i++)
{ {
/** /**
* Add table rows * Add table rows
*/ */
$id = $entries[$i]['id']; $id = $entries[$i]['id'];
$entry_date = $entries[$i]['entry_date']; $entry_date = $entries[$i]['entry_date'];
$entry_text = $entries[$i]['entry_text']; $entry_text = $entries[$i]['entry_text'];
@ -68,31 +68,31 @@ class BlotterTheme extends Themelet {
// Add the new table row(s) // Add the new table row(s)
$table_rows .= $table_rows .=
"<tr class='{$tr_class}' "<tr class='{$tr_class}'
<td>$entry_date</td> <td>$entry_date</td>
<td>$entry_text</td> <td>$entry_text</td>
<td>$important</td> <td>$important</td>
<td><form name='remove$id' method='post' action='".make_link("blotter/remove")."'> <td><form name='remove$id' method='post' action='".make_link("blotter/remove")."'>
<input type='hidden' name='id' value='$id' /> <input type='hidden' name='id' value='$id' />
<input type='submit' style='width: 100%;' value='Remove' /> <input type='submit' style='width: 100%;' value='Remove' />
</form> </form>
</td> </td>
</tr>"; </tr>";
} }
$html = " $html = "
<table id='blotter_entries' class='zebra'> <table id='blotter_entries' class='zebra'>
<thead>$table_header</thead> <thead>$table_header</thead>
<tbody>$add_new</tbody> <tbody>$add_new</tbody>
<tfoot>$table_rows</tfoot> <tfoot>$table_rows</tfoot>
</table> </table>
<br /> <br />
<b>Help:</b><br /> <b>Help:</b><br />
<blockquote>Add entries to the blotter, and they will be displayed.</blockquote>"; <blockquote>Add entries to the blotter, and they will be displayed.</blockquote>";
return $html; return $html;
} }
private function get_html_for_blotter_page($entries) { private function get_html_for_blotter_page($entries) {
/** /**
* This one displays a list of all blotter entries. * This one displays a list of all blotter entries.
@ -101,14 +101,14 @@ class BlotterTheme extends Themelet {
$i_color = $config->get_string("blotter_color","#FF0000"); $i_color = $config->get_string("blotter_color","#FF0000");
$html = ""; $html = "";
$html .= "<html><head><title>Blotter</title></head> $html .= "<html><head><title>Blotter</title></head>
<body><pre>"; <body><pre>";
for ($i = 0 ; $i < count($entries) ; $i++) for ($i = 0 ; $i < count($entries) ; $i++)
{ {
/** /**
* Blotter entries * Blotter entries
*/ */
// Reset variables: // Reset variables:
$i_open = ""; $i_open = "";
$i_close = ""; $i_close = "";
$id = $entries[$i]['id']; $id = $entries[$i]['id'];
@ -122,7 +122,7 @@ class BlotterTheme extends Themelet {
$html .= "</pre></body></html>"; $html .= "</pre></body></html>";
return $html; return $html;
} }
private function get_html_for_blotter($entries) { private function get_html_for_blotter($entries) {
/** /**
* Show the blotter widget * Show the blotter widget
@ -132,35 +132,33 @@ class BlotterTheme extends Themelet {
$i_color = $config->get_string("blotter_color","#FF0000"); $i_color = $config->get_string("blotter_color","#FF0000");
$position = $config->get_string("blotter_position", "subheading"); $position = $config->get_string("blotter_position", "subheading");
$html = "<style type='text/css'> $html = "<style type='text/css'>
#blotter1 {font-size: 80%; #blotter1 {font-size: 80%; position: relative;}
position: relative;} #blotter2 {font-size: 80%;}
#blotter2 {font-size: 80%; </style>";
}
</style>";
$html .= "<script><!-- $html .= "<script><!--
$(document).ready(function() { $(document).ready(function() {
$(\"#blotter2-toggle\").click(function() { $(\"#blotter2-toggle\").click(function() {
$(\"#blotter2\").slideToggle(\"slow\", function() { $(\"#blotter2\").slideToggle(\"slow\", function() {
if($(\"#blotter2\").is(\":hidden\")) { if($(\"#blotter2\").is(\":hidden\")) {
$.cookie(\"blotter2-hidden\", 'true', {path: '/'}); $.cookie(\"blotter2-hidden\", 'true', {path: '/'});
} }
else { else {
$.cookie(\"blotter2-hidden\", 'false', {path: '/'}); $.cookie(\"blotter2-hidden\", 'false', {path: '/'});
} }
}); });
}); });
if($.cookie(\"blotter2-hidden\") == 'true') { if($.cookie(\"blotter2-hidden\") == 'true') {
$(\"#blotter2\").hide(); $(\"#blotter2\").hide();
} }
}); });
//--></script>"; //--></script>";
$entries_list = ""; $entries_list = "";
for ($i = 0 ; $i < count($entries) ; $i++) for ($i = 0 ; $i < count($entries) ; $i++)
{ {
/** /**
* Blotter entries * Blotter entries
*/ */
// Reset variables: // Reset variables:
$i_open = ""; $i_open = "";
$i_close = ""; $i_close = "";
$id = $entries[$i]['id']; $id = $entries[$i]['id'];
@ -175,14 +173,14 @@ class BlotterTheme extends Themelet {
$pos_break = ""; $pos_break = "";
$pos_align = "text-align: right; position: absolute; right: 0px;"; $pos_align = "text-align: right; position: absolute; right: 0px;";
if($position == "left") { $pos_break = "<br />"; $pos_align = ""; } if($position == "left") { $pos_break = "<br />"; $pos_align = ""; }
if (count($entries) == 0) { $out_text = "No blotter entries yet."; $in_text = "Empty.";} if(count($entries) == 0) { $out_text = "No blotter entries yet."; $in_text = "Empty.";}
else { $clean_date = date("m/d/y",strtotime($entries[0]['entry_date'])); else { $clean_date = date("m/d/y",strtotime($entries[0]['entry_date']));
$out_text = "Blotter updated: {$clean_date}"; $out_text = "Blotter updated: {$clean_date}";
$in_text = "<ul>$entries_list</ul>"; $in_text = "<ul>$entries_list</ul>";
} }
$html .= "<div id='blotter1'><span>$out_text</span>{$pos_break}<span style='{$pos_align}'><a href='#' id='blotter2-toggle'>Show/Hide</a> <a href='".make_link("blotter")."'>Show All</a></span></div>"; $html .= "<div id='blotter1'><span>$out_text</span>{$pos_break}<span style='{$pos_align}'><a href='#' id='blotter2-toggle'>Show/Hide</a> <a href='".make_link("blotter")."'>Show All</a></span></div>";
$html .= "<div id='blotter2'>$in_text</div>"; $html .= "<div id='blotter2'>$in_text</div>";
return $html; return $html;
} }
} }
?> ?>