make tag setting work
This commit is contained in:
parent
4a8034cabe
commit
94c0ab0255
@ -238,14 +238,17 @@ class Image {
|
|||||||
public function set_tags($tags) {
|
public function set_tags($tags) {
|
||||||
$tags = tag_explode($tags);
|
$tags = tag_explode($tags);
|
||||||
|
|
||||||
$tags = array_map(array($this, 'resolve_alias'), $tags);
|
$tags = array_map(array('Tag', 'resolve_alias'), $tags);
|
||||||
$tags = array_map(array($this, 'sanitise'), $tags);
|
$tags = array_map(array('Tag', 'sanitise'), $tags);
|
||||||
$tags = array_iunique($tags); // remove any duplicate tags
|
$tags = array_iunique($tags); // remove any duplicate tags
|
||||||
|
|
||||||
|
assert(is_array($tags));
|
||||||
|
assert(count($tags) > 0);
|
||||||
|
|
||||||
// delete old
|
// delete old
|
||||||
$this->delete_tags_from_image();
|
$this->delete_tags_from_image();
|
||||||
|
|
||||||
// insert each new tag
|
// insert each new tags
|
||||||
foreach($tags as $tag) {
|
foreach($tags as $tag) {
|
||||||
$this->database->execute(
|
$this->database->execute(
|
||||||
"INSERT IGNORE INTO tags(tag) VALUES (?)",
|
"INSERT IGNORE INTO tags(tag) VALUES (?)",
|
||||||
@ -253,7 +256,7 @@ class Image {
|
|||||||
$this->database->execute(
|
$this->database->execute(
|
||||||
"INSERT INTO image_tags(image_id, tag_id) ".
|
"INSERT INTO image_tags(image_id, tag_id) ".
|
||||||
"VALUES(?, (SELECT id FROM tags WHERE tag = ?))",
|
"VALUES(?, (SELECT id FROM tags WHERE tag = ?))",
|
||||||
array($image_id, $tag));
|
array($this->id, $tag));
|
||||||
$this->database->execute(
|
$this->database->execute(
|
||||||
"UPDATE tags SET count = count + 1 WHERE tag = ?",
|
"UPDATE tags SET count = count + 1 WHERE tag = ?",
|
||||||
array($tag));
|
array($tag));
|
||||||
|
@ -38,10 +38,10 @@ class ImageInfoBoxBuildingEvent extends Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ImageInfoSetEvent extends Event {
|
class ImageInfoSetEvent extends Event {
|
||||||
var $image_id;
|
var $image;
|
||||||
|
|
||||||
public function ImageInfoSetEvent($image_id) {
|
public function ImageInfoSetEvent($image) {
|
||||||
$this->image_id = int_escape($image_id);
|
$this->image = $image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,9 +86,10 @@ class ViewImage implements Extension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(($event instanceof PageRequestEvent) && $event->page_matches("post/set")) {
|
if(($event instanceof PageRequestEvent) && $event->page_matches("post/set")) {
|
||||||
|
global $config, $database;
|
||||||
$image_id = int_escape($_POST['image_id']);
|
$image_id = int_escape($_POST['image_id']);
|
||||||
|
|
||||||
send_event(new ImageInfoSetEvent($image_id));
|
send_event(new ImageInfoSetEvent(Image::by_id($config, $database, $image_id)));
|
||||||
|
|
||||||
$query = $_POST['query'];
|
$query = $_POST['query'];
|
||||||
$event->page->set_mode("redirect");
|
$event->page->set_mode("redirect");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user