diff --git a/core/database.class.php b/core/database.class.php index 53ed4b4d..6e8a0213 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -292,17 +292,17 @@ class Database { $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db_proto = $this->db->getAttribute(PDO::ATTR_DRIVER_NAME); - if($db_proto == "mysql") { + if($db_proto === "mysql") { $this->engine = new MySQL(); } - else if($db_proto == "pgsql") { + else if($db_proto === "pgsql") { $this->engine = new PostgreSQL(); } - else if($db_proto == "sqlite") { + else if($db_proto === "sqlite") { $this->engine = new SQLite(); } else { - die("Unknown PDO driver: $db_proto"); + die('Unknown PDO driver: '.$db_proto); } if(isset($cache_dsn) && !empty($cache_dsn)) { @@ -345,8 +345,8 @@ class Database { return $stmt; } catch(PDOException $pdoe) { - print "Message: ".$pdoe->getMessage(); - print "
Error: $query"; + print 'Message: '.$pdoe->getMessage(); + print '
Error: '.$query; exit; } } diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 5f110f07..d07a571b 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -194,12 +194,12 @@ class Image { } if(count($tags) == 0) { - $row = $database->get_row("SELECT images.* FROM images WHERE images.id $gtlt {$this->id} ORDER BY images.id $dir LIMIT 1"); + $row = $database->get_row('SELECT images.* FROM images WHERE images.id '.$gtlt.' '.$this->id.' ORDER BY images.id '.$dir.' LIMIT 1'); } else { - $tags[] = "id$gtlt{$this->id}"; + $tags[] = 'id'. $gtlt . $this->id; $querylet = Image::build_search_querylet($tags); - $querylet->append_sql(" ORDER BY images.id $dir LIMIT 1"); + $querylet->append_sql(' ORDER BY images.id '.$dir.' LIMIT 1'); $row = $database->get_row($querylet->sql, $querylet->variables); } @@ -229,14 +229,15 @@ class Image { */ public function get_tag_array() { global $database; - $cached = $database->cache->get("image-{$this->id}-tags"); + $tmp = 'image-'.$this->id.'-tags'; + $cached = $database->cache->get($tmp); if($cached) return $cached; if(!isset($this->tag_array)) { $this->tag_array = $database->get_col("SELECT tag FROM image_tags JOIN tags ON image_tags.tag_id = tags.id WHERE image_id=:id ORDER BY tag", array("id"=>$this->id)); } - $database->cache->set("image-{$this->id}-tags", $this->tag_array); + $database->cache->set($tmp, $this->tag_array); return $this->tag_array; } diff --git a/core/util.inc.php b/core/util.inc.php index 25e020f9..27ad46f2 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -21,6 +21,10 @@ function html_escape($input) { * @retval int */ function int_escape($input) { + /* + Side note, Casting to an integer is FASTER than using intval. + http://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/ + */ return (int)$input; } @@ -56,13 +60,13 @@ function sql_escape($input) { function bool_escape($input) { $input = strtolower($input); return ( - $input == "y" || - $input == "yes" || - $input == "t" || - $input == "true" || - $input == "on" || - $input == 1 || - $input == true + $input === "y" || + $input === "yes" || + $input === "t" || + $input === "true" || + $input === "on" || + $input === 1 || + $input === true ); } @@ -86,7 +90,7 @@ function parse_shorthand_int($limit) { return (int)$limit; } - if(preg_match('/^([\d\.]+)([gmk])?b?$/i', "$limit", $m)) { + if(preg_match('/^([\d\.]+)([gmk])?b?$/i', (string)$limit, $m)) { $value = $m[1]; if (isset($m[2])) { switch(strtolower($m[2])) { @@ -118,7 +122,7 @@ function to_shorthand_int($int) { return sprintf("%.1fKB", $int / 1024); } else { - return "$int"; + return (string)$int; } } @@ -131,7 +135,7 @@ function to_shorthand_int($int) { function autodate($date, $html=true) { $cpu = date('c', strtotime($date)); $hum = date('F j, Y', strtotime($date)); - return ($html ? "" : $hum); + return ($html ? '' : $hum); } @@ -182,17 +186,17 @@ function make_link($page=null, $query=null) { } if(is_null($query)) { - return str_replace("//", "/", "$base/$page"); + return str_replace("//", "/", $base.'/'.$page ); } else { if(strpos($base, "?")) { - return "$base/$page&$query"; + return $base .'/'. $page .'&'. $query; } else if(strpos($query, "#") === 0) { - return "$base/$page$query"; + return $base .'/'. $page . $query; } else { - return "$base/$page?$query"; + return $base .'/'. $page .'?'. $query; } } } @@ -261,14 +265,14 @@ function make_http($link) { function make_form($target, $method="POST", $multipart=False, $form_id="", $onsubmit="") { global $user; $auth = $user->get_auth_html(); - $extra = empty($form_id) ? '' : " id='$form_id'"; + $extra = empty($form_id) ? '' : 'id="'. $form_id .'"'; if($multipart) { $extra .= " enctype='multipart/form-data'"; } if($onsubmit) { - $extra .= " onsubmit='$onsubmit'"; + $extra .= ' onsubmit="'.$onsubmit.'"'; } - return "