Example #1
0
 public function process()
 {
     $id = $this->get('id');
     $state = (string) $this->get('state');
     if (!$this->is_moderator()) {
         throw new ErrorApi(ErrorApi::INSUFFICIENT_RIGHTS);
     }
     if (empty($id) || empty($state)) {
         throw new ErrorApi(ErrorApi::MISSING_INPUT);
     }
     $state = Meta::parse($state);
     if (empty($state)) {
         throw new ErrorApi(ErrorApi::INCORRECT_INPUT);
     }
     $this->db->update('art', array('sortdate' => $this->db->unix_to_date()), $id);
     $this->remove_meta(Meta::ART, $id, Meta::STATE, Meta::STATE_APPROVED);
     $this->remove_meta(Meta::ART, $id, Meta::STATE, Meta::STATE_UNAPPROVED);
     $this->remove_meta(Meta::ART, $id, Meta::STATE, Meta::STATE_DISAPPROVED);
     $this->remove_meta(Meta::ART, $id, Meta::STATE, Meta::STATE_DELETED);
     $this->add_meta(Meta::ART, $id, Meta::STATE, $state);
     $cache = new \Memcached("access_checker");
     $cache->addServer("localhost", 11211);
     $cache->delete('is_pic_safe_' . $this->db->get_field('art', 'md5', $id));
     $this->set_success(true);
 }
Example #2
0
File: Art.php Project: 4otaku/api
 protected function get_filters($params)
 {
     if (!empty($params['filter']) && is_array($params['filter'])) {
         $this->parse_date_filters($params['filter'], array('date'));
         foreach ($params['filter'] as &$filter) {
             if (!isset($filter['name']) || !isset($filter['type']) || !isset($filter['value'])) {
                 continue;
             }
             if (in_array($filter['name'], $this->local_filtered_variables) && Meta::parse($filter['type'])) {
                 if ($filter['name'] == 'date') {
                     $filter['name'] = 'sortdate';
                     $filter['value'] = $this->db->unix_to_date($filter['value']);
                 }
                 if ($filter['name'] == 'user') {
                     $filter['name'] = 'id_user';
                     $value = $this->db->get_field('user', 'id', 'login = ?', $filter['value']);
                     if (empty($value) && Meta::parse($filter['type']) == Meta::IS) {
                         throw new ErrorApi('Пользователя ' . $filter['value'] . ' не существует.', ErrorApi::INCORRECT_INPUT);
                     }
                     $filter['value'] = $value;
                 }
                 $this->local_filters[] = $filter['name'] . ' ' . Meta::parse($filter['type']) . ' ?';
                 $this->local_filter_vars[] = $filter['value'];
                 $filter = null;
             }
         }
         unset($filter);
     }
     return parent::get_filters($params);
 }
Example #3
0
File: Pool.php Project: 4otaku/api
 public function process()
 {
     if ($this->table === null) {
         $this->add_error(ErrorApi::INCORRECT_URL);
         return;
     }
     $ids = (array) $this->get('id');
     foreach ($ids as &$id) {
         if (!is_numeric($id)) {
             $id = null;
         }
     }
     $ids = array_filter($ids);
     if (empty($ids)) {
         $this->add_error(ErrorApi::INCORRECT_INPUT);
         return;
     }
     $data = $this->get_data($ids);
     if ($this->get('add_tags')) {
         $tags = $this->db->join('art_tag', 'at.id = m.meta')->join($this->table . '_tag_count', 'at.id = id_tag')->get_table('meta', array('m.id_item', 'at.*', 'count'), 'm.item_type = ' . Meta::parse(strtoupper($this->table)) . ' and m.meta_type = ' . Meta::ART_TAG . ' and ' . $this->db->array_in('m.id_item', $ids), $ids);
         foreach ($data as &$item) {
             $item['tag'] = array();
         }
         unset($item);
         foreach ($tags as $tag) {
             $link =& $data[$tag['id_item']]['tag'];
             unset($tag['id_item']);
             unset($tag['id']);
             $link[] = $tag;
         }
     }
     $this->add_answer('data', $data);
     $this->set_success(true);
 }
Example #4
0
File: Pool.php Project: 4otaku/api
 public function process()
 {
     $id = $this->get('id');
     if (!$this->is_moderator() && $this->get('remove')) {
         throw new ErrorApi(ErrorApi::INSUFFICIENT_RIGHTS);
     }
     if (empty($id) || !$this->have_changes()) {
         throw new ErrorApi(ErrorApi::MISSING_INPUT);
     }
     if (!$this->check_pool($id)) {
         throw new ErrorApi(ErrorApi::INCORRECT_INPUT);
     }
     $meta = Meta::parse($this->table);
     foreach ((array) $this->get('add') as $item) {
         if (!$this->in_pool($id, $item['id'])) {
             if ($this->add_item($id, $item)) {
                 $this->add_meta(Meta::ART, (int) $item['id'], $meta, $id);
             }
         }
     }
     foreach ((array) $this->get('remove') as $item) {
         if ($this->remove_item($id, (int) $item)) {
             $this->remove_meta(Meta::ART, (int) $item, $meta, $id);
         }
     }
     if ($this->get('title')) {
         $this->db->update($this->table, array('title' => $this->get('title')), $id);
     }
     if ($this->get('text') !== null) {
         $this->db->update($this->table, array('text' => $this->get('text')), $id);
     }
     $this->set_success(true);
 }
Example #5
0
 protected function get_filters()
 {
     $filters = (array) $this->get('filter');
     foreach ($filters as $key => &$filter) {
         $filter = (array) $filter;
         if (!in_array($key, $this->legal_filter)) {
             $filter = null;
         }
         if ($key == 'area') {
             foreach ($filter as &$item) {
                 if (!is_numeric($item)) {
                     $item = Meta::parse($item);
                 }
             }
             unset($item);
             $filter = array_filter($filter);
         }
     }
     unset($filter);
     return array_filter($filters);
 }