Beispiel #1
0
 /**
  * Выполнение очистки сайта
  * @param bool $force выполнять клинап вне зависимости от времени
  * @return null
  */
 public function execute($force = false)
 {
     if (!longval(config::o()->v('cleanup_each'))) {
         return;
     }
     $hour = 3600;
     // Секунд в часу
     $time = stats::o()->read('last_cleanup');
     if (!$force && time() < $time + config::o()->v('cleanup_each') * $hour) {
         return;
     }
     stats::o()->write('last_cleanup', time());
     users::o()->admin_mode();
     users::o()->set_tmpvars(array('id' => -1));
     /* @var $mailer mailer */
     $mailer = n("mailer");
     $mailer->change_type('content')->cleanup();
     $mailer->change_type('categories')->cleanup();
     /* @var $attach attachments */
     $attach = n("attachments");
     $attach->clear();
     users::o()->groups_autoupdate();
     foreach ($this->methods as $m) {
         $this->call_method('clear_' . $m);
     }
     users::o()->remove_tmpvars();
     users::o()->admin_mode(false);
     //cache::o()->clear_ocache(config::o()->v('cache_oldtime') * 3600);
 }
Beispiel #2
0
 /**
  * Добавление/редактирование группы
  * @param int $id ID группы
  * @param bool $add добавление?
  * @param bool $onlyperms только права?
  * @return null
  * @throws EngineException
  */
 public function add($id, $add = false, $onlyperms = false)
 {
     if (is_array($id) && $onlyperms) {
         $row = $id;
     } else {
         $row = users::o()->get_group($id);
     }
     if (!$row) {
         throw new EngineException();
     }
     users::o()->acp_modules($row);
     tpl::o()->assign('id', $add ? 0 : $id);
     tpl::o()->assign('row', $row);
     $r = db::o()->query('SELECT cat FROM groups_perm GROUP BY cat');
     tpl::o()->assign('types', db::o()->fetch2array($r, null, array('cat')));
     $r = db::o()->query('SELECT cat, perm, allowed FROM groups_perm');
     $perms = null;
     while ($row = db::o()->fetch_assoc($r)) {
         $perms[$row["cat"]][] = $row;
     }
     tpl::o()->assign('perms', $perms);
     tpl::o()->assign('allowed_modules', allowed::o()->get("acp_modules"));
     tpl::o()->register_modifier('show_selector', array($this, 'show_selector'));
     tpl::o()->display('admin/groups/' . ($onlyperms ? 'perms' : 'add') . '.tpl');
 }
Beispiel #3
0
 /**
  * Инициализация чата
  * @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');
 }
Beispiel #4
0
 /**
  * Функция вызова captcha
  * @return null
  */
 public function init()
 {
     $background = 'include/backgrounds/' . $this->bckgrnds[rand(0, count($this->bckgrnds) - 1)];
     $code = mb_strtoupper(users::o()->generate_salt(6));
     if (!$_SESSION['captcha_key']) {
         $_SESSION['captcha_key'] = array();
     }
     array_unshift($_SESSION['captcha_key'], $code);
     unset($_SESSION['captcha_key'][self::capacity]);
     /* @var $uploader uploader */
     $uploader = n("uploader");
     $uploader->watermark($background, $code, 'auto', false, '', 'cc', true, false);
 }
Beispiel #5
0
/**
 * Инициализация юзерей
 * @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'));
}
Beispiel #6
0
 /**
  * Инициализация блока контента
  * @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();
 }
Beispiel #7
0
 /**
  * Инициализация блока-торрентов
  * @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));
 }
Beispiel #8
0
 /**
  * Метод редактирования комментария
  * @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);
 }
Beispiel #9
0
 /**
  * Инициализация Ajax-части нижнего блока
  * @return null
  */
 public function init()
 {
     lang::o()->get("blocks/downm");
     switch ($_GET["act"]) {
         case "content":
             users::o()->check_perms("content", 1, 2);
             $sticky = isset($_GET["sticky"]) ? (bool) $_GET["sticky"] : true;
             $this->show_content($sticky);
             break;
         case "comments":
             users::o()->check_perms('comment', 1, 2);
             /* @var $comments comments */
             $comments = n("comments");
             $comments->usertable();
             break;
         default:
             users::o()->check_perms('profile', 1, 2);
             $this->show_online();
             break;
     }
 }
Beispiel #10
0
 /**
  * Форма быстрого редактирования контента
  * @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');
 }
Beispiel #11
0
 /**
  * Обработка значений для preg_replace_callback тега hide
  * @param array $matches входящий массив парсенной строки
  * @param bool $rss RSS?
  * @return string HTML код
  */
 protected function pcre_callback_hide($matches, $rss = false)
 {
     $vars = array();
     if (users::o()->v()) {
         if ($matches[1]) {
             $matches[1] = longval(trim($matches[1]));
             if ($matches[1] <= users::o()->v('content_count')) {
                 return $matches[3];
             }
             if (!$rss) {
                 $vars = array($matches[1], users::o()->v('content_count'));
                 $text = "hidden_need_content_you_have";
             }
         } elseif ($matches[2]) {
             $grps = array_map('longval', explode(",", $matches[2]));
             $c = count($grps);
             for ($i = 0; $i < $c; $i++) {
                 if (!users::o()->get_group($grps[$i])) {
                     continue;
                 }
                 if (!$rss) {
                     $pretext .= ($pretext ? ", " : "") . display::o()->user_group_color($grps[$i]);
                 }
                 if (users::o()->v('group') == $grps[$i]) {
                     return $matches[3];
                 }
             }
             if (!$rss) {
                 $vars = array($pretext, display::o()->user_group_color(users::o()->v('group')));
                 $text = "hidden_group_to_see";
             }
         } else {
             return $matches[3];
         }
     }
     if (!$rss) {
         $text = "hidden_register_to_see";
     }
     //else
     //    return $matches[3];
     if (!$rss) {
         if (!$vars) {
             $vars = furl::o()->construct("registration");
         }
         ob_start();
         /* @var $m message */
         $m = n("message");
         $m->stitle("hidden_text")->sonly_box()->info($text, $vars);
         $cont = ob_get_contents();
         ob_end_clean();
         return $cont;
     }
     return lang::o()->v('hidden_text');
 }
Beispiel #12
0
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"));
// проверка на права
tpl::o()->register_modifier('user', array(users::o(), "v"));
// поле юзера
/**
 * Не смей удалять копирайт ниже, а то дядя Ваня тебя покарает своим большим чёрным банхаммером.
 */
tpl::o()->assign("copyright", "Powered by <a href=\"http://ctrev.cyber-tm.ru/\" title=\"Go to the official site of CTRev\">CTRev v." . ENGINE_VERSION . ' ' . ENGINE_STAGE . "</a> &copy; <a href=\"http://cyber-tm.ru\" title=\"Go to the official site of Cyber-Team\">Cyber-Team</a> 2008-2012");
tpl::o()->assign("designed_by", "Дизайн сайта разработал <u>А. Воробей</u>. All Rights Reserved.");
//tpl::o()->assign_by_ref('config', $CONFIG);
require_once ROOT . 'include/init.php';
Beispiel #13
0
 /**
  * Отображение комментариев пользователя/пользователей
  * @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");
 }
Beispiel #14
0
 /**
  * Проверка dict перед записью
  * @param string $t путь к файлу торрента
  * @param array $filelist список файлов
  * @param int $filesize размер файла
  * @param array $announce_list список аннонсеров
  * @return array массив из словаря и раздела info словаря
  * @throws EngineException 
  */
 protected function check_dict($t, &$filelist = null, &$filesize = null, &$announce_list = null)
 {
     $dict = $this->bdec($t, true);
     if (!$dict) {
         throw new EngineException('bencode_cant_parse_file');
     }
     list($info) = $this->dict_check($dict, "info");
     list($filelist, $filesize) = $this->dict_filelist($info);
     $idict =& $dict['info'];
     if (config::o()->v('DHT_on') == 0) {
         $idict['private'] = 1;
     } elseif (config::o()->v('DHT_on') == 1) {
         unset($idict['private']);
     }
     // не меняем, если -1
     $announce_list = $this->announce_lists($dict);
     $announce_list = serialize($announce_list);
     // удаляем излишки
     unset($dict['nodes']);
     unset($idict['crc32']);
     unset($idict['ed2k']);
     unset($idict['md5sum']);
     unset($idict['sha1']);
     unset($idict['tiger']);
     unset($dict['azureus_properties']);
     $dict['publisher.utf-8'] = $dict['publisher'] = $dict['created by'] = users::o()->v('username');
     $dict['publisher-url.utf-8'] = $dict['publisher-url'] = furl::o()->construct("users", array("user" => users::o()->v('username'), 'noencode' => true));
     return array($dict, $idict);
 }
Beispiel #15
0
 /**
  * Голосование в опросе
  * @param int $poll_id ID опроса
  * @param integer|array $answers ответы
  * @return bool true, в случае успешного завершения
  * @throws EngineException 
  */
 public function vote($poll_id, $answers)
 {
     if (!$this->state) {
         return;
     }
     users::o()->check_perms('polls', 1, 2);
     $poll_id = (int) $poll_id;
     if (!$answers) {
         throw new EngineException('polls_so_much_votes');
     }
     $answers = (array) (is_array($answers) ? array_map('intval', $answers) : array(longval($answers)));
     $user_id = (int) users::o()->v('id');
     $user_ip = users::o()->get_ip();
     $day = 60 * 60 * 24;
     $row = db::o()->p($user_id ? $user_id : $user_ip, $poll_id)->query('SELECT p.*,
         pv.question_id, pv.user_ip, pv.user_id FROM polls AS p
         LEFT JOIN poll_votes AS pv ON pv.question_id=p.id AND ' . ($user_id ? 'pv.user_id = ?' : 'pv.user_id=0 AND pv.user_ip = ?') . '
         WHERE p.id = ? LIMIT 1');
     $row = db::o()->fetch_assoc($row);
     if (!$row) {
         throw new EngineException();
     }
     if ((!$row['change_votes'] || !users::o()->v()) && $row['question_id']) {
         throw new EngineException('polls_you_re_voted');
     }
     if ($row['max_votes'] < count($answers) || !$answers) {
         throw new EngineException('polls_so_much_votes');
     }
     if ($row["poll_ends"]) {
         if (time() - $row["posted_time"] > $row["poll_ends"] * $day) {
             throw new EngineException('polls_already_ends');
         }
     }
     $update = array('answers_id' => serialize($answers));
     try {
         plugins::o()->pass_data(array("row" => &$row), true)->run_hook('polls_vote');
     } catch (PReturn $e) {
         return $e->r();
     }
     if (!$row['question_id']) {
         $update['user_id'] = $user_id;
         $update['question_id'] = $poll_id;
         $update['user_ip'] = $user_ip;
         db::o()->insert($update, 'poll_votes');
     } else {
         db::o()->p($row["user_id"], $row["user_ip"], $row['question_id'])->update($update, 'poll_votes', 'WHERE user_id = ?
                 AND user_ip = ? AND question_id=? LIMIT 1');
     }
     $this->uncache($poll_id, true);
     return true;
 }
Beispiel #16
0
 /**
  * Анти-флуд проверка
  * @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);
     }
 }
Beispiel #17
0
 /**
  * Получение значения переменной
  * @param string $var имя переменной
  * @return mixed значение
  */
 protected function get_data($var)
 {
     $var = self::var_prefix . $var;
     if ($this->data) {
         return $this->data[$var];
     }
     if (!users::o()->v()) {
         return "";
     }
     return users::o()->v($var);
 }
Beispiel #18
0
            $_GET = array_merge($_GET, $index_module);
        } else {
            $module = $imod = '';
        }
    }
}
/**
 * Передаём часть переменных в Smarty Tpl.
 */
tpl::o()->assign("selected_item", $item);
if ($imod) {
    tpl::o()->assign("selected_imod", $imod);
}
tpl::o()->assign("imods", $admin_modules);
lang::o()->get("admin/main");
users::o()->check_inadmin($module, false, true);
$eadmin_file = globals::g('eadmin_file');
$iadmin_file = $eadmin_file . '&item=' . $item;
tpl::o()->assign("iadmin_file", $iadmin_file);
if ($module) {
    $admin_file = $iadmin_file . '&module=' . $module;
    tpl::o()->assign("admin_file", $admin_file);
    $admin_page = null;
} elseif ($admin_page) {
    $module = $admin_page;
    $allowed = $allowed_admin_pages;
    $plugins_isblock = 2;
    $admin_file = $iadmin_file . '&page=' . $admin_page;
    tpl::o()->assign("admin_file", $admin_file);
}
globals::s('admin_file', $admin_file);
Beispiel #19
0
 /**
  * Инициализация 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();
 }
Beispiel #20
0
 /**
  * Функция выборки групп
  * Параметры: current, null, size
  * @param string $name имя поля
  * @param bool $guest в т.ч. и гость
  * @return string HTML код выборки
  */
 public function select_groups($name = "group", $guest = false)
 {
     if (!is_array($name)) {
         $this->join_params($name, array('guest' => $guest));
     }
     $current = $name["current"];
     $guest = $name["guest"];
     $null = $name["null"];
     $size = $name["size"];
     $name = $name["name"];
     if (!$name) {
         $name = "group";
     }
     $sel = "<select name='" . $name . ($size > 1 ? "[]' size='" . $size . "' multiple='multiple'\n            " . ($null ? " onclick='clear_select(this)" : "") : "") . "'>";
     $id = 0;
     if ($null) {
         $sel .= $this->get_null_text();
     }
     foreach (users::o()->get_group() as $id => $group) {
         if ($guest || !$guest && !$group['guest']) {
             $s = !is_array($current) ? $current == $id : in_array($id, $current) ? " selected='selected'" : "";
             $sel .= "<option value='" . $id . "'" . $s . ">" . users::o()->get_group_name($id) . "</option>";
         }
     }
     $sel .= "</select>";
     return $sel;
 }
Beispiel #21
0
 /**
  * Скачивание вложения
  * @param int $id ID вложения
  * @return null
  * @throws EngineException
  */
 public function download($id)
 {
     if (!$this->state) {
         return;
     }
     users::o()->check_perms('attach', 1, 2);
     $id = (int) $id;
     $q = db::o()->p($id)->query("SELECT * FROM attachments WHERE id=? LIMIT 1");
     $row = db::o()->fetch_assoc($q);
     if (!$row) {
         throw new EngineException('file_not_exists');
     }
     $file = config::o()->v("attachments_folder") . "/" . self::attach_prefix . default_filename($row['time'], $row['user']);
     try {
         plugins::o()->pass_data(array("row" => &$row))->run_hook('attachments_download');
     } catch (PReturn $e) {
         return $e->r();
     }
     db::o()->p($id)->update(array("_cb_downloaded" => 'downloaded+1'), "attachments", 'WHERE id = ? LIMIT 1');
     /* @var $uploader uploader */
     $uploader = n("uploader");
     $uploader->download($file, display::o()->html_decode($row["filename"]));
 }
Beispiel #22
0
 /**
  * Получение пасскея пользователя
  * @param string $passkey пасскей пользователя
  * @return string пасскей пользователя или, в случае отсутствия, рандомно сгенерированная строка
  */
 public function get_passkey($passkey)
 {
     if (!$passkey) {
         $passkey = users::o()->generate_salt();
     }
     return $passkey;
 }
Beispiel #23
0
/**
 * Добавление логов
 * @param string $subject тема записи
 * @param string $type тип записи(user|admin|system|other)
 * @param array $vars массив переменных для vsprintf
 * @param int $touid действие по отношению к пользователю
 * @return null
 */
function log_add($subject, $type = "user", $vars = array(), $touid = null)
{
    $langs = lang::o()->get('logs', DEFAULT_LANG, false);
    $subject = "log_" . $subject;
    if (!isset($langs[$subject])) {
        $subject = 'NOSUBJECT_' . $subject;
    } else {
        $subject = $langs[$subject];
    }
    $descr = "";
    if (!$type) {
        $type = "user";
    }
    if (isset($langs["log_" . $subject . "_descr"])) {
        $descr = $langs["log_" . $subject . "_descr"];
    } elseif ($vars) {
        $descr = "%s";
    }
    if ($vars) {
        $vars = (array) $vars;
        $descr = vsprintf($descr, $vars);
    }
    $contents = array("subject" => $subject, "descr" => $descr, "type" => $type, "time" => time(), "byuid" => users::o()->v('id'), "byip" => users::o()->get_ip(), "touid" => (int) $touid);
    db::o()->insert($contents, "logs");
}
Beispiel #24
0
 /**
  * Вывод для настроек параметров по-умолчанию
  * @param array $data массив данных
  * @return null
  */
 public function make_demo($data)
 {
     users::o()->check_perms('acp', 2);
     $settings = $this->make($data);
     if (!$settings) {
         return;
     }
     $defaults = $this->save(self::nocache_id, $data);
     $arr = array("settings" => $settings, "settings_lang" => "__doesnotexists");
     $obj = new arr2obj($arr);
     print $this->display(self::nocache_id, $obj, $defaults, '');
 }
Beispiel #25
0
/**
 * Получение значения параметра определённой группы
 * @param int $group ID группы
 * @param string $param имя параметра
 * @return mixed значение параметра
 */
function smarty_group_value($group, $param)
{
    $gr = users::o()->get_group($group);
    return $gr[$param];
}
Beispiel #26
0
 /**
  * Вывод сообщений чата
  * @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');
 }
 /**
  * Вход для конвертированного пользователя
  * @param array $data массив переменных
  * @return null
  * @throws PReturn
  */
 public function converted_login($data)
 {
     $login = $data['login'];
     $password = $data['password'];
     $error =& $data['error'];
     $id =& $data['id'];
     /* @var $etc etc */
     $etc = n("etc");
     $u = $etc->select_user(null, $login, 'id,password,salt,converted');
     if (!$u['converted']) {
         return;
     }
     $salt = $u['salt'];
     if ($u['password'] != md5($salt . $password . $salt)) {
         $error = lang::o()->v('login_false_signin');
         return;
     }
     $id = $u['id'];
     $salt = users::o()->generate_salt(32);
     $password = users::o()->generate_pwd_hash($password, $salt);
     db::o()->p($id)->update(array('salt' => $salt, 'password' => $password, 'converted' => '0'), 'users', 'WHERE id = ? LIMIT 1');
     throw new PReturn($password);
 }
Beispiel #28
0
 /**
  * Получение объекта класса
  * @return users $this
  */
 public static function o()
 {
     if (!self::$o) {
         $cn = __CLASS__;
         $c = n($cn, true);
         self::$o = new $c();
     }
     return self::$o;
 }
Beispiel #29
0
 /**
  * Проверка, является ли сайт 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;
     }
 }
Beispiel #30
0
 /**
  * Инициализация AJAX функций профиля
  * @return null
  */
 public function init()
 {
     users::o()->check_perms('profile', 1, 2);
     lang::o()->get('profile');
     $act = $_GET['act'];
     $id = (int) $_POST['id'];
     switch ($act) {
         case "show_stats":
             $this->show_user_stats($id);
             break;
         case "show_friends":
             $this->show_user_friends($id);
             break;
         case "show_comments":
             if (!users::o()->perm("comment")) {
                 die(lang::o()->v('users_you_cant_view_this'));
             }
             /* @var $comments comments */
             $comments = n("comments");
             $comments->usertable($id);
             break;
         case "show_content":
             if (!users::o()->perm("content")) {
                 die(lang::o()->v('users_you_cant_view_this'));
             }
             $this->show_last_content($id);
             break;
         default:
             break;
     }
 }