protected function do_add($data) { if (!isset($data['set']) || !is_array($data['set'])) { return array('success' => false); } if (!empty($data['start'])) { $utc = $data['utc'] + 240; $start = date('Y-m-d G:i:s', strtotime($data['start']) + $utc * 60); } else { $start = ''; } $sets = array(); foreach ($data['set'] as $set) { if (preg_match('/[^-\\d\\.a-z]/ui', $set)) { continue; } $set = Database::get_full_row('set', 'id = ?', $set); if (empty($set)) { continue; } $sets[] = $set; if (!$set['grabbed']) { Grabber::get_set($set['id']); } } Database::begin(); Database::insert('game', array('id_user' => $this->user, 'pick_time' => isset($data['pick_time']) ? $data['pick_time'] : 0, 'pause_time' => isset($data['pause_time']) ? $data['pause_time'] : 0, 'type' => isset($data['type']) ? $data['type'] : 1, 'start' => $start)); $id_game = Database::last_id(); $order = 0; foreach ($sets as $set) { Database::insert('game_set', array('id_game' => $id_game, 'order' => ++$order, 'id_set' => $set['id'])); } Database::commit(); return array('success' => true); }
protected function insert_url($url) { $id = Database::get_field('post_url', 'id', 'url = ?', $url); if (empty($id)) { Database::insert('post_url', array('url' => $url)); $id = Database::last_id(); } return $id; }
protected function do_add($data) { $time = date('Y-m-d G:i:s', time() - Config::get('chat', 'loadtime')); $presense = Database::get_count('presense', 'time > ? and id_user = ? and id_game = ?', array($time, $this->user, $this->id)); if (!isset($data['text']) || preg_match('/<>&\\n\\r/', $data['text']) || !$presense) { return array('success' => false); } Database::insert('message', array('id_game' => $this->id, 'id_user' => $this->user, 'text' => $data['text'])); return array('success' => true, 'id' => Database::last_id()); }
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; }
protected function create_data($users) { Database::update('game', array('state' => 1), $this->get_id()); $this->insert_users($users); $sets = Database::order('order', 'asc')->get_full_table('game_set', 'id_game = ?', $this->get_id()); $ids = array(); foreach ($sets as $set) { foreach ($users as $user) { Database::insert('game_booster', array('id_game_set' => $set['id'], 'id_user' => $user)); $booster = Database::last_id(); $booster = $this->make_booster($booster, $set['id_set'], $user); $ids = array_merge($ids, $booster->generate()); } } Grabber::get_images(array_unique($ids)); $this->insert_game_steps($sets); }
protected function process() { Database::insert('art_pack', array('filename' => $this->name, 'title' => $this->title, 'text' => Transform_Text::format(trim($this->text)), 'pretty_text' => $this->text)); $id = Database::last_id(); Database::insert('misc', array('type' => 'pack_status', 'data1' => 'starting', 'data2' => $id)); $newfile = ROOT_DIR . SL . 'files' . SL . 'pack_uploaded' . SL . $id . '.zip'; if (!move_uploaded_file($this->file, $newfile)) { $contents = file_get_contents($this->file); $start = substr($contents, 0, 3000); $end = substr($contents, 3000); unset($contents); $new_start = preg_replace('/^.{0,2000}?Content-Type:\\s+application\\/zip\\s+/is', '', $start); if (empty($new_start)) { $new_start = $start; } file_put_contents($newfile, $start . $end); } $this->set(array('success' => true, 'id' => $id, 'file' => $this->name)); }
break; default: $type = 0; break; } Database::insert('post_update_link', array('update_id' => $id, 'name' => $link['name'], 'size' => str_replace(',', '.', $link['size']), 'sizetype' => $type, 'order' => $i)); $link_id = Database::last_id(); $i++; $j = 0; foreach ($link['url'] as $key => $url) { $alias = $link['alias'][$key]; $exists = Database::get_full_row('post_url', 'url = ?', $url); if ($exists) { $url_id = $exists['id']; } else { Database::insert('post_url', array('url' => $url)); $url_id = Database::last_id(); } if ($url_id == 0) { var_dump($update); var_dump($link); } Database::insert('post_update_link_url', array('link_id' => $link_id, 'url_id' => $url_id, 'alias' => $alias, 'order' => $j)); $j++; } } } Database::delete('cron', 'function = ?', 'gouf_check'); Database::delete('cron', 'function = ?', 'gouf_refresh_links'); Database::insert('cron', array('function' => 'Post_Gouf::check', 'period' => '1m')); Database::insert('cron', array('function' => 'Post::delete_unused_urls', 'period' => '1h'));
public static function get_set($set, $transaction_started = false) { try { if (!$transaction_started) { Database::begin(); } $count = 0; while ($count < 2000) { $doc = new DOMDocument(); $url = 'http://www.mtg.ru/cards/search.phtml?Grp=' . $set . '&page=' . ++$count; @$doc->loadHTMLFile($url); $xpath = new DOMXpath($doc); $elements = $xpath->query(self::$queryCard); foreach ($elements as $element) { $insert = array('mana_cost' => ''); // $class = $element->getAttribute('class'); // $class = explode(' ', $class); // $insert['color'] = str_replace('Color', '', $class[0]); $rarity = $xpath->query(self::$queryRarity, $element)->item(0); if (empty($rarity)) { // Базовая земля или прочая хренька $rarity = 0; } else { $rarity = self::$rarity[$rarity->getAttribute('alt')]; } $name = $element->getElementsByTagName('h2')->item(0); if (empty($name)) { continue; } else { $name = $name->C14N(); } preg_match('/.*?<h2>(.+?)(?:<\\/h2>\\s*$|\\/\\s*<wbr)/sui', $name, $name); $insert['name'] = trim($name[1]); $insert['image'] = $xpath->query(self::$queryImg, $element)->item(0)->getAttribute('src'); $insert['image'] = str_replace('/pictures', '', $insert['image']); $insert['image'] = str_replace('_small/', '/', $insert['image']); $manas = $xpath->query(self::$queryMana, $element); $colors = ''; foreach ($manas as $mana) { $mana_symbol = $mana->getAttribute('alt'); $insert['mana_cost'] .= '(' . $mana_symbol . ')'; $colors .= preg_replace('/[^WUBRG]/u', '', $mana_symbol); } $colors = array_filter(array_unique(str_split($colors))); if (count($colors) > 1) { $insert['color'] = 'M'; } elseif (!trim($insert['mana_cost'])) { $insert['color'] = 'L'; } elseif (!empty($colors)) { $insert['color'] = reset($colors); } else { $insert['color'] = 'A'; } Database::insert('card', $insert); Database::insert('set_card', array('id_set' => $set, 'id_card' => Database::last_id(), 'rarity' => $rarity)); } $last = $xpath->query(self::$queryLast)->item(0); if (!strpos($last->C14N(), '|')) { break; } } Database::update('set', array('grabbed' => 1), 'id = ?', $set); Database::commit(); } catch (DOMException $e) { Database::rollback(); } }
protected function create_session() { // Вносим в БД сессию с дефолтными настройками Database::insert('cookie', ['cookie' => $this->hash]); $id = Database::last_id(); $this->update_lifetime(); return $id; }
protected function do_add_strip($get) { if (empty($get['title'])) { return array('success' => false); } $title = $get['title']; $text = empty($get['text']) ? '' : $get['text']; $date = empty($get['date']) ? '' : $get['date']; $pictures = empty($get['picture']) ? array() : (array) $get['picture']; $order = empty($get['order']) ? 0 : (int) $get['order']; $insert = array('text' => $text, 'title' => $title, 'order' => $order); if (preg_match('/^\\s*(\\d{2})\\s*\\/\\s*(\\d{2})\\s*\\/\\s*(\\d{2})\\s*$/ui', $date, $date_parts)) { $insert['date'] = '20' . $date_parts[1] . '-' . $date_parts[2] . '-' . $date_parts[3]; } Database::insert('strip', $insert); $id = Database::last_id(); foreach ($pictures as $key => $picture) { Database::insert('strip_file', array('id_strip' => $id, 'id_file' => (int) $picture, 'order' => (int) $key)); } return array('success' => true, 'id' => $id); }
public function objectToDb() { $db = new Database(); //TODO HACER CON TRANSACCIONES EN MYSQL $q = "insert into notificacion values({$this->id}, {$this->idJ1}, {$this->idG}, {$this->idE}, {$this->tn}, {$this->fecha})"; $r = $db->query($q); $lastId = $db->last_id(); $q = "insert into jugadorNotificacion values({$this->idJ2}, {$lastId}, {$this->visto})"; $r = $db->query($q); $db->commit(); $db->close(); }
public function insert() { if ($this->is_phantom) { Database::insert($this->table, $this->data); $id = Database::last_id(); if (count($this->primary) == 1) { $key = reset($this->primary); $this->set($key, $id); } $this->is_phantom = false; } return $this; }