image locking
This commit is contained in:
parent
6c85ed3ba0
commit
9c26f9efb4
4 changed files with 70 additions and 11 deletions
|
@ -36,6 +36,7 @@ class Image {
|
|||
var $owner_ip;
|
||||
var $posted;
|
||||
var $source;
|
||||
var $locked;
|
||||
|
||||
/**
|
||||
* One will very rarely construct an image directly, more common
|
||||
|
@ -371,6 +372,19 @@ class Image {
|
|||
$database->execute("UPDATE images SET source=? WHERE id=?", array($source, $this->id));
|
||||
}
|
||||
|
||||
|
||||
public function is_locked() {
|
||||
return ($this->locked === true || $this->locked == "Y");
|
||||
}
|
||||
public function set_locked($tf) {
|
||||
global $database;
|
||||
$ln = $tf ? "Y" : "N";
|
||||
$sln = $database->engine->scoreql_to_sql("SCORE_BOOL_$ln");
|
||||
$sln = str_replace("'", "", $sln);
|
||||
$sln = str_replace('"', "", $sln);
|
||||
$database->execute("UPDATE images SET locked=? WHERE id=?", array($sln, $this->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all tags from this image.
|
||||
*
|
||||
|
|
|
@ -38,6 +38,23 @@ class TagSetEvent extends Event {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* LockSetEvent:
|
||||
* $image_id
|
||||
* $locked
|
||||
*
|
||||
*/
|
||||
class LockSetEvent extends Event {
|
||||
var $image;
|
||||
var $locked;
|
||||
|
||||
public function LockSetEvent(Image $image, $locked) {
|
||||
assert(is_bool($locked));
|
||||
$this->image = $image;
|
||||
$this->locked = $locked;
|
||||
}
|
||||
}
|
||||
|
||||
class TagEdit implements Extension {
|
||||
var $theme;
|
||||
|
||||
|
@ -58,23 +75,37 @@ class TagEdit implements Extension {
|
|||
}
|
||||
|
||||
if($event instanceof ImageInfoSetEvent) {
|
||||
if($this->can_tag()) {
|
||||
if($this->can_tag($event->image)) {
|
||||
send_event(new TagSetEvent($event->image, $_POST['tag_edit__tags']));
|
||||
if($this->can_source()) {
|
||||
if($this->can_source($event->image)) {
|
||||
send_event(new SourceSetEvent($event->image, $_POST['tag_edit__source']));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->theme->display_error($page, "Error", "Anonymous tag editing is disabled");
|
||||
}
|
||||
if($user->is_admin()) {
|
||||
send_event(new LockSetEvent($event->image, $_POST['tag_edit__locked']=="on"));
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof TagSetEvent) {
|
||||
$event->image->set_tags($event->tags);
|
||||
if($user->is_admin() || !$event->image->is_locked()) {
|
||||
$event->image->set_tags($event->tags);
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof SourceSetEvent) {
|
||||
$event->image->set_source($event->source);
|
||||
if($user->is_admin() || !$event->image->is_locked()) {
|
||||
$event->image->set_source($event->source);
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof LockSetEvent) {
|
||||
if($user->is_admin()) {
|
||||
log_debug("tag_edit", "Setting Image #{$event->image->id} lock to: {$event->locked}");
|
||||
$event->image->set_locked($event->locked);
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof ImageDeletionEvent) {
|
||||
|
@ -91,12 +122,15 @@ class TagEdit implements Extension {
|
|||
}
|
||||
|
||||
if($event instanceof ImageInfoBoxBuildingEvent) {
|
||||
if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
|
||||
if($this->can_tag($event->image)) {
|
||||
$event->add_part($this->theme->get_tag_editor_html($event->image), 40);
|
||||
}
|
||||
if($config->get_bool("source_edit_anon") || !$user->is_anonymous()) {
|
||||
if($this->can_source($event->image)) {
|
||||
$event->add_part($this->theme->get_source_editor_html($event->image), 41);
|
||||
}
|
||||
if($user->is_admin()) {
|
||||
$event->add_part($this->theme->get_lock_editor_html($event->image), 42);
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof SetupBuildingEvent) {
|
||||
|
@ -108,14 +142,20 @@ class TagEdit implements Extension {
|
|||
}
|
||||
|
||||
|
||||
private function can_tag() {
|
||||
private function can_tag($image) {
|
||||
global $config, $user;
|
||||
return $config->get_bool("tag_edit_anon") || !$user->is_anonymous();
|
||||
return (
|
||||
($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) &&
|
||||
($user->is_admin() || !$image->is_locked())
|
||||
);
|
||||
}
|
||||
|
||||
private function can_source() {
|
||||
private function can_source($image) {
|
||||
global $config, $user;
|
||||
return $config->get_bool("source_edit_anon") || !$user->is_anonymous();
|
||||
return (
|
||||
($config->get_bool("source_edit_anon") || !$user->is_anonymous()) &&
|
||||
($user->is_admin() || !$image->is_locked())
|
||||
);
|
||||
}
|
||||
|
||||
private function mass_tag_edit($search, $replace) {
|
||||
|
|
|
@ -27,5 +27,10 @@ class TagEditTheme extends Themelet {
|
|||
$h_source = html_escape($image->get_source());
|
||||
return "<tr><td>Source</td><td><input type='text' name='tag_edit__source' value='$h_source'></td></tr>";
|
||||
}
|
||||
|
||||
public function get_lock_editor_html(Image $image) {
|
||||
$h_locked = $image->is_locked() ? " checked" : "";
|
||||
return "<tr><td>Locked</td><td><input type='checkbox' name='tag_edit__locked'$h_locked></td></tr>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -101,7 +101,7 @@ class ViewImageTheme extends Themelet {
|
|||
}
|
||||
|
||||
protected function build_image_editor(Image $image, $editor_parts) {
|
||||
if(count($editor_parts) == 0) return "";
|
||||
if(count($editor_parts) == 0) return ($image->is_locked() ? "<br>[Image Locked]" : "");
|
||||
|
||||
if(isset($_GET['search'])) {$h_query = "search=".url_escape($_GET['search']);}
|
||||
else {$h_query = "";}
|
||||
|
|
Reference in a new issue