예제 #1
0
파일: downm.php 프로젝트: SjayLiFe/CTRev
 /**
  * Вывод списка 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");
 }
예제 #2
0
 /**
  * Установка плагина
  * @param bool $re переустановка?
  * в данном случае необходимо лишь произвести изменения в файлах
  * @return bool статус установки
  * @note метод может возвращать false или 0, в случае, если была какая-то
  * критическая ошибка при удалении
  */
 public function install($re = false)
 {
     if (!$re) {
         config::o()->add('recaptcha_public_key', '', 'string', '', 'register');
         config::o()->add('recaptcha_private_key', '', 'string', '', 'register');
     }
     plugins::o()->insert_template('captcha.tpl', '[*recaptcha_show*][**');
     plugins::o()->insert_template('captcha.tpl', '**]', false);
     return true;
 }
예제 #3
0
파일: content.php 프로젝트: SjayLiFe/CTRev
 /**
  * Инициализация блока контента
  * @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();
 }
예제 #4
0
파일: feedback.php 프로젝트: SjayLiFe/CTRev
 /**
  * Инициализация модуля обратной связи
  * @return null
  */
 public function init()
 {
     $admin_file = globals::g('admin_file');
     lang::o()->get('admin/feedback');
     $act = $_GET["act"];
     switch ($act) {
         case "clear":
             /* @var $o feedback_man_ajax */
             $o = plugins::o()->get_module('feedback', 1, true);
             $o->clear();
             furl::o()->location($admin_file);
             break;
         default:
             $this->show($_GET['sort'], $_GET['type']);
             break;
     }
 }
예제 #5
0
파일: plugins.php 프로젝트: SjayLiFe/CTRev
 /**
  * Инициализация AJAX-части модуля
  * @return null
  * @throws EngineException
  */
 public function init()
 {
     $act = $_GET["act"];
     $plugin = $_POST['id'];
     switch ($act) {
         case "delete":
             $r = plugins::o()->manager->delete($plugin);
             break;
         case "check":
             /* @var $o plugis_man */
             $o = plugins::o()->get_module('plugins', 1);
             print $o->check($plugin);
             die;
             break;
         case "add":
             $r = plugins::o()->manager->add($plugin);
             break;
         case "reinstall":
             $r = plugins::o()->manager->install($plugin, true);
             break;
     }
     if (!$r) {
         throw new EngineException();
     }
     ok();
 }
예제 #6
0
 /**
  * Генерация sitemap.xml
  * @return null
  */
 protected function clear_sitemap()
 {
     /* @var $m main_page_ajax */
     $m = plugins::o()->get_module("main", 2, 1);
     $m->sitemap();
 }
예제 #7
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;
 }
예제 #8
0
 /**
  * Получение объекта класса
  * @return plugins $this
  */
 public static function o()
 {
     if (!self::$o) {
         self::$o = 1;
         // предотвращение зацикливания при вызове plugins::o() в плагине
         self::$o = new self();
     }
     return self::$o;
 }
예제 #9
0
파일: config.php 프로젝트: SjayLiFe/CTRev
 /**
  * Проверка значения конфигурации
  * @param mixed $value значение параметра
  * @param string $type тип параметра
  * @param string $allowed допустимые значения
  * @param string $name имя параметра
  * @return bool true, в случае успешного завершения
  */
 public function check_type($type, &$value, $allowed = null, $name = null)
 {
     if ($type == 'other') {
         /* @var $o cofig_man */
         $o = plugins::o()->get_module('config', 1);
         return (bool) $o->check_field($name, $value);
     } elseif ($type == 'radio' || $type == 'select') {
         $allowed = explode(";", $allowed);
     }
     return input::o()->standart_types_check($type, $value, $allowed, config_man::config_prefix . $name);
 }
예제 #10
0
파일: spages.php 프로젝트: SjayLiFe/CTRev
 /**
  * Сохранение стат. страницы
  * @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);
 }
예제 #11
0
 /**
  * Форма ввода текста с 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;
 }
예제 #12
0
파일: index.php 프로젝트: SjayLiFe/CTRev
    $plugins_isblock = 2;
    $admin_file = $iadmin_file . '&page=' . $admin_page;
    tpl::o()->assign("admin_file", $admin_file);
}
globals::s('admin_file', $admin_file);
/**
 * Загружаем модуль, или индексную страничку во вкладке
 */
if (!$ajax) {
    tpl::o()->display("admin/header.tpl");
} else {
    db::o()->nt_error();
    tpl::o()->assign("from_ajax", 1);
}
if ($module) {
    if (!allowed::o()->is($module, $allowed)) {
        die(lang::o()->v('module_not_exists'));
    }
    $m = plugins::o()->get_module($module, $plugins_isblock, $ajax && !$nno);
    try {
        plugins::o()->call_init($m);
    } catch (EngineException $e) {
        $e->defaultCatch();
    }
}
if (!$ajax) {
    tpl::o()->display("admin/footer.tpl");
} else {
    print '<script type="text/javascript">ajax_complete();</script>';
}
die;
예제 #13
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"]));
 }
예제 #14
0
/**
 * Получение объекта переопределённого класса
 * @param string $class имя класса
 * @param bool $name только имя?
 * @return object объект класса
 */
function n($class, $name = false)
{
    if (!class_exists('plugins')) {
        return $name ? $class : new $class();
    }
    return plugins::o()->get_class($class, $name);
}
예제 #15
0
 /**
  * Удаление типов файлов
  * @param string $id имя типа файлов
  * @return null
  */
 public function delete($id)
 {
     /* @var $aft allowedft_man */
     $aft = plugins::o()->get_module('allowedft', 1);
     if ($aft->is_basic($id)) {
         return;
     }
     db::o()->p($id)->delete('allowed_ft', 'WHERE name=? LIMIT 1');
     log_add('deleted_filetype', 'admin', $id);
 }
예제 #16
0
 /**
  * Скачивание торрент файла
  * @param int $id ID торрент файла
  * @return null
  * @throws EngineException 
  */
 public function download_torrent($id)
 {
     $id = (int) $id;
     try {
         users::o()->check_perms('content');
         $r = db::o()->p($id)->query('SELECT t.banned, c.poster_id, c.posted_time, t.price, d.uid FROM content AS c
             LEFT JOIN content_torrents AS t ON t.cid=c.id
             LEFT JOIN content_downloaded AS d ON d.tid=c.id AND d.uid=' . users::o()->v('id') . '
         WHERE c.id=? LIMIT 1');
         list($banned, $poster_id, $posted_time, $price, $downloaded) = db::o()->fetch_row($r);
         lang::o()->get('torrents');
         if (!$poster_id || $banned) {
             throw new EngineException('content_deleted');
         }
         $off = users::o()->perm('free', 2) ? 1 : (users::o()->perm('free', 1) ? 0.5 : 0);
         $price = $price * (1 - $off);
         if ($poster_id == users::o()->v('id')) {
             $downloaded = true;
         }
         plugins::o()->pass_data(array('price' => &$price, 'id' => $id), true)->run_hook('torrents_download_price');
         if (users::o()->v('bonus_count') < $price) {
             throw new EngineException('content_torrent_no_enough_bonus');
         }
         /* @var $etc etc */
         $etc = n("etc");
         if (!$downloaded) {
             if ($price) {
                 $etc->add_res('bonus', -$price);
             }
             db::o()->insert(array('tid' => $id, 'uid' => users::o()->v('id')), 'content_downloaded');
         }
         $dict = $this->prepare_dict($id, $posted_time, $poster_id);
         $name = 'id' . $id . '[' . $_SERVER["HTTP_HOST"] . '].torrent';
         plugins::o()->pass_data(array('dict' => &$dict, 'name' => &$name))->run_hook('torrents_download_dict');
         /* @var $uploader uploader */
         $uploader = n("uploader");
         $uploader->download_headers($this->benc($dict), $name, "application/x-bittorrent");
     } catch (PReturn $e) {
         return $e->r();
     }
 }
예제 #17
0
 /**
  * Функция сохранения комментария
  * @param string $content содержание комментария
  * @param int $resid ID ресурса
  * @param int $id ID комментария
  * @return bool true в случае успешного сохранения комментария
  * @throws EngineException 
  */
 public function save($content, $resid = "", $id = "")
 {
     if (!$this->state) {
         return;
     }
     $type = $this->type;
     lang::o()->get('comments');
     $id = longval($id);
     /* @var $etc etc */
     $etc = n("etc");
     if (!$id) {
         users::o()->check_perms('comment', 2, 2);
         if (!users::o()->v()) {
             $error = array();
             n("captcha")->check($error);
             if ($error) {
                 return implode("\n", $error);
             }
         }
     } else {
         $q = db::o()->p($id)->query('SELECT poster_id FROM comments WHERE id = ? LIMIT 1');
         $poster = db::o()->fetch_assoc($q);
         if (!$poster) {
             throw new EngineException('comment_was_deleted');
         }
         if ($poster['poster_id'] == users::o()->v('id')) {
             users::o()->check_perms('edit_comm');
         } else {
             users::o()->check_perms('edit_comm', 2);
         }
     }
     $content = trim($content);
     $poster = users::o()->v('id') ? users::o()->v('id') : -1;
     if (!longval($resid) && $resid || !longval($id) && $id || !$id && !$resid) {
         throw new EngineException('comment_wrong_data');
     }
     if (!$content || mb_strlen($content) < config::o()->v('min_comm_symb')) {
         throw new EngineException('comment_small_text');
     }
     if (!$id) {
         $etc->anti_flood('comments', 'toid=' . $resid . ' AND type=' . db::o()->esc($type), array('poster_id', 'edited_time'));
     }
     $upd = array();
     if (!$id) {
         $id = $this->check_double_comment($resid, $content);
         if ($id) {
             $upd["edited_time"] = time();
             unset($upd["subject"]);
         }
     }
     $upd["text"] = $content;
     try {
         plugins::o()->pass_data(array('update' => &$upd, "id" => $id), true)->run_hook('comments_save');
     } catch (PReturn $e) {
         return $e->r();
     }
     if (!$id) {
         $upd = array_merge($upd, array("posted_time" => time(), "edited_time" => time(), "poster_id" => $poster, "toid" => $resid, "type" => $type));
         db::o()->insert($upd, "comments");
         $etc->add_res('comm');
         db::o()->no_error();
         $etc->add_res('comm', 1, $type, $resid);
         /* @var $mailer mailer */
         $mailer = n("mailer");
         $mailer->change_type($type)->update($resid);
     } else {
         db::o()->p($id)->update($upd, "comments", 'WHERE id = ? LIMIT 1');
         log_add("edited_comment", "user", array($id));
     }
     return true;
 }
예제 #18
0
파일: groups.php 프로젝트: SjayLiFe/CTRev
 /**
  * Сохранение группы
  * @param array $data массив данных группы
  * @param array $fgroup изначальные права группы(для прав пользователя)
  * @return null
  * @throws EngineException 
  */
 public function save($data, $fgroup = null)
 {
     $admin_file = globals::g('admin_file');
     if (!$fgroup) {
         $cols = array('name', 'color', 'pm_count', 'system', 'default', 'bot', 'guest', 'content_count', 'karma_count', 'acp_modules', 'bonus_count');
         if ($data['id']) {
             $id = (int) $data['id'];
         }
         $update = rex($data, $cols);
         if (count($update) != count($cols) || !$update['name'] || !$update['color']) {
             throw new EngineException('groups_invalid_input');
         }
     }
     $r = db::o()->query('SELECT id, perm, allowed, dvalue FROM groups_perm');
     $perms = "";
     while ($row = db::o()->fetch_assoc($r)) {
         $p = 'can_' . $row['perm'];
         $dvalue = $fgroup ? $fgroup[$p] : $row['dvalue'];
         if (isset($data[$p]) && strval((int) $data[$p]) === $data[$p] && $data[$p] <= $row['allowed'] && (int) $data[$p] !== (int) $dvalue) {
             $perms .= ($perms ? ";" : "") . $row['id'] . ":" . $data[$p];
         }
     }
     if ($fgroup) {
         return $perms;
     }
     $update['perms'] = $perms;
     $update['acp_modules'] = implode(';', array_map('trim', (array) $update['acp_modules']));
     try {
         plugins::o()->pass_data(array("update" => &$update, "id" => $id), true)->run_hook('admin_groups_save');
     } catch (PReturn $e) {
         return $e->r();
     }
     if ($id) {
         db::o()->p($id)->update($update, 'groups', 'WHERE id=? LIMIT 1');
         log_add('changed_group', 'admin', $id);
     } else {
         db::o()->insert($update, 'groups');
         log_add('added_group', 'admin');
     }
     db::o()->query('ALTER TABLE `groups` ORDER BY `sort`');
     cache::o()->remove('groups');
     furl::o()->location($admin_file);
 }
예제 #19
0
파일: content.php 프로젝트: SjayLiFe/CTRev
 /**
  * Удаление контента
  * @param int $id ID контента
  * @return null
  * @throws EngineException 
  */
 public function delete($id)
 {
     check_formkey();
     $id = (int) $id;
     $lj = $cols = "";
     if ($this->tstate) {
         $cols = ", t.screenshots";
         $lj = ' LEFT JOIN content_torrents AS t ON t.cid=c.id';
     }
     $row = db::o()->p($id)->query('SELECT c.poster_id, c.title, c.posted_time, 
         p.id AS poll_id ' . $cols . ' FROM content AS c ' . $lj . '
             LEFT JOIN polls AS p ON p.type="content" AND p.toid=c.id
             WHERE c.id=? LIMIT 1');
     list($poster_id, $title, $posted_time, $pid, $screenshots) = db::o()->fetch_row($row);
     if ($row) {
         if (users::o()->v('id') == $poster_id) {
             users::o()->check_perms('del_content');
         } else {
             users::o()->check_perms('del_content', '2');
         }
     } else {
         throw new EngineException('content_not_exists');
     }
     db::o()->p($id)->delete('content', 'WHERE id=? LIMIT 1');
     if ($this->tstate) {
         db::o()->p($id)->delete('content_torrents', 'WHERE cid=? LIMIT 1');
         db::o()->p($id)->delete('content_downloaded', 'WHERE tid=? LIMIT 1');
         db::o()->p($id)->delete('content_peers', 'WHERE tid=? LIMIT 1');
         cache::o()->remove("details/l-id" . $id);
         $this->delete_files($posted_time, $poster_id, $screenshots);
     }
     try {
         plugins::o()->pass_data(array('id' => $id), true)->run_hook('content_delete');
     } catch (PReturn $e) {
         return $e->r();
     }
     db::o()->p($id)->delete('content_readed', 'WHERE content_id=? LIMIT 1');
     /* @var $etc etc */
     $etc = n("etc");
     $etc->add_res('content', -1, '', $poster_id);
     log_add("deleted_content", "user", array($title));
     users::o()->admin_mode();
     n("comments")->change_type('content')->clear($id);
     n("rating")->change_type('content')->clear($id);
     n("mailer")->change_type('content')->remove($id);
     if ($pid) {
         n("polls")->delete($pid);
     }
     users::o()->admin_mode(false);
 }
예제 #20
0
파일: chat.php 프로젝트: SjayLiFe/CTRev
 /**
  * Форматирование сообщения
  * @param array $row массив данных сообщения
  * @return null
  */
 public function chat_mf(&$row)
 {
     $t = $row["text"];
     $cmds = 'private|me|hello|bye';
     preg_match('/^\\/(' . $cmds . ')\\s*(?:\\((.+)(?:,\\s*([0-9]+))?\\)\\s+)?(.*)$/siu', $t, $matches);
     if (!$matches) {
         return;
     }
     list(, $cmd, $p1, $p2, $t) = $matches;
     $u = null;
     try {
         plugins::o()->pass_data(array('row' => &$row, 'matches' => $matches), true)->run_hook('chat_formatting');
     } catch (PReturn $e) {
         return $e->r();
     }
     switch ($cmd) {
         case "private":
             if (!users::o()->check_login($p1)) {
                 return;
             }
             if (!$row['poster_id'] || !$p1 || mb_strtolower($row['username']) == mb_strtolower($p1)) {
                 return;
             }
             if (!users::o()->perm('chat_sprivate') && users::o()->v('username_lower') != mb_strtolower($p1) && users::o()->v('id') != $row['poster_id']) {
                 $row["text"] = '';
                 return;
             }
             if (users::o()->v('id') == $row['poster_id']) {
                 $cmd = 'fprivate';
                 $u = $p1;
             }
         case "me":
             if (!$u) {
                 $u = smarty_group_color_link($row["username"], $row["group"]);
             }
             $row["text"] = sprintf(lang::o()->v("chat_" . $cmd . "_saying"), $u, $t);
             break;
         case "hello":
         case "bye":
             $row["text"] = sprintf(lang::o()->v("chat_" . $cmd . "_saying"), smarty_group_color_link($row["username"], $row["group"]));
             break;
     }
     $row["spec"] = true;
 }
예제 #21
0
파일: main.php 프로젝트: SjayLiFe/CTRev
 /**
  * Инициализация 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();
 }
예제 #22
0
 /**
  * Автоапдейт групп
  * @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) . '?)');
     }
 }
예제 #23
0
 /**
  * Удаление пользователя
  * @param int $id ID пользователя
  * @return bool статус удаления
  */
 public function delete_user($id)
 {
     $id = (int) $id;
     $r = $this->select_user($id, null, '`group`, avatar, username');
     if (!$r) {
         return;
     }
     $gr = users::o()->get_group($r['group']);
     if (!$gr['can_bedeleted']) {
         return false;
     }
     try {
         plugins::o()->pass_data(array('r' => $r, 'id' => $id), true)->run_hook('users_delete');
     } catch (PReturn $e) {
         return $e->r();
     }
     if ($r['avatar']) {
         $this->remove_user_avatar($id, $r['avatar']);
     }
     users::o()->admin_mode();
     db::o()->p($id)->delete("bans", "WHERE uid = ?");
     db::o()->p($id)->delete("warnings", "WHERE uid = ?");
     /* @var $pm messages_ajax */
     $pm = plugins::o()->get_module('messages', false, true);
     $pm->clear($id);
     db::o()->p($id)->delete("content_readed", "WHERE user_id = ?");
     /* @var $mailer mailer */
     $mailer = n("mailer");
     /* @var $rating rating */
     $rating = n("rating");
     /* @var $comments */
     $comments = n("comments");
     $mailer->remove($id, true);
     $rating->change_type('users')->clear($id);
     db::o()->p($id, $id)->delete("zebra", "WHERE user_id = ? OR to_userid = ?");
     db::o()->p($id)->delete("bookmarks", "WHERE user_id = ?");
     db::o()->p($id)->delete("invites", "WHERE user_id = ?");
     if (config::o('torrents_on')) {
         db::o()->p($id)->delete("content_downloaded", "WHERE uid = ?");
         db::o()->p($id)->delete("content_peers", "WHERE uid = ?");
     }
     $comments->change_type('users')->clear($id);
     db::o()->p($id)->delete("users", "WHERE id = ?");
     users::o()->admin_mode(false);
     log_add('deleted_user', 'admin', array($r['username'], $id));
     return true;
 }
예제 #24
0
파일: lang.php 프로젝트: SjayLiFe/CTRev
 /**
  * Замена в языковых пакетах
  * @param string $name имя языка
  * @param array $data данные поиска
  * @return null
  */
 public function replace($name, $data)
 {
     $cols = array('what' => 'search', 'with', 'where', 'regexp', 'files');
     extract(rex($data, $cols));
     if (!$what) {
         return;
     }
     $regexp = (bool) $regexp;
     /* @var $obj lang_man */
     $obj = plugins::o()->get_module('lang', 1);
     $dir = LANGUAGES_PATH . '/' . $name;
     if (!$files) {
         $files = $dir;
     } else {
         if (!is_array($files)) {
             $files = (array) $files;
         }
         foreach ($files as $k => $v) {
             $v = validpath($v);
             $files[$k] = $dir . '/' . $v;
         }
     }
     $search->replace_infiles($with, array($obj, 'replace'))->search_infiles($files, $what, $regexp, $where, array($obj, "get"));
     log_add('replaced_in_language', 'admin', $name);
 }
예제 #25
0
파일: blocks.php 프로젝트: SjayLiFe/CTRev
 /**
  * Сохранение блока
  * @param array $data массив данных блока
  * @return null
  * @throws EngineException 
  */
 public function save($data)
 {
     $admin_file = globals::g('admin_file');
     $cols = array('title', 'file', 'type', 'tpl', 'module', 'group_allowed', 'enabled');
     if ($data['id']) {
         $id = (int) $data['id'];
     }
     $update = rex($data, $cols);
     $update['enabled'] = (bool) $update['enabled'];
     $update['module'] = implode(';', (array) $update['module']);
     $update['group_allowed'] = implode(';', (array) $update['group_allowed']);
     if (!$update['title'] || !$update['file'] || !in_array($update['type'], self::$types)) {
         throw new EngineException('blocks_invalid_input');
     }
     $update['settings'] = serialize(modsettings::o()->change_type('blocks')->save($id, $data));
     try {
         plugins::o()->pass_data(array("update" => &$update, "id" => $id), true)->run_hook('admin_blocks_save');
     } catch (PReturn $e) {
         return $e->r();
     }
     if ($id) {
         db::o()->p($id)->update($update, 'blocks', 'WHERE id=? LIMIT 1');
         log_add('changed_block', 'admin', $id);
     } else {
         db::o()->insert($update, 'blocks');
         log_add('added_block', 'admin');
     }
     db::o()->query('ALTER TABLE `blocks` ORDER BY `pos`');
     cache::o()->remove('blocks');
     furl::o()->location($admin_file);
 }
예제 #26
0
파일: bots.php 프로젝트: SjayLiFe/CTRev
 /**
  * Сохранение бота
  * @param array $data массив данных
  * @return null
  * @throws EngineException 
  */
 public function save($data)
 {
     $admin_file = globals::g('admin_file');
     $cols = array('id', 'name', 'firstip', 'lastip', 'agent');
     extract(rex($data, $cols));
     $id = (int) $id;
     /* @var $etc etc */
     $etc = n("etc");
     $etc->get_ips($firstip, $lastip, true);
     if (!$name) {
         throw new EngineException('bots_empty_name');
     }
     if (!$firstip && !$lastip && !$agent) {
         throw new EngineException('bots_empty_data');
     }
     $update = array('name' => $name, 'firstip' => $firstip, 'lastip' => $lastip, 'agent' => $agent);
     try {
         plugins::o()->pass_data(array("update" => &$update, "id" => $id), true)->run_hook('admin_bots_save');
     } catch (PReturn $e) {
         return $e->r();
     }
     if (!$id) {
         db::o()->insert($update, 'bots');
         log_add('added_bot', 'admin');
     } else {
         db::o()->p($id)->update($update, 'bots', 'WHERE id=? LIMIT 1');
         log_add('changed_bot', 'admin', $id);
     }
     furl::o()->location($admin_file);
 }
예제 #27
0
파일: cats.php 프로젝트: SjayLiFe/CTRev
 /**
  * Сохранение категории
  * @param array $data массив данных категории
  * @param array $type тип категории
  * @return null
  * @throws EngineException 
  */
 public function save($type, $data)
 {
     $admin_file = globals::g('admin_file');
     $cols = array('parent_id', 'name', 'transl_name', 'descr', 'post_allow', 'pattern');
     if ($data['id']) {
         $id = (int) $data['id'];
     }
     $update = rex($data, $cols);
     $update['type'] = $type;
     if (!$update['name'] || !$update['transl_name']) {
         throw new EngineException("cats_invalid_input");
     }
     if (!validword($update['transl_name'])) {
         throw new EngineException("cats_invalid_transl_name");
     }
     $update['pattern'] = (int) $update['pattern'];
     if (!$this->cats->get($update['parent_id'])) {
         $update['parent_id'] = 0;
     } else {
         $update['parent_id'] = (int) $update['parent_id'];
     }
     $update['post_allow'] = (bool) $update['post_allow'];
     try {
         plugins::o()->pass_data(array("update" => &$update, "id" => $id), true)->run_hook('admin_cats_save');
     } catch (PReturn $e) {
         return $e->r();
     }
     if ($id) {
         db::o()->p($id)->update($update, 'categories', 'WHERE id=? LIMIT 1');
         log_add('changed_cat', 'admin', $id);
     } else {
         db::o()->insert($update, 'categories');
         log_add('added_cat', 'admin');
     }
     db::o()->query('ALTER TABLE `categories` ORDER BY `sort`');
     cache::o()->remove('categories');
     furl::o()->location($admin_file);
 }
예제 #28
0
파일: login.php 프로젝트: SjayLiFe/CTRev
 /**
  * Сохранение нового пароля
  * @param string $key ключ подтверждения
  * @param string $email E-mail пользователя
  * @param string $password новый пароль
  * @param string $passagain новый пароль(повтор)
  * @return null
  */
 protected function recover_save($key, $email, $password, $passagain)
 {
     if (users::o()->v()) {
         return;
     }
     if ($password != $passagain || !users::o()->check_password($password)) {
         throw new EngineException("recover_pass_not_equals");
     }
     $salt = users::o()->generate_salt();
     $password = users::o()->generate_pwd_hash($password, $salt);
     $update = array("confirm_key" => "", "new_email" => "", "password" => $password, "salt" => $salt);
     plugins::o()->pass_data(array("update" => &$update), true)->run_hook('login_recover_save');
     $count = db::o()->p($key, $email)->update($update, "users", 'WHERE confirm_key=? AND email=?');
     if (!$count) {
         throw new EngineException("recover_user_not_exists");
     }
 }
예제 #29
0
파일: convert.php 프로젝트: SjayLiFe/CTRev
 /**
  * Отображение конвертации
  * @return null
  */
 private function show_convert()
 {
     require_once ROOT . sprintf(self::gpath, $this->cfile);
     $this->getter = new get_convert($this->db, $this->prefix, unserialize($this->groups));
     if ($_GET['convert']) {
         if ($_GET['finish']) {
             db::o()->update(array('value' => '1'), 'convert', 'WHERE field="converted" LIMIT 1');
             stats::o()->remove(self::stfield);
             $pname = sprintf(self::pname, $this->cfile);
             plugins::o()->manager->delete($pname);
             plugins::o()->manager->add($pname);
             printf(lang::o()->v('convert_plugin_installed'));
             print "<script type='text/javascript'>stop_loading();</script>";
             die;
         }
         $this->parse($_POST['toffset'], $_POST['loffset']);
         die;
     }
 }
예제 #30
0
파일: user.php 프로젝트: SjayLiFe/CTRev
 /**
  * Отображение профиля пользователя
  * @param string $username имя пользователя
  * @param string $act запускаемый сабмодуль
  * @return null
  * @throws EngineException
  */
 protected function show_userinfo($username, $act)
 {
     users::o()->check_perms('profile', 1, 2);
     $lj = $cols = "";
     if (users::o()->v()) {
         db::o()->p(users::o()->v('id'));
         $cols = ", z.id AS zebra_id, z.type AS zebra_type";
         $lj = 'LEFT JOIN zebra AS z ON z.user_id=? AND z.to_userid=u.id';
     }
     $row = db::o()->p(mb_strtolower($username))->query('SELECT u.* ' . $cols . '
             FROM users AS u ' . $lj . '
             WHERE u.username_lower=?
             AND u.id>0 LIMIT 1');
     $row = db::o()->fetch_assoc($row);
     if (!$row) {
         throw new EngineException("users_profile_not_exists", $username);
     }
     $row = users::o()->decode_settings($row);
     /*
               if ((int) $row["country"]) {
               $r = db::o()->p($row["country"])->query("SELECT name, image FROM countries WHERE id=? LIMIT 1");
               $r = db::o()->fetch_assoc($r);
               $row["country_name"] = $r["name"];
               $row["country_image"] = $r["image"];
               } */
     $this->title .= ' "' . $username . '"';
     $id = $row['id'];
     $karma = $row["karma_count"];
     $row['age'] = $this->get_age($row['birthday']);
     try {
         plugins::o()->pass_data(array('row' => &$row), true)->run_hook('user_profile');
     } catch (PReturn $e) {
         return $e->r();
     }
     tpl::o()->assign("row", $row);
     tpl::o()->assign("karma", $karma);
     tpl::o()->assign("act", $act);
     tpl::o()->assign("menu", $this->menu);
     n("comments");
     // для display_comments
     n("userfields");
     // для display_userfields
     tpl::o()->display('profile/user.tpl');
 }