/** * Отображение списка логов * @param string $type тип логов * @param string $sort сортировка * @return null */ protected function show($type = null, $sort = null) { tpl::o()->assign('curtype', $type); $orderby = ''; if ($sort) { $sort = explode(",", $sort); $c = count($sort); for ($i = 0; $i < $c; $i += 2) { if (!$this->orderby[$sort[$i]]) { continue; } $orderby .= ($orderby ? ', ' : '') . "`" . $this->orderby[$sort[$i]] . "` " . ($sort[$i + 1] ? "asc" : "desc"); } } if (!$orderby) { $orderby = 'l.`time` DESC'; } $count = db::o()->p($type)->count_rows("logs", $type ? 'type=?' : ""); list($pages, $limit) = display::o()->pages($count, config::o()->v('table_perpage'), 'switch_logs_page', 'page', 5, true); $r = db::o()->p($type)->query('SELECT l.*, u.username, u.group, u2.username AS tusername, u2.group AS tgroup FROM logs AS l LEFT JOIN users AS u ON u.id=l.byuid LEFT JOIN users AS u2 ON u2.id=l.touid ' . ($type ? ' WHERE l.type=?' : "") . ' ' . ($orderby ? ' ORDER BY ' . $orderby : "") . ' ' . ($limit ? ' LIMIT ' . $limit : "")); tpl::o()->assign('res', db::o()->fetch2array($r)); tpl::o()->assign('log_types', $this->types); tpl::o()->assign('pages', $pages); tpl::o()->display('admin/logs/index.tpl'); }
/** * Отображение списка обратной связи * @param string $sort сортировка * @param string $type тип * @return null */ protected function show($sort = null, $type = '') { $orderby = ''; if ($sort) { $sort = explode(",", $sort); $c = count($sort); for ($i = 0; $i < $c; $i += 2) { if (!$this->orderby[$sort[$i]]) { continue; } $orderby .= ($orderby ? ', ' : '') . "`" . $this->orderby[$sort[$i]] . "` " . ($sort[$i + 1] ? "asc" : "desc"); } } if (!$orderby) { $orderby = 'f.`time` DESC'; } $where = $type ? 'f.type=?' : ""; $count = db::o()->p($type)->as_table('f')->count_rows("feedback", $where); list($pages, $limit) = display::o()->pages($count, config::o()->v('table_perpage'), 'switch_feedback_page', 'page', 5, true); $r = db::o()->p($type)->query('SELECT f.*, u.username, u.group FROM feedback AS f LEFT JOIN users AS u ON u.id=f.uid ' . ($where ? ' WHERE ' . $where : "") . ' ' . ($orderby ? ' ORDER BY ' . $orderby : "") . ' ' . ($limit ? ' LIMIT ' . $limit : "")); tpl::o()->assign('res', db::o()->fetch2array($r)); tpl::o()->assign('pages', $pages); tpl::o()->assign('type', $type); tpl::o()->display('admin/feedback/index.tpl'); }
/** * Функция отображения доп. полей * @return null */ protected function show() { $r = db::o()->query('SELECT * FROM users_fields'); tpl::o()->assign('res', db::o()->fetch2array($r)); tpl::o()->register_modifier('cut_type_descr', array($this, 'cut_type_descr')); tpl::o()->display('admin/userfields/index.tpl'); }
/** * Вывод списка 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 */ protected function show() { $r = db::o()->query('SELECT * FROM allowed_ft'); tpl::o()->assign('res', db::o()->fetch2array($r)); tpl::o()->register_modifier('aftbasic', array($this, 'is_basic')); tpl::o()->display('admin/allowedft/index.tpl'); }
/** * Редактирование пользователя * @param int $id ID пользователя * @return null */ protected function edit($id) { $id = (int) $id; lang::o()->get("registration"); lang::o()->get("usercp"); lang::o()->get('admin/groups'); /* @var $etc etc */ $etc = n("etc"); users::o()->set_tmpvars($etc->select_user($id)); if (users::o()->v('confirmed') != 3) { tpl::o()->assign('unco', true); } tpl::o()->assign('inusercp', true); /* @var $usercp usercp */ $usercp = plugins::o()->get_module('usercp'); /* @var $groups groups_man */ $groups = plugins::o()->get_module('groups', 1); ob_start(); $group = users::o()->get_group(users::o()->v('old_group') ? users::o()->v('old_group') : users::o()->v('group')); users::o()->alter_perms($group); $groups->add($group, false, true); $c = ob_get_contents(); ob_end_clean(); tpl::o()->assign('perms', $c); $usercp->show_index(); users::o()->remove_tmpvars(); }
/** * Добавление/редактирование бота * @param int $id ID бота * @return null */ protected function add($id = null) { $id = (int) $id; if ($id) { $r = db::o()->p($id)->query('SELECT * FROM bots WHERE id=? LIMIT 1'); tpl::o()->assign("row", db::o()->fetch_assoc($r)); } tpl::o()->assign("id", $id); tpl::o()->display('admin/bots/add.tpl'); }
/** * Инициализация чата * @return null */ public function init() { if (!users::o()->perm('chat')) { return; } if (!config::o()->mstate('chat')) { return; } lang::o()->get("blocks/chat"); tpl::o()->display('chat/index.tpl'); }
/** * Инициализация юзерей * @return null */ function users_init() { users::o()->init(); if (!defined("DELAYED_SINIT")) { users::o()->write_session(); } tpl::o()->assign('groups', users::o()->get_group()); tpl::o()->assign('curlang', users::o()->get_lang()); tpl::o()->assign('curtheme', users::o()->get_theme()); tpl::o()->assign('curtheme_color', users::o()->get_theme(true)); tpl::o()->assign('curuser', users::o()->v('username')); tpl::o()->assign('curgroup', users::o()->v('group')); }
/** * Инициализация блока новостей * @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() { lang::o()->get("content"); if (!users::o()->perm('content')) { return; } /* @var $content content */ $content = plugins::o()->get_module("content"); if (!is_callable(array($content, "show"))) { return; } tpl::o()->assign('content_in_block', true); $content->show(); }
/** * Стат. страницы * @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'); }
/** * Инициализация блока календаря * @return null */ public function init() { $day_of_week = implode(',', array_map(array(db::o(), 'esc'), array_map('trim', explode(",", lang::o()->v('calendar_day_of_week'))))); $months = input::$months; $monthes = array(); // lol'd foreach ($months as $month) { $monthes[] = db::o()->esc(lang::o()->v('month_' . $month)); } $content = $this->count_content(); tpl::o()->assign("content_count", $content); tpl::o()->assign('day_of_week', $day_of_week); tpl::o()->assign("months", implode(",", $monthes)); tpl::o()->display("blocks/contents/calendar.tpl"); }
/** * Инициализация блока-торрентов * @return null */ public function init() { if (!config::o()->v('torrents_on')) { return; } lang::o()->get("blocks/content"); if (!users::o()->perm('content')) { return; } $curcats = $this->settings['cats']; if (!$curcats) { return; } print "Torrents block inited"; $this->get_children($curcats); tpl::o()->assign('curcats', array_reverse($curcats)); }
/** * Добавление новости * @param int $id ID новости * @return null * @throws EngineException */ protected function add($id) { $id = (int) $id; if ($id) { $row = db::o()->p($id)->query('SELECT * FROM news WHERE id=? LIMIT 1'); $row = db::o()->fetch_assoc($row); if ($row) { if (users::o()->v('id') == $row['poster_id']) { users::o()->check_perms('edit_news'); } else { users::o()->check_perms('edit_news', '2'); } } else { throw new EngineException('news_are_not_exists'); } tpl::o()->assign('row', $row); } tpl::o()->display('news/add.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); }
/** * Отображение настроек БД * @return null */ private function show_database() { require_once ROOT . 'include/classes/class.input.php'; $cfiles = input::o()->scurrent($this->cfile)->select_folder("file", 'install/database', false, "/^(.*)\\.conv\$/siu", 1); tpl::o()->assign('cfiles', $cfiles); $r = db::o()->query('SELECT id, name FROM groups'); tpl::o()->assign('groups', db::o()->fetch2array($r, 'assoc', array('id' => 'name'))); }
/** * Вывод списка категорий * @return null */ protected function show() { $rows = file::o()->open_folder(LANGUAGES_PATH, true); tpl::o()->assign('rows', $rows); tpl::o()->display('admin/languages/index.tpl'); }
/** * Построение дерева категорий * @param int $pid ID родителя * @return string HTML код дерева */ protected function build_tree($pid = null) { if (!$pid) { $elements = $this->cats->get(null, 't'); } else { $elements = $this->cats->get($pid, 'c'); } $c = count($elements); if (!$c) { return; } $html = "<ol" . (!$pid ? " class='sortable' id='cats_order'" : '') . ">"; for ($i = 0; $i < $c; $i++) { tpl::o()->assign('row', $elements[$i]); $id = $elements[$i]['id']; $element = tpl::o()->fetch('admin/cats/element.tpl'); $element .= $this->build_tree($id); $html .= '<li id="catid_' . $id . '">' . $element . '</li>'; } return $html . "</ol>"; }
/** * Конструктор класса * @return null */ protected function plugin_construct() { $this->load(); $this->access_var("types", PVAR_ADD); $this->access_var("allowed_types", PVAR_ADD); /** * @note Ввод доп. пользовательских полей(input_userfields) * params: * string type тип ресурса(profile|register) * array user данные пользователя */ tpl::o()->register_function('input_userfields', array($this, "input")); /** * @note Вывод доп. пользовательских полей(display_userfields) * params: * string type тип ресурса(profile|register) * array user данные пользователя */ tpl::o()->register_function('display_userfields', array($this, "show")); }
/** * Функция создания Человекопонятного URL, исходя из заданных параметров, * по предустановленным правилам * @param string $module имя модуля * @param array $params массив параметров, например: * array('id' => 1, 'name' => 'CTRev', 'cat' => 'demo') * ключ slashes экранирует результат для JavaScript, иначе & заменяется на & * @param bool $page является ли указанный модуль ссылкой на документ? * @param bool $no_end нужно ли в конец добавлять .html/index.html? * @param bool $nobaseurl не добавлять в начало $baseurl * @return string ЧПУ */ public function construct($module, $params = array(), $page = false, $no_end = false, $nobaseurl = false) { $baseurl = globals::g('baseurl'); $burl = true; $assign = false; if (is_array($module)) { $module_t = $module['module']; if ($module['no_end']) { $no_end = $module['no_end']; } if ($module['assign']) { $assign = (string) $module['assign']; } if (!$module_t && $module['page']) { $module = $module['page']; $page = true; } elseif (!$module_t) { return; } else { unset($module['module']); $params = $module; $module = $module_t; } } elseif ($nobaseurl) { $burl = false; } if (!is_array($params)) { $params = array(); } if ($params["_filetype"]) { $filetype = '.' . file::o()->get_filetype($params["_filetype"]); } else { $filetype = ".html"; } $url = $burl ? $baseurl : ""; if (config::o()->v('furl')) { $url .= $this->module_name($module) . ($page ? '' : "/"); $function = $module . '_furl_rules'; } else { $url .= 'index.php?module=' . ($this->rmodules[$module] ? $this->rmodules[$module] : $module); $function = $module . '_nfurl_rules'; } $slashes = $params['slashes']; $noencode = $params['noencode']; $b = $this->is_callable($function); if ($b) { $params = $this->resort($module, $params); } $postfix = ""; $surl = ''; $ourl = $url; if ($params && !$page) { foreach ($params as $param => $value) { if ($this->postfixes[$module][$param]) { $postfix .= $this->postfixes[$module][$param] . $value; } if ($b) { $r = $this->call_method($function, array($param, $value, !$slashes && !$noencode)); } elseif (!config::o()->v('furl')) { $r = $param . "=" . $value; } else { $r = $param . "-" . $value . "/"; } if (!config::o()->v('furl') && $r) { $surl .= '&' . $r; $r = ($slashes || $noencode ? '&' : '&') . $r; } $url .= $r; } } if (!$surl) { $surl = $url; } else { $surl = $ourl . $surl; } $add = ''; if (config::o()->v('furl')) { if (!$no_end && !$page && (!$params || !$b || preg_match('/\\/$/siu', $url))) { $add .= "index"; } if (!$no_end) { $add .= $filetype; } } $add .= $postfix; $url = $url . $add; $surl = $surl . $add; $this->forlocation = array($surl, $url); if ($slashes) { $url = slashes_smarty($url); } if ($assign) { tpl::o()->assign($assign, $url); } else { return $url; } }
/** * Получение объекта класса * @return tpl $this */ public static function o() { if (!self::$o) { self::$o = new self(); } return self::$o; }
/** * Отображение всех блоков * @return null */ protected function show() { $r = db::o()->query('SELECT * FROM blocks'); tpl::o()->assign('rows', db::o()->fetch2array($r, null, array('type' => '__array'))); tpl::o()->assign('types', self::$types); tpl::o()->display('admin/blocks/index.tpl'); }
/** * Отображение типов * @return null */ protected function show_types() { $r = db::o()->query('SELECT cat, COUNT(*) AS c FROM config GROUP BY cat'); tpl::o()->assign('rows', db::o()->fetch2array($r)); tpl::o()->display('admin/config/cats.tpl'); }
/** * Сохранение стат. страницы * @param array $data массив данных * @return null * @throws EngineException */ public function save($data) { $admin_file = globals::g('admin_file'); $cols = array('url', 'title', 'content', 'type'); $update = rex($data, $cols); $id = (int) $data['id']; if (!validword($update['url'])) { throw new EngineException('static_empty_url'); } if (!$update['title']) { throw new EngineException('static_empty_title'); } if ($update['type'] == 'html') { $update['content'] = $data['html']; } elseif ($update['type'] == 'tpl') { $update['content'] = $data['tpl']; if (!validpath($update['content']) || !tpl::o()->template_exists($update['content'])) { throw new EngineException('static_tpl_not_exists'); } } if (!$update['content']) { throw new EngineException('static_empty_content'); } try { plugins::o()->pass_data(array("update" => &$update, "id" => $id), true)->run_hook('admin_static_save'); } catch (PReturn $e) { return $e->r(); } if (!$id) { db::o()->insert($update, 'static'); log_add('added_static', 'admin', $data['url']); } else { db::o()->p($id)->update($update, 'static', 'WHERE id=? LIMIT 1'); log_add('changed_static', 'admin', $data['url']); } furl::o()->location($admin_file); }
/** * Генератор 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); }
/** * Форма ввода текста с BB-кодами * @param string $name имя формы * @param string $text текст * @return string HTML код формы */ public function input_form($name, $text = '') { if (is_array($name)) { $text = $name['text']; $name = $name['name']; } $this->init_smilies(); lang::o()->get('bbcodes'); $c = ''; try { plugins::o()->pass_data(array('name' => $name, 'text' => $text, 'html' => &$c), true)->run_hook('bbcodes_input_form'); } catch (PReturn $e) { return $e->r(); } tpl::o()->assign("textarea_rname", $name); tpl::o()->assign("textarea_name", 'formid' . time() . $this->id++); tpl::o()->assign("textarea_text", $text); tpl::o()->assign("smilies", $this->smilies[1]); tpl::o()->assign("inited_bbcodes", $this->inited_js); if (!$this->inited_js) { $this->inited_js = true; $fs = array_merge($this->smilies[0], $this->smilies[1]); tpl::o()->assign('smilies_array', display::o()->array_export_to_js($fs)); } $c .= tpl::o()->fetch('init_textinput.tpl'); return $c; }
/** * AJAX селектор категорий * @param string $cat ID'ы категорий или имя категории * @return string HTML код селектора */ public function ajax_selector($cat = null) { if ($cat && $cat[0] == ',') { $row_cats = explode(',', trim($cat, ",")); $cat = $row_cats[0]; tpl::o()->assign('row_cats', $row_cats); } elseif ($cat) { $cat = $this->get($cat); $cat = $cat['id']; } if (!$cat) { tpl::o()->assign("cats", $this->get(null, 't')); } else { $categories = $this->get_parents($cat); tpl::o()->assign("categories", $categories[0]); tpl::o()->assign("cids", $categories[1]); } tpl::o()->assign("cattype", $this->type); $r = tpl::o()->fetch('categories.tpl'); return $r; }
/** * Проверка, является ли сайт offline на данный момент * @return null */ public function siteoffline_check() { if (users::o()->perm('acp', 2)) { return; } elseif (!config::o()->v('site_online')) { lang::o()->get("site_offline"); $offline_reason = config::o()->v('siteoffline_reason'); tpl::o()->assign("reason", $offline_reason); tpl::o()->display("site_offline.tpl"); die; } }
/** * Форма быстрого редактирования контента * @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'); }