예제 #1
0
파일: art.php 프로젝트: 4otaku/4otaku
 public function main()
 {
     $post = $this->correct_main_data($this->reader->get_data());
     if (!is_array($post['images'])) {
         $this->writer->set_message('Не все обязательные поля заполнены.')->set_error(Error_Create::MISSING_INPUT);
         return;
     }
     if (query::$url[2] == 'pool' && is_numeric(query::$url[3])) {
         $pool = new Model_Art_Pool(query::$url[3]);
         if (!$pool->correct_password($post['password'])) {
             $this->writer->set_message('Неправильный пароль от группы.')->set_error(Error_Create::INCORRECT_INPUT);
             return;
         }
     } else {
         $pool = false;
     }
     $worker = new Transform_Meta();
     $parsed_tags = $worker->parse_array($post['tag']);
     $tags = $worker->add_tags($parsed_tags);
     $category = $worker->category($post['category']);
     $parsed_author = $worker->parse($post['author'], def::user('author'));
     $author = $worker->author($parsed_author);
     $similar = $this->check_similar($post['images']);
     foreach ($post['images'] as $image_key => $image) {
         if (empty($image['tags'])) {
             $local_tags = $tags;
         } else {
             $parsed_tags = $worker->parse_array($image['tags']);
             $local_tags = $worker->add_tags($parsed_tags);
         }
         $art = new Model_Art();
         $art->set_array(array('md5' => $image['md5'], 'thumb' => $image['thumb'], 'extension' => $image['extension'], 'resized' => $image['resized'], 'animated' => (int) $image['animated'], 'author' => $author, 'category' => $category, 'tag' => $local_tags, 'source' => $post['source']));
         $art->insert();
         if (!empty($similar[$image_key])) {
             foreach ($similar[$image_key] as $item) {
                 $art->add_similar($item);
             }
         }
         if (!empty($pool)) {
             $pool->add_art($art);
         }
         // TODO: перемести input__common::transfer в Model_Common
         if (!empty($post['transfer_to'])) {
             input__common::transfer(array('sure' => 1, 'do' => array('art', 'transfer'), 'where' => $post['transfer_to'], 'id' => $art->get_id()));
         }
     }
     $this->writer->set_success();
     if (count($post['images']) > 1) {
         $this->writer->set_message('Ваши изображения успешно добавлены, и доступны в ' . '<a href="/art/' . def::area(1) . '/">очереди на премодерацию</a>.');
     } else {
         $this->writer->set_message('Ваше изображение успешно добавлено, и доступно по адресу ' . '<a href="/art/' . $art->get_id() . '/">http://4otaku.org/art/' . $art->get_id() . '/</a> или в ' . '<a href="/art/' . def::area(1) . '/">очереди на премодерацию</a>.')->set_param('id', $art->get_id());
     }
 }
예제 #2
0
 public function parse_images()
 {
     $params = array('pack_art', $this->id);
     $art = Database::get_full_table('misc', 'type = ? and data1 = ? order by data4 limit ' . rand(4, 9), $params);
     $total = Database::get_field('misc', 'data4', 'type = ? and data2 = ?', array('pack_status', $this->id));
     $current_order = Database::get_field('art_in_pack', 'max(`order`)', 'pack_id = ?', $this->id);
     $next_order = !is_numeric($current_order) ? 0 : $current_order + 1;
     if (is_array($art)) {
         $insert_in_pack = array();
         foreach ($art as $one) {
             Database::delete('misc', 'type = ? and id = ?', array('pack_art', $one['id']));
             try {
                 $worker = new Transform_Upload_Art($one['data2'], $one['data4']);
                 $data = $worker->process_file();
                 $art = new Model_Art(array('md5' => $data['md5'], 'thumb' => $data['thumb'], 'extension' => $data['extension'], 'resized' => $data['resized'], 'animated' => $data['animated'], 'author' => '|', 'category' => '|nsfw|game_cg|', 'tag' => '|prostavte_tegi|', 'area' => 'cg'));
                 $art->insert();
             } catch (Error $e) {
                 $data = array();
                 if ($e->getCode() == Error_Upload::ALREADY_EXISTS) {
                     $art = new Model_Art($e->getMessage());
                     if ($art['area'] == 'deleted') {
                         $art['area'] = 'cg';
                         $art->commit();
                     }
                 } else {
                     continue;
                 }
             }
             $insert_in_pack[] = array($art->get_id(), $this->id, $next_order, pathinfo($one['data2'], PATHINFO_BASENAME));
             $next_order++;
         }
         Database::bulk_insert('art_in_pack', $insert_in_pack, array('art_id', 'pack_id', 'order', 'filename'));
     }
     if ($count = Database::get_count('misc', 'type = ? and data1 = ?', array('pack_art', $this->id))) {
         Database::update('misc', array('data3' => $total - $count), 'type = ? and data2 = ?', array('pack_status', $this->id));
     } else {
         Database::update('misc', array('data1' => 'done'), 'type = ? and data2 = ?', array('pack_status', $this->id));
         Database::update('art_pack', array('weight' => 0), $this->id);
     }
 }
예제 #3
0
파일: art.php 프로젝트: 4otaku/4otaku
 protected function image_variation($data)
 {
     $id = (int) $data['id'];
     $images = $data['image_variation'];
     $main_image = array_shift($images);
     if (empty($id) || empty($main_image)) {
         return;
     }
     $art = new Model_Art($id);
     $art->set_array(array('animated' => $main_image['animated'], 'extension' => $main_image['extension'], 'md5' => $main_image['md5'], 'resized' => $main_image['resized'], 'thumb' => $main_image['thumb']));
     if ($main_image['resized'] == 1) {
         $art->calculate_resize();
     }
     $art->commit();
     $art->clear_similar();
     foreach ($images as $image) {
         $art->add_similar($image);
     }
 }