public function delete () { $id = query::$get['id']; if (!is_numeric($id)) { return; } $data = Database::get_row('board', 'type, cookie', $id); if ( query::$cookie != $data['cookie'] && query::$cookie != def::get('board', 'moderator') ) { return; } Database::update('board', array('type' => 'deleted'), $id); if ($data['type'] == 'thread') { Database::update('board', array('type' => 'deleted'), 'thread = ?', $id); } $mail = new mail(def::notify('mail')); $mail->text("Deleted board №$id, by " . query::$cookie) ->send(); }
public function __construct($id) { if ($id && is_numeric($id) && $this->type) { $data = Database::get_row('item', array('id', 'dir'), 'type = ? and id_type = ?', array($this->type, $id)); } if (!empty($data)) { $this->id_local = $id; $this->id = $data['id']; $this->dir = $data['dir']; } }
public function description ($query) { $params = array(); if (isset($query['meta']) && $query['meta'] == 'author' && isset($query['alias'])) { $params['type'] = 'author'; $params['id'] = $query['alias']; } elseif (isset($query['id'])) { $params['type'] = 'art'; $params['id'] = $query['id']; } else { return; } $text = Database::get_row( 'description', array('text', 'pretty_text'), 'type = ? and description_id = ?', $params ); if (!empty($text)) { $params = array_merge($params, $text); } if ($params['type'] == 'author') { $user = Meta_Author::get_data_by_alias((array) $params['id']); $user = current($user); $params['username'] = $user['name']; } else { $params['data'] = Database::get_full_row('art', $query['id']); $params['username'] = Database::get_field('user', 'username', $params['data']['user_id']); $params['alias'] = Meta_Author::get_alias_by_name($params['username']); $params['data']['weight'] = Transform_File::weight($params['data']['weight']); $params['data']['date'] = Transform_String::rudate(Database::date_to_unix($params['data']['date'])); } $params['can_edit'] = ($params['username'] == Globals::user_info('username')); return $params; }
public function init() { $config = Config::getInstance(); $this->name = $config->get('cookie', 'name', $this->name); // Удалим все левые куки, нечего захламлять пространство foreach ($_COOKIE as $key => $cook) { if ($key != $this->name) { setcookie ($key, '', time() - 3600); } } if ($config->get('site', 'domain') != 'localhost') { $this->domain = $config->get('site', 'domain'); } // Хэш. Берем либо из cookie, если валиден, либо генерим новый if (!empty($_COOKIE[$this->name]) && ctype_xdigit($_COOKIE[$this->name])) { $this->hash = $_COOKIE[$this->name]; } else { $this->hash = md5(microtime(true)); } // Пробуем прочитать настройки для хэша $sess = Database::get_row('cookie', ['id', 'lastchange'], 'cookie = ?', $this->hash); // Проверяем полученные настройки if (!empty($sess)) { // Настройки есть if (intval($sess['lastchange']) < (time()-3600*24*30)) { // Обновляем cookie еще на 2 мес у клиента, если она поставлена больше месяца назад $this->update_lifetime(); } $this->id = $this->parse_data($sess['id']); } else { $this->id = $this->create_session(); } }
public function save_category_form($term_id) { // Run this method only once if ($this->save_count < 1) { $id = $this->args['id']; $data = Database::get_row($this->args['table'], 'cat_id', $term_id); foreach ($this->args['table']['structure'] as $name => $args) { $data[$name] = isset($_POST[$name]) ? $_POST[$name] : $data[$name]; } if (empty($data['cat_id'])) { $data['cat_id'] = $term_id; Database::insert_row($this->args['table'], $data); } else { Database::update_row($this->args['table'], 'cat_id', $term_id, $data); } $this->save_count++; } }
public static function add_share($post_id, $network) { $network = strtolower($network); $networks = array(); $resp = array(); foreach (static::$networks as $name => $value) { array_push($networks, $name); } $resp['status'] = 'error'; $resp['type'] = 'invalid-format'; $resp['message'] = 'The submitted post ID does not match the required format.'; // Scrub out invalid post_id's if (preg_match('/^[0-9]+$/', $post_id)) { $resp['type'] = 'invalid-network'; $resp['message'] = 'The submitted network name is not supported'; // Scrub out invalid network names if (in_array($network, $networks)) { $data = Database::get_row(static::$table, 'post_id', $post_id); $data[$network . '_shares'] = (int) $data[$network . '_shares'] + 1; if (Database::save_data(static::$table, $data)) { $resp['status'] = 'success'; $resp['type'] = 'success'; $resp['message'] = 'The share was successfully recorded'; } else { $resp['type'] = 'database-error'; $resp['message'] = 'An error occured connecting to the database. Try again later.'; } } } return $resp; }
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; }
public static function get_key($name) { $data = Database::get_row(static::$table, 'name', strtolower(str_replace(' ', '_', $name))); return !empty($data['api_key']) ? $data['api_key'] : ''; }
/** * @param Database $database * @param string $csv */ private function add_alias_csv(Database $database, $csv) { $csv = str_replace("\r", "\n", $csv); foreach (explode("\n", $csv) as $line) { $parts = str_getcsv($line); if (count($parts) == 2) { $pair = array("oldtag" => $parts[0], "newtag" => $parts[1]); if (!$database->get_row("SELECT * FROM aliases WHERE oldtag=:oldtag AND lower(newtag)=lower(:newtag)", $pair)) { if (!$database->get_row("SELECT * FROM aliases WHERE oldtag=:newtag", array("newtag" => $pair['newtag']))) { $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(:oldtag, :newtag)", $pair); } } } } }
protected static function remove_from_database($email) { $email = strtolower($email); $data = Database::get_row(static::$table, 'email', $email); $status = 'error'; if (empty($data['email'])) { $status = 'not-found'; } else { $data['email'] = 'deleted-' . rand(9999, 99999999); $data['status'] = 'deleted'; $data['delete_date'] = date('Y-m-d', time()); $data['delete_time'] = date('H:i:s', time()); $email = ['sender' => !empty(get_option('mailing_list_settings_sender')) ? get_option('mailing_list_settings_sender') : get_bloginfo('admin_email'), 'recipient' => $email, 'subject' => 'Unsubscribe Confirmation', 'template' => 'unsubscribe.php']; new Email($email); $status = Database::update_row(static::$table, 'id', $data['id'], $data) ? 'success' : 'error'; } return $status; }
// Пробуем прочитать настройки для хэша $sess = Database::get_row('settings', array('data', 'lastchange'), 'cookie = ?', query::$cookie); // Проверяем полученные настройки if (isset($sess['data']) && isset($sess['lastchange'])) { // Настройки есть // Обновляем cookie еще на 2 мес у клиента, если она поставлена больше месяца назад if (intval($sess['lastchange']) < time() - 3600 * 24 * 30) { setcookie('settings', query::$cookie, time() + 3600 * 24 * 60, '/', $cookie_domain); // Фиксируем факт обновления в БД Database::update('settings', array('lastchange' => time()), 'cookie = ?', query::$cookie); } // Проверяем валидность настроек и исправляем, если что-то не так if (base64_decode($sess['data']) !== false && is_array(unserialize(base64_decode($sess['data'])))) { // Все ок, применяем сохраненные настройки $sets = array_replace_recursive($sets, unserialize(base64_decode($sess['data']))); $user = Database::get_row('user', 'login, email, rights', 'cookie = ?', query::$cookie); if (!empty($user)) { $sets['user'] = array_replace($sets['user'], $user); } sets::import($sets); } else { // Заполняем поле настройками 'по-умолчанию' (YTowOnt9 разворачивается в пустой массив) Database::update('settings', array('data' => 'YTowOnt9'), 'cookie = ?', query::$cookie); } } else { // Настроек нет, создаем их setcookie('settings', query::$cookie, time() + 3600 * 24 * 60, '/', $cookie_domain); // Вносим в БД сессию с дефолтными настройками Database::insert('settings', array('cookie' => query::$cookie, 'data' => 'YTowOnt9', 'lastchange' => time())); } }
/** * Custom meta box to display popularity (likes & views). * * @package Интоор Library (intoor) * @author Colton James Wiscombe <*****@*****.**> * @copyright 2014 Hazard Media Group LLC * @license MIT License - http://www.opensource.org/licenses/mit-license.html * @link https://github.com/Alekhen/intoor-lib * @version Release: 1.2 */ if (!defined('INTOOR_RESTRICT_ACCESS') || !INTOOR_RESTRICT_ACCESS) { die('Unauthorized Access'); } global $post; $social = Database::get_row(Social::$table, 'post_id', $post->ID); $inflated = $array['inflate']; if (!empty($data[0])) { extract($data[0]); echo "<table style='font-size:1.2em; width:100%;'>"; echo $inflated ? "<thead><tr><th style='width:30%;'></th><td style='width:23%;'><em><small>Real</small></em></td><td style='width:23%;'><em><small>Infl</small></em></td><td style='width:23%;'><em><small>Total</small></em></td></thead>" : ""; echo "<tbody>"; // Display views $views_math = $inflated ? "<td><small>+0</small></td><td><small>= {$views}</small></td>" : ""; echo "<tr><th style='text-align:left;'>Views:</th><td><strong>{$views}</strong></td>{$views_math}</tr>"; // Display likes $likes_math = $inflated ? "<td><small>+{$infl}</small></td><td><small>= " . ($likes + $infl) . "</small></td>" : ""; echo "<tr><th style='text-align:left;'>Likes:</th><td><strong>{$likes}</strong></td>{$likes_math}</tr>"; // Display shares if (!empty($social)) { extract($social);
public static function get_likes($infl = true) { global $post; $data = Database::get_row(static::$table, 'post_id', $post->ID); $likes = $infl && !empty($data['post_id']) ? (int) $data['likes'] + (int) $data['infl'] : (int) $data['likes']; return $likes; }
public static function get_twitter_description($data = array()) { global $post; $data = !empty($data) ? $data : Database::get_row(static::$table, 'post_id', $post->ID); $description = !empty($data['twitter_description']) ? $data['twitter_description'] : ''; $description = !empty($description) ? $description : $post->post_excerpt; return !empty($description) ? '<meta name="twitter:description" content="' . $description . '">' : ''; }