/** * Подсчёт кол-ва контента в данном месяце и в данном году * @param int $month данный месяц * @param int $year данный год * @return string JS массив кол-ва торрентов по дням */ public function count_content($month = null, $year = null) { $month = !$month ? date("n") : $month; $year = !$year ? date("Y") : $year; if (!($r = cache::o()->read('calendar/c' . $month . '-' . $year))) { $year_after = $month == 12 ? $year + 1 : $year; $month_after = $month < 12 ? $month + 1 : 1; $from = mktime(null, null, null, $month, 1, $year); $to = mktime(null, null, null, $month_after, 1, $year_after); $datas = db::o()->p($from, $to)->query('SELECT posted_time FROM content WHERE posted_time BETWEEN ? AND ?'); //$count = count($datas); $content = array(); while ($data = db::o()->fetch_assoc($datas)) { $day = date("j", $data["posted_time"]); $content[$day]++; } $ncontent = ""; for ($i = 0; $i <= 31; $i++) { $ncontent .= ($ncontent !== "" ? ", " : "") . longval($content[$i]); } $r = array("new Array(" . $ncontent . ")"); cache::o()->write($r); } return $r[0]; }
/** * Конструктор? А где конструктор? А нет его. * @return null */ private function __construct() { if (!$this->res) { $res = db::o()->query("SELECT * FROM stats"); $this->res = db::o()->fetch2array($res, null, array("name" => "value")); } }
/** * Инициализация файловых типов * @return null */ public function __construct() { if (self::$inited) { return false; } self::$file_types = db::o()->cname('filetypes')->ckeys('name', 0)->query("SELECT * FROM allowed_ft"); lang::o()->get("file"); self::$inited = true; }
/** * Инициализация блока новостей * @return null */ public function init() { if (!config::o()->mstate('news')) { return; } lang::o()->get('news'); $l = (int) config::o()->v('news_max'); $a = db::o()->cname('news')->query('SELECT n.*, u.username, u.group FROM news AS n LEFT JOIN users AS u ON u.id=n.poster_id ORDER BY n.posted_time DESC' . ($l ? ' LIMIT ' . $l : "")); tpl::o()->assign('rows', $a); tpl::o()->display('news/index.tpl'); }
/** * Стат. страницы * @return null */ public function init() { $url = $_GET['page']; $r = db::o()->p($url)->query('SELECT * FROM static WHERE url=? LIMIT 1'); $row = db::o()->fetch_assoc($r); if (!$row) { furl::o()->location(''); } $this->title = $row['title']; tpl::o()->assign('title', $row['title']); tpl::o()->assign('content', $row['content']); tpl::o()->assign('type', $row['type']); tpl::o()->display('static.tpl'); }
/** * Метод редактирования комментария * @param int $id ID комментария * @return null */ protected function edit_form($id) { $id = (int) $id; lang::o()->get('comments'); $poster = db::o()->p($id)->query('SELECT poster_id, text FROM comments WHERE id=? LIMIT 1'); $poster = db::o()->fetch_assoc($poster); if (!$poster) { return; } if ($poster['poster_id'] == users::o()->v('id')) { users::o()->check_perms('edit_comm'); } else { users::o()->check_perms('edit_comm', 2); } $name = "comment_" . $id; tpl::o()->assign("text", $poster['text']); tpl::o()->assign("id", $id); tpl::o()->assign("name", $name); $this->comments->add("", $name, $id); }
/** * Удаление стат. страницы * @param int $id ID страницы * @return null */ public function delete($id) { $id = (int) $id; db::o()->p($id)->delete('static', 'WHERE id=? LIMIT 1'); log_add('deleted_static', 'admin', $id); }
/** * Вывод статистики по запросам * @return string HTML код */ function query_stat() { if (!config::o()->v('show_process') || !users::o()->perm('acp', 2)) { return; } $r = ""; foreach (db::o()->query_stat as $n => $stat) { $r .= "[" . ($n + 1) . "] => \n <b><font color='" . ($stat['seconds'] > 0.01 ? "red" : "green") . "'>\n " . $stat["seconds"] . "</font></b> [" . $stat["query"] . "]<br>"; } return "<div class='query_stat'>" . $r . "</div>"; }
/** * Автоапдейт групп * @return null */ public function groups_autoupdate() { $a = $k = array(); try { plugins::o()->pass_data(array('update_columns' => &$this->update_columns), true)->run_hook('users_groups_autoupdate'); } catch (PReturn $e) { return $e->r(); } $cols = $this->update_columns; $c = count($cols); $w = array(); foreach ($this->groups as $id => $group) { $t = false; for ($i = 0; $i < $c; $i++) { $v = $group[$cols[$i] . "_count"]; if ($v) { if (!$a[$i] || !in_array($v, $a[$i])) { $a[$i][$k[$i]++] = $v; } $t = true; } } if ($t) { $w[] = $id; } } if (!$w) { return; } $w[] = $this->find_group('default'); for ($i = 0; $i < $c; $i++) { if ($a[$i]) { sort($a[$i]); } } foreach ($this->groups as $id => $group) { $where = ""; for ($i = 0; $i < $c; $i++) { if (!$a[$i]) { continue; } $e = $cols[$i] . "_count"; $v = $group[$e]; if (($j = array_search($v, $a[$i])) !== false) { db::o()->p($v); $where .= ($where ? " AND " : "") . "`" . $e . "`>=?"; if ($a[$i][++$j]) { db::o()->p($a[$i][$j]); $where .= " AND `" . $e . "`<?"; } } } if (!$where) { continue; } db::o()->p($w)->update(array("group" => $id), "users", "WHERE " . $where . " AND `group` IN (@" . count($w) . '?)'); } }
/** * Выборка и вставка значений из таблицы * @param string $table имя таблицы вставки * @param string $orderby сортировка таблицы выборки * @param string $ftable имя таблицы выборки * @param string $cond условие для выборки * @param int $limit ограничение * @param bool $noerr без ошибок? * @return bool статус выбокри/вставки */ private function select4insert($table, $orderby, $ftable, $cond, $limit, $noerr = false) { $query = "SELECT "; $c = count($this->columns); for ($i = 0; $i < $c; $i++) { $query .= ($i ? ', ' : '') . $this->columns[$i]; } $orderby = '`' . implode('`, `', array_map('trim', explode(',', $orderby))) . '`'; $query .= " FROM `" . $this->db . "`.`" . $this->prefix . $ftable . "`" . ($cond ? " WHERE " . $cond : "") . "\n ORDER BY " . $orderby . "\n LIMIT " . $limit . ',' . $this->peronce; $r = db::o()->no_error()->no_parse()->query($query); if (db::o()->errno()) { printf(lang::o()->v('convert_select_error'), $ftable, db::o()->errno(), db::o()->errtext()); if ($noerr) { return false; } else { die; } } while ($row = db::o()->fetch_assoc($r)) { db::o()->ignore()->insert($this->insert($row), $table, true); } db::o()->no_error()->save_last_table(); if (db::o()->errno()) { printf(lang::o()->v('convert_insert_error'), $table, db::o()->errno(), db::o()->errtext()); if ($noerr) { return false; } else { die; } } printf(lang::o()->v('convert_inserted_table'), $limit, $limit + $this->peronce - 1, $table, $ftable); return true; }
/** * Загрузка полей * @return null */ protected function load() { if (self::$fields) { return; } self::$fields = db::o()->cname('userfields')->ckeys('field')->query('SELECT * FROM users_fields'); }
/** * Удаление плагина * @param bool $replaced было ли успешно ВСЁ замененённое сохранено? * @return null */ public function uninstall($replaced = false) { db::o()->no_error()->query("ALTER TABLE `users` DROP `converted`"); }
/** * Сохранение порядка блоков * @return null * @throws EngineException */ public function save_order($sort) { if (!$sort) { throw new EngineException(); } foreach ($sort as $p => $obj) { foreach ($obj as $s => $id) { $id = (int) $id; db::o()->p($id)->update(array('pos' => (int) $s, 'type' => blocks_man::$types[$p]), 'blocks', 'WHERE id=? LIMIT 1'); } } db::o()->query('ALTER TABLE `blocks` ORDER BY `pos`'); }
/** * Сохранение настроек плагина * @param array $data массив данных * @return null * @throws EngineException */ protected function save($data) { $admin_file = globals::g('admin_file'); $id = $data['id']; $settings = serialize(modsettings::o()->save($id, $data)); db::o()->p($id)->update(array('settings' => $settings), 'plugins', 'WHERE file=? LIMIT 1'); plugins::o()->manager->uncache(); furl::o()->location($admin_file); }
* @version 1.00 */ if (!defined('INSITE')) { die('Remote access denied!'); } require_once ROOT . 'include/system/allowed.php'; require_once ROOT . 'include/system/globals.php'; require_once ROOT . 'include/system/autoload.php'; require_once ROOT . 'include/functions.php'; globals::s('start', timer()); // Start time require_once ROOT . 'include/smarty/Smarty.class.php'; require_once ROOT . 'include/functions_smarty.php'; @set_error_handler("myerror_report"); // Присваиваем функцию myerror_report, вместо стандартной, помогает избежать раскрытия путей. db::o()->connect(); init_baseurl(); lang::o()->change_folder(config::o()->v('default_lang')); init_spaths(); tpl::o()->register_modifier('lang', array(lang::o(), 'v')); // языковая переменная tpl::o()->register_modifier('getlang', array(lang::o(), 'get')); // подключение языка прямо в шаблоне tpl::o()->register_modifier('islang', array(lang::o(), 'visset')); // языковая переменная tpl::o()->register_modifier('config', array(config::o(), 'v')); // конфиг. переменная tpl::o()->register_modifier('mstate', array(config::o(), 'mstate')); // разрешён ли модуль tpl::o()->register_modifier('perm', array(users::o(), "perm")); // проверка на права
/** * Очистка старых сообщений чата * @return null */ protected function clear_chat() { if (!config::o()->v('chat_autoclear')) { return; } $hour = 3600; // Секунд в час $when = time() - config::o()->v('chat_autoclear') * $hour; db::o()->p($when)->delete('chat', 'WHERE posted_time <= ?'); }
/** * Отображение друзей пользователя * @param int $id ID пользователя * @return null */ public function show_user_friends($id) { $id = (int) $id; lang::o()->get("usercp"); $res = db::o()->p($id)->query('SELECT u.username,u.group,u.registered,u.gender,u.avatar,z.* FROM zebra AS z LEFT JOIN users AS u ON u.id=z.to_userid WHERE z.user_id=?'); tpl::o()->assign("row", db::o()->fetch2array($res)); tpl::o()->assign("from_profile", true); tpl::o()->display("usercp/friends.tpl"); }
define('INSITE', true); define('INANNOUNCE', true); require_once 'system/php_config.php'; require_once ROOT . 'include/classes/class.db.php'; require_once ROOT . 'include/classes/class.file.php'; // для кеша require_once ROOT . 'include/classes/class.cache.php'; // для кеша конфига require_once ROOT . 'include/classes/class.config.php'; require_once ROOT . 'include/classes/class.fbenc.php'; require_once ROOT . 'include/functions.php'; @set_error_handler("myerror_report"); // Присваиваем функцию myerror_report, вместо стандартной, помогает избежать раскрытия путей. /** * Вывод ошибки последнего запроса к БД * @param string $query строка запрос * @return null */ function db_errhandler($query = null) { $bt = new fbenc(); $bt->err(mysql_error()); } db::o()->errhandler('db_errhandler'); $bt = new fbenc(); db::o()->connect(); db::o()->no_reset(); config::o(array('content', 'announce', 'other')); if (!config::o()->v('torrents_on')) { die('Module turned off'); }
/** * Конструктор? А где конструктор? А нет его. * @param string|array $cat категория конфига * @return null */ private function __construct($cat = '') { $where = ""; if ($cat) { if (is_array($cat)) { $where = ' IN(@' . count($cat) . '?)'; } else { $where = ' =?'; } $where = ' WHERE cat ' . $where; } $r = db::o()->p($cat)->query("SELECT name, value FROM config" . $where); $this->vars = db::o()->fetch2array($r, null, array('name' => 'value')); }
/** * Анти-флуд проверка * @param string $table таблица * @param string $where условие * @param array $columns столбецы автора и времени постинга соотв. * @return null * @throws EngineException */ public function anti_flood($table, $where, $columns = array("poster_id", "posted_time")) { if (!is_array($columns) || !config::o()->v('antispam_time')) { return; } list($author, $time_var) = $columns; $time = time() - config::o()->v('antispam_time'); $lang_var = 'anti_flood_subj'; $uid = users::o()->v('id') ? users::o()->v('id') : -1; $c = db::o()->no_parse()->query('SELECT `' . $time_var . '` FROM `' . db::table($table) . '` WHERE ' . ($where ? $where . " AND " : "") . '`' . $author . "`=" . $uid . "\n AND `" . $time_var . "` >= " . $time . ' ORDER BY `' . $time_var . '` DESC LIMIT 1'); $c = db::o()->fetch_assoc($c); if ($c) { $intrvl_time = display::o()->estimated_time(config::o()->v('antispam_time') + 1, time() - $c[$time_var]); throw new EngineException($lang_var, $intrvl_time); } }
/** * Инициализация AJAX-части модуля * @return null */ public function init() { $POST = globals::g('POST'); lang::o()->get('admin/config'); $cprefix = config_man::config_prefix; $cprefix_length = strlen($cprefix); $keys = array(); $newcfg = array(); $i = 0; $sort = array(); foreach ($POST as $key => $value) { if (strpos($key, $cprefix) !== 0) { continue; } $key = substr($key, $cprefix_length); if (!config::o()->visset($key)) { continue; } $keys[] = $key; $newcfg[$key] = $value; $sort[$key] = ++$i; } if (!$keys) { return; } try { plugins::o()->pass_data(array("newcfg" => &$newcfg, "sort" => &$sort), true)->run_hook('admin_config_save'); } catch (PReturn $e) { return $e->r(); } $r = db::o()->p($keys)->query('SELECT name,type,allowed FROM config WHERE name IN(@' . count($keys) . '?)'); $c = 0; while (list($name, $type, $allowed) = db::o()->fetch_row($r)) { if (!$this->check_type($type, $newcfg[$name], $allowed, $name)) { continue; } $c++; config::o()->set($name, $newcfg[$name], $sort[$name]); } db::o()->query('ALTER TABLE `config` ORDER BY `cat`, `sort`'); log_add('changed_config', 'admin'); print $c; die; }
/** * Отображение комментариев пользователя/пользователей * @param int $id ID пользователя * @param string $where доп. условие * @return null */ public function usertable($id = null, $where = null) { lang::o()->get('profile'); if (!$this->state) { disabled(false); return false; } if (!users::o()->perm('comment')) { n("message")->stype("error")->info('comment_you_cannt_view'); return; } $id = (int) $id; $select = "c.id,c.posted_time,c.type,c.toid"; if (!$id) { $select .= ",c.poster_id"; } $where = $id ? 'c.poster_id=' . $id : ($where ? $where : ''); $comm_row = db::o()->no_parse()->query('SELECT ' . $select . (!$id ? ",u.username,u.group" : "") . ' FROM ' . db::table('comments') . ' AS c ' . (!$id ? 'LEFT JOIN ' . db::table('users') . ' AS u ON c.poster_id=u.id' : '') . ' ' . ($where ? " WHERE " . $where : "") . ' ORDER BY c.posted_time DESC LIMIT ' . config::o()->v('last_profile_comments')); $cr = array(); while ($rows = db::o()->fetch_assoc($comm_row)) { $res = db::o()->p($rows["toid"])->query('SELECT ' . $this->title_cols[$rows["type"]] . ' AS title FROM ' . $rows["type"] . ' WHERE id=? LIMIT 1'); $res = db::o()->fetch_assoc($res); $rows["title"] = $res["title"]; $cr[] = $rows; } tpl::o()->assign("comm_row", $cr); tpl::o()->display("profile/last_comments.tpl"); }
/** * Удаление плагина * @param string $plugin имя плагина * @return bool статус выполнения */ public function delete($plugin) { if (!validword($plugin)) { return false; } if (!$this->uninstall($plugin)) { return false; } db::o()->p($plugin)->delete("plugins", 'WHERE file=?'); if (function_exists('clear_aliases')) { clear_aliases(); } $this->uncache($plugin); return true; }
/** * Форма быстрого редактирования контента * @param int $id ID контента * @return null * @throws EngineException */ protected function quick_edit($id) { lang::o()->get("content"); $cols = $lj = $where = ""; if ($this->tstate) { $cols = ', t.*'; $lj = ' LEFT JOIN content_torrents AS t ON t.cid=c.id'; $where = " AND (t.banned <> '2' OR t.banned IS NULL)"; } $row = db::o()->p($id)->query('SELECT c.* ' . $cols . ' FROM content AS c ' . $lj . ' WHERE c.id=?' . $where . ' LIMIT 1'); $row = db::o()->fetch_assoc($row); if (!$row) { throw new EngineException(); } if (users::o()->v('id') == $row['poster_id']) { users::o()->check_perms('edit_content'); } else { users::o()->check_perms('edit_content', '2'); } tpl::o()->assign('row', $row); tpl::o()->display('content/edit.tpl'); }
<?php /** * Project: CTRev * @file /scrape.php * * @page http://ctrev.cyber-tm.ru/ * @copyright (c) 2008-2012, Cyber-Team * @author The Cheat <*****@*****.**> * @name Скрейп * @version 1.00 */ require_once './include/include_announce.php'; $info_hash = $_GET['info_hash']; if (!$info_hash) { $bt->err('Multi-scrape denied!'); } $infohash = bin2hex($info_hash); $r = db::o()->p($infohash)->query('SELECT seeders, leechers, downloaded FROM content_torrents WHERE info_hash=? LIMIT 1'); $row = db::o()->fetch_assoc($r); if (!$row) { $bt->err('Unknown torrent. Infohash - ' . $infohash); } $bt->benc_resp_raw($bt->benc(array('files' => array($info_hash => array('complete' => (int) $row['seeders'], 'downloaded' => (int) $row['downloaded'], 'incomplete' => (int) $row['leechers'])))));
/** * Инициализация смайлов * @return null */ public function init_smilies() { if ($this->smilies) { return; } $r = db::o()->cname('smilies')->query('SELECT name,image,code,show_bbeditor FROM smilies'); $this->smilies = array(array(), array()); foreach ($r as $row) { $this->smilies[$row['show_bbeditor']][] = $row; } }
/** * Включение/выключение возможности постить в категорию * @param int $id ID категории * @return null */ public function switch_state($id) { db::o()->p($id)->update(array('_cb_post_allow' => 'IF(post_allow="1","0","1")'), 'categories', 'WHERE id=? LIMIT 1'); }
/** * Генератор sitemap.xml * @return null */ public function sitemap() { $file = main_page::sitemap; $r = db::o()->query('SELECT * FROM content'); tpl::o()->assign('content', db::o()->fetch2array($r)); $c = tpl::o()->fetch('content/sitemap.xtpl'); file::o()->write_file($c, $file); }
/** * Создание условия для категории * @param int|array $id ID категории * @param bool $no_int не преобразовывать ID в целое число * @param string $column столбец для поиска * @return string условие, если есть данные */ public function cat_where($id, $no_int = false, $column = 'category_id') { if (!$id) { return; } if (!$column) { $column = 'category_id'; } //return '`'.$column.'` // ' . ($no_int ? "R" : "") . 'LIKE "' . (!$no_int ? "%" : "") . ',' . ($no_int ? "(" . $id . ")" : (int) $id) . ',' . (!$no_int ? "%" : "") . '"'; $column = db::o()->cesc($column) . ' LIKE '; $r = ""; if ($no_int) { if (!is_array($id)) { $id = explode(',', $id); } foreach ($id as $n) { $n = (int) trim($n); if (!$n) { continue; } $r .= ($r ? ' OR ' : '') . $column . '"%,' . $n . ',%"'; } if ($r) { $r = "(" . $r . ")"; } } else { $r = $column . '"%,' . intval($id) . ',%"'; } return $r; }
/** * Вывод сообщений чата * @param int $time время последней проверки или ID сообщения * @param bool $prev показать пред. сообщения, до этого ID * @return null */ public function show($time, $prev = false) { $time = (int) $time; users::o()->check_perms('chat', 2, 2); if ($time && !$prev) { $r = db::o()->p($time)->query('SELECT id FROM chat_deleted WHERE time>=?'); $del = ""; while (list($i) = db::o()->fetch_row($r)) { $del .= ($del ? "," : "") . $i; } tpl::o()->assign('deleted', $del); } $orderby = " ORDER BY c.posted_time DESC "; $limit = $orderby . (config::o()->v('chat_maxmess') ? " LIMIT " . config::o()->v('chat_maxmess') : ""); if ($prev) { $where = ' WHERE c.id < ?' . $limit; tpl::o()->assign('prev', true); } else { $where = $time ? ' WHERE c.edited_time>=?' . $orderby : $limit; } $r = db::o()->p($time)->query('SELECT c.*, u.username, u.group FROM chat AS c LEFT JOIN users AS u ON u.id=c.poster_id ' . $where); tpl::o()->assign('rows', array_reverse(db::o()->fetch2array($r))); tpl::o()->register_modifier('chat_mf', array($this, 'chat_mf')); tpl::o()->display('chat/chat.tpl'); }