Example #1
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);
     }
 }
Example #2
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);
     }
 }
Example #3
0
 /**
  * Стат. страницы
  * @return null
  */
 public function init()
 {
     $url = $_GET['page'];
     $r = db::o()->p($url)->query('SELECT * FROM static WHERE url=? LIMIT 1');
     $row = db::o()->fetch_assoc($r);
     if (!$row) {
         furl::o()->location('');
     }
     $this->title = $row['title'];
     tpl::o()->assign('title', $row['title']);
     tpl::o()->assign('content', $row['content']);
     tpl::o()->assign('type', $row['type']);
     tpl::o()->display('static.tpl');
 }
Example #4
0
 /**
  * Инициализация модуля обратной связи
  * @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;
     }
 }
Example #5
0
 /**
  * Сохранение файла темы
  * @param array $data массив данных файла темы
  * @return null
  * @throws EngineException 
  */
 public function save($data)
 {
     $admin_file = globals::g('admin_file');
     $cols = array('name' => 'id', 'of2e' => 'file', 'f2e' => 'filename', 'folder', 'content');
     extract(rex($data, $cols));
     if (!validfolder($name, THEMES_PATH)) {
         throw new EngineException();
     }
     if (!in_array($folder, self::$spaths)) {
         throw new EngineException('styles_wrong_filename');
     }
     $types = implode('|', array_map('mpc', (array) $this->allowed_types[$folder]));
     $regexp = '/^([\\w\\.\\/]+)\\.(' . $types . ')$/si';
     $f2e = validpath($f2e);
     $of2e = validpath($of2e);
     if (!preg_match($regexp, $f2e) || $of2e && !preg_match($regexp, $of2e)) {
         throw new EngineException('styles_wrong_filename');
     }
     $opath = THEMES_PATH . "/" . $name . '/' . $folder . '/';
     $path = ROOT . $opath;
     if ($f2e != $of2e && file_exists($path . $f2e)) {
         throw new EngineException('styles_file_exists');
     }
     if ($of2e != $f2e && $of2e) {
         unlink($path . $of2e);
     }
     file::o()->write_file($content, $opath . $f2e);
     if (!$of2e) {
         log_add('changed_style_file', 'admin', array($f2e, $of2e, $name));
     } else {
         log_add('added_style_file', 'admin', array($f2e, $name));
     }
     furl::o()->location($admin_file);
 }
Example #6
0
 /**
  * Функция проверки прав пользователей, в случае отсутствия прав - посылает на страницу логина
  * @param string $rule право пользователя(!без префикса can_!)
  * @param int $value значение права, от данного и выше.
  * @param int $def 2 - все
  * 1 - все, кроме гостей
  * 0 - все, кроме гостей и пользователей по-умолчанию
  * @return null
  * @throws EngineException
  */
 public function check_perms($rule = '', $value = 1, $def = 1)
 {
     if ($this->check_adminmode()) {
         return;
     }
     $default = $this->perms['guest'] || $this->perms['bot'] ? 2 : $this->perms['default'];
     $if = false;
     if ($rule) {
         $rule = $this->perms['can_' . $rule];
         $if = (int) $rule < (int) $value;
     }
     $if = $if || $default > $def;
     if ($if && $this->perm_exception) {
         throw new EngineException('not_enought_rights');
         if ($this->perm_exception !== 2) {
             $this->perm_exception(0);
         }
     }
     if ($if) {
         if (globals::g("ajax")) {
             print lang::o()->v('not_enought_rights');
         } else {
             furl::o()->location(furl::o()->construct("login", array("ref" => $_SERVER['REQUEST_URI'])));
         }
         die;
     }
 }
Example #7
0
 /**
  * Подтверждение пользователя
  * @param string $key ключ подтверждения
  * @return null
  * @throws EngineException
  */
 protected function confirm($key)
 {
     users::o()->check_perms();
     if (users::o()->v('confirm_key') != $key) {
         throw new EngineException('false_confirm_key');
     }
     if (users::o()->v('confirmed') != 3) {
         /* @var $etc etc */
         $etc = n("etc");
         $update['confirmed'] = $etc->confirm_user(1, users::o()->v('confirmed'));
     }
     if (users::o()->v('new_email')) {
         $update['email'] = users::o()->v('new_email');
         $update['new_email'] = "";
     }
     $update['confirm_key'] = "";
     db::o()->p(users::o()->v('id'))->update($update, 'users', 'WHERE id=? LIMIT 1');
     furl::o()->location('', 5);
     n("message")->stype("success")->info("successfull_confirmed_email");
 }
Example #8
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);
 }
Example #9
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);
 }
Example #10
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);
 }
Example #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');
 }
Example #12
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);
 }
Example #13
0
 * string text текст формы
 */
tpl::o()->register_function("input_form", array($bbcodes, 'input_form'));
/**
 * @note Генерация ЧПУ(gen_link)
 * params:
 * string module имя модуля
 * bool page является ли указанный модуль ссылкой на документ?
 * bool no_end нужно ли в конец добавлять .html/index.html?
 * bool nobaseurl не добавлять в начало $baseurl
 * bool slashes экранирует результат для JavaScript, иначе & заменяется на &amp;
 * string _filetype тип файла(вместо html)
 * string assign передать значение функции в переменную с именем assign?
 * mixed параметры ссылки
 */
tpl::o()->register_function("gen_link", array(furl::o(), 'construct'));
/**
 * @note Форматирование времени UNIXTIME в человекопонятный формат(date)
 * params:
 * int time время
 * string format формат вывода(ymd или ymdhis, к примеру)
 */
tpl::o()->register_function("date", array($display, 'date'));
tpl::o()->register_modifier("date_time", array($display, 'date'));
/**
 * @note Поле выбора даты(select_date)
 * params:
 * string name префикс полей
 * string type тип формы(ymd, ymdhis, к примеру)
 * int time данное время в формате UNIXTIME
 * bool fromnull начинать с 0?
Example #14
0
 /**
  * Отображение опроса
  * @param int $toid ID ресурса
  * @param int $poll_id ID опроса
  * @param bool $votes показывать результат опроса?
  * @param bool $short показывать результаты опроса как в блоке?
  * @return null
  * @throws EngineException
  */
 public function display($toid = 0, $poll_id = 0, $votes = false, $short = false)
 {
     if (!$this->state) {
         return;
     }
     lang::o()->get('polls');
     if (is_array($toid)) {
         if ($toid['type']) {
             $this->change_type($toid['type']);
         }
         $poll_id = $toid['poll_id'];
         $short = $toid['short'];
         $votes = $toid['votes'];
         $toid = $toid['toid'];
     }
     $type = $this->type;
     $toid = (int) $toid;
     $poll_id = (int) $poll_id;
     $user_id = (int) users::o()->v('id');
     $user_ip = users::o()->get_ip();
     db::o()->p($user_id ? $user_id : $user_ip);
     if ($poll_id) {
         db::o()->p($poll_id);
         $where = 'p.id = ?';
     } elseif ($toid && $type) {
         db::o()->p($toid, $type);
         $where = 'p.toid = ? AND p.type = ?';
     } else {
         $where = 'p.toid = 0';
     }
     $limit = $poll_id || $toid && $type || $short ? 1 : null;
     $res = db::o()->query('SELECT p.*, pv.answers_id AS voted_answers 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 ' . $where . '
         ' . ($limit ? 'LIMIT ' . $limit : ""));
     $count = db::o()->num_rows($res);
     if (!$count && $poll_id) {
         throw new EngineException('polls_this_poll_not_exists');
     }
     if (!$count && !$toid && !$short) {
         $var = lang::o()->v('polls_no_exists') . (users::o()->perm('polls', 3) ? ' ' . sprintf(lang::o()->v('polls_want_add'), furl::o()->construct("polls", array('act' => 'add'))) : '');
         n("message")->info($var);
         return;
     }
     if (!$count) {
         return;
     }
     tpl::o()->assign("votes_styles", $this->styles);
     tpl::o()->assign("styles_count", count($this->styles));
     tpl::o()->assign("show_voting", $votes);
     tpl::o()->assign("short_votes", $short);
     tpl::o()->assign("curtime", time());
     tpl::o()->assign("single_poll", (bool) $poll_id);
     tpl::o()->register_modifier('polls_votepercent', array($this, 'make_percent'));
     tpl::o()->register_modifier('polls_prefilter', array($this, 'prefilter'));
     $multi_polls = !($poll_id || $toid && $type) && !$short;
     if (!tpl::o()->displayed('polls/scripts.tpl')) {
         tpl::o()->display('polls/scripts.tpl');
     }
     if (!$multi_polls) {
         tpl::o()->assign("poll_row", db::o()->fetch_assoc($res));
         tpl::o()->display('polls/show_single.tpl');
     } elseif ($count) {
         tpl::o()->assign("poll_rows", db::o()->fetch2array($res));
         tpl::o()->display('polls/show_multi.tpl');
     }
 }
Example #15
0
 /**
  * Функция восстановления пароля
  * @param string $login логин пользователя
  * @param string $email E-mail пользователя
  * @return null
  */
 protected function recover($login, $email)
 {
     if (users::o()->v()) {
         return;
     }
     $params = array(mb_strtolower($login), $email);
     $where = 'username_lower=? AND email=?';
     $count = db::o()->p($params)->count_rows("users", $where);
     if (!$count) {
         throw new EngineException("recover_user_not_exists");
     }
     $key = users::o()->generate_salt();
     $ok = db::o()->p($params)->update(array("confirm_key" => $key, "new_email" => ""), "users", 'WHERE ' . $where);
     $link = furl::o()->construct('login', array("act" => "recover", "key" => $key, "email" => $email));
     /* @var $etc etc */
     $etc = n("etc");
     $etc->send_mail($email, "recover_pass", array("link" => $link));
 }
Example #16
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);
 }
Example #17
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);
 }
Example #18
0
 /**
  * Сохранение настроек плагина
  * @param array $data массив данных
  * @return null
  * @throws EngineException 
  */
 protected function save($data)
 {
     $admin_file = globals::g('admin_file');
     $id = $data['id'];
     $settings = serialize(modsettings::o()->save($id, $data));
     db::o()->p($id)->update(array('settings' => $settings), 'plugins', 'WHERE file=? LIMIT 1');
     plugins::o()->manager->uncache();
     furl::o()->location($admin_file);
 }
Example #19
0
 /**
  * Обработка тегов
  * @param array $rows массив данных
  * @return null
  */
 protected function prepare_tags(&$rows)
 {
     $rows['tags'] = trim($rows['tags']);
     if ($rows['tags']) {
         $tags = explode(',', $rows['tags']);
         $r = "";
         foreach ($tags as $tag) {
             $tag = trim($tag);
             if (!$tag) {
                 continue;
             }
             $r .= ($r ? ", " : "") . "<a href='" . furl::o()->construct('search', array('auto' => true, 'tag' => $tag)) . "'>" . $tag . "</a>";
         }
         $rows['tags'] = $r;
     }
 }
Example #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);
 }
Example #21
0
/**
 * Функция для превращения имени пользователя в ссылку
 * @param string $text имя пользователя либо HTML текст
 * @param string $subtext имя пользователя
 * @param bool $bbcode BBCode?
 * @return string HTML код ссылки
 */
function smarty_user_link($text, $subtext = "", $bbcode = false)
{
    if (!$subtext) {
        if (!users::o()->check_login($text)) {
            $gr = users::o()->get_group(users::o()->find_group('guest'));
            $subtext = $gr["name"];
        }
    }
    $quote = display::o()->html_encode('"');
    $aopen = $bbcode ? '[url=' . $quote : "<a class='profile_link' href='";
    $aopen2 = $bbcode ? $quote . ']' : "'>";
    $aclose = $bbcode ? '[/url]' : '</a>';
    return (users::o()->perm('profile') ? $aopen . furl::o()->construct("users", array("user" => !$subtext ? $text : $subtext)) . $aopen2 : "") . $text . (users::o()->perm('profile') ? $aclose : "");
}
Example #22
0
 /**
  * Вывод ошибки последнего запроса к БД
  * @param string $query запрос
  * @return null
  */
 public function err($query = null)
 {
     if ($this->error_handler) {
         $eh = $this->error_handler;
         // на случай, если php посчитает это за метод
         return $eh($query);
     }
     if ($this->errno() == 145 && class_exists('furl')) {
         preg_match('/Table \'(.*)\' is marked as crashed and should be repaired$/siu', $this->errtext(), $matches);
         //$table = substr ( $matches [1], strrpos ( $matches [1], "\\" ) + 1 );
         $table = mb_substr($matches[1], mb_strrpos($matches[1], "/") + 1);
         $this->no_parse()->query("REPAIR TABLE " . $table);
         furl::o()->location('', 1);
     }
     $error = $special ? $special : $this->errtext();
     $emess = lang::o()->v('db_error') . ": " . $error . (IN_DEVELOPMENT ? '(' . $query . ')' : "");
     if (!$this->nt_error && class_exists("tpl") && $this->connected) {
         tpl::o()->assign('backtrace', $this->print_backtrace());
         n("message")->stitle("db_error")->error($emess);
     } else {
         print $emess;
     }
     die;
 }
Example #23
0
 /**
  * Функция для запроса подтверждения пользователя и получения ключа подтверждения
  * @param string $email E-mail пользователя
  * @param string $shablon шаблон E-mail сообщения
  * @return string ключ подтверждения
  */
 public function confirm_request($email, $shablon)
 {
     $key = md5(users::o()->generate_salt() . md5($email) . users::o()->generate_salt());
     $link = furl::o()->construct("registration", array("ckey" => $key));
     $this->send_mail($email, $shablon, array("link" => $link));
     return $key;
 }
Example #24
0
 /**
  * Вывод категорий с родителями
  * @param array|string $cat_arr массив данных категорий/строка с их ID
  * @param array $parents массив родителей вида transl_name=>name
  * @param string $type тип категорий(для модификатора)
  * @param string $dividor разделитель для родительских категорий
  * @return string HTML код
  */
 public function print_selected($cat_arr, $parents = null, $type = "content", $dividor = "")
 {
     if (!$cat_arr) {
         return;
     }
     if (!is_array($cat_arr)) {
         $cat_arr = $this->cid2arr($cat_arr);
         $cat_arr = $cat_arr[1];
     }
     if (!$dividor) {
         $dividor = "<b>&nbsp;&raquo;&nbsp;</b>";
     }
     $this->change_type($type);
     $type = $this->type;
     $html = '';
     if ($parents) {
         $html = $dividor;
         foreach ($parents as $trcat => $cat) {
             $html .= '<a href="' . furl::o()->construct($type, array('cat' => $trcat)) . '">' . $cat . '</a>' . $dividor;
         }
     }
     $b = false;
     foreach ($cat_arr as $cat) {
         $html .= ($b ? ",&nbsp;" : "") . '<a href="' . furl::o()->construct($type, array('cat' => $cat['transl_name'])) . '">' . $cat['name'] . '</a>';
         $b = true;
     }
     return $html;
 }
Example #25
0
 /**
  * Получение объекта класса
  * @return furl $this
  */
 public static function o()
 {
     if (!self::$o) {
         self::$singletoned = true;
         self::$o = new self();
         self::$singletoned = false;
     }
     return self::$o;
 }
Example #26
0
 /**
  * Получение переменных для контента
  * @param int $id ID контента
  * @return array массив переменных
  */
 protected function get_vars_content($id)
 {
     $id = (int) $id;
     $q = db::o()->p($id)->query('SELECT title FROM content WHERE id=? LIMIT 1');
     $res = db::o()->fetch_assoc($q);
     $name = $res["title"];
     $link = furl::o()->construct('content', array('title' => $name, 'id' => $id));
     return array("link" => $link, "name" => $name);
 }
Example #27
0
 /**
  * Сохранение языкового файла
  * @param array $data массив данных языкового файла
  * @return null
  * @throws EngineException 
  */
 public function save($data)
 {
     $admin_file = globals::g('admin_file');
     $cols = array('name' => 'id', 'of2e' => 'file', 'f2e' => 'filename', 'values', 'keys');
     extract(rex($data, $cols));
     if (!validfolder($name, LANGUAGES_PATH)) {
         throw new EngineException();
     }
     if (!$values) {
         throw new EngineException('languages_no_values');
     }
     $of2e = preg_replace('/\\.php$/siu', '', $of2e);
     $of2e = validpath($of2e);
     $pp = LANGUAGES_PATH . '/' . $name . '/';
     $ppr = ROOT . $pp;
     $regexp = '/^([\\w\\.\\/]+)(\\.php)?$/si';
     $f2e = validpath($f2e);
     if (!preg_match($regexp, $f2e, $matches) || !preg_match($regexp, $of2e)) {
         throw new EngineException('languages_wrong_filename');
     }
     $f2e = rtrim($matches[1], '/');
     if ($f2e != $of2e && file_exists($ppr . $f2e . '.php')) {
         throw new EngineException('languages_file_exists');
     }
     if ($of2e != $f2e && $of2e) {
         unlink($ppr . $of2e . '.php');
     }
     $arr = $this->build_arr($values, $keys);
     lang::o()->set($f2e, $arr, $name);
     if (!$of2e) {
         log_add('changed_language_file', 'admin', array($f2e, $of2e, $name));
     } else {
         log_add('added_language_file', 'admin', array($f2e, $name));
     }
     furl::o()->location($admin_file);
 }
Example #28
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;
     }
 }
Example #29
0
 /**
  * Автовключение сайта
  * @return null
  */
 public function site_autoon()
 {
     if (!config::o()->v('site_autoon') || config::o()->v('site_online')) {
         return;
     }
     $time = time();
     if ($time >= config::o()->v('site_autoon')) {
         config::o()->set('site_autoon', 0);
         config::o()->set('site_online', 1);
         furl::o()->location();
     }
 }
Example #30
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);
 }