예제 #1
0
파일: art.php 프로젝트: 4otaku/4otaku
 public function process()
 {
     $image = $this->get_file($this->get('image'), 'Пропущено обязательное поле: image', 'Не удалось скачать картинку с указнного адреса');
     $extension = $this->get_extension($image);
     $filename = 'image.' . $extension;
     try {
         $uploader = new Transform_Upload_Art($image, $filename);
         $image = $uploader->process_file();
     } catch (Error_Upload $e) {
         throw new Error_Api($e->getMessage(), $e->getCode());
     }
     $data = array('images' => array(array('md5' => $image['md5'], 'thumb' => $image['thumb'], 'extension' => $image['extension'], 'resized' => $image['resized'], 'animated' => $image['animated'])), 'tag' => (array) $this->get('tag'), 'category' => $this->transform_category(), 'author' => implode(',', (array) $this->get('author')), 'source' => (string) $this->get('source'));
     try {
         $worker = new Create_Art(new Action_Reader_Inner($data), new Action_Writer_Inner());
         $worker->main();
         $result = $worker->process_result();
     } catch (Error_Create $e) {
         throw new Error_Api($e->getMessage(), $e->getCode());
     }
     if ($result->get_error()) {
         throw new Error_Api($result->get_message(), $result->get_error());
     }
     $success = $result->get_success();
     $this->set_success($success);
     if ($success) {
         $this->add_answer('id', $result->get_data('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
파일: wrapper.php 프로젝트: 4otaku/4otaku
	function resize_arts() {
		global $def;

		$arts = obj::db()->sql('select id, md5, extension from art where locate("|need_resize|",tag)');

		if (!empty($arts)) {

			foreach ($arts as $art) {
				$name = $art['md5'].'.'.$art['extension'];
				$path = ROOT_DIR.SL.'images'.SL.'booru'.SL.'full'.SL.$name;

				$worker = new Transform_Upload_Art($path, $name);

				$resized = $worker->resize();

				obj::db()->sql('update art set resized="'.$resized.'", tag=replace(tag,"|need_resize|","|") where id='.$art['id'],0);
			}
		}
	}