Example #1
0
 public function generate()
 {
     $double_ids = array_keys(Database::get_vector('card', 'id', Database::array_in('name', $this->double_list), $this->double_list));
     foreach ($this->pool as $rarity => $cards) {
         $this->double_pool[$rarity] = array();
         foreach ($cards as $card) {
             if (in_array($card, $double_ids)) {
                 $this->double_pool[$rarity][] = $card;
             }
         }
     }
     $rarity = mt_rand(0, $this->rare + $this->uncommon + $this->common);
     parent::generate();
     $this->is_foil = false;
     $this->land = 0;
     $this->common = 0;
     $this->uncommon = 0;
     $this->rare = 0;
     if ($rarity < $this->rare) {
         $this->rare = 1;
     } elseif ($rarity < $this->rare + $this->uncommon) {
         $this->uncommon = 1;
     } else {
         $this->common = 1;
     }
     $this->pool = $this->double_pool;
     parent::generate();
     return $this->ids;
 }
Example #2
0
 protected function author($url)
 {
     $video = $this->get_video($url);
     $authors = array_keys($video['meta']['author']);
     $authors = Database::get_vector('author', array('alias', 'name'), Database::array_in('alias', $authors), $authors);
     $this->data['author'] = $authors;
 }
Example #3
0
 public function generate()
 {
     $shifted_ids = array_keys(Database::get_vector('card', 'id', Database::array_in('name', $this->shifted), $this->shifted));
     foreach ($this->pool as $rarity => &$cards) {
         $this->shifted_pool[$rarity] = array();
         foreach ($cards as $key => $card) {
             if (in_array($card, $shifted_ids)) {
                 unset($cards[$key]);
                 $this->shifted_pool[$rarity][] = $card;
             }
         }
         $cards = array_values($cards);
     }
     unset($cards);
     parent::generate();
     $this->is_foil = false;
     $this->land = 0;
     $this->common = 3;
     if (mt_rand(0, 4) < 1) {
         $this->uncommon = 0;
         $this->rare = 1;
     } else {
         $this->uncommon = 1;
         $this->rare = 0;
     }
     $this->pool = $this->shifted_pool;
     parent::generate();
     return $this->ids;
 }
Example #4
0
	public function main ($query) {
		
		$this->items['themes'] = Database::get_vector(
			'painter_themes',
			array('id', 'name'),
			'disabled = 0 order by id'
		);
	}
Example #5
0
	function personal () {

		return Database::get_vector('head_menu_user',
			array('id', 'url', 'name'),
			'cookie = ? order by `order`',
			query::$cookie
		);
	}
Example #6
0
 public function get_array($keys)
 {
     $condition = Database::array_in("key", $keys);
     $condition = $condition . " and `expires` > NOW()";
     $values = Database::get_vector("cache", array("key", "value"), $condition, $keys);
     foreach ($values as &$value) {
         $value = Database::unpack($value);
     }
     return $values;
 }
Example #7
0
 protected function do_get_card($get)
 {
     $lands = Database::get_vector('card', array('id', 'name', 'image', 'color'), 'id <= 5');
     $cards = $this->game->get_card_list();
     $cards = $cards + $lands;
     ksort($cards);
     foreach ($cards as &$card) {
         $card['image'] .= '?' . filemtime(IMAGES . SL . 'small' . SL . $card['image']);
     }
     return array('success' => true, 'cards' => $cards);
 }
Example #8
0
 protected function transform_language()
 {
     $data = (array) $this->get('language');
     if (empty($data)) {
         return array('none');
     }
     $result = (array) Database::get_vector('language', array('alias', 'name'), Database::array_in('name', $data), $data);
     foreach ($data as &$one) {
         if (in_array($one, $result)) {
             $one = array_search($one, $result);
         }
     }
     return $data;
 }
Example #9
0
	public function js() {
		$return = $this->get_jss_data($this->js, 'admin.js');

		$plugins = sets::array_get('plugins');

		$ids = array_keys($plugins);
		$names = Database::get_vector('plugin', array('id', 'filename'),
			Database::array_in('id', $ids), $ids);

		foreach($plugins as $id => $on) {
			if (!empty($on)) {
				$return['list'][] = 'plugin/' . $names[$id] . '.js';
			}
		}

		return $return;
	}
Example #10
0
	protected function get_latest_art () {	
		$latest_art_count = Config::settings('latest_art', 'count');
		
		$latest = Database::get_table(
			'art',
			array('id', 'user_id', 'name'),
			'area != "deleted" order by date desc limit '.$latest_art_count
		);
		
		$galleries = array();
		$image_limit = Config::settings('latest_art', 'image_limit');
		$galleries_limit =Config::settings('latest_art', 'galleries_limit');
		
		foreach ($latest as $art) {
			
			if (
				!empty($galleries[$art['user_id']]['images']) &&
				count($galleries[$art['user_id']]['images']) >= $image_limit
			) {
				continue;
			}
			
			$galleries[$art['user_id']]['images'][] = array(
				'id' => $art['id'],
				'name' => $art['name'],
			);
		}
		
		$galleries = array_slice($galleries, 0, $galleries_limit, true);
		
		$users = Database::get_vector(
			'user', 
			array('id', 'username'), 
			Database::array_in('id', $galleries),
			array_keys($galleries)
		);

		foreach ($users as $id => $user) {
			$alias = Meta_Author::get_alias_by_name($user);
			$galleries[$id]['link'] = empty($alias) ? $user : $alias;
			$galleries[$id]['username'] = $user;
		}

		$this->items['new'] = $galleries;
	}
Example #11
0
	function get_data() {
		global $url;

		$this->board_categories = Database::get_vector('category',
			array('id', 'alias', 'name'),
			'locate("|board|",area) ORDER BY id');

		if (!$url[2] || $url[2] == 'page') {
			return $this->main();
		} elseif ($url[2] == 'catalog') {
			return $this->catalog(isset($url[3]) ? $url[3] : false);
		} elseif ($url[2] == 'new' || $url[2] == 'updated') {
			return $this->updated();
		} elseif ($url[3] != 'thread') {
			return $this->board();
		} else {
			return $this->thread();
		}
	}
Example #12
0
	protected function edit_painter_theme($id = false) {
		
		if (empty($id)) {
			$this->items = Database::get_vector(
				'painter_themes',
				array('id', 'name'),
				'1 order by id'
			);
			
			$this->flags['mode'] = 'list';
		} else {
			$fields = Database::get_full_row('painter_themes', $id);
			unset($fields['id'], $fields['disabled']);

			$this->items = $fields;		
		
			
			$this->flags['mode'] = 'edit';
			$this->flags['id'] = $id;
		}
	}
Example #13
0
	public static function parse($links) {
		$alias = Database::get_vector('misc', array('data1', 'data2'), 'type = ?', 'site_alias');
		foreach ($links as $key => $link) {
			$type = 'alias';
			$parts = explode('&gt;',$link['link']);
			$links[$key]['url'] = undo_safety(end($parts));
			if (count($parts) == 2) {
				$links[$key]['alias'] = str_replace('&lt;','',$parts[0]);
				$type = 'search';
			}
			$domain = parse_url($link['link'],PHP_URL_HOST);
			if (substr($domain,0,4) == 'www.') {
				$domain = substr($domain,4);
			}
			if ($alias[$domain]) {
				$links[$key][$type] = $alias[$domain];
			} else {
				$links[$key][$type] = $domain;
			}
		}
		return $links;
	}
Example #14
0
 protected function author($url)
 {
     $post = new Model_Post($this->data['id']);
     $post->load();
     $authors = array_keys($post['meta']['author']);
     $authors = Database::get_vector('author', array('alias', 'name'), Database::array_in('alias', $authors), $authors);
     $this->data['author'] = $authors;
 }
Example #15
0
include '../inc.common.php';
$string = 'http://www.pixiv.net/member_illust.php?mode=medium&illust_id=';
$arts = Database::get_vector('art', array('id', 'comment_count'));
$counts = Database::group('post_id')->get_vector('comment', array('post_id', 'count(*)'), 'area != "deleted" and place = "art"');
foreach ($arts as $id => $count) {
    if (isset($counts[$id]) && $count != $counts[$id]) {
        Database::update('art', array('comment_count' => $counts[$id]), $id);
        echo "<br />У арта №{$id} число комментариев изменено с {$count} на " . $counts[$id];
        continue;
    }
    if (!isset($counts[$id]) && $count > 0) {
        Database::update('art', array('comment_count' => 0), $id);
        echo "<br />У арта №{$id} число комментариев изменено с {$count} на 0";
        continue;
    }
}
$posts = Database::get_vector('post', array('id', 'comment_count'));
$counts = Database::group('post_id')->get_vector('comment', array('post_id', 'count(*)'), 'area != "deleted" and place = "post"');
foreach ($posts as $id => $count) {
    if (isset($counts[$id]) && $count != $counts[$id]) {
        Database::update('post', array('comment_count' => $counts[$id]), $id);
        echo "<br />У записи №{$id} число комментариев изменено с {$count} на " . $counts[$id];
        continue;
    }
    if (!isset($counts[$id]) && $count > 0) {
        Database::update('post', array('comment_count' => 0), $id);
        echo "<br />У записи №{$id} число комментариев изменено с {$count} на 0";
        continue;
    }
}
Example #16
0
	function searchtip () {

		$search = obj::get('search');

		$data = urldecode(query::$get['data']);
		$query = $search->prepare_string($data, true);

		if (empty($query)) {
			return;
		}

		$area = $this->parse_area(query::$get['area']);

		$order = implode('+', $area);
		$where = 'and ('.implode('>0 or ',$area).'> 0)';

		$queries = Database::get_vector('search_queries',
			'id, query',
			'(Left(query, ?) = ? '.$where.') order by '.$order.' desc limit 10',
			array(mb_strlen($query), $query));

		$return = array();
		foreach ($queries as $one) {
			$return[] = array('query' => $one,
				'alias' => $one,
				'type' => 'search');
		}

		if (count($area) == 1) {
			$single = reset($area);
			if (in_array($single, $this->_meta_tips)) {

				$meta = array();

				$field = $single.'_main';
				$params = array(mb_strlen($query), $query,
					mb_strlen($query), $query, '|'.$query);
				$meta['tag'] = Database::get_vector('tag',
					'`id`, `alias`, `name` as query',
						'(Left(alias , ?) = ? or Left(name, ?) = ? or
						locate(?, tag.variants)) and '.$field.' > 0
						order by '.$field.' desc limit 2',
					$params
				);

				$params = array(mb_strlen($query), $query,
					mb_strlen($query), $query, '|'.$single.'|');
				$meta['category'] = Database::get_vector('category',
					'`id`, `alias`, `name` as query',
						'(Left(alias , ?) = ? or Left(name, ?) = ?)
						 and locate(?, category.area) limit 2',
					$params
				);

				$params = array(mb_strlen($query), $query,
					mb_strlen($query), $query);
				$meta['language'] = Database::get_vector('language',
					'`id`, `alias`, `name` as query',
					'Left(alias , ?) = ? or Left(name, ?) = ? limit 2',
					$params
				);

				foreach ($meta as $key => $one) {
					foreach ((array) $one as $variant) {
						$variant['type'] = $key;
						$return[] = $variant;
					}
				}
			}
		}

		shuffle($return);
		$return = array_slice($return,0,10);

		foreach ($return as &$one) {

			switch ($one['type']) {
				case 'tag':
					$one['query'] = "Тег: ".$one['query'];
					break;
				case 'category':
					$one['query'] = "Категория: ".$one['query'];
					break;
				case 'language':
					$one['query'] = "Язык: ".$one['query'];
					break;
				default: break;
			}

			if ($one['type'] != 'search') {
				$one['alias'] = '/'.$single.'/'.$one['type'].'/'.$one['alias'].'/';
			}
		}

		return $return;
	}
Example #17
0
<?php

die;
include '../inc.common.php';
$db_arts = Database::get_vector('art', array('id', 'tag'));
$all_tags = Database::get_vector('tag', array('alias', 'id'));
foreach ($db_arts as $id => $tags) {
    $tags = array_unique(array_filter(explode('|', $tags)));
    foreach ($tags as $tag) {
        if (empty($all_tags[$tag])) {
            @($all_tags[$tag][] = $id);
        }
    }
}
$arts = array();
foreach ($all_tags as $tag => $data) {
    if (!is_array($data)) {
        unset($all_tags[$tag]);
    } else {
        foreach ($data as $art) {
            @($arts[$art][] = $tag);
        }
    }
}
foreach ($arts as $art => $tags) {
    ?>
		<a href="/art/<?php 
    echo $art;
    ?>
">Арт №<?php 
    echo $art;
Example #18
0
 public static function get_images($ids)
 {
     $images = Database::get_vector('card', array('id', 'image'), Database::array_in('id', $ids), $ids);
     foreach ($images as $image) {
         if (file_exists(IMAGES . SL . 'small' . SL . $image)) {
             continue;
         }
         $url = preg_replace('/^(\\/.*)(\\/.*)$/ui', 'http://www.mtg.ru/pictures$1_big$2', $image);
         $got = false;
         $i = 0;
         while (!$got && ++$i < 15) {
             usleep(200000);
             $handle = curl_init($url);
             curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($handle, CURLOPT_BINARYTRANSFER, 1);
             $response = curl_exec($handle);
             $code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
             curl_close($handle);
             if ($code == 404) {
                 $url = 'http://www.mtg.ru/pictures' . $image;
             } elseif (md5($response) != 'b7b25d6d52c197be99ed9093958b6f39') {
                 $got = true;
             }
         }
         $worker = new Transform_Upload_Mtg($response, $image);
         try {
             $worker->process_file();
         } catch (Error_Upload $e) {
         }
     }
 }
Example #19
0
<?
die;
include '../inc.common.php';

$pools = Database::get_vector('art_pool', 'id, art');

foreach ($pools as $id => $arts) {

	$arts = explode('|', $arts);
	$arts = array_filter($arts);
	$arts = array_reverse($arts);

	$insert = array();
	$order = 0;
	foreach ($arts as $art) {
		$insert[] = array(
			'art_id' => $art,
			'pool_id' => $id,
			'order' => $order++,
		);
	}

	Database::bulk_insert('art_in_pool', $insert, true);
}

Example #20
0
	protected function get_languages() {
		return Database::get_vector('language',
			'alias, name',
			'1 order by id');
	}
Example #21
0
    public function pick($user, $card, $set, $shift)
    {
        $user_data = Database::get_row('game_user', array('order', 'force_picks'), 'id_user = ? and id_game = ?', array($user, $this->get_id()));
        $max = Database::get_field('game_user', 'max(`order`)', 'id_game = ?', $this->get_id());
        $order = ($user_data['order'] + ($max + 1) * 15 + $shift * ($set % 2 ? 1 : -1)) % ($max + 1);
        $user_booster = Database::get_field('game_user', 'id_user', '`order` = ? and id_game = ?', array($order, $this->get_id()));
        $id_booster = Database::join('game_set', 'gs.id = gb.id_game_set')->get_field('game_booster', 'gb.`id`', 'gs.`order` = ? and gs.id_game = ? and gb.id_user = ?', array($set, $this->get_id(), $user_booster));
        $pick = $shift + ($set - 1) * 15;
        Database::update('game_booster_card', array('id_user' => $user, 'pick' => $pick, 'forced' => 0), 'id = ? and id_user = 0 and not exists
			(select 1 from (select * from `game_booster_card` where id_game_booster = ?) as t
			where t.pick = ? and t.id_user > 0)', array($card, $id_booster, $shift));
        $success = Database::count_affected() > 0;
        if ($user_data['force_picks']) {
            Database::update('game_user', array('force_picks' => 0), 'id_user = ? and id_game = ?', array($user, $this->get_id()));
        }
        if ($success) {
            $picked_count = Database::join('game_booster', 'gb.id_game_set = gs.id')->join('game_booster_card', 'gbc.id_game_booster = gb.id')->get_count('game_set', 'gs.id_game = ? and gs.order = ? and gbc.pick = ? and gbc.id_user > 0', array($this->get_id(), $set, $pick));
            $force_users = Database::get_vector('game_user', 'id_user', 'id_game = ? and force_picks > ?', array($this->get_id(), 1));
            $user_count = Database::get_count('game_user', 'id_game = ?', $this->get_id());
            $cache_key = 'force_lock_' . $this->get_id() . '_' . $pick;
            if (count($force_users) + $picked_count >= $user_count && !Cache::get($cache_key)) {
                Cache::set($cache_key, 1);
                if (!empty($force_users)) {
                    $this->force_picks($force_users, $set, $shift);
                }
                $this->shift_game_steps();
                Cache::delete($cache_key);
            }
        }
        return $success;
    }
Example #22
0
	function parse_text ($text) {
		$text = explode(' ', $this->prepare_string($text));

		foreach ($text as $key => $word) {
			if ($word{0} == '-') {
				$text[$key] = substr($word,1);
				$signs[$key] = '-';
			} else {
				$signs[$key] = '+';
			}
		}

		$cache = (array) Database::get_vector('morphy_cache',
			array('word', 'cache'),
			Database::array_in('word', $text),
			$text
		);

		$delta = array_diff($text, array_keys($cache));
		if (!empty($delta)) {
			$delta = $this->morphyphp($delta);
		}

		$text = array_flip($text);
		$return = array();
		foreach ($cache as $word => $one) {
			$return[$text[$word]] = $one;
		}

		$return = $return + $delta;

		foreach ($return as $key => $word) {
			$return[$key] = $signs[$key] . $word;
		}

		ksort($return);
		return $return;
	}
Example #23
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 #24
0
<?
die;
$where = "";
$params = array();

if (empty($where)) die;

include '../inc.common.php';
include '../engine/upload/functions.php';

$arts = Database::get_vector('art', array('id','md5','extension','resized','animated'), $where, $params);

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

	$is_animated = is_animated($file);

	if ($is_animated && empty($art['animated'])) {
		Database::update('art', array('animated' => 1), $id);
	} elseif (!$is_animated && !empty($art['animated'])) {
		Database::update('art', array('animated' => 0), $id);
	}

	if (!empty($art['resized'])) {
		$sizefile = filesize($file);
		$dimensions = getimagesize($file);

		if ($sizefile > 1024*1024) {
			$sizefile = round($sizefile/(1024*1024),1).' мб';
		} elseif ($sizefile > 1024) {
			$sizefile = round($sizefile/1024,1).' кб';
Example #25
0
 protected function set_default_name()
 {
     $info = (array) Database::get_vector('info', array('key', 'value'), 'id = ? and key in (?,?,?)', array($this->id, 'name', 'md5', 'extension'));
     if (!empty($info['name'])) {
         $this->file_name = $info['name'];
         return;
     }
     if (!empty($info['md5']) && !empty($info['extension'])) {
         $this->file_name = $info['md5'] . '.' . $info['extension'];
         return;
     }
 }