Exemple #1
0
 public function process()
 {
     $id = $this->get('id');
     if (empty($id)) {
         throw new ErrorApi(ErrorApi::MISSING_INPUT);
     }
     if (!$this->is_moderator()) {
         throw new ErrorApi(ErrorApi::INSUFFICIENT_RIGHTS);
     }
     $this->db->begin();
     $types = array(Meta::ART, Meta::ART_PACK, Meta::ART_GROUP, Meta::ART_MANGA, Meta::ART_ARTIST);
     foreach ($types as $type) {
         $item_ids = $this->db->get_vector('meta', 'id_item', 'item_type = ? and meta_type = ? and meta = ?', array($type, Meta::ART_TAG, $id), false);
         if (!empty($item_ids)) {
             $this->db->update('meta', array('meta' => DatabaseAction::get(DatabaseAction::DECREMENT)), 'item_type = ? and meta_type = ? and ' . $this->db->array_in('id_item', $item_ids), array_merge(array($type, Meta::TAG_COUNT), $item_ids));
         }
         $this->db->delete('meta', 'item_type = ? and meta_type = ? and meta = ?', array($type, Meta::ART_TAG, $id));
     }
     $this->db->delete('art_tag_count', 'id_tag = ?', $id);
     $this->db->delete('art_artist_tag_count', 'id_tag = ?', $id);
     $this->db->delete('art_pack_tag_count', 'id_tag = ?', $id);
     $this->db->delete('art_group_tag_count', 'id_tag = ?', $id);
     $this->db->delete('art_manga_tag_count', 'id_tag = ?', $id);
     $this->db->delete('art_tag_variant', 'id_tag = ?', $id);
     $this->db->delete('art_tag', $id);
     $this->db->commit();
 }
Exemple #2
0
 public function process()
 {
     $id_item = (int) $this->get('id_item');
     $area = Meta::parse($this->get('area'));
     $parent = (int) $this->get('parent');
     $name = (string) $this->get('name');
     $mail = (string) $this->get('mail');
     $text = (string) $this->get('text');
     $text = trim($text);
     if (empty($text) || empty($id_item) || empty($area)) {
         throw new ErrorApi(ErrorApi::MISSING_INPUT);
     }
     if (!empty($parent) && !$this->db->get_count('comment', $parent)) {
         throw new ErrorApi(ErrorApi::COMMENT_PARENT_DO_NOT_EXIST);
     }
     if ($parent) {
         $root = $this->db->get_field('comment', 'rootparent', $parent);
         if (!$root) {
             $root = $parent;
         }
     } else {
         $root = 0;
     }
     $name = $name ? $name : $this->db->get_field('user', 'login', 1);
     $mail = $mail ? $mail : $this->db->get_field('user', 'email', 1);
     $time = time();
     $this->db->insert('comment', array('parent' => $parent, 'rootparent' => $root, 'id_item' => $id_item, 'area' => $area, 'username' => $name, 'email' => $mail, 'ip' => ip2long($this->get_ip()), 'cookie' => $this->get_cookie(), 'text' => $text, 'sortdate' => $this->db->unix_to_date($time)));
     $this->db->update('meta', array('meta' => DatabaseAction::get(DatabaseAction::INCREMENT)), 'item_type = ? and id_item = ? and meta_type = ?', array(Meta::ART, $id_item, Meta::COMMENT_COUNT));
     $this->add_single_meta(Meta::ART, $id_item, Meta::COMMENT_DATE, $time);
     $this->set_success(true);
 }
Exemple #3
0
 protected function do_sort($id, $order)
 {
     $this->db->begin();
     $id_field = $this->get_id_field();
     $old_order = $this->db->order('order', 'asc')->get_vector($this->table . '_item', array('order', 'id_art'), $id_field . ' = ?', $id);
     $max = max(array_keys($old_order));
     $old_keys = array();
     foreach ($order as $art_id) {
         $old_key = array_search($art_id, $old_order);
         if ($old_key === false) {
             $old_key = $max + 1;
             $max++;
         }
         $old_keys[] = $old_key;
     }
     sort($old_keys);
     foreach ($order as $art_id) {
         $old_order[array_shift($old_keys)] = $art_id;
     }
     $this->db->update($this->table . '_item', array('order' => DatabaseAction::get(DatabaseAction::ADD, $max)), $id_field . ' = ?', $id);
     foreach ($old_order as $key => $art_id) {
         $this->db->replace($this->table . '_item', array('order' => $key, $id_field => $id, 'id_art' => $art_id), array($id_field, 'id_art'));
     }
     $this->db->commit();
 }
Exemple #4
0
 public function process()
 {
     $id = $this->get('id');
     if (empty($id)) {
         throw new ErrorApi(ErrorApi::MISSING_INPUT);
     }
     if (!$this->is_moderator()) {
         throw new ErrorApi(ErrorApi::INSUFFICIENT_RIGHTS);
     }
     $parent = $this->db->get_field('comment', 'parent', $id);
     $this->db->begin();
     $this->db->update('comment', array('deleted' => 1), $id);
     $this->db->update('comment', array('parent' => $parent), 'parent = ?', $id);
     if (!$parent) {
         $comments = $this->db->get_vector('comment', array('id', 'parent', 'rootparent'), 'rootparent = ? and deleted = 0', $id);
         foreach ($comments as $comment_id => $one) {
             $temp = $one;
             $i = 0;
             $rootparent = 0;
             while ($temp['parent'] && $i < 20) {
                 $i++;
                 $rootparent = $temp['parent'];
                 $temp = $comments[$temp['parent']];
             }
             $this->db->update('comment', array('rootparent' => $rootparent), $comment_id);
         }
     }
     $data = $this->db->get_row('comment', array('id_item', 'area'), $id);
     $this->db->update('meta', array('meta' => DatabaseAction::get(DatabaseAction::DECREMENT)), 'item_type = ? and id_item = ? and meta_type = ?', array($data['area'], $data['id_item'], Meta::COMMENT_COUNT));
     $time = $this->db->order('sortdate')->get_field('comment', 'sortdate', 'area = ? and id_item = ? and deleted = 0', array($data['area'], $data['id_item']));
     $this->db->update('meta', array('meta' => strtotime($time)), 'item_type = ? and id_item = ? and meta_type = ?', array($data['area'], $data['id_item'], Meta::COMMENT_DATE));
     $this->db->commit();
     $this->set_success(true);
 }
Exemple #5
0
 public function process()
 {
     $id = (int) $this->get('id');
     $approve = $this->get('approve');
     $cookie = $this->get_cookie(true);
     $ip = ip2long($this->get_ip(true));
     if (empty($id) || $approve === null || empty($cookie) || empty($ip)) {
         throw new ErrorApi(ErrorApi::MISSING_INPUT);
     }
     $test = $this->db->get_count('art_rating', 'id_art = ? and (cookie = ? or ip = ?)', array($id, $cookie, $ip));
     if ($test) {
         throw new ErrorApi('Вы уже голосовали за этот арт', ErrorApi::INCORRECT_INPUT);
     }
     $this->db->insert('art_rating', array('id_art' => $id, 'cookie' => $cookie, 'ip' => $ip, 'rating' => $approve ? 1 : -1));
     $this->db->update('meta', array('meta' => DatabaseAction::get($approve ? DatabaseAction::INCREMENT : DatabaseAction::DECREMENT)), 'item_type = ? and id_item = ? and meta_type = ?', array(Meta::ART, $id, Meta::ART_RATING));
     $this->set_success(true);
 }
Exemple #6
0
 protected function after_remove($item_id, $tag_id)
 {
     $this->db->update($this->count_table, array('count' => DatabaseAction::get(DatabaseAction::DECREMENT)), 'id_tag = ?', $tag_id);
 }
Exemple #7
0
 public function process()
 {
     $id = (int) $this->get('id');
     $name = (string) $this->get('name');
     $variant = $this->get('variant');
     $color = $this->get('color');
     $merge = (int) $this->get('merge');
     $no_changes = empty($merge) && $color === null && $variant === null && empty($name);
     if (empty($id) || $no_changes) {
         throw new ErrorApi(ErrorApi::MISSING_INPUT);
     }
     if ($variant !== null) {
         $this->db->delete('art_tag_variant', 'id_tag = ?', $id);
         $variant = empty($variant) ? array() : (array) $variant;
         foreach ((array) $variant as $item) {
             $item = (string) $item;
             if ($this->db->get_count('art_tag', 'name = ?', $item) || $this->db->get_count('art_tag_variant', 'name = ?', $item)) {
                 $this->add_error(ErrorApi::TAG_EXISTS);
             } else {
                 $this->db->insert('art_tag_variant', array('id_tag' => $id, 'name' => $item));
             }
         }
     }
     if ($color !== null) {
         $color = preg_replace('/[^a-f\\d]/ui', '', (string) $color);
         $color = substr($color, 0, 6);
         $this->db->update('art_tag', array('color' => $color), $id);
     }
     if (!empty($name)) {
         if ($this->db->get_count('art_tag_variant', 'name = ?', $name)) {
             $this->add_error(ErrorApi::TAG_EXISTS);
         } else {
             $success = $this->db->update('art_tag', array('name' => $name), $id);
             if (!$success) {
                 $this->add_error(ErrorApi::TAG_EXISTS);
             }
         }
     }
     if (!empty($merge)) {
         $tag = $this->db->get_full_row('art_tag', $merge);
         if (!$tag) {
             $this->add_error(ErrorApi::INCORRECT_INPUT);
         } else {
             if (!$this->is_moderator()) {
                 $this->add_error(ErrorApi::INSUFFICIENT_RIGHTS);
             } else {
                 $this->db->update('art_tag_variant', array('id_tag' => $id), 'id_tag = ?', $merge);
                 $this->db->insert('art_tag_variant', array('id_tag' => $id, 'name' => $tag['name']));
                 $this->db->delete('art_tag', $merge);
                 $arts_first = $this->db->get_vector('meta', 'id_item', 'item_type = ? and meta_type = ? and meta = ?', array(Meta::ART, Meta::ART_TAG, $id), false);
                 $arts_second = $this->db->get_vector('meta', 'id_item', 'item_type = ? and meta_type = ? and meta = ?', array(Meta::ART, Meta::ART_TAG, $merge), false);
                 $delete = array_intersect($arts_first, $arts_second);
                 $this->db->delete('meta', 'item_type = ? and meta_type = ? and meta = ? and ' . $this->db->array_in('id_item', $delete), array_merge(array(Meta::ART, Meta::ART_TAG, $merge), $delete));
                 $this->db->update('meta', array('meta' => DatabaseAction::get(DatabaseAction::DECREMENT)), 'item_type = ? and meta_type = ? and ' . $this->db->array_in('id_item', $delete), array_merge(array(Meta::ART, Meta::TAG_COUNT), $delete));
                 $update = array_diff($arts_second, $arts_first);
                 $this->db->update('meta', array('meta' => $id), 'item_type = ? and meta_type = ? and meta = ? and ' . $this->db->array_in('id_item', $update), array_merge(array(Meta::ART, Meta::ART_TAG, $merge), $update));
             }
         }
     }
     $this->set_success(true);
 }