Example #1
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 #2
0
 protected function link($url)
 {
     $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_vector('post_link', 'post_id = ?', $this->data['id']);
     foreach ($links as &$link) {
         $link = new Model_Post_Link($link);
     }
     $this->data['link'] = $links;
 }
Example #3
0
 public function set_deck($user, $cards)
 {
     $count = (int) Database::join('game_booster', 'gb.id_game_set = gs.id')->get_count('game_set', 'gs.id_game = ? and gb.id_user = ?', array($this->get_id(), $user));
     if ($count < 2) {
         throw new Error();
     }
     parent::set_deck($user, $cards);
 }
Example #4
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 #5
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 #6
0
 /**
  * Returns a list of the field names and values for a given userlevel
  *
  * @param int $id incident id
  * @param int $user_level the user's role level
  * @return Result
  */
 public static function view_everything($id, $user_level)
 {
     $db = new Database();
     $db->select('form_response.form_response', 'form_field.field_name');
     $db->from('form_response');
     $db->join('form_field', 'form_response.form_field_id', 'form_field.id');
     $db->where(array('form_response.incident_id' => $id, 'form_field.field_ispublic_visible <=' => $user_level));
     $db->orderby('form_field.field_position');
     return $db->get();
 }
Example #7
0
 protected function get_links()
 {
     $id = $this->get_id();
     $post = new Model_Post($id);
     $links = Database::join('post_link_url', 'plu.link_id = pl.id')->join('post_url', 'plu.url_id = pu.id')->get_full_table('post_link', 'pl.post_id = ?', $id);
     foreach ($links as $link) {
         $link = new Model_Post_Link($link);
         $post->add_link($link);
     }
     return $post->get('link');
 }
Example #8
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 #9
0
 protected function get_data()
 {
     $data = parent::get_data();
     $this->game['booster'] = Database::join('set', 's.id = gs.id_set')->order('gs.order', 'asc')->get_table('game_set', 's.name, s.id, gs.state', 'gs.id_game = ?', $this->game['id']);
     foreach ($this->game['booster'] as &$booster) {
         $booster['name'] = str_replace("'", '&apos;', $booster['name']);
     }
     if (empty($this->game['start']) || $this->game['start'] == '0000-00-00 00:00:00') {
         $this->game['start'] = 0;
     } else {
         $this->game['start'] = strtotime($this->game['start']);
     }
     $data['game'] = $this->game;
     return $data;
 }
Example #10
0
	public function update() {

		if (!Check::num(query::$get['id'])) {
			return array();
		}

		$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_vector('post_link',
				'pl.post_id = ?', query::$get['id']);

		foreach ($links as &$link) {
			$link = new Model_Post_Link($link);
		}

		return $links;
	}
Example #11
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 #12
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 #13
0
 /**
  * Lists the reports.
  * @param int $page
  */
 function index($page = 1)
 {
     $this->template->content = new View('admin/mhi');
     $this->template->content->title = Kohana::lang('ui_admin.multiple_hosted_instances');
     $this->template->content->domain_name = $_SERVER['HTTP_HOST'];
     // check, has the form been submitted?
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     if ($_POST) {
         $post = Validation::factory($_POST);
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('action', 'required', 'alpha', 'length[1,1]');
         $post->add_rules('instance_id.*', 'required', 'numeric');
         if ($post->validate()) {
             if ($post->action == 'a') {
                 // Approve Action
                 foreach ($post->instance_id as $item) {
                     $update = new Mhi_Site_Model($item);
                     if ($update->loaded == true) {
                         $update->site_active = '1';
                         $update->save();
                     }
                 }
                 $form_action = strtoupper(Kohana::lang('ui_admin.approved'));
             } elseif ($post->action == 'u') {
                 // Unapprove Action
                 foreach ($post->instance_id as $item) {
                     $update = new Mhi_Site_Model($item);
                     if ($update->loaded == true) {
                         $update->site_active = '0';
                         $update->save();
                     }
                 }
                 $form_action = strtoupper(Kohana::lang('ui_admin.unapproved'));
             } elseif ($post->action == 'd') {
                 // Delete Action
                 foreach ($post->instance_id as $item) {
                     $update = new Mhi_Site_Model($item);
                     if ($update->loaded == true) {
                         $update->delete();
                     }
                 }
                 $form_action = Kohana::lang('ui_admin.deleted');
             }
             $form_saved = TRUE;
         } else {
             $form_error = TRUE;
         }
     }
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     // Status is the "Show All/Pending/Approved tabs'
     if (!empty($_GET['status'])) {
         $status = strtolower($_GET['status']);
         if ($status == 'a') {
             $filter = 'site_active = 1';
         } elseif ($status == 'p') {
             $filter = 'site_active = 0';
         }
     } else {
         $status = '0';
         $filter = '1=1';
         // Using 1=1 is a way to preserve the "where" statement to reduce code complexity
     }
     $this->template->content->status = $status;
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'), 'total_items' => ORM::factory('mhi_site')->where($filter)->count_all()));
     $this->template->content->pagination = $pagination;
     $db = new Database();
     $db->select('mhi_site.*, mhi_users.email, mhi_users.firstname, mhi_users.lastname');
     $db->from('mhi_site');
     $db->join('mhi_users', 'mhi_users.id', 'mhi_site.user_id');
     $db->where($filter);
     $db->orderby('mhi_site.site_dateadd', 'desc');
     $db->limit((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset);
     $instances = $db->get();
     $this->template->content->instances = $instances;
     $this->template->content->total_items = $pagination->total_items;
     // Javascript Header
     $this->template->js = new View('admin/mhi_js');
 }
Example #14
0
 protected static function load_settings($id)
 {
     return Database::join('user_setting', 'us.id_setting = s.id and id_user = '******'setting', array('s.setting', 'coalesce(us.value, s.default)'));
 }
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
$set = array_shift($argv);
if (empty($set)) {
    die('Set needed' . "\n");
}
$set = Database::get_full_row('set', 'id = ?', $set);
if (empty($set)) {
    die('Incorrect set' . "\n");
}
if (!$set['grabbed']) {
    Grabber::get_set($set['id']);
}
$folder = IMAGES . SL . 'import';
if (!file_exists($folder . SL . $set['id']) || !is_dir($folder . SL . $set['id'])) {
    die('No import folder' . "\n");
}
$cards = Database::join('set_card', 'sc.id_card = c.id')->get_table('card', 'image', 'sc.id_set = ?', $set['id']);
$images = glob($folder . SL . $set['id'] . SL . '*.jpg');
$import = array();
foreach ($images as $image) {
    $compare = str_replace($folder, '', $image);
    $compare = str_replace('.full.jpg', '.jpg', $compare);
    $compare = preg_replace('/[^a-zA-Z\\.\\/\\d\\-]|\\.(?!jpg$)/sui', '', $compare);
    foreach ($cards as $id => $card) {
        if ($compare == $card['image']) {
            $import[$image] = $card['image'];
            unset($cards[$id]);
            break;
        }
    }
}
if (!empty($cards)) {
 public function join($table, $field, $type = NULL)
 {
     if ($type != NULL) {
         $type = strtoupper($type) . " ";
     }
     self::$join = $type . "JOIN " . $table . " ON " . $field;
     return self::get_instance();
 }
Example #18
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 #19
0
 public static function get_land_cards($set)
 {
     if (empty(self::$card_cache[$set])) {
         $card_ids = Database::join('set_card', 'sc.id_card = c.id')->group('sc.rarity')->get_table('card', array('sc.rarity', 'group_concat(c.`id`) as ids'), 'sc.id_set = ? and c.color = ?', array($set, 'L'));
         $cards = array();
         foreach ($card_ids as $group) {
             $cards[$group['rarity']] = explode(',', $group['ids']);
         }
         self::$card_land_cache[$set] = $cards;
     }
     return self::$card_land_cache[$set];
 }
Example #20
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 #21
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;
 }