Пример #1
0
 /**
  * Сохранение предупреждения
  * @param array $data массив данных
  * @return null
  */
 protected function save($data)
 {
     $admin_file = globals::g('admin_file');
     $id = (int) $data['id'];
     $cols = array('user' => 'username', 'reason', 'notify');
     extract(rex($data, $cols));
     $notify = (bool) $notify;
     /* @var $etc etc */
     $etc = n("etc");
     if ($user || !$id) {
         $r = $etc->select_user(null, $user, "id,email,warnings_count");
         $uid = $r["id"];
         $email = $r["email"];
         $warns = $r["warnings_count"];
     }
     if (!$uid && !$id || !$reason) {
         throw new EngineException('warnings_no_user');
     }
     $etc->warn_user($uid, $reason, $warns, $notify, $email, $id);
     if ($id) {
         $this->show($id);
         return;
     } else {
         furl::o()->location($admin_file);
     }
 }
Пример #2
0
 /**
  * Сохранение бана
  * @param array $data массив данных
  * @return null
  * @throws EngineException 
  */
 protected function save($data)
 {
     $admin_file = globals::g('admin_file');
     $id = (int) $data['id'];
     $cols = array('user' => 'username', 'email', 'ip_f', 'ip_t', 'reason', 'period', 'up' => 'update');
     extract(rex($data, $cols));
     $ip_f = ip2ulong($ip_f);
     $ip_t = ip2ulong($ip_t);
     $period = (double) $period;
     /* @var $etc etc */
     $etc = n("etc");
     $uid = 0;
     if ($user) {
         $r = $etc->select_user(null, $user, "id");
         $uid = $r["id"];
     }
     if (!$uid && !$email && !$ip_f && !$ip_t) {
         throw new EngineException("bans_nothing_banned");
     }
     $etc->ban_user($uid, !$id || $up ? $period : 0, $reason, $email, $ip_f, $ip_t, $id);
     if ($id) {
         $this->show($id);
         return;
     } else {
         furl::o()->location($admin_file);
     }
 }
Пример #3
0
 /**
  * Сохранение бота
  * @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);
 }
Пример #4
0
 /**
  * Построение плагина
  * @param array $data массив данных
  * @return null 
  * @throws EngineException
  */
 public function build($data)
 {
     lang::o()->get('admin/plugins');
     $data_params = array("plugin", "version", "author", "name", "descr", "comp", "comp_min", "comp_max");
     extract(rex($data, $data_params));
     if (!validword($plugin)) {
         throw new EngineException("plugins_invalid_name");
     }
     $settings = modsettings::o()->make($data);
     $defaults = modsettings::o()->save(modsettings::nocache_id, $data);
     $vars = array($plugin, var_export((string) $version, true), var_export((string) $author, true), var_export((string) $name, true), var_export((string) $descr, true), var_export((string) $comp, true), var_export((string) $comp_min, true), var_export((string) $comp_max, true), var_export((array) $settings, true), $plugin, var_export((array) $defaults, true));
     $contents = @file_get_contents(ROOT . self::plugin_template);
     $contents = vsprintf($contents, $vars);
     /* @var $uploader uploader */
     $uploader = n("uploader");
     $uploader->download_headers($contents, 'plugin.' . $plugin . '.php', 'text/plain');
 }
Пример #5
0
 /**
  * Сохранение стат. страницы
  * @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);
 }
Пример #6
0
 /**
  * Замена в теме
  * @param string $name имя темы
  * @param array $data данные поиска
  * @return null
  */
 public function replace($name, $data)
 {
     $cols = array('what' => 'search', 'with', 'regexp', 'files');
     extract(rex($data, $cols));
     if (!$what) {
         return;
     }
     $regexp = (bool) $regexp;
     $dir = THEMES_PATH . '/' . $name;
     if (!$files) {
         $files = $dir;
     } else {
         if (!is_array($files)) {
             $files = (array) $files;
         }
         foreach ($files as $k => $v) {
             $v = validpath($v, false, styles_man::$spaths);
             $files[$k] = $dir . '/' . $v;
         }
     }
     $search->replace_infiles($with)->search_infiles($files, $what, $regexp);
     log_add('replaced_in_style', 'admin', $name);
 }
Пример #7
0
 /**
  * Сохранение группы
  * @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);
 }
Пример #8
0
 /**
  * Построение настроек из формы
  * @param array $data массив данных
  * @return array массив настроек
  */
 public function make($data)
 {
     $data_params = array('params' => 'mparam', 'key' => 'keytype', 'val' => 'valtype', 'limit' => 'keylimit', 'enum' => 'enumvals');
     extract(rex($data, $data_params));
     if (!$params) {
         return;
     }
     $params = (array) $params;
     $key = (array) $key;
     $val = (array) $val;
     $limit = (array) $limit;
     $enum = (array) $enum;
     $r = array();
     foreach ($params as $k => $param) {
         if (!$param || !validword($param)) {
             continue;
         }
         $v = $val[$k];
         $l = (int) $limit[$k];
         $e = trim($enum[$k]);
         $k = $key[$k];
         $a = "";
         switch ($k) {
             case "unlimited":
                 $a = "[]";
             case "simple":
                 break;
             case "limited":
                 if (!$l || $l < 2) {
                     $a = false;
                 } else {
                     $a = "[" . $l . "]";
                 }
                 break;
             case "string":
             case "integer":
                 $a = "[" . $k . "]";
                 break;
             default:
                 $a = false;
                 break;
         }
         if ($a === false) {
             continue;
         }
         $param = $param . $a;
         $a = "";
         switch ($v) {
             case "string":
             case "integer":
             case "text":
                 $a = $v;
                 break;
             case "enum":
                 if (!preg_match('/^([a-z0-9\\-\\_]+(;|$))+$/si', $e)) {
                     $a = false;
                 } else {
                     $a = $v . '[' . $e . ']';
                 }
         }
         if ($a === false) {
             continue;
         }
         $r[$param] = $a;
     }
     return $r;
 }
Пример #9
0
 /**
  * Обработка данных поиска
  * @param array $data данные поиска
  * @return array массив условия, сортировки и значения subupdate
  */
 protected function users_data_prepare($data)
 {
     /* @var $search search */
     $search = n("search");
     $unco = (bool) $_GET['unco'];
     $inadmin = users::o()->check_inadmin("users");
     try {
         $where = array();
         plugins::o()->pass_data(array('where' => &$where, 'orderby' => &$this->orderby, 'data' => &$data), true)->run_hook('search_users_begin');
         $data_params = array("uname" => "user", "email", "ip", "icq", "skype", "name", "country", "group", "reg_type", "lv_type", "subupdate", 'orderby');
         extract(rex($data, $data_params));
         if ($unco) {
             $where[] = "confirmed <> '3'";
         }
         if ($uname && ($cwhere = $search->like_where($uname, 'username'))) {
             $where[] = $cwhere;
         }
         if ($email && ($cwhere = $search->like_where($email, 'email'))) {
             $where[] = $cwhere;
         }
         if ($ip && ($ip = $search->search_ip($ip))) {
             $where[] = $ip;
         }
         /*
          if ($icq)
          $where [] = $search->search_settings('icq', $icq);
          if ($skype)
          $where [] = $search->search_settings('skype', $skype);
          if ($name)
          $where [] = $search->search_settings('name_surname', $name);
          $country = (int) $country;
          if ($country)
          $where [] = $search->search_settings('country', $country);
         */
         $group = (int) $group;
         if ($group) {
             $where[] = '`group`=' . $group;
         }
         $day = 60 * 60 * 24;
         $sign1 = !$reg_type ? "==" : ($reg_type == 1 ? ">=" : "<=");
         $registered = display::o()->make_time("reg", "ymd");
         if ($registered) {
             switch ($sign1) {
                 case "==":
                     $registered2 = $registered + $day;
                     break;
                 case ">=":
                     $registered2 = time();
                     break;
                 case "<=":
                     $registered2 = $last_visited;
                     $last_visited = 0;
                     break;
             }
         }
         if ($registered || $registered2) {
             $where[] = 'registered BETWEEN ' . longval($registered) . ' AND ' . longval($registered2 - ($sign1 != ">=" ? 1 : 0));
         }
         $sign2 = !$lv_type ? "==" : ($lv_type == 1 ? ">=" : "<=");
         $last_visited = display::o()->make_time("lv", "ymd");
         if ($last_visited) {
             switch ($sign2) {
                 case "==":
                     $last_visited2 = $last_visited + $day;
                     break;
                 case ">=":
                     $last_visited2 = time();
                     break;
                 case "<=":
                     $last_visited2 = $last_visited;
                     $last_visited = 0;
                     break;
             }
         }
         if ($last_visited || $last_visited2) {
             $where[] = 'last_visited BETWEEN ' . longval($last_visited) . ' AND ' . longval($last_visited2 - ($sign2 != ">=" ? 1 : 0));
         }
         plugins::o()->run_hook('search_users_end');
         if (!$inadmin && !$where) {
             n("message")->stype("error")->sdie()->info('nothing_selected');
         }
         if ($orderby) {
             $sort = explode(",", $orderby);
             $c = count($sort);
             $orderby = '';
             for ($i = 0; $i < $c; $i += 2) {
                 if (!$this->orderby[$sort[$i]]) {
                     continue;
                 }
                 $orderby .= ($orderby ? ', ' : '') . "`" . $this->orderby[$sort[$i]] . "` " . ($sort[$i + 1] ? "asc" : "desc");
             }
         }
         $where[] = 'id>0';
         $where = $where ? "(" . implode(") AND (", $where) . ")" : null;
     } catch (PReturn $e) {
         return $e->r();
     }
     return array($where, $orderby, $subupdate);
 }
Пример #10
0
 /**
  * Сохранение категории
  * @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);
 }
Пример #11
0
/**
 * Project:             CTRev
 * @file                /announce.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';
require_once ROOT . '/include/classes/class.etc.php';
$etc = new etc();
$a = array("passkey", "peer_id", "port", "uploaded", "ip", "left", "compact", "event", "info_hash", "no_peer_id");
$c = count($a);
extract(rex($_REQUEST, $a));
if ($_REQUEST['num want']) {
    $_REQUEST['numwant'] = $_REQUEST['num want'];
}
if ($_REQUEST['num_want']) {
    $_REQUEST['numwant'] = $_REQUEST['num_want'];
}
$numwant = (int) $_REQUEST['numwant'];
$ip = ip2ulong($ip ? $ip : $_SERVER['REMOTE_ADDR']);
if (!$ip) {
    $bt->err('Invalid IP.');
}
$info_hash = bin2hex($info_hash);
$seeder = $left > 0 ? '0' : '1';
$area = $seeder ? 'seeders' : 'leechers';
//$bt->err('Unknown user. Passkey - ' . print_r($_SERVER, true));
Пример #12
0
 /**
  * Сохранение настроек и данных пользователя
  * @param array $data данные юзера
  * @return null
  * @throws EngineException
  */
 protected function save_main($data)
 {
     $inadmin = users::o()->check_inadmin("users");
     /* @var $etc etc */
     $etc = n("etc");
     if ($inadmin) {
         $id = (int) $data['uid'];
         users::o()->set_tmpvars($etc->select_user($id));
         $sadmin = users::o()->perm("system");
         $gr = users::o()->get_group(users::o()->v('group'));
         $suser = $gr['system'];
         if ($suser && !$sadmin) {
             throw new EngineException("access_denied");
         }
     } else {
         $id = users::o()->v('id');
         users::o()->check_perms();
         check_formkey();
     }
     //$register = plugins::o()->get_module('registration');
     display::o()->remove_time_fields("his", "birthday");
     $birthday = display::o()->make_time("birthday", "ymd");
     $this->check_areas($data, $error, $inadmin);
     if ($error) {
         throw new EngineException(implode("<br>", $error));
     }
     extract(rex($data, array("email", "gid" => "group", "gender", "admin_email", "user_email", "use_dst", "timezone", "interval", "password", "email", "avatar_url", "username")));
     $update = array();
     if ($password) {
         $salt = users::o()->v('salt');
         $update["password"] = users::o()->generate_pwd_hash($password, $salt);
         if (!$inadmin) {
             users::o()->write_cookies(users::o()->v('username'), $update["password"]);
         }
     }
     if ($email != users::o()->v('email')) {
         if (config::o()->v('confirm_email') && !$inadmin) {
             $update["new_email"] = $email;
             $update["confirm_key"] = $etc->confirm_request($email, "confirm_email");
         } else {
             $update["email"] = $email;
         }
     }
     $settings = rex($data, array("name_surname", "signature", 'hidden', 'announce_pk' => 'passkey', 'show_age'));
     $settings["show_age"] = (bool) $settings["show_age"];
     $settings["hidden"] = users::o()->perm("behidden") || $inadmin ? (bool) $settings["hidden"] : 0;
     if (config::o()->v("torrents_on")) {
         $settings['announce_pk'] = serialize($settings['announce_pk']);
     }
     /* @var $uf userfields */
     $uf = n("userfields");
     $settings = array_merge($settings, $uf->change_type('profile')->save($data));
     if ($inadmin) {
         $gid = (int) $gid;
         if ($etc->change_group($id, $gid, true)) {
             $update['group'] = $gid;
             /* @var $groups groups_man */
             $groups = plugins::o()->get_module('groups', 1);
             $group = users::o()->get_group(users::o()->v('group'));
             $update["add_permissions"] = $groups->save($data, $group);
         }
         $update['username'] = $username;
         $update['username_lower'] = mb_strtolower($username);
     }
     $update["gender"] = $gender == "f" ? "f" : "m";
     $update["admin_email"] = (bool) $admin_email;
     $update["user_email"] = (bool) $user_email;
     $update["timezone"] = (int) $timezone;
     $update["dst"] = (bool) $use_dst;
     $update["mailer_interval"] = (int) $interval;
     //print_r($update);
     if ($birthday) {
         $update["birthday"] = $birthday;
     }
     if ($avatar_url && is(config::o()->v('allowed_avatar'), ALLOWED_AVATAR_URL)) {
         $this->clear_avatar(true);
         /* @var $uploader uploader */
         $uploader = n("uploader")->upload_via_url();
         $avatar_name = display::avatar_prefix . users::o()->v('id');
         $uploader->upload($avatar_url, config::o()->v('avatars_folder'), $tmp = 'avatars', $avatar_name);
         //$uploader->upload_via_url(true)->check($avatar_url, /* ссылка */ $tmp = 'avatars');
         $update["avatar"] = $avatar_name;
     }
     try {
         plugins::o()->pass_data(array('update' => &$update, 'settings' => &$settings), true)->run_hook('usercp_save_main');
     } catch (PReturn $e) {
         return $e->r();
     }
     $update["settings"] = users::o()->make_settings($settings);
     users::o()->remove_tmpvars();
     db::o()->p($id)->update($update, "users", 'WHERE id=? LIMIT 1');
     if (!$inadmin) {
         users::o()->setcookie("theme", $data['theme']);
         users::o()->setcookie("lang", $data['lang']);
         users::o()->setcookie("theme_color", $data['theme_color']);
     } else {
         log_add("changed_user", 'admin', null, $id);
     }
 }
Пример #13
0
 /**
  * Сохранение шаблона
  * @param array $data массив данных шаблона
  * @return null
  * @throws EngineException 
  */
 public function save($data)
 {
     $admin_file = globals::g('admin_file');
     $cols = array('name', 'rname', 'type', 'size', 'values', 'html', 'descr', 'formdata');
     if ($data['id']) {
         $id = (int) $data['id'];
     }
     if (!$data['pattern_name']) {
         $data['pattern_name'] = 'tmp' . time();
     }
     // Меньше ошибок - лучше
     $update = array();
     $update['name'] = $data['pattern_name'];
     $pattern = rex($data, $cols);
     $pattern = $this->build_pattern($pattern);
     try {
         plugins::o()->pass_data(array("update" => &$update, "pattern" => &$pattern, "id" => $id), true)->run_hook('admin_patterns_save');
     } catch (PReturn $e) {
         return $e->r();
     }
     $update['pattern'] = serialize($pattern);
     if ($id) {
         db::o()->p($id)->update($update, 'patterns', 'WHERE id=? LIMIT 1');
         cache::o()->remove('patterns/pattern-id' . $id);
         log_add('changed_pattern', 'admin', $id);
     } else {
         db::o()->insert($update, 'patterns');
         log_add('added_pattern', 'admin');
     }
     furl::o()->location($admin_file);
 }
Пример #14
0
 /**
  * Переход по степеням в регистрации
  * @param integer|string $step текущая стадия регистрации
  * @param array $data массив данных
  * @return null
  * @throws EngineException
  */
 protected function step_by_step($step, $data)
 {
     $error = array();
     /* @var $uf userfields */
     $uf = n("userfields")->change_type('register');
     // для input_userfields и метода save
     if ($data['to_check'] && is_numeric($step)) {
         $this->check_steps($error, $step, $data);
         if ($step >= 3) {
             try {
                 $uf->save($data);
             } catch (EngineException $e) {
                 $error[] = $e->getEMessage();
             }
         }
         if (!$error) {
             ok();
         } else {
             $error = implode("<br>", $error);
         }
         throw new EngineException($error);
     } elseif ($step == "last") {
         if (!config::o()->v('allowed_register') && !config::o()->v('allowed_invite')) {
             die("ERROR!");
         }
         $refered_by = 0;
         /* @var $etc etc */
         $etc = n("etc");
         $this->check_steps($error, $step, $data, $refered_by);
         if ($error) {
             throw new EngineException(implode("<br>", $error));
         }
         $salt = users::o()->generate_salt();
         display::o()->remove_time_fields("his", "birthday");
         $birthday = display::o()->make_time("birthday", "ymd");
         $cols = array('username', 'password', 'email', 'gender', 'timezone', 'admin_email', 'user_email', 'use_dst', 'invite');
         extract(rex($data, $cols));
         $password = users::o()->generate_pwd_hash($password, $salt);
         $update = array("username" => $username, "username_lower" => mb_strtolower($username), "passkey" => users::o()->generate_salt(), "password" => $password, "salt" => $salt, "registered" => time(), "birthday" => $birthday, "email" => $email, "confirmed" => longval($etc->confirm_user(0, 0)), "group" => users::o()->find_group('default'), "refered_by" => (int) $refered_by, "confirm_key" => config::o()->v('confirm_email') ? $etc->confirm_request($email, "confirm_register") : "");
         if (config::o()->v('bonus_by_default')) {
             $update['bonus_count'] = config::o()->v('bonus_by_default');
         }
         $update["gender"] = $gender == "f" ? "f" : "m";
         $update["admin_email"] = (bool) $admin_email;
         $update["user_email"] = (bool) $user_email;
         $update["dst"] = (bool) $use_dst;
         $update["timezone"] = (int) $timezone;
         $cols = array("name_surname" => 'name');
         $settings = rex($data, $cols);
         $settings["show_age"] = (bool) $data['show_age'];
         $settings = array_merge($settings, $uf->save($data));
         try {
             plugins::o()->pass_data(array('update' => &$update, 'settings' => &$settings), true)->run_hook('register_user');
             $update['settings'] = users::o()->make_settings($settings);
             $id = db::o()->insert($update, "users");
             plugins::o()->pass_data(array('id' => $id))->run_hook('register_user_finish');
         } catch (PReturn $e) {
             return $e->r();
         }
         if ($invite) {
             db::o()->p($invite)->update(array("to_userid" => $id), "invites", 'WHERE invite_id=? LIMIT 1');
         } elseif (!config::o()->v('confirm_email') && !config::o()->v('confirm_admin')) {
             users::o()->write_cookies($username, $password);
         }
         ok();
     }
     tpl::o()->display("register/main_step.tpl");
 }
Пример #15
0
 /**
  * Сохранение смайлов
  * @param array $data массив данных
  * @return null
  * @throws EngineException 
  */
 public function save($data)
 {
     $admin_file = globals::g('admin_file');
     $cols = array('id', 'name', 'code', 'image', 'sb' => 'show_bbeditor');
     extract(rex($data, $cols));
     $id = (int) $id;
     $name = (array) $name;
     $code = (array) $code;
     $image = (array) $image;
     $sb = (array) $sb;
     $c = count($name);
     if ($id && $c != 1) {
         throw new EngineException('smilies_empty_data');
     }
     if (!$name || $c != count($code) || $c != count($image)) {
         throw new EngineException('smilies_empty_data');
     }
     foreach ($name as $i => $iname) {
         $icode = trim($code[$i]);
         $iname = trim($iname);
         $iimage = trim($image[$i]);
         $isb = (bool) $sb[$i];
         if (!$icode || !$iname || !$iimage) {
             continue;
         }
         if (!file_exists(ROOT . config::o()->v('smilies_folder') . '/' . $iimage) || !in_array(file::o()->get_filetype($iimage), $this->allowed_types)) {
             continue;
         }
         if (db::o()->p($icode, $id)->count_rows('smilies', 'code = ?' . ($id ? ' AND id<>?' : ''))) {
             continue;
         }
         $update = array('code' => $icode, 'name' => $iname, 'image' => $iimage, 'show_bbeditor' => $isb);
         try {
             plugins::o()->pass_data(array("update" => &$update, "id" => $id), true)->run_hook('admin_smilies_save');
         } catch (PReturn $e) {
             if (!$e->r()) {
                 continue;
             }
             return $e->r();
         }
         if (!$id) {
             db::o()->insert($update, 'smilies', true);
         } else {
             db::o()->p($id)->update($update, 'smilies', 'WHERE id=? LIMIT 1');
         }
     }
     cache::o()->remove('smilies');
     if (!$id) {
         db::o()->save_last_table();
         furl::o()->location($admin_file);
     } else {
         $this->show($id);
         return;
     }
 }
Пример #16
0
 /**
  * Настройка сайта
  * @param array $data массив данных
  * @param array $error массив ошибок
  * @return null
  */
 protected function config($data, &$error)
 {
     include_once ROOT . 'include/classes/class.cache.php';
     include_once ROOT . 'include/classes/class.users.php';
     include_once ROOT . 'include/classes/class.config.php';
     cache::o()->clear();
     $params = array('site_title', 'baseurl', 'contact_email', 'furl', 'cache_on');
     $upd = rex($data, $params);
     // предустановка параметров, если не заданы
     if (!$upd['baseurl']) {
         $upd['baseurl'] = preg_replace('/^(.*)(\\/|\\\\)(.*?)$/siu', '\\1', $_SERVER['PHP_SELF']);
     }
     if (!$upd['contact_email']) {
         $upd['contact_email'] = 'admin@' . $_SERVER['SERVER_NAME'];
     }
     if (!isset($data['furl'])) {
         $upd['furl'] = (bool) $_SERVER['HTTP_FURL_AVALIABLE'];
     } else {
         $upd['furl'] = (bool) $upd['furl'];
     }
     if (!isset($data['cache_on'])) {
         $upd['cache_on'] = true;
     } else {
         $upd['cache_on'] = (bool) $upd['cache_on'];
     }
     $upd['secret_key'] = users::o()->generate_salt();
     foreach ($upd as $k => $v) {
         config::o()->set($k, $v);
     }
 }
Пример #17
0
 /**
  * Сохранение статьи
  * @param array $data массив данных
  * @param int $id ID статьи
  * @param bool $short быстрое редактирование?
  * @return int ID созданной(отредактированной) статьи
  * @throws EngineException 
  */
 public function save($data, $id = null, $short = false)
 {
     $data_params = array("title", "cat" => "cats", "content", "imname", "tfname", "tags", "on_top", "sticky", "edit_reason", "price");
     extract(rex($data, $data_params));
     check_formkey();
     lang::o()->get('content');
     $id = (int) $id;
     $price = (double) $price;
     if ($id) {
         $lj = $cols = "";
         if ($this->tstate) {
             $cols = ", t.*";
             $lj = " LEFT JOIN content_torrents AS t ON t.cid=c.id";
         }
         $row = db::o()->p($id)->query('SELECT c.* ' . $cols . ' FROM content AS c ' . $lj . ' WHERE c.id=? LIMIT 1');
         $row = db::o()->fetch_assoc($row);
         if ($row) {
             if ($this->tstate && $row["banned"] == 2) {
                 throw new EngineException("content_torrent_cant_be_edited");
             }
             if (users::o()->v('id') == $row['poster_id']) {
                 users::o()->check_perms('edit_content');
             } else {
                 users::o()->check_perms('edit_content', '2');
             }
             $edit_count = $row['edit_count'];
         } else {
             throw new EngineException('content_not_exists');
         }
     }
     if (!$content) {
         throw new EngineException('content_no_content');
     }
     if (!$title) {
         throw new EngineException('content_no_title');
     }
     if (!is_null($cat) || !$id) {
         $mcats = $cat;
         $cats = $this->cats;
         $cat = $cats->save_selected($mcats);
         if (!$cat) {
             throw new EngineException('content_no_selected_cat');
         }
     }
     try {
         $update = array('title' => $title);
         $torrent = array();
         if (!is_null($content) || !$id) {
             $update['content'] = $content;
         }
         if (!is_null($cat) || !$id) {
             $update['category_id'] = $cat;
         }
         if (!is_null($tags) || !$id) {
             $update['tags'] = preg_replace('/\\s*,\\s*/su', ',', $tags);
         }
         if (!is_null($sticky) && users::o()->perm('msticky_content')) {
             $update['sticky'] = $sticky ? "1" : "0";
         } elseif (!$id) {
             $update['sticky'] = "0";
         }
         $error = "";
         plugins::o()->pass_data(array('update' => &$update, 'id' => $id, 'error' => &$error), true)->run_hook('content_save_begin');
         $bt = $getpeers = null;
         if ($this->tstate) {
             if (!is_null($price) && $price <= config::o()->v('max_torrent_price') && users::o()->perm('ct_price')) {
                 $torrent['price'] = $price;
             } elseif (!$id) {
                 $torrent['price'] = config::o()->v('default_torrent_price');
             }
             $torrent['last_active'] = time();
             /* @var $bt bittorrent */
             $bt = n("bittorrent");
             /* @var $getpeers geetpeers */
             $getpeers = n("getpeers");
         } elseif (!is_null($on_top) && users::o()->perm('edit_content', 2)) {
             $update['on_top'] = $on_top ? '1' : '0';
         } elseif (!$id) {
             $update['on_top'] = '0';
         }
         if (!$id) {
             $sdata = array($mcats, $tfname, $imname, $getpeers, $bt, $torrent);
             $id = $this->save_add($update, $error, $sdata);
         } else {
             $sdata = array($row, $edit_reason, $edit_count, $tfname, $imname, $getpeers, $bt, $torrent);
             $this->save_edit($update, $error, $sdata);
         }
         plugins::o()->pass_data(array('id' => $id))->run_hook('content_save_end');
         n("attachments")->change_type('content')->define_toid($data, $id);
         try {
             n("polls")->change_type('content')->save($data, $id);
         } catch (EngineException $e) {
             if ($e->getCode()) {
                 throw $e;
             }
         }
     } catch (PReturn $e) {
         return $e->r();
     }
     if ($error) {
         throw new EngineException('content_torrent_uploaded_but', array(furl::o()->construct('content', array('id' => $id, 'title' => $title)), $error));
     }
     return $id;
 }
Пример #18
0
 /**
  * Сохранение опроса
  * @param array $data массив данных
  * @param int $toid ID ресурса
  * @param int $poll_id ID опроса
  * @return int ID опроса, в случае успешного завершения
  * @throws EngineException 
  */
 public function save($data, $toid = 0, $poll_id = 0)
 {
     if (!$this->state) {
         return;
     }
     $type = $this->type;
     lang::o()->get('polls');
     $cols = array('question', 'max_votes', 'poll_ends', 'show_voted', 'change_votes', 'answers');
     extract(rex($data, $cols));
     $max_votes = (int) $max_votes;
     $poll_ends = (int) $poll_ends;
     $toid = (int) $toid;
     $poll_id = (int) $poll_id;
     if (!$poll_id && (!$toid || !$type)) {
         users::o()->check_perms('polls', 3);
     } else {
         if ($toid && $type) {
             users::o()->perm_exception();
         }
         if ($poll_id) {
             db::o()->p($poll_id);
             $where = 'id = ?';
         } else {
             db::o()->p($toid, $type);
             $where = 'toid = ? AND type = ?';
         }
         $row = db::o()->query('SELECT id, poster_id, answers, question FROM polls
             WHERE ' . $where . " LIMIT 1");
         $row = db::o()->fetch_assoc($row);
         if (!$row) {
             users::o()->check_perms('polls', 2);
         } else {
             $poll_id = $row['id'];
             if ($row['poster_id'] == users::o()->v('id')) {
                 users::o()->check_perms('edit_polls');
             } else {
                 users::o()->check_perms('edit_polls', 2);
             }
         }
     }
     $show_voted = (bool) $show_voted;
     $change_votes = (bool) $change_votes;
     $answers = array_values(array_filter(array_map('trim', (array) $answers)));
     if (!$question || !$answers || !$max_votes || $poll_ends < 0) {
         throw new EngineException('polls_areas_cant_be_empty', null, 0);
     }
     if (count($answers) < 2) {
         throw new EngineException('polls_so_few_answers', null, 1);
     }
     $answers = serialize($answers);
     $update = array('question' => $question, 'answers' => $answers, 'show_voted' => $show_voted, 'change_votes' => $change_votes, 'poll_ends' => $poll_ends, 'max_votes' => $max_votes);
     try {
         plugins::o()->pass_data(array('update' => &$update, "id" => $poll_id), true)->run_hook('polls_save');
     } catch (PReturn $e) {
         return $e->r();
     }
     if (!$poll_id) {
         $update['toid'] = $toid;
         $update['type'] = $type;
         $update['posted_time'] = time();
         $update['poster_id'] = users::o()->v('id');
         $id = db::o()->insert($update, 'polls');
     } else {
         $id = db::o()->p($poll_id)->update($update, 'polls', 'WHERE id = ? LIMIT 1');
         if ($row['answers'] != $answers) {
             db::o()->p($poll_id)->delete('poll_votes', 'WHERE question_id = ?');
         }
         if ($row['answers'] != $answers || $row['question'] != $question) {
             log_add("edited_poll", "user", array($row['question'], $id));
         }
         $this->uncache($poll_id);
     }
     return $id;
 }
Пример #19
0
 /**
  * Сохранение блока
  * @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);
 }
Пример #20
0
 /**
  * Сохранение типов файлов
  * @param array $data массив данных
  * @return null
  * @throws EngineException 
  */
 public function save($data)
 {
     $admin_file = globals::g('admin_file');
     $oname = $data['old_name'];
     $cols = array('name', 'image', 'types', 'MIMES', 'max_filesize', 'max_width', 'max_height', 'makes_preview', 'allowed');
     $update = rex($data, $cols);
     $update['makes_preview'] = (bool) $update['makes_preview'];
     $update['allowed'] = (bool) $update['allowed'];
     $update['max_filesize'] = (int) $update['max_filesize'];
     $update['max_width'] = (int) $update['max_width'];
     $update['max_height'] = (int) $update['max_height'];
     if (!validword($update['name'])) {
         throw new EngineException('allowedft_invalid_name');
     }
     if (!$update['max_filesize']) {
         throw new EngineException('allowedft_invalid_filesize');
     }
     if (!$update['types']) {
         throw new EngineException('allowedft_invalid_types');
     }
     try {
         plugins::o()->pass_data(array("update" => &$update, "oname" => $oname), true)->run_hook('admin_allowedft_save');
     } catch (PReturn $e) {
         return $e->r();
     }
     if ($oname) {
         db::o()->p($oname)->update($update, 'allowed_ft', 'WHERE name=? LIMIT 1');
     } else {
         db::o()->insert($update, 'allowed_ft');
         log_add('added_filetype', 'admin', $update['name']);
     }
     furl::o()->location($admin_file);
 }
Пример #21
0
 /**
  * Замена в языковых пакетах
  * @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);
 }
Пример #22
0
 /**
  * Сохранение доп. полей
  * @param array $data массив данных
  * @return null
  * @throws EngineException 
  */
 public function save($data)
 {
     $admin_file = globals::g('admin_file');
     $oname = $data['old_field'];
     $values = (array) $data['values'];
     $keys = (array) $data['keys'];
     $cols = array('field', 'name', 'allowed', 'descr', 'type', 'show_register', 'show_profile');
     $update = rex($data, $cols);
     $update['show_register'] = (bool) $update['show_register'];
     $update['show_profile'] = (bool) $update['show_profile'];
     if (!validword($update['field'])) {
         throw new EngineException('userfields_empty_field');
     }
     if (!$update['name']) {
         throw new EngineException('userfields_empty_name');
     }
     /* @var $uf userfields */
     $uf = n("userfields");
     $ct = $uf->get_var('types', $update['type']);
     if (is_null($ct)) {
         throw new EngineException('userfields_empty_type');
     }
     if ($ct) {
         $allowed =& $update['allowed'];
         if ($ct == 2) {
             $allowed = array();
             $cv = count($values);
             if ($cv == count($keys) && $cv >= 2) {
                 for ($i = 0; $i < $cv; $i++) {
                     $key = $keys[$i];
                     $value = $values[$i];
                     if (!validword($key, 'latin', 1) && !is_numeric($key)) {
                         continue;
                     }
                     if (!$value) {
                         continue;
                     }
                     $allowed[$key] = $value;
                 }
                 $allowed = serialize($allowed);
             }
         }
         if (!$allowed) {
             throw new EngineException('userfields_empty_allowed');
         }
     }
     try {
         plugins::o()->pass_data(array('update' => &$update, 'oname' => $oname), true)->run_hook('admin_userfields_save');
     } catch (PReturn $e) {
         return $e->r();
     }
     if ($oname) {
         db::o()->p($oname)->update($update, 'users_fields', 'WHERE field=? LIMIT 1');
     } else {
         db::o()->insert($update, 'users_fields');
         log_add('added_userfield', 'admin', $update['field']);
     }
     cache::o()->remove('userfields');
     furl::o()->location($admin_file);
 }