Example #1
0
	function edit_art_groups() {
		global $check;
		if ($check->num(query::$post['id']) && query::$post['type'] == 'art' && is_array(query::$post['group'])) {

			$qroups = array_filter(array_unique(query::$post['group']));

			foreach ($qroups as $key => $group) {
				if (Database::get_count('art_pool',
					'id = ? and password != "" and password != ?',
					array($group, md5(query::$post['password'])))
				) {
					unset($qroups[$key]);
				}
			}

			foreach ($qroups as $group) {
				$order = Database::order('order')->
					get_field('art_in_pool', 'order', 'pool_id = ?', $group);

				Database::insert('art_in_pool', array(
					'art_id' => query::$post['id'],
					'pool_id' => $group,
					'order' => $order + 1
				));
			}
		}
	}
Example #2
0
 public function add_art($art)
 {
     if (!$this->last_order_known) {
         $this->last_order = (int) Database::order('order')->get_field('art_in_pool', 'order', 'pool_id = ?', $this->get_id());
         $this->last_order_known = true;
     }
     Database::insert('art_in_pool', array('art_id' => $art->get_id(), 'pool_id' => $this->get_id(), 'order' => ++$this->last_order));
 }
Example #3
0
 protected function category($url)
 {
     $video = $this->get_video($url);
     $categories = array_keys($video['meta']['category']);
     $options = Database::order('id', 'asc')->get_vector('category', array('alias', 'name'), 'locate(?, area)', '|video|');
     $this->data['category'] = $categories;
     $this->data['option'] = $options;
 }
Example #4
0
 protected function get_data()
 {
     $logs = Database::order('order')->get_vector('strip', array('id', 'order', 'title', 'date'), '`order` > 0');
     foreach ($logs as &$log) {
         $log['date'] = strtotime($log['date']);
         $log['date'] = $log['date'] > 0 ? date('y/m/d', $log['date']) : '';
     }
     return array('logs' => $logs);
 }
Example #5
0
 protected function language($url)
 {
     $post = new Model_Post($this->data['id']);
     $post->load();
     $languages = array_keys($post['meta']['language']);
     $options = Database::order('id', 'asc')->get_vector('language', array('alias', 'name'));
     $this->data['language'] = $languages;
     $this->data['option'] = $options;
 }
Example #6
0
 protected function get_data()
 {
     $data = parent::get_data();
     $data['sets'] = Database::order('order', 'asc')->get_table('set');
     if (empty($data['sets'])) {
         $data['sets'] = Grabber::get_set_list();
     }
     return $data;
 }
Example #7
0
 protected function get_data()
 {
     $strip = Database::get_full_row('strip', $this->id);
     if (empty($strip)) {
         return array('error' => true);
     }
     $strip['text'] = Transform_Text::format($strip['text']);
     return array('strip' => $strip, 'images' => Database::join('file', 'sf.id_file = f.id')->order('sf.order', 'asc')->get_full_table('strip_file', 'id_strip = ?', $strip['id']), 'next' => $strip['order'] ? Database::order('order', 'asc')->get_full_row('strip', '`order` > ?', $strip['order']) : false);
 }
Example #8
0
	function get_comments($limit, $area) {
		global $error; global $def;
		$return = obj::db()->sql('select place, post_id from comment where (area != "deleted"'.$area.') group by place, post_id order by max(sortdate) desc limit '.$limit);
		if (is_array($return)) {
			$select = array(
				$def['type'][0] => "id, comment_count, title, last_comment",
				$def['type'][1] => "id, comment_count, title, id as image, last_comment",
				$def['type'][2] => "id, comment_count, id as title, thumb as image, last_comment",
				"orders" => "id, comment_count, title, email as image, last_comment",
				"news" => "id, comment_count, title, image, last_comment"
			);
			foreach ($return as $one) {
				$queries[$one['place']] .= '" or id="'.$one['post_id'];
				$comment_query .= ' or (post_id="'.$one['post_id'].'" and place="'.$one['place'].'")';
			}
			$return = array();
			foreach ($queries as $key => $query) {
				if ($_comments = obj::db()->sql('select '.$select[$key].', "'.$key.'" as "place" from '.$key.' where ('.substr($query,5).'")','last_comment')) {
					$return = $return + $_comments;
				}
			}
			krsort($return);
			$comments = obj::db()->sql('select * from comment where (('.substr($comment_query,4).') and area != "deleted") order by sortdate');
			foreach ($return as &$one) {
				foreach ($comments as $comment)
					if ($comment['post_id'] == $one['id'] && $comment['place'] == $one['place'])
						$one['comments'][] = $comment;
				switch ($one['place']) {
					case $def['type'][0]:
						$image = Database::order('order', 'asc')
							->get_field('post_image', 'file', 'post_id = ?', $one['id']);

						$one['image'] = '/images/post/thumb/'.$image.'.jpg';
						break;
					case $def['type'][1]:
						$one['image'] = 'http://www.gravatar.com/avatar/'.md5(strtolower($one['image'])).'?s=100&d=identicon&r=G';
						$one['title'] = "Видео: ".$one['title'];
						break;
					case $def['type'][2]:
						$one['image'] = '/images/booru/thumbs/'.$one['image'].'.jpg';
						$one['title'] = "Изображение №".$one['title'];
						break;
					case "orders":
						$one['image'] = 'http://www.gravatar.com/avatar/'.md5(strtolower($one['image'])).'?s=100&d=identicon&r=G';
						$one['title'] = "Заказ: ".$one['title'];
						break;
					case "news":
						$one['image'] = '/images/news/thumb/'.$one['image'].'.jpg';
						break;
				}
			}

			return $return;
		}
		else $error = true;
	}
Example #9
0
 protected function get_data()
 {
     $strip = Database::get_full_row('strip', $this->id);
     if (empty($strip)) {
         return array('error' => true);
     }
     $strip['date'] = strtotime($strip['date']);
     $strip['date'] = $strip['date'] > 0 ? date('y / m / d', $strip['date']) : '';
     return array('files' => Database::order('time')->get_full_vector('file'), 'strip' => $strip, 'today' => date('y / m / d'), 'images' => Database::join('file', 'sf.id_file = f.id')->order('sf.order', 'asc')->get_full_table('strip_file', 'id_strip = ?', $this->id));
 }
Example #10
0
 public function check()
 {
     $data = Database::order('pu.lastcheck', 'ASC')->limit(self::LINKS_PER_CHECK)->join('post_link_url', 'pu.id = plu.url_id')->join('post_link', 'pl.id = plu.link_id')->join('post', 'p.id = pl.post_id')->group('pu.id')->get_table('post_url', array('pu.id', 'pu.url'), 'p.area is not null and p.area != ?', 'deleted');
     $links = array();
     foreach ($data as $item) {
         $link = html_entity_decode($item['url'], ENT_QUOTES, 'UTF-8');
         $link = str_replace(''', "'", $link);
         $link = trim($link);
         $links[$item['id']] = $link;
     }
     $this->test_links($links);
 }
Example #11
0
 public function get_action()
 {
     $action = Database::order('time', 'asc')->get_full_row('game_step', 'id_game = ? and time > current_timestamp', $this->get_id());
     if (!empty($action)) {
         $action['time'] = strtotime($action['time']);
     }
     if (preg_match('/^pick_\\d+$/', $action['type'])) {
         $action['data'] = (int) str_replace('pick_', '', $action['type']);
         $action['type'] = 'pick';
     } else {
         $action['data'] = false;
     }
     return $action;
 }
Example #12
0
 protected function do_get($data)
 {
     $this->write_presense();
     if (empty($data['first_load'])) {
         $message_time = date('Y-m-d G:i:s', time() - Config::get('chat', 'loadtime'));
         $messages = Database::join('user', 'u.id = m.id_user')->order('m.time', 'ASC')->get_table('message', 'm.id, m.id_user, m.text, unix_timestamp(m.time) as time, u.login', 'm.time > ? and m.id_game = ?', array($message_time, $this->id));
     } else {
         $message_time = date('Y-m-d G:i:s', time() - Config::get('chat', 'firsttime'));
         $messages = Database::join('user', 'u.id = m.id_user')->limit(50)->order('m.time')->get_table('message', 'm.id, m.id_user, m.text, unix_timestamp(m.time) as time, u.login', 'm.time > ? and m.id_game = ?', array($message_time, $this->id));
         $messages = array_reverse($messages);
     }
     $time = date('Y-m-d G:i:s', time() - Config::get('chat', 'loadtime'));
     $data = array('success' => true, 'presense' => Database::join('user', 'u.id = p.id_user')->get_table('presense', 'u.id, u.login', 'p.time > ? and id_game = ?', array($time, $this->id)), 'message' => $messages, 'last_game_change' => strtotime(Database::order('update')->get_field('game', 'update')));
     return $data;
 }
Example #13
0
 public function add_booster($user)
 {
     $set = Database::order('order')->get_row('game_set', array('id_set', 'order'), 'id_game = ?', $this->get_id());
     if (!$set) {
         return false;
     }
     Database::insert('game_set', array('id_game' => $this->get_id(), 'id_set' => $set['id_set'], 'order' => $set['order'] + 1));
     $id = Database::last_id();
     Database::insert('game_booster', array('id_game_set' => $id, 'id_user' => $user));
     $booster = Database::last_id();
     $booster = $this->make_booster($booster, $set['id_set'], $user);
     $booster->set_in_deck(false);
     $ids = $booster->generate();
     Grabber::get_images(array_unique($ids));
     return true;
 }
Example #14
0
 protected function get_data()
 {
     if (!$this->id) {
         return array('error' => true);
     }
     $strip = Database::get_full_row('strip', '`order` = ?', $this->id);
     if (empty($strip)) {
         return array('error' => true);
     }
     $strip['text'] = Transform_Text::format($strip['text']);
     $logs = Database::order('order')->limit(30)->get_vector('strip', array('id', 'order', 'title', 'date'), '`order` > 0');
     foreach ($logs as &$log) {
         $log['date'] = strtotime($log['date']);
         $log['date'] = $log['date'] > 0 ? date('y/m/d', $log['date']) : '';
     }
     return array('page' => $this->id, 'logs' => $logs, 'strip' => $strip, 'images' => Database::join('file', 'sf.id_file = f.id')->order('sf.order', 'asc')->get_full_table('strip_file', 'id_strip = ?', $strip['id']), 'next' => Database::order('order', 'asc')->get_full_row('strip', '`order` > ?', $strip['order']), 'back' => Database::order('order')->get_field('strip', 'order', '`order` < ?', $strip['order']), 'autosave' => isset($_COOKIE['autosave']) ? (int) $_COOKIE['autosave'] : 0);
 }
Example #15
0
 protected function get_data()
 {
     $data = parent::get_data();
     $data['note'] = Database::order('n.time')->join('note', 'u.id = n.id_user')->get_full_table('user', 'n.id_game = ?', $this->game);
     foreach ($data['note'] as &$note) {
         $note['text'] = nl2br($note['text']);
         $md5 = md5($note['login']);
         $parts = array(hexdec($md5[0] . $md5[1]), hexdec($md5[2] . $md5[3]), hexdec($md5[4] . $md5[5]));
         foreach ($parts as &$part) {
             $part = dechex(ceil($part / 2));
             if (strlen($part) == 1) {
                 $part = '0' . $part;
             }
         }
         $note['color'] = implode($parts);
     }
     return $data;
 }
Example #16
0
	public function get_all () {
		$where = query::$get['where'];

		if (!is_numeric(query::$get['count']) || !in_array($where, $this->tag_areas)) {
			$this->reply($this->empty_reply);
		}

		$tags = Database::order($where.'_main')->limit(query::$get['count'])
			->get_vector('tag', 'name', $where.'_main > 0');

		$tags = array_values((array) $tags);

		foreach ($tags as &$tag) {
			$tag = html_entity_decode($tag);
			$tag = undo_safety($tag);
		}

		sort($tags);

		$this->reply($tags);
	}
Example #17
0
 protected function shift_game_steps()
 {
     $start = time();
     $steps = Database::order('time', 'asc')->get_vector('game_step', array('id', 'time'), 'id_game = ? and time > ?', array($this->get_id(), date('Y-m-d G:i:s', $start)));
     if (empty($steps)) {
         return;
     }
     $step = reset($steps);
     $shift = strtotime($step) - $start;
     if ($shift < 3) {
         return;
     }
     foreach ($steps as $id => $step) {
         Database::update('game_step', array('time' => date('Y-m-d G:i:s', strtotime($step) - $shift)), $id);
     }
 }
Example #18
0
 protected function get_data()
 {
     return array('files' => Database::order('filename', 'asc')->get_full_vector('file'));
 }
Example #19
0
 protected function get_data()
 {
     return array('strips' => Database::order('order', 'asc')->get_full_table('strip'));
 }
Example #20
0
File: add.php Project: 4otaku/mburb
 protected function get_data()
 {
     return array('files' => Database::order('time')->get_full_vector('file'), 'date' => date('y / m / d'));
 }
Example #21
0
#!/usr/bin/php
<?php 
include_once 'inc.common.php';
define('LOCK_FILE', '/tmp/cron_lock');
$cron = new Cron();
ini_set('memory_limit', '1024M');
ini_set('time_limit', '1800');
if ($key = key($_GET)) {
    $cron->process($key);
    var_dump(memory_get_peak_usage(true));
    exit;
}
if (file_exists(LOCK_FILE) && filemtime(LOCK_FILE) > time() - 3600) {
    exit;
}
$time = Database::unix_to_date();
$tasks = Database::order('id', 'asc')->get_vector('cron', array('function', 'period'), 'last_time < ?', $time);
if (empty($tasks)) {
    exit;
}
touch(LOCK_FILE);
foreach ($tasks as $task => $period) {
    $cron->process($task);
    $nexttime = Database::unix_to_date(Transform_Time::parse($period) - 15);
    Database::update('cron', array('last_time' => $nexttime), 'function = ?', $task);
}
unlink(LOCK_FILE);
Example #22
0
	public function art_variation_list () {
		if (!Check::num(query::$get['id']) || query::$get['type'] != 'art') {
			return false();
		}

		$return = (array) Database::order('order', 'ASC')
			->get_full_table('art_variation', 'art_id = ?', query::$get['id']);

		$image = Database::get_full_row('art', query::$get['id']);

		array_unshift($return, $image);

		return $return;
	}
Example #23
0
 public function __construct($url)
 {
     parent::__construct($url);
     $this->id = Database::order('order', 'asc')->get_field('strip', 'order', '`order` > 0');
 }
Example #24
0
	protected function get_zip($id) {

		$image_dir = ROOT_DIR.SL.'images'.SL.'board'.SL.'full'.SL;
		$data = Database::get_vector('board', 'id, sortdate',
			'`type`!= ? and (id= ? or thread = ?)',
			array('deleted', $id, $id));

		$ids = array();
		foreach ($data as $key => $item) {
			$ids[] = $key;
			$data[$key] = array('id' => $key, 'sortdate' => $item);
		}

		if (!empty($data)) {
			$attachments = Database::order('order', 'asc')->
				get_table('board_attachment', 'post_id, data',
				'(type = "image" or type = "random") and '.Database::array_in('post_id', $ids),
				$ids);

			foreach ($attachments as $file) {
				$data[$file['post_id']]['image'][] =
					unserialize(base64_decode($file['data']));
			}

			$images = array();
			foreach ($data as $key => $item) {

				if (empty($item['image'])) {
					unset ($data[$key]);
				} else {
					$i = 0;
					foreach($item['image'] as $image) {
						$i++;
						$append = $i > 1 ? '_'.$i : '';

						$image_file_name = $item['id'].$append.'.'.
							end(explode('.', $image['full']));
						$images[$image_file_name] = $image['full'];
					}
				}
			}
			$zip_name = 'thread_'.$id.'_'.max(array_keys($data)).'.zip';
			if (!file_exists(self::$work_dir.$zip_name)) {
				$zip = new ZipArchive;
				if ($zip->open(self::$work_dir.$zip_name, ZipArchive::CREATE) === true) {
					foreach ($images as $name => $image) {
						if (file_exists($image_dir.$image)) {
							$zip->addFile($image_dir.$image, $name);
						}
					}
					$zip->close();
				}
			}
			return self::$work_dir.$zip_name;
		}

		return false;
	}
Example #25
0
	function slideshow() {
		global $check; global $def; global $sets; global $url;
		$types = array ('tag','author','category','mixed','date','pool');
		if (in_array(query::$get['type'],$types) && $check->num(query::$get['id'])) {
			$limit = ' order by sortdate desc limit '.(query::$get['id'] - 1).', 5'; $area_prefix = 'area="'.$def['area'][0].'" and ';
			switch (query::$get['type']) {
				case "mixed":
					$url['area'] = 'main';  $area_prefix = '';
					$area = "(".engine::mixed_make_sql(engine::mixed_parse(html_entity_decode(urldecode(query::$get['area'])))).")";
					break;
				case "date":
					$parts = explode('-',query::$get['area']);
					if (is_numeric($parts[0].$parts[1].$parts[2]) && count($parts) == 3)
						$area = '(pretty_date ="'.obj::transform('text')->rumonth($parts[1]).' '.$parts[2].', '.$parts[0].'")';
					break;
				case "pool":
					$pool = Database::order('order', 'asc')
						->limit(5, query::$get['id'] - 1)
						->get_vector('art_in_pool', 'art_id', 'pool_id = ?', query::$get['area']);

					$area = "(id=".implode(' or id=',$pool).")";
					$limit = ''; $area_prefix = '';

					break;
				default:
					$area = '(locate("|'.urldecode(query::$get['area']).'|",art.'.query::$get['type'].'))';
			}
			if (!$sets['show']['nsfw'] && query::$get['type'] != 'pool')
				$area .= ' and !locate("|nsfw|",art.category)';
			elseif ($sets['show']['nsfw'] && query::$get['type'] != 'pool') {
				if (!$sets['show']['yaoi']) $area .= ' and !(locate("|yaoi|",art.tag) and locate("|nsfw|",art.category))';
				if (!$sets['show']['furry']) $area .= ' and !(locate("|furry|",art.tag) and locate("|nsfw|",art.category))';
				if (!$sets['show']['guro']) $area .= ' and !(locate("|guro|",art.tag) and locate("|nsfw|",art.category))';
			}
			$return = obj::db()->sql('select id, md5, extension, resized from art where ('.$area_prefix.$area.')'.$limit,'id');
			if (query::$get['type'] == 'pool') {
				$_return = $return; unset($return);
				foreach ($pool as $one) $return[$one] = $_return[$one];
			}
			if (is_array($return)) {
				foreach ($return as &$art) {
					if (!$art['resized']) $sizes = getimagesize('images/booru/full/'.$art['md5'].'.'.$art['extension']);
					else $sizes = getimagesize('images/booru/resized/'.$art['md5'].'.jpg');
					$art['height'] = $sizes[1];
				}
				if ($sets['show']['translation']) {
					$where = 'art_id='.implode(' or art_id=',array_keys($return));
					$translations = obj::db()->sql('select art_id, data from art_translation where ('.$where.' and active = 1)','art_id');
					if (is_array($translations)) foreach ($translations as $key => $translation) {
						$return[$key]['translations']['full'] = unserialize(base64_decode($translation));
						if ($return[$key]['resized'] && is_array($return[$key]['translations']['full'])) {
							$size = explode('x',$return[$key]['resized']);
							$coeff = $size[0] / $def['booru']['resizewidth'];
							foreach ($return[$key]['translations']['full'] as $one) {
								foreach ($one as $field => &$param) if ($field != 'text') $param = round($param / $coeff);
								$return[$key]['translations']['resized'][] = $one;
							}
						}
					}
				}
				return $return;
			}
			else die ("finish");
		}
	}
Example #26
0
 protected function get_post_data($items)
 {
     if (is_object($items)) {
         $items = array($items['id'] => $items);
     }
     $keys = array_keys($items);
     $images = Database::order('order', 'asc')->get_full_table('post_image', Database::array_in('post_id', $keys), $keys);
     foreach ($images as $image) {
         $image = new Model_Post_Image($image);
         $items[$image['post_id']]->add_image($image);
     }
     $links = Database::join('post_link_url', 'plu.link_id = pl.id')->join('post_url', 'plu.url_id = pu.id')->order('pl.order', 'asc')->order('plu.order', 'asc')->get_full_table('post_link', Database::array_in('pl.post_id', $keys), $keys);
     foreach ($links as $link) {
         $link = new Model_Post_Link($link);
         $items[$link['post_id']]->add_link($link);
     }
     $torrents = Database::order('order', 'asc')->get_full_table('post_torrent', Database::array_in('post_id', $keys), $keys);
     $hashes = array();
     foreach ($torrents as $torrent) {
         $hashes[] = $torrent['hash'];
     }
     if (!empty($hashes)) {
         $torrents_data = array();
         $raw_data = (array) Database::db('tracker')->get_table('peers', array('info_hash', 'state'), Database::array_in('info_hash', $hashes, true));
         foreach ($raw_data as $data) {
             $key = $data['info_hash'];
             if (empty($torrents_data[$key])) {
                 $torrents_data[$key] = array('seeders' => 0, 'leechers' => 0);
             }
             if ($data['state']) {
                 $torrents_data[$key]['seeders']++;
             } else {
                 $torrents_data[$key]['leechers']++;
             }
         }
         foreach ($torrents as &$torrent) {
             $hash = pack("H*", $torrent['hash']);
             if (!empty($torrents_data[$hash])) {
                 $torrent['seeders'] = $torrents_data[$hash]['seeders'];
                 $torrent['leechers'] = $torrents_data[$hash]['leechers'];
             } else {
                 $torrent['seeders'] = 0;
                 $torrent['leechers'] = 0;
             }
         }
         unset($torrent);
     }
     foreach ($torrents as $torrent) {
         $torrent = new Model_Post_Torrent($torrent);
         $items[$torrent['post_id']]->add_torrent($torrent);
     }
     $files = Database::order('order', 'asc')->get_full_table('post_file', Database::array_in('post_id', $keys), $keys);
     foreach ($files as $file) {
         $file = new Model_Post_File($file);
         $items[$file['post_id']]->add_file($file);
     }
     $extras = Database::order('order', 'asc')->get_full_table('post_extra', Database::array_in('post_id', $keys), $keys);
     foreach ($extras as $extra) {
         $extra = new Model_Post_Extra($extra);
         $items[$extra['post_id']]->add_extra($extra);
     }
 }
Example #27
0
 protected function get_items_post(Database_Instance $query)
 {
     foreach ($this->sorters as $sorter) {
         $sorter->set_prefix('ps');
         $query->order($sorter);
     }
     $data = $query->join('post', 'p.id = ps.id')->get_vector('post_status', 'p.*', '(' . $this->area_condition . ') and overall > 0', $this->area_params);
     $this->count = Database::get_counter();
     foreach ($data as $key => $item) {
         $item['id'] = $key;
         $data[$key] = new Model_Post($item);
     }
     $keys = array_keys($data);
     $images = Database::order('order', 'asc')->group('post_id')->get_full_table('post_image', Database::array_in('post_id', $keys), $keys);
     foreach ($images as $image) {
         $image = new Model_Post_Image($image);
         $data[$image['post_id']]->add_image($image);
     }
     $links = Database::join('post_link_url', 'plu.link_id = pl.id')->join('post_url', 'plu.url_id = pu.id')->order('pl.order', 'asc')->order('plu.order', 'asc')->get_full_table('post_link', Database::array_in('pl.post_id', $keys), $keys);
     foreach ($links as $link) {
         $link = new Model_Post_Link($link);
         $data[$link['post_id']]->add_link($link);
     }
     return $data;
 }