/** * Сохранение бота * @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); }
/** * Сохранение бана * @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); } }
/** * Сохранение предупреждения * @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); } }
/** * Инициализация модуля обратной связи * @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; } }
/** * Сохранение стат. страницы * @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); }
/** * Генератор пароля для шаблонов Smarty * @param array $params массив параметров(pname - имя поля пароля, paname - имя поля повтора пароля) * @return string HTML код генератора */ function smarty_passgen($params) { $theme_path = globals::g('theme_path'); $name = $params["pname"]; $name2 = $params["paname"]; return '<img src="' . $theme_path . 'engine_images/passgen.png" alt="' . lang::o()->v('passgen') . '" class="passgen clickable" title="' . lang::o()->v('passgen') . '" onclick="passgen(\'' . addslashes($name) . '\', \'' . addslashes($name2) . '\');">'; }
/** * Модификатор для заголовка контента, добавляющий к нему иконку * @param string $title заголовок контента * @param string $image имя иконки(типа .png, хранящяяся в engine_images) * @param string $text подсказка к иконке * @return string заголовок с картинкой */ public function prepend_title_icon($title, $image, $text = "") { $theme_path = globals::g('theme_path'); $title = '<img src="' . $theme_path . '/engine_images/' . $image . '.png" alt="' . $text . '" title="' . $text . '" align="left">' . $title; return $title; }
/** * Сохранение настроек плагина * @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); }
/** * Функция проверки прав пользователей, в случае отсутствия прав - посылает на страницу логина * @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; } }
/** * Сохранение группы * @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); }
/** * "Ловля" исключений по-умолчанию * @param bool $eajax ручная настройка из Ajax или нет * @return null */ public function defaultCatch($eajax = null) { $ajax = globals::g('ajax'); $eajax = is_null($eajax) ? $ajax : $eajax; if ($eajax) { print $this->getEMessage(); die; } else { n("message")->stype("error")->sdie()->info($this->getMessage(), $this->getVars()); } }
/** * Инициализация AJAX-части модуля * @return null */ public function init() { $POST = globals::g('POST'); lang::o()->get('admin/config'); $cprefix = config_man::config_prefix; $cprefix_length = strlen($cprefix); $keys = array(); $newcfg = array(); $i = 0; $sort = array(); foreach ($POST as $key => $value) { if (strpos($key, $cprefix) !== 0) { continue; } $key = substr($key, $cprefix_length); if (!config::o()->visset($key)) { continue; } $keys[] = $key; $newcfg[$key] = $value; $sort[$key] = ++$i; } if (!$keys) { return; } try { plugins::o()->pass_data(array("newcfg" => &$newcfg, "sort" => &$sort), true)->run_hook('admin_config_save'); } catch (PReturn $e) { return $e->r(); } $r = db::o()->p($keys)->query('SELECT name,type,allowed FROM config WHERE name IN(@' . count($keys) . '?)'); $c = 0; while (list($name, $type, $allowed) = db::o()->fetch_row($r)) { if (!$this->check_type($type, $newcfg[$name], $allowed, $name)) { continue; } $c++; config::o()->set($name, $newcfg[$name], $sort[$name]); } db::o()->query('ALTER TABLE `config` ORDER BY `cat`, `sort`'); log_add('changed_config', 'admin'); print $c; die; }
/** * Функция переадресации * @param string $url URL переадресации * @param int $time время переадресации * @param bool $no_clean не очищать экран и не выполнять функцию die()? * @return null */ public function location($url, $time = 0, $no_clean = false) { $baseurl = globals::g('baseurl'); if ($this->denied_locations) { return; } if ($this->forlocation && $this->forlocation[1] == $url) { $url = $this->forlocation[0]; } if ($time) { $no_clean = true; } if ($no_clean) { $contents = ob_get_contents(); } ob_end_clean(); if (!preg_match("/^http\\:\\/\\/(.*?)\$/siu", $url)) { $url = $baseurl . $url; } if (!$time) { @header("Location: " . $url); } else { @header("Refresh: " . $time . ", url=" . $url); } if (!$no_clean) { die; } else { print $contents; } }
/** * Выдаёт сообщение о том, что всё хорошо * @param bool $print функция print вместо die? * @return null */ function ok($print = false) { if (globals::g('ok_denied')) { return; } if ($print) { print OK_MESSAGE; } else { die(OK_MESSAGE); } }
/** * Сохранение типов файлов * @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); }
/** * Функция вывода ошибки(именно ошибки типа fatal error, а не сообщения об ошибке, * которое выводится через функцию message) * @param string|array $lang_var языковая переменная, в соответствии с коорой будет выводится на экран сообщение, * либо цельный текст, так же, может содержать в себе все остальные паремтры в качестве ассоциативного массива. * @param array $vars массив значений, включаемых в сообщение, работают, блягодаря функции vsprintf * @return null */ public function error($lang_var, $vars = array()) { $title = $this->params['title']; $this->params = array(); $ajax = globals::g('ajax'); ob_end_clean(); if (!$title && !is_null($title)) { $title = lang::o()->v('error'); } elseif ($title && lang::o()->visset($title)) { $title = lang::o()->v($title); } if (lang::o()->visset($lang_var)) { $vars = !is_array($vars) && $vars ? array($vars) : $vars; if (is_array($vars)) { $message = vsprintf(lang::o()->v($lang_var), $vars); } else { $message = lang::o()->v($lang_var); } } else { $message = $lang_var; } if ($ajax) { print $title . ": " . $message; die; } tpl::o()->assign('message', $message); tpl::o()->assign('title', $title); tpl::o()->display("error.tpl"); die; }
/** * Сохранение смайлов * @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; } }
/** * Сохранение шаблона * @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); }
/** * Инициализация AJAX-части модуля * @return null */ public function init() { $POST = globals::g('POST'); $act = $_GET['act']; $name = $_POST['id']; if (!validfolder($name, LANGUAGES_PATH)) { die; } switch ($act) { case "replace": $_POST['search'] = $POST['search']; $_POST['with'] = $POST['with']; $this->replace($name, $_POST); break; case "clone": $this->copy($name, $_POST['new']); break; case "delete": $this->delete($name); break; case "delete_file": $this->delete_file($name, $_POST['file']); break; case "default": $this->bydefault($name); break; } ok(); }
/** * Отправка сообщения с подстановкой переменных * @param string|array $email E-mail пользователя * @param string $shablon шаблон сообщения * @param array $vars массив переменных * @return string|int статус отыслки или список ошибок */ public function send_mail($email, $shablon, $vars = array()) { $baseurl = globals::g('baseurl'); lang::o()->get("mail_shablons"); $body = lang::o()->v("mail_body_" . $shablon); $vars['siteurl'] = $baseurl; $vars['sitename'] = $vars['site_title'] = config::o()->v('site_title'); foreach ($vars as $key => $value) { $body = str_replace('$' . $key, $value, $body); } send_mail(lang::o()->v("mail_subject_" . $shablon), $body, $email, $error); return $error; }
/** * Отображение конфигурации сайта * @return null */ protected function show_config() { init_baseurl(); $prebaseurl = globals::g('prebaseurl'); $prebaseurl = $prebaseurl == "/" ? "/" : rtrim($prebaseurl, '/'); tpl::o()->assign('baseurl', $prebaseurl); globals::s('prebaseurl', $prebaseurl); tpl::o()->display('config'); }
/** * Сохранение блока * @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); }
* @page http://ctrev.cyber-tm.ru/ * @copyright (c) 2008-2012, Cyber-Team * @author The Cheat <*****@*****.**> * @name Главная страница сайта * @version 1.00 */ if (!file_exists('install/lock') && file_exists('install/')) { @header('Location: install.php'); die; } define('DELAYED_UINIT', true); // отложенная инициализация юзерей... include_once "./include/include.php"; $module = $_GET['module']; blocks::set_module($module ? $module : "index"); $this_file = globals::g('baseurl') . "index.php?module=" . $module; tpl::o()->assign("this_file", $this_file); $ajax = (bool) $_REQUEST['from_ajax']; // Из AJAX $nno = (bool) $_REQUEST['nno']; // Стандартный класс(без постфикса '_ajax') if (!$ajax && ($current = stats::o()->read(DATABASE_STATS)) != DATABASE_VERSION) { /* @var $m message */ $m = n("message"); $m->error('need_to_upgrade_database', array(DATABASE_VERSION, $current ? $current : "unknown")); } globals::s('ajax', $ajax); tpl::o()->assign('from_ajax', $ajax); tpl::o()->assign('module_loaded', $module); if ($module) { if (!allowed::o()->is($module)) {
/** * Сохранение категории * @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); }
} else { $module = $imod = ''; } } } /** * Передаём часть переменных в Smarty Tpl. */ tpl::o()->assign("selected_item", $item); if ($imod) { tpl::o()->assign("selected_imod", $imod); } tpl::o()->assign("imods", $admin_modules); lang::o()->get("admin/main"); users::o()->check_inadmin($module, false, true); $eadmin_file = globals::g('eadmin_file'); $iadmin_file = $eadmin_file . '&item=' . $item; tpl::o()->assign("iadmin_file", $iadmin_file); if ($module) { $admin_file = $iadmin_file . '&module=' . $module; tpl::o()->assign("admin_file", $admin_file); $admin_page = null; } elseif ($admin_page) { $module = $admin_page; $allowed = $allowed_admin_pages; $plugins_isblock = 2; $admin_file = $iadmin_file . '&page=' . $admin_page; tpl::o()->assign("admin_file", $admin_file); } globals::s('admin_file', $admin_file); /**
/** * Выборка файлов(для АЦ) * @param string $path путь к дирректории * @param string $name имя дирректории * @param string $folder выбранная дирректория * @param array $apaths разрешённые дирректории внутри основной * @param bool $deny_delete запретить удалять? * @return null */ public function filechooser($path, $name, $folder = null, $apaths = null, $deny_delete = false) { $ajax = globals::g('ajax'); if (!validfolder($name, $path)) { return; } lang::o()->get('admin/filechooser'); $npath = ($path ? $path . '/' : '') . $name; if ($apaths) { $apaths = (array) $apaths; } if ($folder) { $folder = preg_replace('/(?:^|^(.*)\\/)[^\\/]+\\/\\.\\.\\/$/siu', '\\1', $folder); $folder = rtrim($folder, '/'); $folder = validpath($folder . '/', false, $apaths); $folder = rtrim($folder, '/'); if ($folder) { $npath .= "/" . rtrim($folder, '/'); } } $rows = file::o()->open_folder($npath, false, '^.+(\\.[a-z]+)?$'); if ($rows === false) { return; } file::o()->sort($npath, $rows); $arr = array(); foreach ($rows as $row) { $f = ROOT . $npath . '/' . $row; if (!$folder && $apaths && !validpath($row . '/', false, $apaths)) { continue; } if ($row == 'index.html') { continue; } $arr[$row] = array(is_dir($f), is_writable($f), filesize($f), filemtime($f)); } tpl::o()->assign('id', $name); tpl::o()->assign('files', $arr); tpl::o()->assign('deny_add', false); if ($folder) { tpl::o()->assign('parent', $folder . '/'); } elseif ($apaths) { tpl::o()->assign('deny_modify', true); } tpl::o()->assign('deny_delete', (bool) $deny_delete); if ($ajax) { ok(true); } tpl::o()->display('admin/filechooser.tpl'); }
/** * Сохранение доп. полей * @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); }