/** * Вывод списка online-пользователей * @return null */ public function show_online() { $i = (int) config::o()->v('online_interval'); if (!$i) { $i = 15; } $time = time() - $i; $res = db::o()->p($time)->query('SELECT userdata FROM sessions WHERE time > ? GROUP BY IF(uid>0,uid,ip)'); $res = db::o()->fetch2array($res); tpl::o()->assign("res", $res); $c = count($res); $mo = stats::o()->read("max_online"); if (!intval($mo) || $mo < $c) { $mo = $c; stats::o()->write("max_online", $c); stats::o()->write("max_online_time", time()); } $mot = stats::o()->read("max_online_time"); tpl::o()->assign("record_total", $mo); tpl::o()->assign("record_time", $mot); /* @var $user user */ $user = plugins::o()->get_module("user"); lang::o()->get("profile"); tpl::o()->register_modifier("gau", array($user, "get_age")); tpl::o()->assign("bdl", $this->bd_list()); tpl::o()->display("blocks/contents/online.tpl"); }
/** * Очистка таблиц перед вставкой * @return null */ private function truncate_tables() { $content = $this->convert_tables(); $c = preg_match_all('/\\s*?^table\\s+(\\w+)/miu', $content, $matches); for ($i = 0; $i < $c; $i++) { db::o()->truncate_table($matches[1][$i]); } stats::o()->remove(self::stfield); printf(lang::o()->v('convert_truncated_tables'), $c); }
/** * Инициализация AJAX-части модуля * @return null */ public function init() { lang::o()->get('admin/pages/main'); if (!users::o()->perm('system')) { return; } $act = $_GET["act"]; users::o()->admin_mode(); /* @var $etc etc */ $etc = n("etc"); $all = false; switch ($act) { case "attachments": $all = true; case "unattachments": /* @var $attach attachments */ $attach = n("attachments"); $attach->clear(0, $all); break; case "sitemap": $this->sitemap(); ok(); break; case "cleanup": /* @var $cleanup cleanup */ $cleanup = n("cleanup"); $cleanup->execute(true); break; case "cache": cache::o()->clear(); break; case "cache_tpl": cache::o()->clear_tpl(); break; case "stats": $st = stats::o()->read(); foreach ($st as $s => $v) { stats::o()->write($s, 0); } break; case "logs": /* @var $logs logs_man_ajax */ $logs = plugins::o()->get_module('logs', 1, true); $logs->clear(); break; case "peers": db::o()->truncate_table('content_peers'); db::o()->update(array('leechers' => 0, 'seeders' => 0), 'content_torrents'); break; case "downloaded": db::o()->truncate_table('content_downloaded'); db::o()->update(array('downloaded' => 0), 'content_torrents'); break; case "chat": /* @var $chat chat */ $chat = plugins::o()->get_module('chat'); $chat->truncate(); break; case "pm": /* @var $pm messages_ajax */ $pm = plugins::o()->get_module('messages', false, true); $pm->clear(); break; case "ratings": $r = db::o()->query('SELECT toid, type FROM ratings GROUP BY toid, type'); /* @var $rating rating */ $rating = n("rating"); while ($row = db::o()->fetch_assoc($r)) { $rating->change_type($row['type'])->clear($row['toid']); } break; // Далее: Важная часть сайта, да // Далее: Важная часть сайта, да case "content": $r = db::o()->query('SELECT id FROM content'); while (list($id) = db::o()->fetch_row($r)) { try { $etc->delete_content($id); } catch (EngineException $e) { } } break; case "comments": /* @var $comments comments */ $comments = n("comments"); $comments->clear(null, true); break; case "polls": /* @var $polls polls */ $polls = n("polls"); $polls->clear(); break; case "news": /* @var $news news_ajax */ $news = plugins::o()->get_module('news', false, true); $news->clear(); break; case "bans": $r = db::o()->query('SELECT id FROM bans'); while (list($id) = db::o()->fetch_row($r)) { $etc->unban_user(null, $id); } break; case "warnings": $r = db::o()->query('SELECT id FROM warnings'); while (list($id) = db::o()->fetch_row($r)) { $etc->unwarn_user(null, null, $id); } break; } log_add('system_clean', 'admin', array(lang::o()->v('main_page_clear_' . $act), $act)); ok(); }
/** * Отображение контента * @param int $id ID контента * @param bool $full детальный? * @param bool $fe от редактирования? * @param array $data категория/дата * @return null * @throws EngineException */ public function show($id = null, $full = null, $fe = false, $data = null) { lang::o()->get('content'); if (!$data) { $data = $_REQUEST; } $id = (int) $id; try { list($where, $cat, $orderby, $lj) = $this->show_prepare($data, $id, $full, $fe); $where = implode(" AND ", $where); $page = 'page'; if (!$full && !$fe) { $slj = $lj; //if ($this->tstate) // $lj = " LEFT JOIN content_torrents AS t ON t.cid=c.id"; $crow = db::o()->no_parse()->query('SELECT COUNT(*) FROM ' . db::table('content') . ' AS c ' . $slj . ($where ? ' WHERE ' . $where : "")); $count = db::o()->fetch_row($crow); $count = $count[0]; $perpage = config::o()->v('content_perpage'); $maxpage = intval($count / $perpage) + ($count % $perpage != 0 ? 1 : 0); list($pages, $limit) = display::o()->pages($count, $perpage, 'change_tpage', $page, '', true); tpl::o()->assign("pages", $pages); tpl::o()->assign('page', $_GET[$page]); tpl::o()->assign('maxpage', $maxpage); } elseif ($full) { $limit = 1; } $query = $this->show_query($full, $lj, $where, $orderby, $limit); $rows = db::o()->fetch2array(db::o()->no_parse()->query($query)); if ($full && !$rows) { throw new EngineException("content_not_exists"); } $last_clean = stats::o()->read('last_clean_rc'); if (!$fe && $full && !$rows[0]['readed'] && $rows[0]['posted_time'] > $last_clean) { $this->make_readed($id); } if (!$fe && $full) { $this->show_meta($rows[0]); } plugins::o()->pass_data(array('rows' => &$rows), true)->run_hook('content_show_end'); tpl::o()->register_modifier("show_image", array($this, 'show_image')); tpl::o()->register_modifier("prepend_title_icon", array($this, 'prepend_title_icon')); tpl::o()->register_modifier("content_prefilter", array($this, 'prefilter')); tpl::o()->assign('content_row', $rows); tpl::o()->assign('last_clean_rc', $last_clean); tpl::o()->assign('statuses', self::$status); n('rating'); // для display_rating //if ($full) { n("comments"); // для display_comments n('polls'); // для display_polls n('attachments'); // для display_attachments //} if (tpl::o()->template_exists('content/cats/' . $cat . ".tpl") && $cat) { tpl::o()->display('content/cats/' . $cat . ".tpl"); } else { tpl::o()->display('content/index.tpl'); } } catch (PReturn $e) { return $e->r(); } }
/** * Очистка прочтённого контента * @return null */ protected function clear_readcontent() { if (!config::o()->v('clean_rc_interval')) { return; } $day = 86400; // Секунд в день $time = stats::o()->read('last_clean_rc'); if (time() < $time + config::o()->v('clean_rc_interval') * $day) { return; } db::o()->truncate_table('content_readed'); stats::o()->write('last_clean_rc', time()); }
/** * Получение списка категорий * @param int $category ID категории * @param string $incat ID'ы подкатегорий * @return string список категорий */ public function get_catid($category, $incat) { $mid = stats::o()->read(convert::stfield); $incat = unserialize($incat); if (!$incat) { return ',' . $category . ','; } $r = ''; foreach ($incat as $ic) { if ($ic) { $r .= "," . ($mid + $ic); } } return ($r ? $r : ',' . $category) . ','; }
/** * Получение объекта класса * @return stats $this */ public static function o() { if (!self::$o) { self::$o = new self(); } return self::$o; }
if (!file_exists('install/lock') && file_exists('install/')) { @header('Location: install.php'); die; } define('DELAYED_UINIT', true); // отложенная инициализация юзерей... include_once "./include/include.php"; $module = $_GET['module']; blocks::set_module($module ? $module : "index"); $this_file = globals::g('baseurl') . "index.php?module=" . $module; tpl::o()->assign("this_file", $this_file); $ajax = (bool) $_REQUEST['from_ajax']; // Из AJAX $nno = (bool) $_REQUEST['nno']; // Стандартный класс(без постфикса '_ajax') if (!$ajax && ($current = stats::o()->read(DATABASE_STATS)) != DATABASE_VERSION) { /* @var $m message */ $m = n("message"); $m->error('need_to_upgrade_database', array(DATABASE_VERSION, $current ? $current : "unknown")); } globals::s('ajax', $ajax); tpl::o()->assign('from_ajax', $ajax); tpl::o()->assign('module_loaded', $module); if ($module) { if (!allowed::o()->is($module)) { die(lang::o()->v('module_not_exists')); } $mod = plugins::o()->get_module($module, false, $ajax && !$nno); if (!$mod) { die(lang::o()->v('module_not_exists')); }
/** * Создание администратора * @param array $data массив данных * @param array $error массив ошибок * @return null */ protected function create_admin($data, &$error) { @mb_internal_encoding('UTF-8'); $group = 6; // группа админа extract(rex($data, array('username', 'password', 'passagain', 'email'))); include_once ROOT . 'include/classes/class.users.php'; if ($password != $passagain) { $error[] = lang::o()->v('install_error_passwords_not_match'); } if (!users::o()->check_login($username)) { $error[] = lang::o()->v('install_error_wrong_username'); } if (!users::o()->check_password($password)) { $error[] = lang::o()->v('install_error_wrong_password'); } $tmp = false; // reference if (!users::o()->check_email($email, $tmp)) { $error[] = lang::o()->v('install_error_wrong_email'); } if ($error) { return; } db::o()->truncate_table('users'); $salt = users::o()->generate_salt(); $salt2 = users::o()->generate_salt(); $passhash = users::o()->generate_pwd_hash($password, $salt); $insert = array('username' => $username, 'username_lower' => mb_strtolower($username), 'confirmed' => 3, 'email' => $email, 'password' => $passhash, 'salt' => $salt, 'registered' => time(), 'group' => $group, 'passkey' => $salt2); users::o()->write_cookies($username, $passhash); db::o()->insert($insert, "users"); stats::o()->write(DATABASE_STATS, DATABASE_VERSION); }