forked from Cavemanon/cavepaintings
merge type hints
This commit is contained in:
@@ -27,6 +27,8 @@ $tag_n = 0; // temp hack
|
||||
$_flexihash = null;
|
||||
$_fh_last_opts = null;
|
||||
|
||||
require_once "lib/flexihash.php";
|
||||
|
||||
/**
|
||||
* An object representing an entry in the images table. As of 2.2, this no
|
||||
* longer necessarily represents an image per se, but could be a video,
|
||||
@@ -196,12 +198,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);
|
||||
}
|
||||
|
||||
@@ -251,8 +253,14 @@ class Image {
|
||||
*/
|
||||
public function get_image_link() {
|
||||
global $config;
|
||||
if(strlen($config->get_string('image_ilink')) > 0) {
|
||||
return $this->parse_link_template($config->get_string('image_ilink'));
|
||||
|
||||
$image_ilink = $config->get_string('image_ilink'); // store a copy for speed.
|
||||
|
||||
if( !empty($image_ilink) ) { /* empty is faster than strlen */
|
||||
if(!startsWith($image_ilink, "http://") && !startsWith($image_ilink, "/")) {
|
||||
$image_ilink = make_link($image_ilink);
|
||||
}
|
||||
return $this->parse_link_template($image_ilink);
|
||||
}
|
||||
else if($config->get_bool('nice_urls', false)) {
|
||||
return $this->parse_link_template(make_link('_images/$hash/$id - $tags.$ext'));
|
||||
@@ -280,8 +288,14 @@ class Image {
|
||||
*/
|
||||
public function get_thumb_link() {
|
||||
global $config;
|
||||
if(strlen($config->get_string('image_tlink')) > 0) {
|
||||
return $this->parse_link_template($config->get_string('image_tlink'));
|
||||
|
||||
$image_tlink = $config->get_string('image_tlink'); // store a copy for speed.
|
||||
|
||||
if( !empty($image_tlink) ) { /* empty is faster than strlen */
|
||||
if(!startsWith($image_tlink, "http://") && !startsWith($image_tlink, "/")) {
|
||||
$image_tlink = make_link($image_tlink);
|
||||
}
|
||||
return $this->parse_link_template($image_tlink);
|
||||
}
|
||||
else if($config->get_bool('nice_urls', false)) {
|
||||
return $this->parse_link_template(make_link('_thumbs/$hash/thumb.jpg'));
|
||||
@@ -338,8 +352,8 @@ class Image {
|
||||
*/
|
||||
public function get_mime_type() {
|
||||
$type = strtolower($this->ext);
|
||||
if($type == "jpg") $type = "jpeg";
|
||||
return "image/$type";
|
||||
if($type === "jpg") $type = "jpeg";
|
||||
return 'image/'.$type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,7 +393,7 @@ class Image {
|
||||
public function set_locked($tf) {
|
||||
global $database;
|
||||
$ln = $tf ? "Y" : "N";
|
||||
$sln = $database->engine->scoreql_to_sql("SCORE_BOOL_$ln");
|
||||
$sln = $database->engine->scoreql_to_sql('SCORE_BOOL_'.$ln);
|
||||
$sln = str_replace("'", "", $sln);
|
||||
$sln = str_replace('"', "", $sln);
|
||||
if($sln != $this->locked) {
|
||||
@@ -458,7 +472,7 @@ class Image {
|
||||
global $database;
|
||||
$this->delete_tags_from_image();
|
||||
$database->execute("DELETE FROM images WHERE id=:id", array("id"=>$this->id));
|
||||
log_info("core-image", "Deleted Image #{$this->id} ({$this->hash})");
|
||||
log_info("core-image", 'Deleted Image #'.$this->id.' ('.$this->hash.')');
|
||||
|
||||
unlink($this->get_image_filename());
|
||||
unlink($this->get_thumb_filename());
|
||||
@@ -469,7 +483,7 @@ class Image {
|
||||
* It DOES NOT remove anything from the database.
|
||||
*/
|
||||
public function remove_image_only() {
|
||||
log_info("core-image", "Removed Image File ({$this->hash})");
|
||||
log_info("core-image", 'Removed Image File ('.$this->hash.')');
|
||||
@unlink($this->get_image_filename());
|
||||
@unlink($this->get_thumb_filename());
|
||||
}
|
||||
@@ -522,7 +536,6 @@ class Image {
|
||||
|
||||
if($opts != $_fh_last_opts) {
|
||||
$_fh_last_opts = $opts;
|
||||
require_once("lib/flexihash.php");
|
||||
$_flexihash = new Flexihash();
|
||||
foreach(explode(",", $opts) as $opt) {
|
||||
$parts = explode("=", $opt);
|
||||
@@ -550,7 +563,7 @@ class Image {
|
||||
private static function build_search_querylet($terms) {
|
||||
assert(is_array($terms));
|
||||
global $database;
|
||||
if($database->engine->name == "mysql")
|
||||
if($database->engine->name === "mysql")
|
||||
return Image::build_ugly_search_querylet($terms);
|
||||
else
|
||||
return Image::build_accurate_search_querylet($terms);
|
||||
@@ -593,7 +606,7 @@ class Image {
|
||||
// various types of querylet
|
||||
foreach($terms as $term) {
|
||||
$positive = true;
|
||||
if(strlen($term) > 0 && $term[0] == '-') {
|
||||
if(is_string($term) && !empty($term) && ($term[0] == '-')) {
|
||||
$positive = false;
|
||||
$term = substr($term, 1);
|
||||
}
|
||||
@@ -641,7 +654,7 @@ class Image {
|
||||
if(count($tag_querylets) == 0) {
|
||||
$query = new Querylet("SELECT images.* FROM images ");
|
||||
|
||||
if(strlen($img_search->sql) > 0) {
|
||||
if(!empty($img_search->sql)) {
|
||||
$query->append_sql(" WHERE ");
|
||||
$query->append($img_search);
|
||||
}
|
||||
@@ -658,7 +671,7 @@ class Image {
|
||||
)
|
||||
"), array("tag"=>$tag_querylets[0]->tag));
|
||||
|
||||
if(strlen($img_search->sql) > 0) {
|
||||
if(!empty($img_search->sql)) {
|
||||
$query->append_sql(" AND ");
|
||||
$query->append($img_search);
|
||||
}
|
||||
@@ -760,7 +773,7 @@ class Image {
|
||||
// turn each term into a specific type of querylet
|
||||
foreach($terms as $term) {
|
||||
$negative = false;
|
||||
if((strlen($term) > 0) && ($term[0] == '-')) {
|
||||
if( !empty($term) && ($term[0] == '-')) {
|
||||
$negative = true;
|
||||
$term = substr($term, 1);
|
||||
}
|
||||
@@ -789,11 +802,13 @@ class Image {
|
||||
foreach($tag_querylets as $tq) {
|
||||
global $tag_n;
|
||||
$sign = $tq->positive ? "+" : "-";
|
||||
$sql .= " $sign (tag LIKE :tag$tag_n)";
|
||||
$terms["tag$tag_n"] = $tq->tag;
|
||||
//$sql .= " $sign (tag LIKE :tag$tag_n)";
|
||||
$sql .= ' '.$sign.' (tag LIKE :tag'.$tag_n.')';
|
||||
//$terms["tag$tag_n"] = $tq->tag;
|
||||
$terms['tag'.$tag_n] = $tq->tag;
|
||||
$tag_n++;
|
||||
|
||||
if($sign == "+") $positive_tag_count++;
|
||||
if($sign === "+") $positive_tag_count++;
|
||||
else $negative_tag_count++;
|
||||
}
|
||||
$tag_search = new Querylet($sql, $terms);
|
||||
@@ -815,14 +830,14 @@ class Image {
|
||||
if($positive_tag_count + $negative_tag_count == 0) {
|
||||
$query = new Querylet("SELECT images.*,UNIX_TIMESTAMP(posted) AS posted_timestamp FROM images ");
|
||||
|
||||
if(strlen($img_search->sql) > 0) {
|
||||
if(!empty($img_search->sql)) {
|
||||
$query->append_sql(" WHERE ");
|
||||
$query->append($img_search);
|
||||
}
|
||||
}
|
||||
|
||||
// one positive tag (a common case), do an optimised search
|
||||
else if($positive_tag_count == 1 && $negative_tag_count == 0) {
|
||||
else if($positive_tag_count === 1 && $negative_tag_count === 0) {
|
||||
$query = new Querylet(
|
||||
// MySQL is braindead, and does a full table scan on images, running the subquery once for each row -_-
|
||||
// "{$this->get_images} WHERE images.id IN (SELECT image_id FROM tags WHERE tag LIKE ?) ",
|
||||
@@ -836,7 +851,7 @@ class Image {
|
||||
",
|
||||
$tag_search->variables);
|
||||
|
||||
if(strlen($img_search->sql) > 0) {
|
||||
if(!empty($img_search->sql)) {
|
||||
$query->append_sql(" AND ");
|
||||
$query->append($img_search);
|
||||
}
|
||||
@@ -858,24 +873,24 @@ class Image {
|
||||
if($tags_ok) {
|
||||
$tag_id_list = join(', ', $tag_id_array);
|
||||
|
||||
$subquery = new Querylet("
|
||||
SELECT images.*, SUM({$tag_search->sql}) AS score
|
||||
$subquery = new Querylet('
|
||||
SELECT images.*, SUM('.$tag_search->sql.') AS score
|
||||
FROM images
|
||||
LEFT JOIN image_tags ON image_tags.image_id = images.id
|
||||
JOIN tags ON image_tags.tag_id = tags.id
|
||||
WHERE tags.id IN ({$tag_id_list})
|
||||
WHERE tags.id IN ('.$tag_id_list.')
|
||||
GROUP BY images.id
|
||||
HAVING score = :score",
|
||||
HAVING score = :score',
|
||||
array_merge(
|
||||
$tag_search->variables,
|
||||
array("score"=>$positive_tag_count)
|
||||
)
|
||||
);
|
||||
$query = new Querylet("
|
||||
$query = new Querylet('
|
||||
SELECT *, UNIX_TIMESTAMP(posted) AS posted_timestamp
|
||||
FROM ({$subquery->sql}) AS images ", $subquery->variables);
|
||||
FROM ('.$subquery->sql.') AS images ', $subquery->variables);
|
||||
|
||||
if(strlen($img_search->sql) > 0) {
|
||||
if(!empty($img_search->sql)) {
|
||||
$query->append_sql(" WHERE ");
|
||||
$query->append($img_search);
|
||||
}
|
||||
@@ -921,15 +936,15 @@ class Tag {
|
||||
if(is_string($tags)) {
|
||||
$tags = explode(' ', $tags);
|
||||
}
|
||||
else if(is_array($tags)) {
|
||||
//else if(is_array($tags)) {
|
||||
// do nothing
|
||||
}
|
||||
//}
|
||||
|
||||
$tags = array_map("trim", $tags);
|
||||
|
||||
$tag_array = array();
|
||||
foreach($tags as $tag) {
|
||||
if(is_string($tag) && strlen($tag) > 0) {
|
||||
if(is_string($tag) && !empty($tag)) {
|
||||
$tag_array[] = $tag;
|
||||
}
|
||||
}
|
||||
@@ -946,13 +961,13 @@ class Tag {
|
||||
public static function implode($tags) {
|
||||
assert(is_string($tags) || is_array($tags));
|
||||
|
||||
if(is_string($tags)) {
|
||||
// do nothing
|
||||
}
|
||||
else if(is_array($tags)) {
|
||||
if(is_array($tags)) {
|
||||
sort($tags);
|
||||
$tags = implode(' ', $tags);
|
||||
}
|
||||
//else if(is_string($tags)) {
|
||||
// do nothing
|
||||
//}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
Reference in New Issue
Block a user