Example #1
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 #2
0
 protected function test_links($links)
 {
     $this->worker->enable_limit(self::MAX_DOWNLOAD_SIZE)->add($links)->exec();
     foreach ($links as $id => $link) {
         $status = $this->test_result($link);
         if ($status === false) {
             continue;
         }
         Database::update('post_url', array('status' => $status, 'lastcheck' => Database::unix_to_date()), $id);
         if ($status == self::STATUS_UNKNOWN) {
             $this->create_unknown_file($link);
         }
     }
     $this->worker->flush();
     $keys = array_keys($links);
     $post_ids = Database::join('post_link_url', 'plu.link_id = pl.id')->join('post_url', 'plu.url_id = pu.id')->get_vector('post_link', 'post_id', Database::array_in('pu.id', $keys), $keys);
     $post_ids = array_unique($post_ids);
     foreach ($post_ids as $post_id) {
         $status = new Model_Post_Status($post_id);
         $status->load()->calculate()->commit();
     }
     $update_ids = Database::join('post_update_link_url', 'pulu.link_id = pul.id')->join('post_url', 'pulu.url_id = pu.id')->get_vector('post_update_link', 'update_id', Database::array_in('pu.id', $keys), $keys);
     $update_ids = array_unique($update_ids);
     foreach ($update_ids as $update_id) {
         $status = new Model_Post_Update_Status($update_id);
         $status->load()->calculate()->commit();
     }
 }
Example #3
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 #4
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 #5
0
	public function get_content ($query, $perpage, $page, $start) {
		
		$names = Database::set_counter()->get_vector(
			'user', 
			array('id', 'username'), 
			"last_draw != '0000-00-00 00:00:00' order by last_draw desc limit $start, $perpage"
		);

		$authors = Database::get_full_table(
			'meta', 
			Database::array_in('name', $names),
			$names
		);
		
		$items = array();
		$names = array_values($names);
		
		foreach ($authors as $author) {
			$order_id = array_search($author['name'], $names);
			$items[$order_id] = $author;
		}
		
		ksort($items);

		$return = array();
		$aliases = array();
		
		foreach ($items as $id => $item) {
			$return[$id] = new Item_Author($item);
			$aliases[] = $item['alias'];
		}
		unset ($items);
		
		$condition = Database::make_search_condition('meta', array(array('+', $aliases, 'author')));
		
		$arts = Database::get_table('art', 
			array('id', 'user_id', 'meta', 'name', 'comments'),
			$condition.' and area="main" order by date desc'
		);
	
		foreach ($return as $id => $gallery) {
			
			foreach ($arts as $art_id => $art) {
				
				if (strpos($art['meta'], 'author__'.$gallery['alias'])) {
					
					$gallery->add_to('images', $art);
					unset($arts[$art_id]);
				}
				
				if (count($gallery['images']) > 4) {
					break;
				}
			}
		}
	
		return $return;
	}
Example #6
0
 protected function link($data)
 {
     $link_ids = Database::get_table('post_update_link', 'id', 'update_id = ?', $this->model->get_id());
     Database::delete('post_update_link_url', Database::array_in('link_id', $link_ids), $link_ids);
     Database::delete('post_update_link', 'update_id = ?', $this->model->get_id());
     $links = Check::link_array($data['link']);
     $links = Transform_Link::parse($links);
     foreach ($links as $link) {
         $link = new Model_Post_Update_Link($link);
         $this->model->add_link($link);
     }
 }
Example #7
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 #8
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 #9
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 #10
0
    protected function do_get($dev_null)
    {
        $data = Database::join('game_set', 'gs.id_game = g.id')->join('user', 'u.id = g.id_user')->join('game_user', 'g.id = gu.id_game and gu.signed_out = 0 and gu.id_user = '******'set', 'gs.id_set = s.id')->group('g.id')->get_table('game', array('g.id, g.id_user, g.state, u.login, g.pick_time, g.update,
				g.pause_time, g.start, g.type', 'group_concat(s.name) as booster', 'gu.id_user as presense'), 'g.state != ? and g.update > ?', array(4, date('Y-m-d G:i:s', time() - 86400)));
        $date_missed = time() - 10800;
        $ids = array();
        foreach ($data as $key => $item) {
            if ($item['state'] > 0 && empty($item['presense']) && strtotime($item['update']) < $date_missed) {
                unset($data[$key]);
                continue;
            }
            if (empty($item['start']) || $item['start'] == '0000-00-00 00:00:00') {
                unset($data[$key]['start']);
            } else {
                $data[$key]['start'] = strtotime($item['start']);
            }
            $ids[] = $item['id'];
        }
        $count = Database::group('id_game')->get_vector('game_user', array('id_game', 'count(`id_user`)'), Database::array_in('id_game', $ids), $ids);
        foreach ($data as $key => $item) {
            $data[$key]['user_count'] = isset($count[$item['id']]) ? $count[$item['id']] : 0;
        }
        return array('success' => true, 'data' => $data);
    }
Example #11
0
	public function decrement_array ($keys, $value = 1) {
		if (is_array($value)) {
			$value = current($value);
		}

		$sql = "update <pr>cache set `value` = `value` - ? where";
		$sql .= Database::array_in("key", $keys);

		if (is_array($value)) {
			$value = current($value);
		}

		array_unshift($keys, $value);

		Database::sql($sql, $keys);
	}
Example #12
0
	function parse_meta ($meta, $table) {
		$fields = array('alias', 'name');
		if ($table == 'tag') {
			$fields[] = 'variants';
		}

		if (preg_match('/[^a-z_\d]/iu', $table)) {
			return array();
		}

		$meta = array_filter(explode('|', $meta));
		$data = (array) Database::get_table($table,
			$fields,
			Database::array_in('alias', $meta),
			$meta
		);

		$text = '';
		foreach ($data as $one) {
			$text .= ' '.$one['alias'].' '.$one['name'].' '.$one['variants'];
		}

		return $this->parse_text($text);
	}
Example #13
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 #14
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 #15
0
 public function set_deck($user, $cards)
 {
     $old_ids = Database::join('game_booster', 'gb.id_game_set = gs.id')->join('game_booster_card', 'gbc.id_game_booster = gb.id')->get_vector('game_set', 'gbc.id', 'gs.id_game = ? and gbc.id_user = ? and deck = 1', array($this->get_id(), $user));
     $old_ids = array_keys($old_ids);
     Database::update('game_booster_card', array('deck' => 0), Database::array_in('id', $old_ids), $old_ids);
     foreach ($cards as $card) {
         if (!is_numeric($card)) {
             throw new Error();
         }
         $id = Database::join('game_booster', 'gb.id_game_set = gs.id')->join('game_booster_card', 'gbc.id_game_booster = gb.id')->get_field('game_set', 'gbc.id', 'gs.id_game = ? and gbc.id_user = ? and gbc.id_card = ? and deck = 0', array($this->get_id(), $user, $card));
         if (!$id) {
             throw new Error();
         }
         Database::update('game_booster_card', array('deck' => 1), $id);
     }
     Database::update('game_user', array('created_deck' => 1), 'id_game = ? and id_user = ?', array($this->get_id(), $user));
 }
Example #16
0
	public function single ($query) {

		$config = Globals::user('comments', 'single_item');

		$perpage = $config['per_page'];
		$display = $config['display'];
		$inverted = $config['inverted'];

		if ($query['page'] != 'all') {			
			$page = $query['page'];
			$start = ($page - 1) * $perpage;
			$limit = " limit $start, $perpage";	
		} else {
			$limit = "";
			$page = 1;
			$start = 0;
		}
		
		$root = $display == 'ladder' ? "and root = 0" : "";		
		$direction = (bool) $inverted ? "desc" : "asc";
		
		$params = array('deleted', $query['place'], $query['item_id']);
		$condition = "area != ? and place = ? and item_id = ? $root order by date $direction $limit";

		$comments = Database::set_counter()->get_full_vector('comment', $condition, $params, false);
		
		$total = Database::get_counter();
		$current = (bool) $inverted ? $total - $start : $start;
			
		if ($display == 'ladder') {
			$roots = array_keys($comments);
			
			$condition = "area != ? and place = ? and item_id = ? and ".
				Database::array_in('root', $roots)." order by date";
			$params = array_merge($params, $roots);
			
			$children = Database::get_full_vector('comment', $condition, $params, false);
			$this->build_tree($children);
		} else {
			$children = array();
		}
		
		if ($display == 'quotation') {
			$parents = array();
			
			foreach ($comments as $comment) {
				$parents[] = $comment['parent'];
			}
			
			$condition = "area != ? and place = ? and item_id = ? and ".
				Database::array_in('id', $parents);
			$params = array_merge($params, $parents);
							
			$parents = Database::get_full_vector('comment', $condition, $params, false);
		} else {
			$parents = array();
		}		

		foreach ($comments as $id => $comment) {
			$item_children = array();
			$item_parent = null;
			
			foreach ($children as $child_id => $child) {
				if ($id == $child['root']) {				
					$item_children[$child_id] = new Item_Comment($child, $display);
				}
			}
			
			foreach ($parents as $parent_id => $parent) {
				if ($parent_id == $comment['parent']) {				
					$item_parent = new Item_Comment($parent);
				}
			}
			
			$this->items[$id] = new Item_Comment(
				array_merge(
					$comment, 
					array(
						'items' => $item_children,
						'quotation' => $item_parent,
						'index' => (bool) $inverted ? $current-- : ++$current,
					)
				),
				$display
			);
		}

		$this->items[] = new Item_Comment_Navi(array(
			'curr_page' => $page,
			'pagecount' => ceil($total / $perpage),
			'query' => $query,
			'module' => 'comments',
		));
	}
Example #17
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 #18
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 #19
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;
 }