Commit f32b7e73 authored by Mal's avatar Mal

Two annoying bugs: Missing semicolons on some javascript function

assignments, and loose comparison of empty strings changed to strict.
parent fddd3b19
......@@ -282,7 +282,7 @@ class Browser extends Base {
$old_width, $old_height,
$type, $new_path, $old_path="") {
// If old path isn't given, saving the new image over the old one.
if ($old_path == "") {
if ($old_path === "") {
$old_path = $new_path;
}
$old_image = null;
......
......@@ -34,7 +34,7 @@ class Cart extends Base {
if ($cart_items = $result->fetch_assoc()) {
$image = $cart_items["image"];
$full = $cart_items["full"];
if ($image == "" && $full == "") {
if ($image === "" && $full === "") {
$object["content"] =
'<i>No extra content to display for this item.<i>';
}
......@@ -81,7 +81,7 @@ class Cart extends Base {
$total_price += $price * $quantity;
$total_weight += $weight;
}
if ($first == "" || $last == "" || $email == "" || $address == "") {
if ($first === "" || $last === "" || $email === "" || $address === "") {
$order_verified = false;
}
if ($order_verified) {
......@@ -299,7 +299,7 @@ class Cart extends Base {
// If an item can be downloaded, display an 'add to cart' button
// rather than an input for quantity.
$quantity = '<button class="item-add">Add to cart</button>';
if ($download == "") {
if ($download === "") {
$quantity = '<label for="item-quantity-'.$count.
'">Quantity: </label><input id="item-quantity-'.$count.
'" class="item-quantity" value="0" size="1">';
......@@ -544,7 +544,7 @@ class Cart extends Base {
$rules = array();
$destination_query = '(destination_name="'.$destination.
'" OR destination_code="'.$destination.'")';
if ($destination == "") {
if ($destination === "") {
// Need to be careful with an empty destination parameter, don't
// want to match when only one of the two fields has been filled out.
$destination_query = 'destination_name="" AND destination_code=""';
......@@ -619,7 +619,7 @@ class Cart extends Base {
}
$mysqli->close();
if ($business == "" || $currency == "") {
if ($business === "" || $currency === "") {
return "Payment options not set.";
}
$message = "An order was received at ".$_SERVER['HTTP_HOST']."\n\n".
......
......@@ -359,7 +359,7 @@ class Gift extends Base {
}
else if ($type == "gift-type") {
// Firstly check for name formatting.
if ($name == "") {
if ($name === "") {
$object['error'] = "Gift type name is empty.";
}
else if (strpos($name, " ") === false && strpos($name, "-") === false) {
......@@ -371,7 +371,7 @@ class Gift extends Base {
$claim_count = $mysqli->escape_string($_POST['claimCount']);
// Remove the record if the posted title is empty.
if ($title == "") {
if ($title === "") {
$query = 'DELETE FROM gift_type WHERE name="'.$name.'"';
if (!$mysqli->query($query)) {
error_log('Gift->EditRegistry 3: '.$mysqli->error);
......@@ -631,10 +631,10 @@ class Gift extends Base {
$messages = "";
}
else {
if ($messages == "") $messages = '<div class="messages">';
if ($messages === "") $messages = '<div class="messages">';
$messages .= $gift_item['claim_name']." chose this gift";
$claim_message = $gift_item['claim_message'];
$messages .= $claim_message == "" ? ".<br>" :
$messages .= $claim_message === "" ? ".<br>" :
", and said:<br>&quot;".$claim_message."&quot;<br>";
}
}
......
......@@ -657,7 +657,7 @@ class Graph extends Base {
$x_label = "time";
$object = array();
if ($graph_id == "") {
if ($graph_id === "") {
$object['error'] = "graphId not given";
$mysqli->close();
return $object;
......@@ -698,7 +698,7 @@ class Graph extends Base {
$y_label = $mysqli->escape_string($_POST['yLabel']);
$x_label = "time";
$object = array();
if ($graph_id == "") {
if ($graph_id === "") {
$object['error'] = "graphId not given";
$mysqli->close();
return $object;
......
......@@ -115,10 +115,10 @@ class Post extends Base {
// area to customise the format below.
$this->config->set_timezone();
$date = date("l F d, Y", $timestamp);
$title = $title == "" ? "" : '<h2>'.$title.'</h2>';
$author = $author == "" ? "" : 'By '.$author.' on ';
$category = $category == "" ? "" : 'tags: '.$category;
$enclosure = $enclsoure == "" ? "" : ' enclosure: '.$enclosure;
$title = $title === "" ? "" : '<h2>'.$title.'</h2>';
$author = $author === "" ? "" : 'By '.$author.' on ';
$category = $category === "" ? "" : 'tags: '.$category;
$enclosure = $enclsoure === "" ? "" : ' enclosure: '.$enclosure;
return $title.
'<div class="published">'.$author.$date.'</div>'.
'<div class="editable">'.$description.'</div>'.
......@@ -265,14 +265,14 @@ class Post extends Base {
}
$time = time();
$permalink = $old_permalink;
if ($author == "") {
if ($author === "") {
$author = $this->user->name;
}
// Only create a new permalink if the title was changed.
if (strcmp($title, $old_title) != 0) {
$this->config->set_timezone();
$date = date("Y-m-d", $time);
if ($title == "") {
if ($title === "") {
$permalink = $date."-".mt_rand();
}
else {
......@@ -371,7 +371,7 @@ class Post extends Base {
private function RemovePermalinkPage($id, $permalink = "") {
$mysqli = connect_db();
if ($permalink == "") {
if ($permalink === "") {
$query = 'SELECT permalink FROM post WHERE user="'.$this->owner.
'" AND box_id="'.$id.'"';
if ($result = $mysqli->query($query)) {
......@@ -382,7 +382,7 @@ class Post extends Base {
else {
error_log('Post->RemovePermalinkPage 1: '.$mysqli->error);
}
if ($permalink == "") {
if ($permalink === "") {
$mysqli->close();
return;
}
......
......@@ -85,7 +85,7 @@ class Reader extends Base {
$first = $item->get_permalink();
// This will run the first time a page is loaded.
if ($_SESSION['reader-first'] == "") {
if ($_SESSION['reader-first'] === "") {
foreach ($feed->get_items(0, $this->PostsPerRequest()) as $item) {
if (!$item) break;
$content .= $this->GetPost($item);
......@@ -231,7 +231,7 @@ class Reader extends Base {
if ($title != "") {
$content .= '<h4 class="reader-title">';
// Link the permalink to the title if it exists.
$content .= $permalink == "" ? $title :
$content .= $permalink === "" ? $title :
'<a href="'.$permalink.'">'.$title.'</a>';
$content .= '</h4>';
}
......@@ -246,7 +246,7 @@ class Reader extends Base {
}
$content .= '<div class="reader-description">'.$description.'</div>'.
'<div class="reader-date">'.$date;
if ($title == "" && $permalink != "") {
if ($title === "" && $permalink != "") {
$content .= '<a href="'.$permalink.'">#</a>';
}
$content .= '</div>';
......
......@@ -42,16 +42,16 @@ class Stock extends Base {
$category = $mysqli->escape_string($_POST["category"]);
$available = $mysqli->escape_string($_POST["available"]);
if ($name == "") {
if ($name === "") {
$object["error"] = "No product name given";
}
else if ($user == "") {
else if ($user === "") {
$object["error"] = "No supplier given";
}
else if ($unit == "") {
else if ($unit === "") {
$object["error"] = "No units given";
}
else if ($price == "") {
else if ($price === "") {
$object["error"] = "No price given";
}
else {
......
......@@ -685,6 +685,6 @@ if (!this.dobrado.cart) {
dobrado.cart.select = function(filename) {
$(browserTarget).val(filename);
}
};
})();
......@@ -491,7 +491,7 @@ $special.draginit = $special.dragstart = $special.dragend = drag;
*/
this.isImmediatePropagationStopped = function () {
return isImmediatePropagationStopped;
}
};
}
/***
......@@ -587,7 +587,7 @@ $special.draginit = $special.dragstart = $special.dragend = drag;
handlers = [];
return this; // allow chaining
}
};
}
/***
......@@ -671,7 +671,7 @@ $special.draginit = $special.dragstart = $special.dragend = drag;
else {
return "(" + this.fromRow + ":" + this.fromCell + " - " + this.toRow + ":" + this.toCell + ")";
}
}
};
}
......
......@@ -118,6 +118,6 @@ if (!this.dobrado.writer) {
$("#writer-content").val("Write a new post...");
$(".writer-post").button("option", "disabled", true);
}
}
};
})();
......@@ -389,7 +389,7 @@ if (!this.dobrado.extended) {
saveStyle();
}
previousTab = $(ui.tab).html();
}
};
dobrado.extended.styleEditor = function(style, updateMedia) {
if (style) {
......
......@@ -40,7 +40,7 @@ foreach ($us_style as $us_selector => $us_rules) {
if ($property == "property") continue;
$value = $mysqli->escape_string($us_value);
// If value is empty, the rule should be removed.
if ($value == "") {
if ($value === "") {
$query = 'DELETE FROM box_style WHERE user="'.$owner.'" AND media="'.
$media.'" AND selector="'.$selector.'" AND property="'.$property.'"';
if (!$mysqli->query($query)) {
......
......@@ -42,7 +42,7 @@ $new_page = $mysqli->escape_string($_POST['page']);
$new_owner = $mysqli->escape_string($_POST['owner']);
// If owner is empty, default to the current page owner.
if ($new_owner == "") $new_owner = $_SESSION['owner'];
if ($new_owner === "") $new_owner = $_SESSION['owner'];
if (!can_edit_page($new_owner."/".$new_page)) {
$mysqli->close();
......
......@@ -94,7 +94,7 @@ function copy_page($current_page, $current_owner,
// the same as the current page. (ie in the case of creating a new post
// we want permissions from the page containing the writer module, not the
// default posts page.)
if ($permission_page == "") {
if ($permission_page === "") {
$permission_page = $current_page;
}
$query = 'INSERT INTO user_permission (user, page, visitor, edit, copy) '.
......
......@@ -22,7 +22,7 @@ function new_user($user, $owner, $config,
if (in_array($user->name, $reserved)) {
return "Username: ".$user->name." is reserved.";
}
if ($user->name == "" || !preg_match("/^[a-z0-9_-]{1,50}$/i", $user->name)) {
if ($user->name === "" || !preg_match("/^[a-z0-9_-]{1,50}$/i", $user->name)) {
return "Username: ".$user->name." is the wrong format.";
}
......@@ -41,7 +41,7 @@ function new_user($user, $owner, $config,
}
// If password is an empty string create a random one.
if ($password == "") {
if ($password === "") {
$chars = "abcdefghijklmnopqrstuvwxyz1234567890";
$length = strlen($chars) - 1;
for ($i = 0; $i < 8; $i++) {
......
......@@ -33,7 +33,7 @@ function permission($action, $mode, $name = "") {
else if (count($matches) == 2) {
$page = $matches[1];
}
if ($user == "" || $page == "" || $owner == "") return false;
if ($user === "" || $page === "" || $owner === "") return false;
if ($mode == "page" && $user == $owner) return true;
// An empty 'page' value is used to signify site permission below,
// and the owner is always 'admin' in this case.
......
......@@ -69,7 +69,7 @@ function rss($user) {
// Replace encoded spaces in the html.
$description = preg_replace("/&nbsp;/", ' ', $item['description']);
// Skip empty items.
if ($title == "" && $description == "") continue;
if ($title === "" && $description === "") continue;
echo "<item>\n";
if ($title != "") {
......
......@@ -17,7 +17,7 @@
function write_file($filename, $content) {
// Remove a file if all relevant style rules have been removed.
if ($content == "") {
if ($content === "") {
unlink($filename);
return;
}
......@@ -123,7 +123,7 @@ function write_site_style() {
function write_page_style($user, $file) {
preg_match("/([^\/]+).css$/", $file, $matches);
$page = $matches[1];
if ($page == "") return;
if ($page === "") return;
$mysqli = connect_db();
$query = 'SELECT media, selector, property, value FROM page_style '.
......
......@@ -38,7 +38,7 @@ $description = $mysqli->escape_string($_POST['description']);
$display = $mysqli->escape_string($_POST['display']);
$update = false;
if ($label == "") {
if ($label === "") {
$object['error'] = "Please provide a module name.";
echo json_encode($object);
return;
......
......@@ -264,7 +264,7 @@ abstract class Base {
error_log('Base->RequestFeedId 1: '.$mysqli->error);
}
// Otherwise generate a new feed id.
if ($feed_id == "") {
if ($feed_id === "") {
$feed_id = mt_rand();
while (true) {
$query = 'SELECT feed_id FROM api WHERE feed_id="'.$feed_id.'"';
......
......@@ -156,7 +156,7 @@ class Extended extends Base {
error_log('Extended->Callback 6: '.$mysqli->error);
}
if ($object["content"]) {
if ($object["content"] === "") {
$object["content"] = '<div id="published-page" class="hidden">'.
'This page is published: <button>public</button></div>'.
'<div id="unpublished-page">This page is <b>not</b> '.
......@@ -332,7 +332,7 @@ class Extended extends Base {
$module_content = $module->Content($id);
if ($module_content === false) continue;
if ($module->CanEdit($id) && strip_tags($module_content) == "") {
if ($module->CanEdit($id) && strip_tags($module_content) === "") {
$module_content = '<i>(module has no content)</i>';
}
$content .= '<h3><a href="#">'.$label.'</a></h3><div>'.
......
......@@ -23,7 +23,7 @@ class Page {
public $config = NULL;
function __construct($user, $owner, $config) {
if ($_GET['page'] == "" ||
if ($_GET['page'] === "" ||
!preg_match("/^[a-z0-9_-]{1,200}$/i", $_GET['page'])) {
$this->name = "index";
}
......
......@@ -47,7 +47,7 @@ foreach ($us_style as $us_selector => $us_rules) {
if ($property == "property") continue;
$value = $mysqli->escape_string($us_value);
// If value is empty, the rule should be removed.
if ($value == "") {
if ($value === "") {
$query = 'DELETE FROM page_style WHERE user="'.$owner.'" AND name="'.
$page.'" AND media="'.$media.'" AND selector="'.$selector.
'" AND property="'.$property.'"';
......
......@@ -36,10 +36,12 @@ if (substr($owner, 0, 5) == "guest" && strlen($owner) == 20) {
}
$mysqli = connect_db();
$published = $mysqli->escape_string($_POST['published']);
// Look for a current value to toggle if none was given.
if ($published == "") {
$published = "";
if (isset($_POST['published'])) {
$published = $mysqli->escape_string($_POST['published']);
}
else {
// Look for a current value to toggle if none was given.
$query = 'SELECT published FROM published WHERE user="'.$owner.'" AND page="'.
$_SESSION['page'].'"';
if ($result = $mysqli->query($query)) {
......@@ -53,7 +55,8 @@ if ($published == "") {
$result->close();
}
// If still have no value, toggle the default which is unpublished.
if ($published == "") $published = 1;
// Note that strict comparison must be used when comparing 0 to "".
if ($published === "") $published = 1;
$query = 'INSERT INTO published VALUES ("'.$owner.'","'.$_SESSION['page'].
'","'.$published.'") ON DUPLICATE KEY UPDATE published="'.$published.'"';
......
......@@ -45,7 +45,7 @@ foreach ($us_style as $us_selector => $us_rules) {
if ($property == "property") continue;
$value = $mysqli->escape_string($us_value);
// If value is empty, the rule should be removed.
if ($value == "") {
if ($value === "") {
$query = 'DELETE FROM site_style WHERE media="'.$media.'" AND selector="'.
$selector.'" AND property="'.$property.'"';
if (!$mysqli->query($query)) error_log('site_style 1: '.$mysqli->error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment