From 32dbdccd0041c11e7e26d1ad2bbcfec4fb0e9566 Mon Sep 17 00:00:00 2001 From: Daku Date: Tue, 10 May 2016 21:15:50 +0100 Subject: [PATCH 1/3] has_children uses Y/N, not TRUE/FALSE --- core/basethemelet.class.php | 2 +- ext/relatationships/main.php | 4 ++-- ext/relatationships/theme.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/basethemelet.class.php b/core/basethemelet.class.php index 9bfb1a18..68678e06 100644 --- a/core/basethemelet.class.php +++ b/core/basethemelet.class.php @@ -67,7 +67,7 @@ class BaseThemelet { $custom_classes = ""; if(class_exists("Relationships")){ if(property_exists($image, 'parent_id') && $image->parent_id !== NULL){ $custom_classes .= "shm-thumb-has_parent "; } - if(property_exists($image, 'has_children') && $image->has_children == TRUE){ $custom_classes .= "shm-thumb-has_child "; } + if(property_exists($image, 'has_children') && $image->has_children == 'Y'){ $custom_classes .= "shm-thumb-has_child "; } } return "". diff --git a/ext/relatationships/main.php b/ext/relatationships/main.php index 8ecc6991..5bbfe0b0 100644 --- a/ext/relatationships/main.php +++ b/ext/relatationships/main.php @@ -25,7 +25,7 @@ class Relationships extends Extension { public function onImageInfoSet(ImageInfoSetEvent $event) { if(isset($_POST['tag_edit__tags']) ? !preg_match('/parent[=|:]/', $_POST["tag_edit__tags"]) : TRUE) { //Ignore tag_edit__parent if tags contain parent metatag - if (isset($_POST["tag_edit__parent"]) ? ctype_digit($_POST["tag_edit__parent"]) : FALSE) { + if(isset($_POST["tag_edit__parent"]) ? ctype_digit($_POST["tag_edit__parent"]) : FALSE) { $this->set_parent($event->image->id, (int) $_POST["tag_edit__parent"]); }else{ $this->remove_parent($event->image->id); @@ -83,7 +83,7 @@ class Relationships extends Extension { public function onImageDeletion(ImageDeletionEvent $event) { global $database; - if($event->image->has_children){ + if($event->image->has_children == 'Y'){ $database->execute("UPDATE images SET parent_id = NULL WHERE parent_id = :iid", array("iid"=>$event->image->id)); } diff --git a/ext/relatationships/theme.php b/ext/relatationships/theme.php index 39018ae3..05e8a286 100644 --- a/ext/relatationships/theme.php +++ b/ext/relatationships/theme.php @@ -12,7 +12,7 @@ class RelationshipsTheme extends Themelet { $page->add_block(new Block(null, "This post belongs to a $a.", "main", 5)); } - if($image->has_children == TRUE){ + if($image->has_children == 'Y'){ $ids = $database->get_col("SELECT id FROM images WHERE parent_id = :iid", array("iid"=>$image->id)); $html = "This post has ".(count($ids) > 1 ? "child posts" : "a child post").""; From a3296e18ae6ab08cb895f3b3b6650a14d5d1e50a Mon Sep 17 00:00:00 2001 From: Daku Date: Wed, 11 May 2016 14:49:22 +0100 Subject: [PATCH 2/3] create index for has_children --- ext/relatationships/main.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ext/relatationships/main.php b/ext/relatationships/main.php index 5bbfe0b0..90875300 100644 --- a/ext/relatationships/main.php +++ b/ext/relatationships/main.php @@ -21,6 +21,12 @@ class Relationships extends Extension { $config->set_int("ext_relationships_version", 1); log_info("relationships", "extension installed"); } + if ($config->get_int("ext_relationships_version") < 2){ + $database->execute("CREATE INDEX images__has_children ON images(has_children)"); + + $config->set_int("ext_relationships_version", 2); + log_info("relationships", "extension updated"); + } } public function onImageInfoSet(ImageInfoSetEvent $event) { From 44876a58d976669dc0e16fe4f9e689a1d4cdd470 Mon Sep 17 00:00:00 2001 From: Daku Date: Sun, 22 May 2016 16:17:31 +0100 Subject: [PATCH 3/3] we should be using bool_escape instead... --- core/basethemelet.class.php | 2 +- ext/relatationships/main.php | 2 +- ext/relatationships/theme.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/basethemelet.class.php b/core/basethemelet.class.php index 68678e06..de23c99b 100644 --- a/core/basethemelet.class.php +++ b/core/basethemelet.class.php @@ -67,7 +67,7 @@ class BaseThemelet { $custom_classes = ""; if(class_exists("Relationships")){ if(property_exists($image, 'parent_id') && $image->parent_id !== NULL){ $custom_classes .= "shm-thumb-has_parent "; } - if(property_exists($image, 'has_children') && $image->has_children == 'Y'){ $custom_classes .= "shm-thumb-has_child "; } + if(property_exists($image, 'has_children') && bool_escape($image->has_children)){ $custom_classes .= "shm-thumb-has_child "; } } return "". diff --git a/ext/relatationships/main.php b/ext/relatationships/main.php index 90875300..e81aefbb 100644 --- a/ext/relatationships/main.php +++ b/ext/relatationships/main.php @@ -89,7 +89,7 @@ class Relationships extends Extension { public function onImageDeletion(ImageDeletionEvent $event) { global $database; - if($event->image->has_children == 'Y'){ + if(bool_escape($event->image->has_children)){ $database->execute("UPDATE images SET parent_id = NULL WHERE parent_id = :iid", array("iid"=>$event->image->id)); } diff --git a/ext/relatationships/theme.php b/ext/relatationships/theme.php index 05e8a286..abc4302e 100644 --- a/ext/relatationships/theme.php +++ b/ext/relatationships/theme.php @@ -12,7 +12,7 @@ class RelationshipsTheme extends Themelet { $page->add_block(new Block(null, "This post belongs to a $a.", "main", 5)); } - if($image->has_children == 'Y'){ + if(bool_escape($image->has_children)){ $ids = $database->get_col("SELECT id FROM images WHERE parent_id = :iid", array("iid"=>$image->id)); $html = "This post has ".(count($ids) > 1 ? "child posts" : "a child post")."";