コード例 #1
0
ファイル: Abstract.php プロジェクト: 4otaku/api
 public function process()
 {
     $process = array();
     $links = (array) $this->get('file');
     foreach ($links as $key => $link) {
         $ret = filter_var($link, FILTER_VALIDATE_URL);
         if ($ret === false) {
             unset($links[$key]);
             $this->answers[] = array('error' => true, 'error_code' => Error::INCORRECT_URL, 'error_text' => $link . ' is not correct url');
         }
     }
     if (!empty($links)) {
         $limit = Config::getInstance()->get('art', 'filesize');
         $worker = new Http();
         $worker->enable_limit($limit)->add($links)->exec();
         foreach ($links as $link) {
             $file = $worker->get($link);
             $headers = $worker->get_headers($link);
             if (!$file) {
                 $this->answers[] = array('error' => true, 'error_code' => Error::INCORRECT_URL, 'error_text' => $link . ' is not responding');
             } elseif (!isset($headers['Content-Length']) || $headers['Content-Length'] > $limit) {
                 $this->answers[] = array('error' => true, 'error_code' => ErrorUpload::FILE_TOO_LARGE, 'error_text' => $link . ' is too large');
             } else {
                 $name = explode('?', basename($link));
                 $process[] = array('name' => $name[0] ? $name[0] : 'tmp', 'file' => $file);
             }
         }
     }
     foreach ($_FILES as $file) {
         if (is_array($file['tmp_name'])) {
             foreach ($file['tmp_name'] as $key => $tmp_name) {
                 $process[] = array('name' => $file['name'][$key], 'file' => $tmp_name);
             }
         } else {
             $process[] = array('name' => $file['name'], 'file' => $file['tmp_name']);
         }
     }
     foreach ($process as $item) {
         $this->process_file($item['file'], $item['name']);
     }
     if ($this->have_successful) {
         $this->set_success(true);
     }
     $this->add_answer('files', $this->answers);
 }
コード例 #2
0
ファイル: Fetcher.php プロジェクト: 4otaku/api
 protected function fetchMeta($id, $md5)
 {
     $response = Http::download("http://danbooru.donmai.us/posts.json?limit=1&tags=md5:{$md5}");
     $response = json_decode($response, true);
     if (empty($response)) {
         throw new Error("Не удалось найти арт с хешем {$md5} на Danbooru.");
     }
     $art = reset($response);
     $tags = array_filter(preg_split('/\\s+/', $art["tag_string"]));
     if ($art["rating"] != "s") {
         $tags[] = "nsfw";
     }
     $this->setTags($id, $tags);
     $request = new ApiRequestInner(array('id' => $id, 'add_tags' => 1));
     $worker = new ApiReadArt($request);
     $worker->process_request();
     $response = $worker->get_response();
     $existing = $response['data'][0];
     if (!$existing['source']) {
         $source = array();
         if (!empty($art['pixiv_id'])) {
             $source[] = 'http://www.pixiv.net/member_illust.php?mode=medium&illust_id=' . $art['pixiv_id'];
         } elseif (!empty($art['source'])) {
             $source[] = $art['source'];
         }
         $source[] = 'https://danbooru.donmai.us/posts/' . $art['id'];
         $this->setSource($id, implode(" ", $source));
     }
     $uncolored_tags = array_map(function ($tag) {
         return $tag['name'];
     }, array_filter($existing['tag'], function ($tag) {
         return empty($tag['color']);
     }));
     $markers = array('tag_string_artist' => 'AA0000', 'tag_string_character' => '00AA00', 'tag_string_copyright' => 'AA00AA');
     foreach ($markers as $key => $color) {
         if (empty($art[$key])) {
             continue;
         }
         $tags = array_filter(preg_split('/\\s+/', $art[$key]));
         foreach ($tags as $tag) {
             if (!in_array($tag, $uncolored_tags)) {
                 continue;
             }
             $this->setTagColor($tag, $color);
         }
     }
 }
コード例 #3
0
ファイル: boot.php プロジェクト: 4otaku/art
use Otaku\Framework\Http;
use Otaku\Framework\Session;
use Otaku\Framework\Query;
use Otaku\Art\Module\Main as Module;
include_once 'framework/init.php';
define('API', ROOT_DIR . SL . 'api' . SL);
define('API_LIBS', API . 'libs' . SL);
define('API_IMAGES', API . 'images' . SL);
new Autoload(array('Art' => LIBS, 'Api' => API_LIBS, 'Framework' => FRAMEWORK_LIBS), FRAMEWORK_EXTERNAL);
mb_internal_encoding('UTF-8');
$config = Config::getInstance();
$config->parse(CONFIG . SL . 'define.ini', true);
$config->parse(CONFIG . SL . 'settings.ini');
$config->add(['safe' => ['mode' => $safeMode]], true);
$domain = $config->get('site', 'domain');
if ($domain && $domain != $_SERVER['SERVER_NAME']) {
    $url = 'http://' . $domain . $_SERVER['REQUEST_URI'];
    Http::redirect($url, true);
}
$session = Session::getInstance();
$session->init();
$config->add($session->get_data());
$query = new Query($_SERVER['REQUEST_URI'], array_replace($_POST, $_GET));
unset($_GET, $_POST);
\RainTPL::configure('tpl_dir', TPL . SL);
\RainTPL::configure('cache_dir', CACHE . SL . 'tpl' . SL);
\RainTPL::configure('path_replace', false);
$module = new Module($query);
$request = $module->gather_request();
$request->perform();
$module->dispatch();
コード例 #4
0
ファイル: Request.php プロジェクト: 4otaku/framework
	public function do_request($data)
	{
		$config = Config::getInstance();
		$url = $config->get('api', 'url');
		$api = $this->get_api();

		if (!$api) {
			return;
		}

		if (!$config->get('api', 'inner')) {
			$url .= '/' . str_replace('_', '/', $api);

			if (function_exists('igbinary_serialize')) {
				$data['format'] = 'igbinary';
				$data = igbinary_serialize($data);
				$url .= '?f=igbinary';
			} else {
				$data['format'] = 'json';
				$data = json_encode($data, JSON_NUMERIC_CHECK);
				$url .= '?f=json';
			}

			$response = Http::post($url, $data);

			if (empty($response)) {
				throw new Error('No response: ' . $url);
			}

			if (function_exists('igbinary_unserialize')) {
				$response = igbinary_unserialize($response);
			} else {
				$response = json_decode($response, true);
			}
		} else {
			$class = 'Otaku\Api\Api' . implode('', array_map('ucfirst',
					explode('_', $api)));
			$api_request = new ApiRequestInner($data);
			$worker = new $class($api_request);
			$response = $worker->process_request()->get_response();
		}

		$this->process_response($response);
	}
コード例 #5
0
ファイル: Http.php プロジェクト: 4otaku/framework
	public static function post ($url, $data) {
		$worker = new Http(array(
			CURLOPT_POST => 1,
			CURLOPT_POSTFIELDS => $data
		), array(
			'Content-Type' => 'text/plain'
		));
		$worker->add($url)->exec();

		return $worker->get($url);
	}