protected function get_params(Query $query) { $plugins = Database::get_vector('plugin', array('id', 'filename', 'css', 'js', 'script')); $enabled = (array) Config::getInstance()->get('plugins'); $js = []; $css = []; $script = []; foreach ($plugins as $id => $plugin) { if (empty($enabled[$id])) { continue; } if ($plugin['js']) { $js[] = $plugin['filename']; } if ($plugin['css']) { $css[] = $plugin['filename']; } if ($plugin['script']) { $script[] = file_get_contents(JS . SL . 'plugins' . SL . $plugin['filename'] . '.head.js'); } } $this->set_param('plugin_css', $this->get_meta_address('css', $css, 'plugins')); $this->set_param('plugin_js', $this->get_meta_address('js', $js, 'plugins')); $this->set_param('plugin_script', $script); }
protected function recieve_succesful($data) { $query = $this->get_query()->to_url_array(); $pos = ($this->get_query()->page() - 1) * $this->get_query()->per_page(); foreach ($data as &$item) { $pos++; $item['query'] = implode('&', array_merge(array('pos=' . $pos), $query)); } unset($item); $temp_tags = array(); $count = array(); foreach ($data as $item) { foreach ($item['tag'] as $tag) { $temp_tags[$tag['name']] = $tag; $count[$tag['name']] = $tag['count']; } } arsort($count); $max = Config::getInstance()->get('sidebar', 'tags'); $count = array_slice($count, 0, $max, true); $tags = array(); foreach ($count as $key => $count) { $tags[] = $temp_tags[$key]; } $this->modules['list']->recieve_data($data); $this->modules['tags']->recieve_data($tags); }
public function get_cookie($strict = false) { $name = Config::getInstance()->get('cookie', 'name', false); if ($name && isset($_COOKIE[$name])) { return $_COOKIE[$name]; } return $strict ? null : $this->get('cookie'); }
public function __construct(Query $query, $disabled = false) { $config = Config::getInstance()->get('comment'); $this->reverse = (bool) $config['reverse']; $this->per_page = (int) $config['per_page']; $this->is_tree = (bool) $config['tree']; parent::__construct($query, $disabled); }
protected function get_params(Query $query) { $this->set_param('query', $query->to_url_string()); $this->set_param('start', max(1, $query->get('start'))); $this->set_param('auto', Config::getInstance()->get('slideshow', 'auto')); $delay = Config::getInstance()->get('slideshow', 'delay'); if ($delay < 10) { $delay = '0' . $delay; } $this->set_param('delay', $delay); }
public function recieve_data($response) { $url = Config::getInstance()->get('api', 'image_url'); foreach ($response['files'] as $item) { if (empty($item['error'])) { $this->data[] = ['name' => $item['name'], 'size' => $item['weight'], 'url' => $url . $item['image'], 'thumbnail_url' => $url . $item['thumbnail'], 'upload_key' => $item['upload_key'], 'tags' => $this->get_auto_tags($item)]; } else { $this->data[] = ['code' => $item['error_code'], 'error' => $item['error_text']]; } } }
public function recieve_data($data) { $link = $this->get_link($data); if (empty($link)) { return; } $api_url = Config::getInstance()->get('api', 'url'); $prefix = !Config::getInstance()->get('api', 'inner') ? 'http://' . parse_url($api_url, PHP_URL_HOST) . '/' : ROOT_DIR . SL . 'api' . SL; $link = $prefix . $link; if (!file_exists($link)) { return; } $size = filesize($link); $filename = $this->get_filename($link); if (isset($_SERVER['HTTP_RANGE'])) { list($size_unit, $range_orig) = explode('=', $_SERVER['HTTP_RANGE'], 2); if ($size_unit == 'bytes') { list($range, $extra_ranges) = explode(',', $range_orig, 2); } else { $range = '-'; } } else { $range = '-'; } list($seek_start, $seek_end) = explode('-', $range, 2); $seek_end = empty($seek_end) ? ($size - 1) : min(abs(intval($seek_end)), $size - 1); $seek_start = (empty($seek_start) || $seek_end < abs(intval($seek_start))) ? 0 : max(abs(intval($seek_start)), 0); if ($seek_start > 0 || $seek_end < ($size - 1)) { $this->header['status'] = 206; } else { $this->header['status'] = 200; } $this->header['Accept-Ranges'] = 'bytes'; $this->header['Content-Ranges'] = 'bytes '.$seek_start.'-'.$seek_end.'/'.$size; $this->header['Content-Disposition'] = 'attachment; filename="' . $filename . '"'; $this->header['Content-Length'] = $seek_end - $seek_start + 1; $this->link = $link; $this->from = $seek_start; }
public function recieve_data($data) { $data['tip'] = $this->make_tooltip($data); $data['hidden'] = $this->is_filtered($data['tag']); $large = Config::getInstance()->get('art', 'largethumbs') ? 'large' : ''; if (!empty($data['md5'])) { $data['src'] = Config::getInstance()->get('api', 'image_url') . 'art/' . $data['md5'] . '_' . $large . 'thumb.jpg'; } else { $data['src'] = '/images/empty_' . $large . 'pool.jpg'; } parent::recieve_data($data); }
public function get_headers() { $return = $this->headers; $headers = apache_request_headers(); if (isset($headers['Origin'])) { $host = parse_url($headers['Origin'], PHP_URL_HOST); $allow = Config::getInstance()->get('domain', 'allow'); if ($host == $allow || strpos($host, '.' . $allow)) { $return['Access-Control-Allow-Origin'] = $headers['Origin']; } } return $return; }
protected function get_params(Query $query) { $data = Config::getInstance()->get(); if (isset($data['default']['name'])) { $this->set_param('name', $data['default']['name']); } elseif (isset($data['user']['login'])) { $this->set_param('name', $data['user']['login']); } if (isset($data['default']['mail'])) { $this->set_param('mail', $data['default']['mail']); } elseif (isset($data['user']['email'])) { $this->set_param('mail', $data['user']['email']); } $this->set_param('id_item', (int) $query->url(0)); }
protected function check_resize($target) { $config = Config::getInstance(); $resized = false; $this->sizes = $this->worker->get_image_width() . 'x' . $this->worker->get_image_height(); $resize_width = $config->get('art', 'resizewidth') * $config->get('art', 'resizestep'); if ($this->worker->get_image_width() > $resize_width || $this->info[0] > $resize_width) { if ($this->scale($config->get('art', 'resizewidth'), $target, 95, false)) { $resized = true; } } elseif ($this->size > $config->get('art', 'resizeweight')) { if ($this->scale(false, $target, 95, false)) { $resized = true; } } return $resized; }
protected function is_filtered($tags, $strict = false) { $filtered = array(); foreach (Config::getInstance()->get('filter') as $name => $type) { if ($type == 'hide' || $strict && $type == 'remove') { $filtered[] = strtolower($name); } } if ($tags) { foreach ($tags as $tag) { if (in_array(strtolower($tag['name']), $filtered)) { return true; } } } return false; }
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); }
public function recieve_data($data) { $data['hidden'] = empty($data['tag']) ? false : $this->is_filtered($data['tag'], true); $url = Config::getInstance()->get('api', 'image_url'); $resized = Config::getInstance()->get('art', 'resized'); $data['src_resized'] = $url . 'art/' . $data['md5'] . '_resize.jpg'; $data['src_full'] = $url . 'art/' . $data['md5'] . '.' . $data['ext']; $data['src'] = $data['resized'] && $resized ? $data['src_resized'] : $data['src_full']; $data['resized'] = (int) ($data['resized'] && $resized); foreach ($data['translation'] as &$translation) { $translation['id'] = $translation['id_translation']; $translation['id_art'] = $data['id']; $translation['text'] = new Text($translation['text']); $translation['text']->html_escape(); $length = strlen((string) $translation['text']); $translation['width'] = max(100, min(350, $length * 2)); } parent::recieve_data($data); }
protected function get_params(Query $query) { $menu = Database::get_table('head_menu_user', array('id', 'url', 'name'), 'cookie = ? order by `order`', Config::getInstance()->get('cookie', 'hash')); $this->set_param('personal', $menu); }
<?php include_once 'static.php'; use Otaku\Framework\Config; 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);
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); }
#!/usr/bin/php <?php use Otaku\Framework\Config; use Otaku\Framework\Cache; use Otaku\Framework\Cron; if (PHP_SAPI != 'cli') { die; } include dirname(__DIR__) . '/framework/init.php'; new Autoload(array('Api' => LIBS, 'Framework' => FRAMEWORK_LIBS), FRAMEWORK_EXTERNAL); Config::getInstance()->parse('define.ini', true); Cache::$base_prefix = Config::getInstance()->get('cache', 'prefix'); Cron::set_name('Api'); define('LOCK_FILE', '/tmp/cron_api_lock'); if (!empty($argv[1]) && !empty($argv[2])) { Cron::set_db('api'); Cron::process($argv[1], $argv[2]); exit; } if (file_exists(LOCK_FILE) && filemtime(LOCK_FILE) > time() - 3600) { exit; } touch(LOCK_FILE); Cron::process_db('api'); unlink(LOCK_FILE);
protected function get_params(Query $query) { $this->set_param('filter', Config::getInstance()->get('filter')); $this->set_param('content', Config::getInstance()->get('content')); }
public function __construct($url, $get = [], $clean = true) { parent::__construct($url, $get, $clean); $pool_count = 0; foreach ($this->get() as $key => $items) { $negated = false; if (strpos($key, '-') === 0) { $key = substr($key, 1); $negated = true; } $is_comparable = in_array($key, $this->comparable_keys); $is_equal = in_array($key, $this->equal_keys); $is_other = in_array($key, $this->other_keys); $is_pool = in_array($key, $this->pool_keys); if (!$is_comparable && !$is_equal) { if ($is_other) { $item = is_array($items) ? reset($items) : $items; if ($key == 'mode' && !in_array($item, $this->possible_modes)) { continue; } $this->other[$key] = $item; } continue; } list($is, $not, $more, $less) = $this->parse((array) $items, $is_comparable, $negated); if (!isset($this->parsed[$key])) { $this->parsed[$key] = ['is' => [], 'not' => [], 'more' => [], 'less' => []]; } $this->parsed[$key]['is'] = array_merge($this->parsed[$key]['is'], $is); $this->parsed[$key]['not'] = array_merge($this->parsed[$key]['not'], $not); $this->parsed[$key]['more'] = array_merge($this->parsed[$key]['more'], $more); $this->parsed[$key]['less'] = array_merge($this->parsed[$key]['less'], $less); if ($is_pool && $pool_count !== false) { if (!empty($not) || !empty($more) || !empty($less)) { $pool_count = false; } else { $pool_count += count($is); $this->pool_mode = $key; } } } if ($pool_count !== 1 || $this->is_pool_list()) { $this->pool_mode = false; } if (!empty($this->other['sort']) && !in_array($this->other['sort'], $this->legal_sort)) { unset($this->other['sort']); } ksort($this->other); if (isset($this->other['per_page']) && $this->other['per_page'] == 'all') { if ($this->get_pool_mode() || !empty($this->parsed['parent']['is'])) { $this->other['per_page'] = 999999; $this->per_page_all = true; } else { unset($this->other['per_page']); } } if (isset($this->other['per_page'])) { $this->other['per_page'] = (int) $this->other['per_page']; } if (empty($this->other['per_page'])) { if (isset($this->other['mode']) && $this->other['mode'] == 'comment') { $this->other['per_page'] = Config::getInstance()->get('art', 'per_page_comment'); } else { $this->other['per_page'] = Config::getInstance()->get('art', 'per_page'); } $this->forced_per_page = false; } }
protected function translate_data($data) { if (isset($data['sort'])) { $data['sort_by'] = $data['sort']; unset($data['sort']); } elseif (!empty($data['pool_mode']) && isset($data['pool_value']) && array_key_exists($data['pool_mode'], $this->pool_sorted)) { $data['sort_by'] = $data['pool_mode']; $data['sort_value'] = $data['pool_value']; $data['sort_order'] = $this->pool_sorted[$data['pool_mode']]; } elseif (!Config::getInstance()->get('content', 'moderated') && (!isset($data['mode']) || !in_array($data['mode'], $this->pool_modes))) { $data['sort_by'] = 'created'; } if (isset($data['order'])) { $data['sort_order'] = $data['order']; unset($data['order']); } if (isset($data['variations']) && $data['variations'] == 'yes') { $data['no_group'] = 1; unset($data['variations']); } $no_state = (bool) $data['pool_mode']; $data['filter'] = array(); foreach ($data['parsed'] as $key => $parts) { if (!array_key_exists($key, $this->filter_types)) { continue; } foreach ($parts as $operation => $items) { foreach ($items as $item) { $data['filter'][] = array('name' => $this->filter_types[$key], 'type' => $operation, 'value' => $item); } if ($key == 'parent' && $operation == 'is') { $data['no_group'] = 1; $no_state = true; } } } unset($data['parsed']); if ($this->stateful_api) { if (Config::getInstance()->get('safe', 'mode')) { $data['filter'][] = array('name' => 'state', 'type' => 'is', 'value' => 'approved'); $data['filter'][] = array('name' => 'state', 'type' => 'is', 'value' => 'tagged'); $data['filter'][] = array('name' => $this->filter_types['tag'], 'type' => 'not', 'value' => 'nsfw'); $data['filter'][] = array('name' => $this->filter_types['tag'], 'type' => 'not', 'value' => 'loli'); } elseif (!$no_state) { $approved = empty($data['approved']) || !isset($this->approved_filters[$data['approved']]) ? $this->default_approved_state : $data['approved']; $tagged = empty($data['tagged']) || !isset($this->tagged_filters[$data['tagged']]) ? $this->default_tagged_state : $data['tagged']; foreach ($this->approved_filters[$approved] as $type => $value) { $data['filter'][] = array('name' => 'state', 'type' => $type, 'value' => $value); } foreach ($this->tagged_filters[$tagged] as $type => $value) { $data['filter'][] = array('name' => 'state', 'type' => $type, 'value' => $value); } } } foreach (Config::getInstance()->get('filter') as $value => $type) { if ($type == 'remove') { $data['filter'][] = array('name' => $this->filter_types['tag'], 'type' => 'not', 'value' => $value); } } unset($data['pool_mode']); unset($data['pool_value']); unset($data['approved']); unset($data['tagged']); return $data; }
protected function make_request() { return new RequestRead('art_list_comment', $this, ['per_page' => Config::getInstance()->get('sidebar', 'comments'), 'add_meta' => true]); }
protected function make_request() { return new RequestRead($this->get_request_name(), $this, array($this->request_type => $this->term, 'per_page' => Config::getInstance()->get('art', 'tag_tip'))); }