From b8cb7633e6ddd9fb8830ca928d92b2ad20f249b1 Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Sat, 2 Aug 2014 19:08:52 +0600 Subject: [PATCH 01/19] R593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Переработка системы групп пользователей Signed-off-by: Dark Nightmare --- install/sql/mysql.sql | 5 +- upload/ajax.php | 8 +- upload/ajax/edit_group_profile.php | 47 ++++++++++++ upload/group-config.php | 91 +++++++++++++++++++++++ upload/groupcp.php | 46 +++--------- upload/language/en/main.php | 5 ++ upload/language/ru/main.php | 5 ++ upload/language/ua/main.php | 5 ++ upload/templates/default/group-config.tpl | 63 ++++++++++++++++ upload/templates/default/groupcp.tpl | 37 ++++----- 10 files changed, 257 insertions(+), 55 deletions(-) create mode 100644 upload/ajax/edit_group_profile.php create mode 100644 upload/group-config.php create mode 100644 upload/templates/default/group-config.tpl diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index fe0a74fb6..77e1f10d9 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -790,13 +790,14 @@ CREATE TABLE IF NOT EXISTS `bb_groups` ( `group_id` mediumint(8) NOT NULL AUTO_INCREMENT, `group_time` int(11) NOT NULL DEFAULT '0', `group_type` tinyint(4) NOT NULL DEFAULT '1', + `release_group` tinyint(4) NOT NULL DEFAULT '0', `group_name` varchar(40) NOT NULL DEFAULT '', - `group_description` varchar(255) NOT NULL DEFAULT '', + `group_description` text NOT NULL DEFAULT '', `group_moderator` mediumint(8) NOT NULL DEFAULT '0', `group_single_user` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`group_id`), KEY `group_single_user` (`group_single_user`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -------------------------------------------------------- diff --git a/upload/ajax.php b/upload/ajax.php index 58539d0c8..49a2b37b5 100644 --- a/upload/ajax.php +++ b/upload/ajax.php @@ -52,9 +52,11 @@ switch ($ajax->action) require(INC_DIR . 'functions_admin.php'); break; + case 'manage_group': case 'group_membership': require(INC_DIR . 'functions_group.php'); break; + } // position in $ajax->valid_actions['xxx'] @@ -78,6 +80,7 @@ class ajax_common 'change_user_opt' => array('admin'), 'manage_user' => array('admin'), 'manage_admin' => array('admin'), + 'manage_group' => array('user'), 'mod_action' => array('mod'), 'topic_tpl' => array('mod'), @@ -336,7 +339,10 @@ class ajax_common { require(AJAX_DIR . 'group_membership.php'); } - + function manage_group() + { + require(AJAX_DIR . 'edit_group_profile.php'); + } function post_mod_comment() { require(AJAX_DIR . 'post_mod_comment.php'); diff --git a/upload/ajax/edit_group_profile.php b/upload/ajax/edit_group_profile.php new file mode 100644 index 000000000..7affe0a48 --- /dev/null +++ b/upload/ajax/edit_group_profile.php @@ -0,0 +1,47 @@ +request['group_id']) OR !$group_info = get_group_data($group_id)) +{ + $this->ajax_die($lang['NO_GROUP_ID_SPECIFIED']); +} +if (!$mode = (string) $this->request['mode']) +{ + $this->ajax_die('No mode specified'); +} + +$value = $this->request['value'] = (string) (isset($this->request['value'])) ? $this->request['value'] : 0; + +// TODO Check for permissions + +switch ($mode) +{ + case 'group_name': + case 'group_description': + $value = htmlCHR($value); + $this->response['new_value'] = $value; + break; + case 'group_type': + $this->response['new_value'] = $value; + break; + case 'release_group': + $this->response['new_value'] = $value; + break; + default: + $this->ajax_die('Unknown mode'); + + +} +$value_sql = DB()->escape($value, true); +DB()->query("UPDATE ". BB_GROUPS ." SET $mode = $value_sql WHERE group_id = $group_id LIMIT 1"); + +// Just for debug +/* +$this->response['new_value'] = $value; +$this->response['group_id'] = $group_id; +$this->response['mode'] = $mode; +*/ + diff --git a/upload/group-config.php b/upload/group-config.php new file mode 100644 index 000000000..70632b1c7 --- /dev/null +++ b/upload/group-config.php @@ -0,0 +1,91 @@ +session_start(array('req_login' => true)); + +$group_id = isset($_REQUEST[POST_GROUPS_URL]) ? intval($_REQUEST[POST_GROUPS_URL]) : null; +$group_info = array(); +$is_moderator = false; + +if ($group_id) +{ + if (!$group_info = get_group_data($group_id)) + { + bb_die($lang['GROUP_NOT_EXIST']); + } + if (!$group_info['group_id'] || !$group_info['group_moderator'] || !$group_info['moderator_name']) + { + bb_die("Invalid group data [group_id: $group_id]"); + } + $is_moderator = ($userdata['user_id'] == $group_info['group_moderator'] || IS_ADMIN); +} + +if ($is_moderator) +{ + + // TODO Creation Date, Admin panel, Avatar, Some tasty features + + $group_type = ''; + if ($group_info['group_type'] == GROUP_OPEN) + { + $group_type = $lang['GROUP_OPEN']; + } + elseif ($group_info['group_type'] == GROUP_CLOSED) + { + $group_type = $lang['GROUP_CLOSED']; + } + elseif ($group_info['group_type'] == GROUP_HIDDEN) + { + $group_type = $lang['GROUP_HIDDEN']; + } + + $s_hidden_fields = ''; + + $template->assign_vars(array( + 'PAGE_TITLE' => $lang['GROUP_CONTROL_PANEL'], + 'GROUP_NAME' => htmlCHR($group_info['group_name']), + 'GROUP_ID' => $group_id, + 'GROUP_DESCRIPTION' => htmlCHR($group_info['group_description']), + + 'U_GROUP_URL' => GROUP_URL . $group_id, + + 'GROUP_TYPE' => $group_type, + 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, + 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED, + 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN, + 'S_GROUP_OPEN_CHECKED' => ($group_info['group_type'] == GROUP_OPEN) ? ' checked="checked"' : '', + 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? ' checked="checked"' : '', + 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN) ? ' checked="checked"' : '', + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_GROUPCP_ACTION' => "groupcp.php?" . POST_GROUPS_URL . "=$group_id", + 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, + )); + + $template->set_filenames(array('body' => 'group-config.tpl')); + + $template->assign_vars(array('PAGE_TITLE' => 'Настройка группы')); + + require(PAGE_HEADER); + + $template->pparse('body'); + + require(PAGE_FOOTER); +} +else +{ + $redirect = 'index.php'; + + if ($group_id) + { + $redirect = GROUP_URL . $group_id; + } + redirect($redirect); +} \ No newline at end of file diff --git a/upload/groupcp.php b/upload/groupcp.php index a8a91c5f6..9fb3f6950 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -4,14 +4,16 @@ define('IN_FORUM', true); define('BB_SCRIPT', 'groupcp'); define('BB_ROOT', './'); require(BB_ROOT ."common.php"); +require(INC_DIR .'bbcode.php'); require(INC_DIR .'functions_group.php'); +$page_cfg['include_bbcode_js'] = true; $page_cfg['use_tablesorter'] = true; $s_member_groups = $s_pending_groups = $s_member_groups_opt = $s_pending_groups_opt = ''; $select_sort_mode = $select_sort_order = ''; -function generate_user_info(&$row, $date_format, $group_mod, &$from, &$posts, &$joined, &$pm, &$email, &$www, &$user_time) +function generate_user_info(&$row, $date_format, $group_mod, &$from, &$posts, &$joined, &$pm, &$email, &$www, &$user_time, &$avatar) { global $lang, $images, $bb_cfg; @@ -20,6 +22,7 @@ function generate_user_info(&$row, $date_format, $group_mod, &$from, &$posts, &$ $user_time = ( !empty($row['user_time']) ) ? bb_date($row['user_time']) : $lang['NONE']; $posts = ( $row['user_posts'] ) ? $row['user_posts'] : 0; $pm = ($bb_cfg['text_buttons']) ? ''. $lang['SEND_PM_TXTB'] .'' : '' . $lang['SEND_PRIVATE_MESSAGE'] . ''; + $avatar = get_avatar($row['user_id'], $row['avatar_ext_id'], !bf($row['user_opt'], 'user_opt', 'dis_avatar'), true, 50, 50); if (bf($row['user_opt'], 'user_opt', 'user_viewemail') || $group_mod) { @@ -184,34 +187,6 @@ if (!$group_id) else bb_die($lang['NO_GROUPS_EXIST']); } } -else if (!empty($_POST['groupstatus'])) -{ - if (!$is_moderator) - { - bb_die($lang['NOT_GROUP_MODERATOR']); - } - - $new_group_type = (int) $_POST['group_type']; - - if (!in_array($new_group_type, array(GROUP_OPEN, GROUP_CLOSED, GROUP_HIDDEN), true)) - { - bb_die("Invalid group type: $new_group_type"); - } - - DB()->query(" - UPDATE ". BB_GROUPS ." SET - group_type = $new_group_type - WHERE group_id = $group_id - AND group_single_user = 0 - LIMIT 1 - "); - - $message = $lang['GROUP_TYPE_UPDATED'] .'

'; - $message .= sprintf($lang['CLICK_RETURN_GROUP'], '', '') .'

'; - $message .= sprintf($lang['CLICK_RETURN_INDEX'], '', ''); - - bb_die($message); -} else if (@$_POST['joingroup']) { if ($group_info['group_type'] != GROUP_OPEN) @@ -420,7 +395,7 @@ else // Members $group_members = DB()->fetch_rowset(" - SELECT u.username, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time + SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u WHERE ug.group_id = $group_id AND ug.user_pending = 0 @@ -513,7 +488,7 @@ else $username = $group_moderator['username']; $user_id = $group_moderator['user_id']; - generate_user_info($group_moderator, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time); + generate_user_info($group_moderator, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); $group_type = ''; if ($group_info['group_type'] == GROUP_OPEN) @@ -535,9 +510,10 @@ else 'GROUP_INFO' => true, 'PAGE_TITLE' => $lang['GROUP_CONTROL_PANEL'], 'GROUP_NAME' => htmlCHR($group_info['group_name']), - 'GROUP_DESCRIPTION' => $group_info['group_description'], - 'GROUP_DETAILS' => $group_details, + 'GROUP_DESCRIPTION' => bbcode2html($group_info['group_description']), + 'GROUP_DETAILS' => $group_details, 'MOD_USER' => profile_url($group_moderator), + 'MOD_AVATAR' => $avatar, 'MOD_FROM' => $from, 'MOD_JOINED' => $joined, 'MOD_POSTS' => $posts, @@ -546,6 +522,7 @@ else 'MOD_WWW' => $www, 'MOD_TIME' => (!empty($group_info['group_time'])) ? bb_date($group_info['group_time']) : $lang['NONE'], 'U_SEARCH_USER' => "search.php?mode=searchuser", + 'U_GROUP_CONFIG' => "group-config.php?g=$group_id", 'GROUP_TYPE' => $group_type, 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED, @@ -564,7 +541,7 @@ else { $user_id = $member['user_id']; - generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time); + generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); if ($group_info['group_type'] != GROUP_HIDDEN || $is_group_member || $is_moderator) { @@ -574,6 +551,7 @@ else 'ROW_NUMBER' => $i + ( $start + 1 ), 'ROW_CLASS' => $row_class, 'USER' => profile_url($member), + 'AVATAR_IMG' => $avatar, 'FROM' => $from, 'JOINED' => $joined, 'POSTS' => $posts, diff --git a/upload/language/en/main.php b/upload/language/en/main.php index 35a93c165..c3384aafc 100644 --- a/upload/language/en/main.php +++ b/upload/language/en/main.php @@ -699,6 +699,7 @@ $lang['ORDER'] = 'Order'; // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'User Groups'; +$lang['GROUP_RETURN'] = 'Return to User Group page'; $lang['MEMBERSHIP_DETAILS'] = 'Group Membership Details'; $lang['JOIN_A_GROUP'] = 'Join a Group'; @@ -710,6 +711,9 @@ $lang['GROUP_MEMBERS'] = 'Group Members'; $lang['GROUP_MODERATOR'] = 'Group Moderator'; $lang['PENDING_MEMBERS'] = 'Pending Members'; +$lang['GROUP_TIME'] = 'Created'; +$lang['RELEASE_GROUP'] = 'Release Group'; + $lang['GROUP_TYPE'] = 'Group type'; $lang['GROUP_OPEN'] = 'Open group'; $lang['GROUP_CLOSED'] = 'Closed group'; @@ -724,6 +728,7 @@ $lang['GROUP_MEMBER_HIDDEN'] = 'Hidden groups'; $lang['NO_GROUPS_EXIST'] = 'No Groups Exist'; $lang['GROUP_NOT_EXIST'] = 'That user group does not exist'; +$lang['NO_GROUP_ID_SPECIFIED'] = 'Group ID is not specified'; $lang['NO_GROUP_MEMBERS'] = 'This group has no members'; $lang['HIDDEN_GROUP_MEMBERS'] = 'This group is hidden; you cannot view its membership'; diff --git a/upload/language/ru/main.php b/upload/language/ru/main.php index f8d7d76c0..d34a09425 100644 --- a/upload/language/ru/main.php +++ b/upload/language/ru/main.php @@ -699,6 +699,7 @@ $lang['ORDER'] = ''; // не нужно, в английском использ // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'Группы'; +$lang['GROUP_RETURN'] = 'Вернуться на страницу группы'; $lang['MEMBERSHIP_DETAILS'] = 'Информация о членстве в группах'; $lang['JOIN_A_GROUP'] = 'Вступить в группу'; @@ -710,6 +711,9 @@ $lang['GROUP_MEMBERS'] = 'Члены группы'; $lang['GROUP_MODERATOR'] = 'Модератор группы'; $lang['PENDING_MEMBERS'] = 'Кандидаты в члены группы'; +$lang['GROUP_TIME'] = 'Дата создания'; +$lang['RELEASE_GROUP'] = 'Релиз группа'; + $lang['GROUP_TYPE'] = 'Тип группы'; $lang['GROUP_OPEN'] = 'Группа с открытым членством'; $lang['GROUP_CLOSED'] = 'Группа с закрытым членством'; @@ -724,6 +728,7 @@ $lang['GROUP_MEMBER_HIDDEN'] = 'Скрытые группы'; $lang['NO_GROUPS_EXIST'] = 'Нет ни одной группы'; $lang['GROUP_NOT_EXIST'] = 'Такой группы не существует'; +$lang['NO_GROUP_ID_SPECIFIED'] = 'Не указан ID группы'; $lang['NO_GROUP_MEMBERS'] = 'В этой группе нет ни одного члена'; $lang['HIDDEN_GROUP_MEMBERS'] = 'Эта группа скрыта, вы не можете посмотреть ее состав'; diff --git a/upload/language/ua/main.php b/upload/language/ua/main.php index 49594376b..610b1d48b 100644 --- a/upload/language/ua/main.php +++ b/upload/language/ua/main.php @@ -699,6 +699,7 @@ $lang['ORDER'] = ''; // не потрібно, в англійській вик // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'Групи'; +$lang['GROUP_RETURN'] = 'Вернуться на страницу группы'; $lang['MEMBERSHIP_DETAILS'] = 'Інформація про членство в групах'; $lang['JOIN_A_GROUP'] = 'Вступити в групу'; @@ -715,6 +716,9 @@ $lang['GROUP_OPEN'] = 'Група з відкритим членством'; $lang['GROUP_CLOSED'] = 'Група з закритим членством'; $lang['GROUP_HIDDEN'] = 'Прихована група'; +$lang['GROUP_TIME'] = 'Дата создания'; +$lang['RELEASE_GROUP'] = 'Релиз группа'; + $lang['GROUP_MEMBER_MOD'] = 'Є модератором груп'; $lang['GROUP_MEMBER_MEMBER'] = 'Є членом груп'; $lang['GROUP_MEMBER_PENDING'] = 'Кандидат у члени груп'; @@ -724,6 +728,7 @@ $lang['GROUP_MEMBER_HIDDEN'] = 'Приховані групи'; $lang['NO_GROUPS_EXIST'] = 'Немає ні однієї групи'; $lang['GROUP_NOT_EXIST'] = 'Такої групи не існує'; +$lang['NO_GROUP_ID_SPECIFIED'] = 'Не указан ID группы'; $lang['NO_GROUP_MEMBERS'] = 'В цій групі немає жодного члена'; $lang['HIDDEN_GROUP_MEMBERS'] = 'Ця група прихована, ви не можете побачити її складу'; diff --git a/upload/templates/default/group-config.tpl b/upload/templates/default/group-config.tpl new file mode 100644 index 000000000..36d31f753 --- /dev/null +++ b/upload/templates/default/group-config.tpl @@ -0,0 +1,63 @@ + +

{PAGE_TITLE} :: {GROUP_NAME}

+ +
+ {S_HIDDEN_FIELDS} + + + + + + + + + + + + + + + + + + + + + + + + + + +
{L_GROUP_INFORMATION}
{L_GROUP_NAME}:
{L_GROUP_DESCRIPTION}:
+

+ +

+

+ + +

+
{L_GROUP_TYPE}: +

+    +    + +

+
{L_RELEASE_GROUP} +    + +
{L_AVATAR} 
+
\ No newline at end of file diff --git a/upload/templates/default/groupcp.tpl b/upload/templates/default/groupcp.tpl index 710ba98e7..216ab9481 100644 --- a/upload/templates/default/groupcp.tpl +++ b/upload/templates/default/groupcp.tpl @@ -54,16 +54,21 @@ {L_GROUP_INFORMATION} +

{GROUP_NAME}

- {L_GROUP_NAME}: - {GROUP_NAME} + +
 
+ + + + {GROUP_DESCRIPTION} + + - - {L_GROUP_DESCRIPTION}: - {GROUP_DESCRIPTION} + {L_GROUP_TIME} + {MOD_TIME} - {L_GROUP_MEMBERSHIP}:

{GROUP_DETAILS} @@ -78,15 +83,8 @@ - {L_GROUP_TYPE}: - -

-    -    - -   -

- + Настройка группы: + Перейти в панель управления группой @@ -102,6 +100,7 @@ # + {L_AVATAR} {L_USERNAME} {L_PM} {L_EMAIL} @@ -113,10 +112,11 @@ # - {L_GROUP_MODERATOR} + {L_GROUP_MODERATOR} {ROW_NUMBER} + {MOD_AVATAR} {MOD_USER} {MOD_PM} {MOD_EMAIL} @@ -128,13 +128,14 @@   - {L_GROUP_MEMBERS} + {L_GROUP_MEMBERS} {member.ROW_NUMBER} + {member.AVATAR_IMG} {member.USER} {member.PM} {member.EMAIL} @@ -166,7 +167,7 @@ - +

From 61b27dd4448aaa50a6b4c6e98150c52db4b83aa7 Mon Sep 17 00:00:00 2001 From: Exile Date: Sat, 2 Aug 2014 19:50:08 +0400 Subject: [PATCH 02/19] r593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Форматирование. --- install/sql/mysql.sql | 2 +- upload/ajax.php | 14 ++++---- upload/{group-config.php => group_config.php} | 4 +-- upload/groupcp.php | 12 +++---- upload/language/ua/main.php | 6 ++-- .../{group-config.tpl => group_config.tpl} | 2 +- upload/templates/default/groupcp.tpl | 32 +++++++++---------- 7 files changed, 37 insertions(+), 35 deletions(-) rename upload/{group-config.php => group_config.php} (96%) rename upload/templates/default/{group-config.tpl => group_config.tpl} (100%) diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index 77e1f10d9..1c419c05a 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -797,7 +797,7 @@ CREATE TABLE IF NOT EXISTS `bb_groups` ( `group_single_user` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`group_id`), KEY `group_single_user` (`group_single_user`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -------------------------------------------------------- diff --git a/upload/ajax.php b/upload/ajax.php index 49a2b37b5..c1180fe3a 100644 --- a/upload/ajax.php +++ b/upload/ajax.php @@ -52,8 +52,8 @@ switch ($ajax->action) require(INC_DIR . 'functions_admin.php'); break; - case 'manage_group': case 'group_membership': + case 'manage_group': require(INC_DIR . 'functions_group.php'); break; @@ -80,7 +80,6 @@ class ajax_common 'change_user_opt' => array('admin'), 'manage_user' => array('admin'), 'manage_admin' => array('admin'), - 'manage_group' => array('user'), 'mod_action' => array('mod'), 'topic_tpl' => array('mod'), @@ -92,6 +91,7 @@ class ajax_common 'gen_passkey' => array('user'), 'change_torrent' => array('user'), 'change_tor_status' => array('user'), + 'manage_group' => array('user'), 'view_post' => array('guest'), 'view_torrent' => array('guest'), @@ -339,10 +339,12 @@ class ajax_common { require(AJAX_DIR . 'group_membership.php'); } - function manage_group() - { - require(AJAX_DIR . 'edit_group_profile.php'); - } + + function manage_group() + { + require(AJAX_DIR . 'edit_group_profile.php'); + } + function post_mod_comment() { require(AJAX_DIR . 'post_mod_comment.php'); diff --git a/upload/group-config.php b/upload/group_config.php similarity index 96% rename from upload/group-config.php rename to upload/group_config.php index 70632b1c7..fcab87f7b 100644 --- a/upload/group-config.php +++ b/upload/group_config.php @@ -1,7 +1,7 @@ ($group_info['release_group']) ? true : false, )); - $template->set_filenames(array('body' => 'group-config.tpl')); + $template->set_filenames(array('body' => 'group_config.tpl')); $template->assign_vars(array('PAGE_TITLE' => 'Настройка группы')); diff --git a/upload/groupcp.php b/upload/groupcp.php index 9fb3f6950..e9fd3fb10 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -3,7 +3,7 @@ define('IN_FORUM', true); define('BB_SCRIPT', 'groupcp'); define('BB_ROOT', './'); -require(BB_ROOT ."common.php"); +require(BB_ROOT .'common.php'); require(INC_DIR .'bbcode.php'); require(INC_DIR .'functions_group.php'); @@ -22,7 +22,7 @@ function generate_user_info(&$row, $date_format, $group_mod, &$from, &$posts, &$ $user_time = ( !empty($row['user_time']) ) ? bb_date($row['user_time']) : $lang['NONE']; $posts = ( $row['user_posts'] ) ? $row['user_posts'] : 0; $pm = ($bb_cfg['text_buttons']) ? ''. $lang['SEND_PM_TXTB'] .'' : '' . $lang['SEND_PRIVATE_MESSAGE'] . ''; - $avatar = get_avatar($row['user_id'], $row['avatar_ext_id'], !bf($row['user_opt'], 'user_opt', 'dis_avatar'), true, 50, 50); + $avatar = get_avatar($row['user_id'], $row['avatar_ext_id'], !bf($row['user_opt'], 'user_opt', 'dis_avatar'), true, 50, 50); if (bf($row['user_opt'], 'user_opt', 'user_viewemail') || $group_mod) { @@ -511,9 +511,9 @@ else 'PAGE_TITLE' => $lang['GROUP_CONTROL_PANEL'], 'GROUP_NAME' => htmlCHR($group_info['group_name']), 'GROUP_DESCRIPTION' => bbcode2html($group_info['group_description']), - 'GROUP_DETAILS' => $group_details, + 'GROUP_DETAILS' => $group_details, 'MOD_USER' => profile_url($group_moderator), - 'MOD_AVATAR' => $avatar, + 'MOD_AVATAR' => $avatar, 'MOD_FROM' => $from, 'MOD_JOINED' => $joined, 'MOD_POSTS' => $posts, @@ -522,7 +522,7 @@ else 'MOD_WWW' => $www, 'MOD_TIME' => (!empty($group_info['group_time'])) ? bb_date($group_info['group_time']) : $lang['NONE'], 'U_SEARCH_USER' => "search.php?mode=searchuser", - 'U_GROUP_CONFIG' => "group-config.php?g=$group_id", + 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", 'GROUP_TYPE' => $group_type, 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED, @@ -551,7 +551,7 @@ else 'ROW_NUMBER' => $i + ( $start + 1 ), 'ROW_CLASS' => $row_class, 'USER' => profile_url($member), - 'AVATAR_IMG' => $avatar, + 'AVATAR_IMG' => $avatar, 'FROM' => $from, 'JOINED' => $joined, 'POSTS' => $posts, diff --git a/upload/language/ua/main.php b/upload/language/ua/main.php index 610b1d48b..55a149897 100644 --- a/upload/language/ua/main.php +++ b/upload/language/ua/main.php @@ -699,7 +699,7 @@ $lang['ORDER'] = ''; // не потрібно, в англійській вик // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'Групи'; -$lang['GROUP_RETURN'] = 'Вернуться на страницу группы'; +$lang['GROUP_RETURN'] = 'Вернуться на страницу групи'; $lang['MEMBERSHIP_DETAILS'] = 'Інформація про членство в групах'; $lang['JOIN_A_GROUP'] = 'Вступити в групу'; @@ -717,7 +717,7 @@ $lang['GROUP_CLOSED'] = 'Група з закритим членством'; $lang['GROUP_HIDDEN'] = 'Прихована група'; $lang['GROUP_TIME'] = 'Дата создания'; -$lang['RELEASE_GROUP'] = 'Релиз группа'; +$lang['RELEASE_GROUP'] = 'Реліз група'; $lang['GROUP_MEMBER_MOD'] = 'Є модератором груп'; $lang['GROUP_MEMBER_MEMBER'] = 'Є членом груп'; @@ -728,7 +728,7 @@ $lang['GROUP_MEMBER_HIDDEN'] = 'Приховані групи'; $lang['NO_GROUPS_EXIST'] = 'Немає ні однієї групи'; $lang['GROUP_NOT_EXIST'] = 'Такої групи не існує'; -$lang['NO_GROUP_ID_SPECIFIED'] = 'Не указан ID группы'; +$lang['NO_GROUP_ID_SPECIFIED'] = 'Не указан ID групи'; $lang['NO_GROUP_MEMBERS'] = 'В цій групі немає жодного члена'; $lang['HIDDEN_GROUP_MEMBERS'] = 'Ця група прихована, ви не можете побачити її складу'; diff --git a/upload/templates/default/group-config.tpl b/upload/templates/default/group_config.tpl similarity index 100% rename from upload/templates/default/group-config.tpl rename to upload/templates/default/group_config.tpl index 36d31f753..8aa99ff7b 100644 --- a/upload/templates/default/group-config.tpl +++ b/upload/templates/default/group_config.tpl @@ -10,8 +10,8 @@ console.log(data); } } - +

{PAGE_TITLE} :: {GROUP_NAME}

diff --git a/upload/templates/default/groupcp.tpl b/upload/templates/default/groupcp.tpl index 216ab9481..59feca4ad 100644 --- a/upload/templates/default/groupcp.tpl +++ b/upload/templates/default/groupcp.tpl @@ -17,7 +17,7 @@ - + @@ -56,18 +56,18 @@ - - + + - - + + @@ -83,8 +83,8 @@ - - + +
{groups.MEMBERSHIP}

{GROUP_NAME}

-
 
-
- - {GROUP_DESCRIPTION} - - +
 
+
+ + {GROUP_DESCRIPTION} + +
{L_GROUP_TIME}{MOD_TIME}{L_GROUP_TIME}{MOD_TIME}
{L_GROUP_MEMBERSHIP}:
Настройка группы:Перейти в панель управления группойНастройка группы:Перейти в панель управления группой
@@ -100,7 +100,7 @@ # - {L_AVATAR} + {L_AVATAR} {L_USERNAME} {L_PM} {L_EMAIL} @@ -116,7 +116,7 @@ {ROW_NUMBER} - {MOD_AVATAR} + {MOD_AVATAR} {MOD_USER} {MOD_PM} {MOD_EMAIL} @@ -135,7 +135,7 @@ {member.ROW_NUMBER} - {member.AVATAR_IMG} + {member.AVATAR_IMG} {member.USER} {member.PM} {member.EMAIL} From 82960dd8e707ff114d32ff5b714f09314f6a7c39 Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Sat, 2 Aug 2014 23:32:19 +0600 Subject: [PATCH 03/19] R593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Добавлена проверка прав в ajax + Добавлена возможность указать релиз группу при создании группы в администраторской панели + Исправленна работа bbcode + Исправлены мелкие недочеты Signed-off-by: Dark Nightmare --- upload/admin/admin_groups.php | 5 +++ upload/ajax/edit_group_profile.php | 7 ++-- upload/ajax/html/jumpbox_guest.html | 5 --- upload/ajax/html/jumpbox_user.html | 5 --- upload/group_config.php | 2 +- upload/groupcp.php | 24 +++++++++----- upload/language/en/main.php | 2 ++ upload/language/ru/main.php | 2 ++ upload/language/ua/main.php | 2 ++ upload/templates/admin/admin_groups.tpl | 7 ++++ upload/templates/default/group_config.tpl | 2 +- upload/templates/default/groupcp.tpl | 40 ++++++++++++++--------- upload/triggers/cron_allowed | 0 13 files changed, 64 insertions(+), 39 deletions(-) delete mode 100644 upload/ajax/html/jumpbox_guest.html delete mode 100644 upload/ajax/html/jumpbox_user.html delete mode 100644 upload/triggers/cron_allowed diff --git a/upload/admin/admin_groups.php b/upload/admin/admin_groups.php index 30b819a04..81c3be58a 100644 --- a/upload/admin/admin_groups.php +++ b/upload/admin/admin_groups.php @@ -30,6 +30,7 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'group_moderator' => $row['group_moderator'], 'group_mod_name' => $row['moderator_name'], 'group_type' => $row['group_type'], + 'release_group' => $row['release_group'], ); $mode = 'editgroup'; $template->assign_block_vars('group_edit', array()); @@ -42,6 +43,7 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'group_moderator' => '', 'group_mod_name' => '', 'group_type' => GROUP_OPEN, + 'release_group' => 0, ); $mode = 'newgroup'; } @@ -66,6 +68,7 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'S_GROUP_OPEN_CHECKED' => ($group_info['group_type'] == GROUP_OPEN) ? HTML_CHECKED : '', 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? HTML_CHECKED : '', 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN ) ? HTML_CHECKED : '', + 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, 'S_GROUP_ACTION' => "admin_groups.php", 'S_HIDDEN_FIELDS' => $s_hidden_fields, )); @@ -90,6 +93,7 @@ else if (!empty($_POST['group_update'])) else { $group_type = isset($_POST['group_type']) ? intval($_POST['group_type']) : GROUP_OPEN; + $release_group = isset($_POST['release_group']) ? intval($_POST['release_group']) : 0; $group_name = isset($_POST['group_name']) ? trim($_POST['group_name']) : ''; $group_desc = isset($_POST['group_description']) ? trim($_POST['group_description']) : ''; @@ -112,6 +116,7 @@ else if (!empty($_POST['group_update'])) $sql_ary = array( 'group_type' => (int) $group_type, + 'release_group' => (int) $release_group, 'group_name' => (string) $group_name, 'group_description' => (string) $group_desc, 'group_moderator' => (int) $group_moderator, diff --git a/upload/ajax/edit_group_profile.php b/upload/ajax/edit_group_profile.php index 7affe0a48..1b6356d04 100644 --- a/upload/ajax/edit_group_profile.php +++ b/upload/ajax/edit_group_profile.php @@ -2,7 +2,7 @@ if (!defined('IN_AJAX')) die(basename(__FILE__)); -global $bb_cfg, $lang; +global $bb_cfg, $userdata, $lang; if (!$group_id = intval($this->request['group_id']) OR !$group_info = get_group_data($group_id)) { @@ -15,7 +15,10 @@ if (!$mode = (string) $this->request['mode']) $value = $this->request['value'] = (string) (isset($this->request['value'])) ? $this->request['value'] : 0; -// TODO Check for permissions +if (!IS_ADMIN && $userdata['user_id'] != $group_info['group_moderator']) +{ + $this->ajax_die($lang['ONLY_FOR_MOD']); +} switch ($mode) { diff --git a/upload/ajax/html/jumpbox_guest.html b/upload/ajax/html/jumpbox_guest.html deleted file mode 100644 index e25cf03e0..000000000 --- a/upload/ajax/html/jumpbox_guest.html +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/upload/ajax/html/jumpbox_user.html b/upload/ajax/html/jumpbox_user.html deleted file mode 100644 index e25cf03e0..000000000 --- a/upload/ajax/html/jumpbox_user.html +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/upload/group_config.php b/upload/group_config.php index fcab87f7b..45a44c030 100644 --- a/upload/group_config.php +++ b/upload/group_config.php @@ -71,7 +71,7 @@ if ($is_moderator) $template->set_filenames(array('body' => 'group_config.tpl')); - $template->assign_vars(array('PAGE_TITLE' => 'Настройка группы')); + $template->assign_vars(array('PAGE_TITLE' => $lang['GROUP_CONFIGURATION'])); require(PAGE_HEADER); diff --git a/upload/groupcp.php b/upload/groupcp.php index e9fd3fb10..f108668c6 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -73,7 +73,7 @@ if (!$group_id) $sql = " SELECT - g.group_name, g.group_description, g.group_id, g.group_type, + g.group_name, g.group_description, g.group_id, g.group_type, g.release_group, IF(ug.user_id IS NOT NULL, IF(ug.user_pending = 1, $pending, $member), 0) AS membership, g.group_moderator, u.username AS moderator_name, IF(g.group_moderator = ug.user_id, 1, 0) AS is_group_mod, @@ -130,7 +130,7 @@ if (!$group_id) continue; } - $data = array('id' => $row['group_id'], 'm' => ($row['members'] - $row['candidates']), 'c' => $row['candidates']); + $data = array('id' => $row['group_id'], 'm' => ($row['members'] - $row['candidates']), 'c' => $row['candidates'], 'rg' => $row['release_group']); $groups[$type][$row['group_name']] = $data; } @@ -140,15 +140,17 @@ if (!$group_id) global $lang; $options = ''; + foreach ($params as $name => $data) { $text = htmlCHR(str_short(rtrim($name), HTML_SELECT_MAX_LENGTH)); - $members = ($data['m']) ? $lang['MEMBERS_IN_GROUP'] .': '. $data['m'] : $lang['NO_GROUP_MEMBERS']; + $members = ($data['m']) ? $lang['MEMBERS_IN_GROUP'] .': '. $data['m'] : $lang['NO_GROUP_MEMBERS']; $candidates = ($data['c']) ? $lang['PENDING_MEMBERS'] .': '. $data['c'] : $lang['NO_PENDING_GROUP_MEMBERS']; - $options .= '
  • '. $text .'
  • '; - $options .= '
    • '. $members .'
    • '; + $options .= '
    • '. $text .'
    • '; + $options .= ($data['rg']) ? '
      • '. $lang['RELEASE_GROUP'] .'
      • ' : ''; + $options .= '
      • '. $members .'
      • '; if (IS_AM) { $options .= '
      • '. $candidates .'
      • '; @@ -412,7 +414,7 @@ else if ($is_moderator) { $modgroup_pending_list = DB()->fetch_rowset(" - SELECT u.username, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email + SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u WHERE ug.group_id = $group_id AND ug.user_pending = 1 @@ -522,8 +524,11 @@ else 'MOD_WWW' => $www, 'MOD_TIME' => (!empty($group_info['group_time'])) ? bb_date($group_info['group_time']) : $lang['NONE'], 'U_SEARCH_USER' => "search.php?mode=searchuser", - 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", - 'GROUP_TYPE' => $group_type, + + 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", + 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, + 'GROUP_TYPE' => $group_type, + 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED, 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN, @@ -591,7 +596,7 @@ else { $user_id = $member['user_id']; - generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time); + generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); $row_class = !($i % 2) ? 'row1' : 'row2'; @@ -599,6 +604,7 @@ else $template->assign_block_vars('pending', array( 'ROW_CLASS' => $row_class, + 'AVATAR_IMG'=> $avatar, 'USER' => profile_url($member), 'FROM' => $from, 'JOINED' => $joined, diff --git a/upload/language/en/main.php b/upload/language/en/main.php index c3384aafc..3d0b8ffa4 100644 --- a/upload/language/en/main.php +++ b/upload/language/en/main.php @@ -699,6 +699,8 @@ $lang['ORDER'] = 'Order'; // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'User Groups'; +$lang['GROUP_CONFIGURATION'] = 'Group Configuration'; +$lang['GROUP_GOTO_CONFIG'] = 'Go to Group Configuration panel'; $lang['GROUP_RETURN'] = 'Return to User Group page'; $lang['MEMBERSHIP_DETAILS'] = 'Group Membership Details'; $lang['JOIN_A_GROUP'] = 'Join a Group'; diff --git a/upload/language/ru/main.php b/upload/language/ru/main.php index d34a09425..5a1eefddd 100644 --- a/upload/language/ru/main.php +++ b/upload/language/ru/main.php @@ -699,6 +699,8 @@ $lang['ORDER'] = ''; // не нужно, в английском использ // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'Группы'; +$lang['GROUP_CONFIGURATION'] = 'Настройка группы'; +$lang['GROUP_GOTO_CONFIG'] = 'Перейти в панель управления группой'; $lang['GROUP_RETURN'] = 'Вернуться на страницу группы'; $lang['MEMBERSHIP_DETAILS'] = 'Информация о членстве в группах'; $lang['JOIN_A_GROUP'] = 'Вступить в группу'; diff --git a/upload/language/ua/main.php b/upload/language/ua/main.php index 55a149897..731fa2ea1 100644 --- a/upload/language/ua/main.php +++ b/upload/language/ua/main.php @@ -699,6 +699,8 @@ $lang['ORDER'] = ''; // не потрібно, в англійській вик // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'Групи'; +$lang['GROUP_CONFIGURATION'] = 'Настройка группы'; +$lang['GROUP_GOTO_CONFIG'] = 'Перейти в панель управления группой'; $lang['GROUP_RETURN'] = 'Вернуться на страницу групи'; $lang['MEMBERSHIP_DETAILS'] = 'Інформація про членство в групах'; $lang['JOIN_A_GROUP'] = 'Вступити в групу'; diff --git a/upload/templates/admin/admin_groups.tpl b/upload/templates/admin/admin_groups.tpl index 076a978b6..dbf4bfd00 100644 --- a/upload/templates/admin/admin_groups.tpl +++ b/upload/templates/admin/admin_groups.tpl @@ -33,6 +33,13 @@
        {L_GROUP_HIDDEN}
        + + {L_RELEASE_GROUP} + +    + + + {L_DELETE_OLD_GROUP_MOD} diff --git a/upload/templates/default/group_config.tpl b/upload/templates/default/group_config.tpl index 8aa99ff7b..f204536d8 100644 --- a/upload/templates/default/group_config.tpl +++ b/upload/templates/default/group_config.tpl @@ -33,7 +33,7 @@

        - +

        diff --git a/upload/templates/default/groupcp.tpl b/upload/templates/default/groupcp.tpl index 59feca4ad..5fe2cd091 100644 --- a/upload/templates/default/groupcp.tpl +++ b/upload/templates/default/groupcp.tpl @@ -56,15 +56,21 @@

        {GROUP_NAME}

        - -
         
        - - - - {GROUP_DESCRIPTION} - - + +
         
        + + + +
        {GROUP_DESCRIPTION}
        + + + + + {L_GROUP_TYPE} + {L_RELEASE_GROUP} + + {L_GROUP_TIME} {MOD_TIME} @@ -83,8 +89,8 @@ - Настройка группы: - Перейти в панель управления группой + {L_GROUP_CONFIGURATION}: + {L_GROUP_GOTO_CONFIG} @@ -154,13 +160,13 @@ - {L_NO_GROUP_MEMBERS} + {L_NO_GROUP_MEMBERS} - {L_HIDDEN_GROUP_MEMBERS} + {L_HIDDEN_GROUP_MEMBERS} @@ -197,7 +203,8 @@ - + + @@ -207,12 +214,13 @@ - + - + + @@ -224,7 +232,7 @@ - - - - - diff --git a/upload/templates/default/group_config.tpl b/upload/templates/default/group_config.tpl index f204536d8..8aa99ff7b 100644 --- a/upload/templates/default/group_config.tpl +++ b/upload/templates/default/group_config.tpl @@ -33,7 +33,7 @@

        - +

        diff --git a/upload/templates/default/groupcp.tpl b/upload/templates/default/groupcp.tpl index 5fe2cd091..59feca4ad 100644 --- a/upload/templates/default/groupcp.tpl +++ b/upload/templates/default/groupcp.tpl @@ -56,21 +56,15 @@ - - + + - - - - - - @@ -89,8 +83,8 @@ - - + +
        {L_SELECT}#{L_AVATAR} {L_USERNAME} {L_PM} {L_EMAIL}{L_WEBSITE}
        {L_PENDING_MEMBERS}{L_PENDING_MEMBERS}
        {pending.AVATAR_IMG} {pending.USER} {pending.PM} {pending.EMAIL}
        +   diff --git a/upload/triggers/cron_allowed b/upload/triggers/cron_allowed deleted file mode 100644 index e69de29bb..000000000 From fc9ed7577530471cab7cec0afcd76a5796ff446b Mon Sep 17 00:00:00 2001 From: Exile Date: Sat, 2 Aug 2014 22:01:01 +0400 Subject: [PATCH 04/19] Revert "R593" This reverts commit 82960dd8e707ff114d32ff5b714f09314f6a7c39. --- upload/admin/admin_groups.php | 5 --- upload/ajax/edit_group_profile.php | 7 ++-- upload/ajax/html/jumpbox_guest.html | 5 +++ upload/ajax/html/jumpbox_user.html | 5 +++ upload/group_config.php | 2 +- upload/groupcp.php | 24 +++++--------- upload/language/en/main.php | 2 -- upload/language/ru/main.php | 2 -- upload/language/ua/main.php | 2 -- upload/templates/admin/admin_groups.tpl | 7 ---- upload/templates/default/group_config.tpl | 2 +- upload/templates/default/groupcp.tpl | 40 +++++++++-------------- upload/triggers/cron_allowed | 0 13 files changed, 39 insertions(+), 64 deletions(-) create mode 100644 upload/ajax/html/jumpbox_guest.html create mode 100644 upload/ajax/html/jumpbox_user.html create mode 100644 upload/triggers/cron_allowed diff --git a/upload/admin/admin_groups.php b/upload/admin/admin_groups.php index 81c3be58a..30b819a04 100644 --- a/upload/admin/admin_groups.php +++ b/upload/admin/admin_groups.php @@ -30,7 +30,6 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'group_moderator' => $row['group_moderator'], 'group_mod_name' => $row['moderator_name'], 'group_type' => $row['group_type'], - 'release_group' => $row['release_group'], ); $mode = 'editgroup'; $template->assign_block_vars('group_edit', array()); @@ -43,7 +42,6 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'group_moderator' => '', 'group_mod_name' => '', 'group_type' => GROUP_OPEN, - 'release_group' => 0, ); $mode = 'newgroup'; } @@ -68,7 +66,6 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'S_GROUP_OPEN_CHECKED' => ($group_info['group_type'] == GROUP_OPEN) ? HTML_CHECKED : '', 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? HTML_CHECKED : '', 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN ) ? HTML_CHECKED : '', - 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, 'S_GROUP_ACTION' => "admin_groups.php", 'S_HIDDEN_FIELDS' => $s_hidden_fields, )); @@ -93,7 +90,6 @@ else if (!empty($_POST['group_update'])) else { $group_type = isset($_POST['group_type']) ? intval($_POST['group_type']) : GROUP_OPEN; - $release_group = isset($_POST['release_group']) ? intval($_POST['release_group']) : 0; $group_name = isset($_POST['group_name']) ? trim($_POST['group_name']) : ''; $group_desc = isset($_POST['group_description']) ? trim($_POST['group_description']) : ''; @@ -116,7 +112,6 @@ else if (!empty($_POST['group_update'])) $sql_ary = array( 'group_type' => (int) $group_type, - 'release_group' => (int) $release_group, 'group_name' => (string) $group_name, 'group_description' => (string) $group_desc, 'group_moderator' => (int) $group_moderator, diff --git a/upload/ajax/edit_group_profile.php b/upload/ajax/edit_group_profile.php index 1b6356d04..7affe0a48 100644 --- a/upload/ajax/edit_group_profile.php +++ b/upload/ajax/edit_group_profile.php @@ -2,7 +2,7 @@ if (!defined('IN_AJAX')) die(basename(__FILE__)); -global $bb_cfg, $userdata, $lang; +global $bb_cfg, $lang; if (!$group_id = intval($this->request['group_id']) OR !$group_info = get_group_data($group_id)) { @@ -15,10 +15,7 @@ if (!$mode = (string) $this->request['mode']) $value = $this->request['value'] = (string) (isset($this->request['value'])) ? $this->request['value'] : 0; -if (!IS_ADMIN && $userdata['user_id'] != $group_info['group_moderator']) -{ - $this->ajax_die($lang['ONLY_FOR_MOD']); -} +// TODO Check for permissions switch ($mode) { diff --git a/upload/ajax/html/jumpbox_guest.html b/upload/ajax/html/jumpbox_guest.html new file mode 100644 index 000000000..e25cf03e0 --- /dev/null +++ b/upload/ajax/html/jumpbox_guest.html @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/upload/ajax/html/jumpbox_user.html b/upload/ajax/html/jumpbox_user.html new file mode 100644 index 000000000..e25cf03e0 --- /dev/null +++ b/upload/ajax/html/jumpbox_user.html @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/upload/group_config.php b/upload/group_config.php index 45a44c030..fcab87f7b 100644 --- a/upload/group_config.php +++ b/upload/group_config.php @@ -71,7 +71,7 @@ if ($is_moderator) $template->set_filenames(array('body' => 'group_config.tpl')); - $template->assign_vars(array('PAGE_TITLE' => $lang['GROUP_CONFIGURATION'])); + $template->assign_vars(array('PAGE_TITLE' => 'Настройка группы')); require(PAGE_HEADER); diff --git a/upload/groupcp.php b/upload/groupcp.php index f108668c6..e9fd3fb10 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -73,7 +73,7 @@ if (!$group_id) $sql = " SELECT - g.group_name, g.group_description, g.group_id, g.group_type, g.release_group, + g.group_name, g.group_description, g.group_id, g.group_type, IF(ug.user_id IS NOT NULL, IF(ug.user_pending = 1, $pending, $member), 0) AS membership, g.group_moderator, u.username AS moderator_name, IF(g.group_moderator = ug.user_id, 1, 0) AS is_group_mod, @@ -130,7 +130,7 @@ if (!$group_id) continue; } - $data = array('id' => $row['group_id'], 'm' => ($row['members'] - $row['candidates']), 'c' => $row['candidates'], 'rg' => $row['release_group']); + $data = array('id' => $row['group_id'], 'm' => ($row['members'] - $row['candidates']), 'c' => $row['candidates']); $groups[$type][$row['group_name']] = $data; } @@ -140,17 +140,15 @@ if (!$group_id) global $lang; $options = ''; - foreach ($params as $name => $data) { $text = htmlCHR(str_short(rtrim($name), HTML_SELECT_MAX_LENGTH)); - $members = ($data['m']) ? $lang['MEMBERS_IN_GROUP'] .': '. $data['m'] : $lang['NO_GROUP_MEMBERS']; + $members = ($data['m']) ? $lang['MEMBERS_IN_GROUP'] .': '. $data['m'] : $lang['NO_GROUP_MEMBERS']; $candidates = ($data['c']) ? $lang['PENDING_MEMBERS'] .': '. $data['c'] : $lang['NO_PENDING_GROUP_MEMBERS']; - $options .= '
      • '. $text .'
      • '; - $options .= ($data['rg']) ? '
        • '. $lang['RELEASE_GROUP'] .'
        • ' : ''; - $options .= '
        • '. $members .'
        • '; + $options .= '
        • '. $text .'
        • '; + $options .= '
          • '. $members .'
          • '; if (IS_AM) { $options .= '
          • '. $candidates .'
          • '; @@ -414,7 +412,7 @@ else if ($is_moderator) { $modgroup_pending_list = DB()->fetch_rowset(" - SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email + SELECT u.username, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u WHERE ug.group_id = $group_id AND ug.user_pending = 1 @@ -524,11 +522,8 @@ else 'MOD_WWW' => $www, 'MOD_TIME' => (!empty($group_info['group_time'])) ? bb_date($group_info['group_time']) : $lang['NONE'], 'U_SEARCH_USER' => "search.php?mode=searchuser", - - 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", - 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, - 'GROUP_TYPE' => $group_type, - + 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", + 'GROUP_TYPE' => $group_type, 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED, 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN, @@ -596,7 +591,7 @@ else { $user_id = $member['user_id']; - generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); + generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time); $row_class = !($i % 2) ? 'row1' : 'row2'; @@ -604,7 +599,6 @@ else $template->assign_block_vars('pending', array( 'ROW_CLASS' => $row_class, - 'AVATAR_IMG'=> $avatar, 'USER' => profile_url($member), 'FROM' => $from, 'JOINED' => $joined, diff --git a/upload/language/en/main.php b/upload/language/en/main.php index 3d0b8ffa4..c3384aafc 100644 --- a/upload/language/en/main.php +++ b/upload/language/en/main.php @@ -699,8 +699,6 @@ $lang['ORDER'] = 'Order'; // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'User Groups'; -$lang['GROUP_CONFIGURATION'] = 'Group Configuration'; -$lang['GROUP_GOTO_CONFIG'] = 'Go to Group Configuration panel'; $lang['GROUP_RETURN'] = 'Return to User Group page'; $lang['MEMBERSHIP_DETAILS'] = 'Group Membership Details'; $lang['JOIN_A_GROUP'] = 'Join a Group'; diff --git a/upload/language/ru/main.php b/upload/language/ru/main.php index 5a1eefddd..d34a09425 100644 --- a/upload/language/ru/main.php +++ b/upload/language/ru/main.php @@ -699,8 +699,6 @@ $lang['ORDER'] = ''; // не нужно, в английском использ // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'Группы'; -$lang['GROUP_CONFIGURATION'] = 'Настройка группы'; -$lang['GROUP_GOTO_CONFIG'] = 'Перейти в панель управления группой'; $lang['GROUP_RETURN'] = 'Вернуться на страницу группы'; $lang['MEMBERSHIP_DETAILS'] = 'Информация о членстве в группах'; $lang['JOIN_A_GROUP'] = 'Вступить в группу'; diff --git a/upload/language/ua/main.php b/upload/language/ua/main.php index 731fa2ea1..55a149897 100644 --- a/upload/language/ua/main.php +++ b/upload/language/ua/main.php @@ -699,8 +699,6 @@ $lang['ORDER'] = ''; // не потрібно, в англійській вик // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'Групи'; -$lang['GROUP_CONFIGURATION'] = 'Настройка группы'; -$lang['GROUP_GOTO_CONFIG'] = 'Перейти в панель управления группой'; $lang['GROUP_RETURN'] = 'Вернуться на страницу групи'; $lang['MEMBERSHIP_DETAILS'] = 'Інформація про членство в групах'; $lang['JOIN_A_GROUP'] = 'Вступити в групу'; diff --git a/upload/templates/admin/admin_groups.tpl b/upload/templates/admin/admin_groups.tpl index dbf4bfd00..076a978b6 100644 --- a/upload/templates/admin/admin_groups.tpl +++ b/upload/templates/admin/admin_groups.tpl @@ -33,13 +33,6 @@
            {L_GROUP_HIDDEN}
        {L_RELEASE_GROUP} -    - -
        {L_DELETE_OLD_GROUP_MOD}

        {GROUP_NAME}

        -
         
        -
        - -
        {GROUP_DESCRIPTION}
        - -
        +
         
        +
        + + {GROUP_DESCRIPTION} + +
        {L_GROUP_TYPE}{L_RELEASE_GROUP}
        {L_GROUP_TIME} {MOD_TIME}
        {L_GROUP_CONFIGURATION}:{L_GROUP_GOTO_CONFIG}Настройка группы:Перейти в панель управления группой
        @@ -160,13 +154,13 @@ - {L_NO_GROUP_MEMBERS} + {L_NO_GROUP_MEMBERS} - {L_HIDDEN_GROUP_MEMBERS} + {L_HIDDEN_GROUP_MEMBERS} @@ -203,8 +197,7 @@ - - + @@ -214,13 +207,12 @@ - + - - + @@ -232,7 +224,7 @@ - + + + + diff --git a/upload/templates/default/group_config.tpl b/upload/templates/default/group_config.tpl index 8aa99ff7b..f204536d8 100644 --- a/upload/templates/default/group_config.tpl +++ b/upload/templates/default/group_config.tpl @@ -33,7 +33,7 @@

        - +

        diff --git a/upload/templates/default/groupcp.tpl b/upload/templates/default/groupcp.tpl index 59feca4ad..5fe2cd091 100644 --- a/upload/templates/default/groupcp.tpl +++ b/upload/templates/default/groupcp.tpl @@ -56,15 +56,21 @@ - - + + + + + + + + @@ -83,8 +89,8 @@ - - + +
        #{L_AVATAR}{L_SELECT} {L_USERNAME} {L_PM} {L_EMAIL}{L_WEBSITE}
        {L_PENDING_MEMBERS}{L_PENDING_MEMBERS}
        {pending.AVATAR_IMG} {pending.USER} {pending.PM} {pending.EMAIL}
        +   diff --git a/upload/triggers/cron_allowed b/upload/triggers/cron_allowed new file mode 100644 index 000000000..e69de29bb From 93241028924f5a914769ff4f136b7b7fcdc322e1 Mon Sep 17 00:00:00 2001 From: Exile Date: Sat, 2 Aug 2014 22:16:19 +0400 Subject: [PATCH 05/19] r593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Разрешили конфликт ревизий. --- upload/admin/admin_groups.php | 5 +++ upload/ajax/edit_group_profile.php | 7 ++-- upload/group_config.php | 2 +- upload/groupcp.php | 24 +++++++++----- upload/language/en/main.php | 2 ++ upload/language/ru/main.php | 2 ++ upload/language/ua/main.php | 2 ++ upload/templates/admin/admin_groups.tpl | 7 ++++ upload/templates/default/group_config.tpl | 2 +- upload/templates/default/groupcp.tpl | 40 ++++++++++++++--------- 10 files changed, 64 insertions(+), 29 deletions(-) diff --git a/upload/admin/admin_groups.php b/upload/admin/admin_groups.php index 30b819a04..81c3be58a 100644 --- a/upload/admin/admin_groups.php +++ b/upload/admin/admin_groups.php @@ -30,6 +30,7 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'group_moderator' => $row['group_moderator'], 'group_mod_name' => $row['moderator_name'], 'group_type' => $row['group_type'], + 'release_group' => $row['release_group'], ); $mode = 'editgroup'; $template->assign_block_vars('group_edit', array()); @@ -42,6 +43,7 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'group_moderator' => '', 'group_mod_name' => '', 'group_type' => GROUP_OPEN, + 'release_group' => 0, ); $mode = 'newgroup'; } @@ -66,6 +68,7 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'S_GROUP_OPEN_CHECKED' => ($group_info['group_type'] == GROUP_OPEN) ? HTML_CHECKED : '', 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? HTML_CHECKED : '', 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN ) ? HTML_CHECKED : '', + 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, 'S_GROUP_ACTION' => "admin_groups.php", 'S_HIDDEN_FIELDS' => $s_hidden_fields, )); @@ -90,6 +93,7 @@ else if (!empty($_POST['group_update'])) else { $group_type = isset($_POST['group_type']) ? intval($_POST['group_type']) : GROUP_OPEN; + $release_group = isset($_POST['release_group']) ? intval($_POST['release_group']) : 0; $group_name = isset($_POST['group_name']) ? trim($_POST['group_name']) : ''; $group_desc = isset($_POST['group_description']) ? trim($_POST['group_description']) : ''; @@ -112,6 +116,7 @@ else if (!empty($_POST['group_update'])) $sql_ary = array( 'group_type' => (int) $group_type, + 'release_group' => (int) $release_group, 'group_name' => (string) $group_name, 'group_description' => (string) $group_desc, 'group_moderator' => (int) $group_moderator, diff --git a/upload/ajax/edit_group_profile.php b/upload/ajax/edit_group_profile.php index 7affe0a48..1b6356d04 100644 --- a/upload/ajax/edit_group_profile.php +++ b/upload/ajax/edit_group_profile.php @@ -2,7 +2,7 @@ if (!defined('IN_AJAX')) die(basename(__FILE__)); -global $bb_cfg, $lang; +global $bb_cfg, $userdata, $lang; if (!$group_id = intval($this->request['group_id']) OR !$group_info = get_group_data($group_id)) { @@ -15,7 +15,10 @@ if (!$mode = (string) $this->request['mode']) $value = $this->request['value'] = (string) (isset($this->request['value'])) ? $this->request['value'] : 0; -// TODO Check for permissions +if (!IS_ADMIN && $userdata['user_id'] != $group_info['group_moderator']) +{ + $this->ajax_die($lang['ONLY_FOR_MOD']); +} switch ($mode) { diff --git a/upload/group_config.php b/upload/group_config.php index fcab87f7b..45a44c030 100644 --- a/upload/group_config.php +++ b/upload/group_config.php @@ -71,7 +71,7 @@ if ($is_moderator) $template->set_filenames(array('body' => 'group_config.tpl')); - $template->assign_vars(array('PAGE_TITLE' => 'Настройка группы')); + $template->assign_vars(array('PAGE_TITLE' => $lang['GROUP_CONFIGURATION'])); require(PAGE_HEADER); diff --git a/upload/groupcp.php b/upload/groupcp.php index e9fd3fb10..f108668c6 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -73,7 +73,7 @@ if (!$group_id) $sql = " SELECT - g.group_name, g.group_description, g.group_id, g.group_type, + g.group_name, g.group_description, g.group_id, g.group_type, g.release_group, IF(ug.user_id IS NOT NULL, IF(ug.user_pending = 1, $pending, $member), 0) AS membership, g.group_moderator, u.username AS moderator_name, IF(g.group_moderator = ug.user_id, 1, 0) AS is_group_mod, @@ -130,7 +130,7 @@ if (!$group_id) continue; } - $data = array('id' => $row['group_id'], 'm' => ($row['members'] - $row['candidates']), 'c' => $row['candidates']); + $data = array('id' => $row['group_id'], 'm' => ($row['members'] - $row['candidates']), 'c' => $row['candidates'], 'rg' => $row['release_group']); $groups[$type][$row['group_name']] = $data; } @@ -140,15 +140,17 @@ if (!$group_id) global $lang; $options = ''; + foreach ($params as $name => $data) { $text = htmlCHR(str_short(rtrim($name), HTML_SELECT_MAX_LENGTH)); - $members = ($data['m']) ? $lang['MEMBERS_IN_GROUP'] .': '. $data['m'] : $lang['NO_GROUP_MEMBERS']; + $members = ($data['m']) ? $lang['MEMBERS_IN_GROUP'] .': '. $data['m'] : $lang['NO_GROUP_MEMBERS']; $candidates = ($data['c']) ? $lang['PENDING_MEMBERS'] .': '. $data['c'] : $lang['NO_PENDING_GROUP_MEMBERS']; - $options .= '
      • '. $text .'
      • '; - $options .= '
        • '. $members .'
        • '; + $options .= '
        • '. $text .'
        • '; + $options .= ($data['rg']) ? '
          • '. $lang['RELEASE_GROUP'] .'
          • ' : ''; + $options .= '
          • '. $members .'
          • '; if (IS_AM) { $options .= '
          • '. $candidates .'
          • '; @@ -412,7 +414,7 @@ else if ($is_moderator) { $modgroup_pending_list = DB()->fetch_rowset(" - SELECT u.username, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email + SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u WHERE ug.group_id = $group_id AND ug.user_pending = 1 @@ -522,8 +524,11 @@ else 'MOD_WWW' => $www, 'MOD_TIME' => (!empty($group_info['group_time'])) ? bb_date($group_info['group_time']) : $lang['NONE'], 'U_SEARCH_USER' => "search.php?mode=searchuser", - 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", - 'GROUP_TYPE' => $group_type, + + 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", + 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, + 'GROUP_TYPE' => $group_type, + 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED, 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN, @@ -591,7 +596,7 @@ else { $user_id = $member['user_id']; - generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time); + generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); $row_class = !($i % 2) ? 'row1' : 'row2'; @@ -599,6 +604,7 @@ else $template->assign_block_vars('pending', array( 'ROW_CLASS' => $row_class, + 'AVATAR_IMG'=> $avatar, 'USER' => profile_url($member), 'FROM' => $from, 'JOINED' => $joined, diff --git a/upload/language/en/main.php b/upload/language/en/main.php index c3384aafc..3d0b8ffa4 100644 --- a/upload/language/en/main.php +++ b/upload/language/en/main.php @@ -699,6 +699,8 @@ $lang['ORDER'] = 'Order'; // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'User Groups'; +$lang['GROUP_CONFIGURATION'] = 'Group Configuration'; +$lang['GROUP_GOTO_CONFIG'] = 'Go to Group Configuration panel'; $lang['GROUP_RETURN'] = 'Return to User Group page'; $lang['MEMBERSHIP_DETAILS'] = 'Group Membership Details'; $lang['JOIN_A_GROUP'] = 'Join a Group'; diff --git a/upload/language/ru/main.php b/upload/language/ru/main.php index d34a09425..5a1eefddd 100644 --- a/upload/language/ru/main.php +++ b/upload/language/ru/main.php @@ -699,6 +699,8 @@ $lang['ORDER'] = ''; // не нужно, в английском использ // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'Группы'; +$lang['GROUP_CONFIGURATION'] = 'Настройка группы'; +$lang['GROUP_GOTO_CONFIG'] = 'Перейти в панель управления группой'; $lang['GROUP_RETURN'] = 'Вернуться на страницу группы'; $lang['MEMBERSHIP_DETAILS'] = 'Информация о членстве в группах'; $lang['JOIN_A_GROUP'] = 'Вступить в группу'; diff --git a/upload/language/ua/main.php b/upload/language/ua/main.php index 55a149897..3bde9dcf0 100644 --- a/upload/language/ua/main.php +++ b/upload/language/ua/main.php @@ -699,6 +699,8 @@ $lang['ORDER'] = ''; // не потрібно, в англійській вик // Group control panel // $lang['GROUP_CONTROL_PANEL'] = 'Групи'; +$lang['GROUP_CONFIGURATION'] = 'Налаштування групи'; +$lang['GROUP_GOTO_CONFIG'] = 'Перейти в панель управління групою'; $lang['GROUP_RETURN'] = 'Вернуться на страницу групи'; $lang['MEMBERSHIP_DETAILS'] = 'Інформація про членство в групах'; $lang['JOIN_A_GROUP'] = 'Вступити в групу'; diff --git a/upload/templates/admin/admin_groups.tpl b/upload/templates/admin/admin_groups.tpl index 076a978b6..dbf4bfd00 100644 --- a/upload/templates/admin/admin_groups.tpl +++ b/upload/templates/admin/admin_groups.tpl @@ -33,6 +33,13 @@
            {L_GROUP_HIDDEN}
        {L_RELEASE_GROUP} +    + +
        {L_DELETE_OLD_GROUP_MOD}

        {GROUP_NAME}

        -
         
        -
        - - {GROUP_DESCRIPTION} - - +
         
        +
        + +
        {GROUP_DESCRIPTION}
        + +
        {L_GROUP_TYPE}{L_RELEASE_GROUP}
        {L_GROUP_TIME} {MOD_TIME}
        Настройка группы:Перейти в панель управления группой{L_GROUP_CONFIGURATION}:{L_GROUP_GOTO_CONFIG}
        @@ -154,13 +160,13 @@ - {L_NO_GROUP_MEMBERS} + {L_NO_GROUP_MEMBERS} - {L_HIDDEN_GROUP_MEMBERS} + {L_HIDDEN_GROUP_MEMBERS} @@ -197,7 +203,8 @@ - + + @@ -207,12 +214,13 @@ - + - + + @@ -224,7 +232,7 @@ - - - - - - '; - $html .= ($bb_cfg['seed_bonus_enabled']) ? '' : ''; - $html .= ' - - - - - - '; - $html .= ($bb_cfg['seed_bonus_enabled']) ? '' : ''; - $html .= ' - - - - '; - $html .= ($bb_cfg['seed_bonus_enabled']) ? '' : ''; - $html .= ''; - - $this->response['user_ratio'] = ' - - - '; - break; -} - -$this->response['html'] = $html; +request['mode']; +$html = ''; + +switch($mode) +{ + case 'birthday_week': + $stats = $datastore->get('stats'); + $datastore->enqueue(array( + 'stats', + )); + + if ($stats['birthday_week_list']) + { + foreach($stats['birthday_week_list'] as $week) + { + $html[] = profile_url($week) .' ('. birthday_age($week['user_birthday']) .')'; + } + $html = sprintf($lang['BIRTHDAY_WEEK'], $bb_cfg['birthday_check_day'], join(', ', $html)); + } + else $html = sprintf($lang['NOBIRTHDAY_WEEK'], $bb_cfg['birthday_check_day']); + break; + + case 'birthday_today': + $stats = $datastore->get('stats'); + $datastore->enqueue(array( + 'stats', + )); + + if ($stats['birthday_today_list']) + { + foreach($stats['birthday_today_list'] as $today) + { + $html[] = profile_url($today) .' ('. birthday_age($today['user_birthday']) .')'; + } + $html = $lang['BIRTHDAY_TODAY'] . join(', ', $html); + } + else $html = $lang['NOBIRTHDAY_TODAY']; + break; + + case 'get_forum_mods': + $forum_id = (int) $this->request['forum_id']; + + $datastore->enqueue(array( + 'moderators', + )); + + $moderators = array(); + $mod = $datastore->get('moderators'); + + if (isset($mod['mod_users'][$forum_id])) + { + foreach ($mod['mod_users'][$forum_id] as $user_id) + { + $moderators[] = ''. $mod['name_users'][$user_id] .''; + } + } + + if (isset($mod['mod_groups'][$forum_id])) + { + foreach ($mod['mod_groups'][$forum_id] as $group_id) + { + $moderators[] = ''. $mod['name_groups'][$group_id] .''; + } + } + + $html = ': '; + $html .= ($moderators) ? join(', ', $moderators) : $lang['NONE']; + unset($moderators, $mod); + $datastore->rm('moderators'); + break; + + case 'change_tz': + $tz = (int) $this->request['tz']; + if ($tz < -12) $tz = -12; + if ($tz > 13) $tz = 13; + if ($tz != $bb_cfg['board_timezone']) + { + // Set current user timezone + DB()->query("UPDATE ". BB_USERS ." SET user_timezone = $tz WHERE user_id = ". $userdata['user_id'] ." LIMIT 1"); + $bb_cfg['board_timezone'] = $tz; + cache_rm_user_sessions ($userdata['user_id']); + } + break; + + case 'get_traf_stats': + $user_id = (int) $this->request['user_id']; + $btu = get_bt_userdata($user_id); + $profiledata = get_userdata($user_id); + + $speed_up = ($btu['speed_up']) ? humn_size($btu['speed_up']).'/s' : '0 KB/s'; + $speed_down = ($btu['speed_down']) ? humn_size($btu['speed_down']).'/s' : '0 KB/s'; + $user_ratio = ($btu['u_down_total'] > MIN_DL_FOR_RATIO) ? ''. get_bt_ratio($btu) .'' : $lang['IT_WILL_BE_DOWN'] .' '. humn_size(MIN_DL_FOR_RATIO) .''; + + $html = ' + + + + + + '; + $html .= ($bb_cfg['seed_bonus_enabled']) ? '' : ''; + $html .= ' + + + + + + '; + $html .= ($bb_cfg['seed_bonus_enabled']) ? '' : ''; + $html .= ' + + + + '; + $html .= ($bb_cfg['seed_bonus_enabled']) ? '' : ''; + $html .= ''; + + $this->response['user_ratio'] = ' + + + '; + break; +} + +$this->response['html'] = $html; $this->response['mode'] = $mode; \ No newline at end of file diff --git a/upload/ajax/manage_admin.php b/upload/ajax/manage_admin.php index 6405aeede..559f4753d 100644 --- a/upload/ajax/manage_admin.php +++ b/upload/ajax/manage_admin.php @@ -1,107 +1,107 @@ -request['mode']; - -switch ($mode) -{ - case 'clear_cache': - - foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) - { - if (!in_array('db_sqlite', $cache_val)) - { - CACHE($cache_name)->rm(); - } - } - - $this->response['cache_html'] = ''. $lang['ALL_CACHE_CLEARED'] .''; - - break; - - case 'clear_datastore': - - global $datastore; - - $datastore->clean(); - - $this->response['datastore_html'] = ''. $lang['DATASTORE_CLEARED'] .''; - - break; - - case 'clear_template_cache': - - global $template; - - $match = 'tpl_'; - $match_len = strlen($match); - $dir = $template->cachedir; - $res = @opendir($dir); - while (($file = readdir($res)) !== false) - { - if (substr($file, 0, $match_len) === $match) - { - @unlink($dir . $file); - } - } - closedir($res); - - $this->response['template_cache_html'] = ''. $lang['ALL_TEMPLATE_CLEARED'] .''; - - break; - - case 'indexer': - - exec("indexer --config {$bb_cfg['sphinx_config_path']} --all --rotate", $result); - - if (!is_file($bb_cfg['sphinx_config_path'].".log")) - { - file_put_contents($bb_cfg['sphinx_config_path'].".log", "####Logger from dimka3210.####".date("H:i:s", TIMENOW)."##############################\r\n\r\n\r\n\r\n", FILE_APPEND); - } - - file_put_contents($bb_cfg['sphinx_config_path'].".log", "##############################".date("H:i:s", TIMENOW)."##############################\r\n", FILE_APPEND); - - foreach ($result as $row) - { - file_put_contents($bb_cfg['sphinx_config_path'].".log", $row."\r\n", FILE_APPEND); - } - - file_put_contents($bb_cfg['sphinx_config_path'].".log", "\r\n", FILE_APPEND); - file_put_contents($bb_cfg['sphinx_config_path'].".log", "\r\n", FILE_APPEND); - - $this->response['indexer_html'] = ''. $lang['INDEXER'] .''; - - break; - - case 'update_user_level': - - require(INC_DIR .'functions_group.php'); - - update_user_level('all'); - - $this->response['update_user_level_html'] = ''. $lang['USER_LEVELS_UPDATED'] .''; - - break; - - case 'sync_topics': - - sync('topic', 'all'); - sync_all_forums(); - - $this->response['sync_topics_html'] = ''. $lang['TOPICS_DATA_SYNCHRONIZED'] .''; - - break; - - case 'sync_user_posts': - - sync('user_posts', 'all'); - - $this->response['sync_user_posts_html'] = ''. $lang['USER POSTS COUNT SYNCHRONIZED'] .''; - - break; -} - +request['mode']; + +switch ($mode) +{ + case 'clear_cache': + + foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) + { + if (!in_array('db_sqlite', $cache_val)) + { + CACHE($cache_name)->rm(); + } + } + + $this->response['cache_html'] = ''. $lang['ALL_CACHE_CLEARED'] .''; + + break; + + case 'clear_datastore': + + global $datastore; + + $datastore->clean(); + + $this->response['datastore_html'] = ''. $lang['DATASTORE_CLEARED'] .''; + + break; + + case 'clear_template_cache': + + global $template; + + $match = 'tpl_'; + $match_len = strlen($match); + $dir = $template->cachedir; + $res = @opendir($dir); + while (($file = readdir($res)) !== false) + { + if (substr($file, 0, $match_len) === $match) + { + @unlink($dir . $file); + } + } + closedir($res); + + $this->response['template_cache_html'] = ''. $lang['ALL_TEMPLATE_CLEARED'] .''; + + break; + + case 'indexer': + + exec("indexer --config {$bb_cfg['sphinx_config_path']} --all --rotate", $result); + + if (!is_file($bb_cfg['sphinx_config_path'].".log")) + { + file_put_contents($bb_cfg['sphinx_config_path'].".log", "####Logger from dimka3210.####".date("H:i:s", TIMENOW)."##############################\r\n\r\n\r\n\r\n", FILE_APPEND); + } + + file_put_contents($bb_cfg['sphinx_config_path'].".log", "##############################".date("H:i:s", TIMENOW)."##############################\r\n", FILE_APPEND); + + foreach ($result as $row) + { + file_put_contents($bb_cfg['sphinx_config_path'].".log", $row."\r\n", FILE_APPEND); + } + + file_put_contents($bb_cfg['sphinx_config_path'].".log", "\r\n", FILE_APPEND); + file_put_contents($bb_cfg['sphinx_config_path'].".log", "\r\n", FILE_APPEND); + + $this->response['indexer_html'] = ''. $lang['INDEXER'] .''; + + break; + + case 'update_user_level': + + require(INC_DIR .'functions_group.php'); + + update_user_level('all'); + + $this->response['update_user_level_html'] = ''. $lang['USER_LEVELS_UPDATED'] .''; + + break; + + case 'sync_topics': + + sync('topic', 'all'); + sync_all_forums(); + + $this->response['sync_topics_html'] = ''. $lang['TOPICS_DATA_SYNCHRONIZED'] .''; + + break; + + case 'sync_user_posts': + + sync('user_posts', 'all'); + + $this->response['sync_user_posts_html'] = ''. $lang['USER POSTS COUNT SYNCHRONIZED'] .''; + + break; +} + $this->response['mode'] = $mode; \ No newline at end of file diff --git a/upload/ajax/manage_user.php b/upload/ajax/manage_user.php index 94d87d3d1..b1783e083 100644 --- a/upload/ajax/manage_user.php +++ b/upload/ajax/manage_user.php @@ -1,84 +1,84 @@ -request['mode']; -$user_id = $this->request['user_id']; - -switch ($mode) -{ - case 'delete_profile': - - if ($userdata['user_id'] == $user_id) $this->ajax_die($lang['USER_DELETE_ME']); - if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['USER_DELETE_CONFIRM']); - - if ($user_id != BOT_UID) - { - delete_user_sessions($user_id); - user_delete($user_id); - - $this->response['info'] = $lang['USER_DELETED']; - } - else $this->ajax_die($lang['USER_DELETE_CSV']); - - break; - - case 'delete_topics': - - if (empty($this->request['confirmed']) && $userdata['user_id'] == $user_id) $this->prompt_for_confirm($lang['DELETE_USER_POSTS_ME']); - if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['DELETE_USER_ALL_POSTS_CONFIRM']); - - if (IS_ADMIN) - { - $user_topics = DB()->fetch_rowset("SELECT topic_id FROM ". BB_TOPICS ." WHERE topic_poster = $user_id", 'topic_id'); - $deleted_topics = topic_delete($user_topics); - $deleted_posts = post_delete('user', $user_id); - - $this->response['info'] = $lang['USER_DELETED_POSTS']; - } - else $this->ajax_die($lang['NOT_ADMIN']); - - break; - - case 'delete_message': - - if (empty($this->request['confirmed']) && $userdata['user_id'] == $user_id) $this->prompt_for_confirm($lang['DELETE_USER_POSTS_ME']); - if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['DELETE_USER_POSTS_CONFIRM']); - - if (IS_ADMIN) - { - post_delete('user', $user_id); - - $this->response['info'] = $lang['USER_DELETED_POSTS']; - } - else $this->ajax_die($lang['NOT_ADMIN']); - - break; - - case 'user_activate': - - if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['DEACTIVATE_CONFIRM']); - - DB()->query("UPDATE ". BB_USERS ." SET user_active = '1' WHERE user_id = ". $user_id); - - $this->response['info'] = $lang['USER_ACTIVATE_ON']; - - break; - - case 'user_deactivate': - - if ($userdata['user_id'] == $user_id) $this->ajax_die($lang['USER_DEACTIVATE_ME']); - if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['ACTIVATE_CONFIRM']); - - DB()->query("UPDATE ". BB_USERS ." SET user_active = '0' WHERE user_id = ". $user_id); - delete_user_sessions($user_id); - - $this->response['info'] = $lang['USER_ACTIVATE_OFF']; - - break; -} - -$this->response['mode'] = $mode; +request['mode']; +$user_id = $this->request['user_id']; + +switch ($mode) +{ + case 'delete_profile': + + if ($userdata['user_id'] == $user_id) $this->ajax_die($lang['USER_DELETE_ME']); + if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['USER_DELETE_CONFIRM']); + + if ($user_id != BOT_UID) + { + delete_user_sessions($user_id); + user_delete($user_id); + + $this->response['info'] = $lang['USER_DELETED']; + } + else $this->ajax_die($lang['USER_DELETE_CSV']); + + break; + + case 'delete_topics': + + if (empty($this->request['confirmed']) && $userdata['user_id'] == $user_id) $this->prompt_for_confirm($lang['DELETE_USER_POSTS_ME']); + if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['DELETE_USER_ALL_POSTS_CONFIRM']); + + if (IS_ADMIN) + { + $user_topics = DB()->fetch_rowset("SELECT topic_id FROM ". BB_TOPICS ." WHERE topic_poster = $user_id", 'topic_id'); + $deleted_topics = topic_delete($user_topics); + $deleted_posts = post_delete('user', $user_id); + + $this->response['info'] = $lang['USER_DELETED_POSTS']; + } + else $this->ajax_die($lang['NOT_ADMIN']); + + break; + + case 'delete_message': + + if (empty($this->request['confirmed']) && $userdata['user_id'] == $user_id) $this->prompt_for_confirm($lang['DELETE_USER_POSTS_ME']); + if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['DELETE_USER_POSTS_CONFIRM']); + + if (IS_ADMIN) + { + post_delete('user', $user_id); + + $this->response['info'] = $lang['USER_DELETED_POSTS']; + } + else $this->ajax_die($lang['NOT_ADMIN']); + + break; + + case 'user_activate': + + if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['DEACTIVATE_CONFIRM']); + + DB()->query("UPDATE ". BB_USERS ." SET user_active = '1' WHERE user_id = ". $user_id); + + $this->response['info'] = $lang['USER_ACTIVATE_ON']; + + break; + + case 'user_deactivate': + + if ($userdata['user_id'] == $user_id) $this->ajax_die($lang['USER_DEACTIVATE_ME']); + if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['ACTIVATE_CONFIRM']); + + DB()->query("UPDATE ". BB_USERS ." SET user_active = '0' WHERE user_id = ". $user_id); + delete_user_sessions($user_id); + + $this->response['info'] = $lang['USER_ACTIVATE_OFF']; + + break; +} + +$this->response['mode'] = $mode; $this->response['url'] = html_entity_decode(make_url('/') . PROFILE_URL . $user_id); \ No newline at end of file diff --git a/upload/ajax/mod_action.php b/upload/ajax/mod_action.php index 8faf91ae4..80153be06 100644 --- a/upload/ajax/mod_action.php +++ b/upload/ajax/mod_action.php @@ -1,130 +1,130 @@ -request['mode']; - -switch ($mode) -{ - case 'tor_status': - $topics = (string) $this->request['topic_ids']; - $status = (int) $this->request['status']; - - // Валидность статуса - if (!isset($lang['TOR_STATUS_NAME'][$status])) - { - $this->ajax_die($lang['STATUS_DOES_EXIST'] . $new_status); - } - - $topic_ids = DB()->fetch_rowset("SELECT attach_id FROM ". BB_BT_TORRENTS ." WHERE topic_id IN($topics)", 'attach_id'); - - foreach($topic_ids as $attach_id) - { - change_tor_status($attach_id, $status); - } - $this->response['status'] = $bb_cfg['tor_icons'][$status]; - $this->response['topics'] = explode(',', $topics); - break; - - case 'edit_topic_title': - $topic_id = (int) $this->request['topic_id']; - $topic_title = (string) $this->request['topic_title']; - $new_title = clean_title($topic_title); - - if (!$topic_id) $this->ajax_die($lang['INVALID_TOPIC_ID']); - if ($new_title == '') $this->ajax_die($lang['DONT_MESSAGE_TITLE']); - - if (!$t_data = DB()->fetch_row("SELECT forum_id FROM ". BB_TOPICS ." WHERE topic_id = $topic_id LIMIT 1")) - { - $this->ajax_die($lang['INVALID_TOPIC_ID_DB']); - } - $this->verify_mod_rights($t_data['forum_id']); - - $topic_title_sql = DB()->escape($new_title); - - DB()->query("UPDATE ". BB_TOPICS ." SET topic_title = '$topic_title_sql' WHERE topic_id = $topic_id LIMIT 1"); - - // Обновление кеша новостей на главной - $news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id'])); - if (isset($news_forums[$t_data['forum_id']]) && $bb_cfg['show_latest_news']) - { - $datastore->enqueue('latest_news'); - $datastore->update('latest_news'); - } - - $net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id'])); - if (isset($net_forums[$t_data['forum_id']]) && $bb_cfg['show_network_news']) - { - $datastore->enqueue('network_news'); - $datastore->update('network_news'); - } - - $this->response['topic_id'] = $topic_id; - $this->response['topic_title'] = $new_title; - break; - - case 'profile_ip': - $user_id = (int) $this->request['user_id']; - $profiledata = get_userdata($user_id); - - if (!$user_id) $this->ajax_die($lang['NO_USER_ID_SPECIFIED']); - - $reg_ip = DB()->fetch_rowset("SELECT username, user_id, user_rank FROM ". BB_USERS ." - WHERE user_reg_ip = '{$profiledata['user_reg_ip']}' - AND user_reg_ip != '' - AND user_id != {$profiledata['user_id']} - ORDER BY username ASC"); - - $last_ip = DB()->fetch_rowset("SELECT username, user_id, user_rank FROM " .BB_USERS ." - WHERE user_last_ip = '{$profiledata['user_last_ip']}' - AND user_last_ip != '' - AND user_id != {$profiledata['user_id']}"); - - $link_reg_ip = $link_last_ip = ''; - - if (!empty($reg_ip)) - { - $link_reg_ip .= $lang['OTHER_IP'] .' '; - foreach ($reg_ip as $row) - { - $link_reg_ip .= profile_url($row) .' '; - } - } - - if (!empty($last_ip)) - { - $link_last_ip .= $lang['OTHER_IP'] .' '; - foreach ($last_ip as $row) - { - $link_last_ip .= profile_url($row) .' '; - } - } - - if ($profiledata['user_level'] == ADMIN && !IS_ADMIN) $reg_ip = $last_ip = $lang['HIDDEN']; - elseif ($profiledata['user_level'] == MOD && IS_MOD) $reg_ip = $last_ip = $lang['HIDDEN']; - else - { - $user_reg_ip = decode_ip($profiledata['user_reg_ip']); - $user_last_ip = decode_ip($profiledata['user_last_ip']); - $reg_ip = ''. $user_reg_ip .''; - $last_ip = ''. $user_last_ip .''; - } - - $this->response['ip_list_html'] = ' -
        {L_SELECT}#{L_AVATAR} {L_USERNAME} {L_PM} {L_EMAIL}{L_WEBSITE}
        {L_PENDING_MEMBERS}{L_PENDING_MEMBERS}
        {pending.AVATAR_IMG} {pending.USER} {pending.PM} {pending.EMAIL}
        +   From 749558815203360841627f78d79285ce2cac0494 Mon Sep 17 00:00:00 2001 From: Exile Date: Sat, 2 Aug 2014 22:27:46 +0400 Subject: [PATCH 06/19] r593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Конвертирование последней косячной ветки к правильным окончаниям строк. --- contributors.txt | 88 +- install/php-fpm+nginx/nginx.conf | 288 +- install/sphinx/sphinx.conf | 206 +- other/converter/TBDevYSE_pre6/ReadMe.txt | 40 +- .../TBDevYSE_pre6/for_tbdev/pass.php | 86 +- .../converter/TBDevYSE_pre6/root/convert.php | 522 +- .../root/converter/constants.php | 14 +- .../TBDevYSE_pre6/root/converter/settings.php | 38 +- other/recover/converter/constants.php | 14 +- other/recover/converter/settings.php | 38 +- upgrade/r575-poll_upgrade.php | 150 +- upload/.htaccess | 16 +- upload/admin/admin_attach_cp.php | 1114 +- upload/admin/admin_attachments.php | 1440 +-- upload/admin/admin_board.php | 302 +- upload/admin/admin_bt_forum_cfg.php | 302 +- upload/admin/admin_bt_tracker_cfg.php | 130 +- upload/admin/admin_disallow.php | 192 +- upload/admin/admin_extensions.php | 1564 +-- upload/admin/admin_forum_prune.php | 124 +- upload/admin/admin_forumauth.php | 506 +- upload/admin/admin_forumauth_list.php | 728 +- upload/admin/admin_forums.php | 2442 ++--- upload/admin/admin_mass_email.php | 206 +- upload/admin/admin_ranks.php | 512 +- upload/admin/admin_rebuild_search.php | 1252 +-- upload/admin/admin_reports.php | 1118 +- upload/admin/admin_smilies.php | 744 +- upload/admin/admin_ug_auth.php | 950 +- upload/admin/admin_user_ban.php | 726 +- upload/admin/admin_user_search.php | 2106 ++-- upload/admin/admin_words.php | 316 +- upload/ajax/avatar.php | 68 +- upload/ajax/change_tor_status.php | 210 +- upload/ajax/change_torrent.php | 206 +- upload/ajax/change_user_opt.php | 64 +- upload/ajax/change_user_rank.php | 54 +- upload/ajax/edit_user_profile.php | 334 +- upload/ajax/gen_passkey.php | 48 +- upload/ajax/group_membership.php | 136 +- upload/ajax/index_data.php | 262 +- upload/ajax/manage_admin.php | 212 +- upload/ajax/manage_user.php | 166 +- upload/ajax/mod_action.php | 258 +- upload/ajax/post_mod_comment.php | 118 +- upload/ajax/topic_tpl.php | 342 +- upload/ajax/user_register.php | 150 +- upload/ajax/view_post.php | 104 +- upload/ajax/view_torrent.php | 342 +- .../includes/functions_includes.php | 406 +- upload/bt/includes/.htaccess | 2 +- upload/callseed.php | 188 +- upload/cron.php | 10 +- upload/crossdomain.xml | 8 +- upload/files/.htaccess | 4 +- upload/files/thumbs/.htaccess | 4 +- upload/groupcp.php | 1258 +-- upload/includes/captcha/captcha.php | 798 +- upload/includes/class.correct.php | 6206 +++++------ upload/includes/class.reflection.php | 364 +- upload/includes/class.utf8.php | 8140 +++++++------- upload/includes/cron/jobs/cache_gc.php | 26 +- upload/includes/cron/jobs/captcha_gen_gc.php | 120 +- upload/includes/cron/jobs/db_backup.php | 72 +- upload/includes/cron/jobs/site_backup.php | 64 +- upload/includes/db/mysql.php | 1966 ++-- upload/includes/functions.php | 5598 +++++----- upload/includes/functions_admin_cron.php | 312 +- upload/includes/functions_report_admin.php | 1038 +- upload/includes/functions_upload.php | 330 +- upload/includes/page_footer_dev.php | 202 +- upload/includes/posting_tpl.php | 162 +- upload/includes/template.php | 2408 ++-- upload/includes/ucp/register.php | 1552 +-- upload/includes/ucp/topic_watch.php | 198 +- upload/includes/ucp/viewprofile.php | 478 +- upload/language/en/html/advert.html | 32 +- upload/language/en/html/sidebar1.html | 44 +- upload/language/en/html/sidebar2.html | 34 +- upload/language/en/main.php | 5970 +++++----- upload/language/ru/html/advert.html | 32 +- upload/language/ru/html/sidebar1.html | 44 +- upload/language/ru/html/sidebar2.html | 34 +- upload/language/ru/main.php | 5970 +++++----- upload/language/ru/search_stopwords.txt | 938 +- upload/language/ru/search_synonyms.txt | 148 +- upload/language/ua/html/advert.html | 32 +- upload/language/ua/html/sidebar1.html | 44 +- upload/language/ua/html/sidebar2.html | 34 +- upload/language/ua/search_stopwords.txt | 938 +- upload/language/ua/search_synonyms.txt | 148 +- upload/misc.php | 286 +- upload/opensearch_desc.xml | 14 +- upload/opensearch_desc_bt.xml | 14 +- upload/poll.php | 474 +- upload/report.php | 1504 +-- upload/robots.txt | 24 +- upload/templates/default/css/admin.css | 16 +- upload/templates/default/css/main.css | 3068 +++--- upload/templates/default/modcp.tpl | 252 +- upload/templates/default/posting_tpl.tpl | 9702 ++++++++--------- upload/templates/default/usercp_bonus.tpl | 104 +- .../templates/default/usercp_topic_watch.tpl | 252 +- upload/templates/default/viewtopic.tpl | 1272 +-- upload/viewforum.php | 1186 +- upload/viewtopic.php | 1888 ++-- 106 files changed, 43880 insertions(+), 43880 deletions(-) diff --git a/contributors.txt b/contributors.txt index 5425119a7..9776221fe 100644 --- a/contributors.txt +++ b/contributors.txt @@ -1,45 +1,45 @@ -Уважаемые пользователи TorrentPier II! - -За помощь, оказанную в развитии нашего движка, выражаем особую благодарность нижеперечисленным участникам форума: - -*************************** -** Сборы 2013 года ** -*************************** - -emilio13 -UralSOFT -aik -Sarymian -eve -Алексей Письменский -qaqra -rserg99 -leszav -Dr_Brown -Bullit -Triceratop (http://goldenshara.com/) -Ramzess - -**************************** -** Сборы 2014 года ** -**************************** - -SamSeGo -alesel (http://sporttracker.kz/) -Bullit -igorsaevets -vasilich619 -wint1000 (http://asmlocator.ru/) -Philstone (http://worldofminecraft.su/) -Nightwolf -nord51 -Вася - -***************************** -** Прочая информация ** -***************************** - -Большое вам всем спасибо за помощь. - -Если в данных списках кто-то не указан, либо если вы хотите указать дополнительно адрес своего трекера, отправьте письмо по адресу admin@torrentpier.me, +Уважаемые пользователи TorrentPier II! + +За помощь, оказанную в развитии нашего движка, выражаем особую благодарность нижеперечисленным участникам форума: + +*************************** +** Сборы 2013 года ** +*************************** + +emilio13 +UralSOFT +aik +Sarymian +eve +Алексей Письменский +qaqra +rserg99 +leszav +Dr_Brown +Bullit +Triceratop (http://goldenshara.com/) +Ramzess + +**************************** +** Сборы 2014 года ** +**************************** + +SamSeGo +alesel (http://sporttracker.kz/) +Bullit +igorsaevets +vasilich619 +wint1000 (http://asmlocator.ru/) +Philstone (http://worldofminecraft.su/) +Nightwolf +nord51 +Вася + +***************************** +** Прочая информация ** +***************************** + +Большое вам всем спасибо за помощь. + +Если в данных списках кто-то не указан, либо если вы хотите указать дополнительно адрес своего трекера, отправьте письмо по адресу admin@torrentpier.me, с указанием вашего ника на форуме и адреса вашего трекера, дабы мы могли вас добавить в этот список. \ No newline at end of file diff --git a/install/php-fpm+nginx/nginx.conf b/install/php-fpm+nginx/nginx.conf index 3be984daa..e32641d2a 100644 --- a/install/php-fpm+nginx/nginx.conf +++ b/install/php-fpm+nginx/nginx.conf @@ -1,145 +1,145 @@ -user www www; -worker_processes 4; - -#error_log /var/log/nginx/error.log; -#error_log /var/log/nginx/error.log notice; -#error_log /var/log/nginx/error.log info; - -pid /var/run/nginx.pid; - -worker_rlimit_nofile 1024; -events { - worker_connections 1024; -} - -http { - include mime.types; - default_type application/octet-stream; - - #log_format main '$remote_addr - $remote_user [$time_local] $request ' - # '"$status" $body_bytes_sent "$http_referer" ' - # '"$http_user_agent" "$http_x_forwarded_for"'; - - #log_format IP .$remote_addr.; - - access_log off; - - server_tokens off; - reset_timedout_connection on; - - sendfile on; - - # http://en.wikipedia.org/wiki/Asynchronous_I/O - # aio sendfile; - - output_buffers 1 64k; - - tcp_nopush on; - tcp_nodelay on; - send_lowat 12000; - log_not_found off; - - keepalive_timeout 65; - - limit_req_zone $binary_remote_addr zone=one:16m rate=5r/s; - - gzip on; - gzip_vary on; - gzip_min_length 2048; - gzip_comp_level 5; - gzip_http_version 1.0; - gzip_proxied any; - gzip_disable "msie6"; - gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; - - client_max_body_size 10m; - large_client_header_buffers 4 8k; - client_body_temp_path /tmp/nginx/client_temp 1 2; - - server { - #listen 80 default sndbuf=32k rcvbuf=8k accept_filter=httpready; - #listen [::]:80 default sndbuf=32k rcvbuf=8k accept_filter=httpready; - - listen 80 default sndbuf=32k rcvbuf=8k; - server_name sitedomain.ru; - - charset utf8; - - access_log off; - - location / { - root /var/www; - index index.html index.htm index.php; - } - - error_page 404 /404.html; - error_page 500 502 503 504 /50x.html; - - # pass the PHP scripts to FastCGI server listening on /tmp/php.sock; - # - location ~ \.php$ { - #limit_req zone=one burst=20 nodelay; - #limit_req_log_level info; - - root /var/www; - fastcgi_index index.php; - fastcgi_pass unix:/tmp/php.sock; # 127.0.0.1:9000; - fastcgi_intercept_errors on; - - # FreeBSD Optimization - fastcgi_pass_request_body off; - client_body_in_file_only clean; - fastcgi_param REQUEST_BODY_FILE $request_body_file; - - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name; - - include fastcgi_params; - } - - # Old XBTT config -# location ^~ /bt/ { -# access_log off; -# if ( $query_string ~ "^uk=([^&?]{10})[&?]+(.*)$" ) { -# set $uk $1; -# set $qs $2&ip=$remote_addr; -# } -# if ( $query_string ~ "^uk=([^&?]{10})[&?]+((.*&|)ip=.*)$" ) { -# set $uk $1; -# set $qs $2; -# } -# if ( $qs ) { -# rewrite ^.*/([a-z]+)(\.php|)$ /$uk/$1?$qs break; -# } -# rewrite ^/?(.*)$ /$1?ip=$remote_addr&$query_string break; -# proxy_pass http://127.0.0.1:2710/; -# } - - # Cached Images - location ~* \.(jpg|jpeg|gif|png|css|js|ico)$ { - root /var/www; - access_log off; - expires 30d; - add_header Cache-Control public; - } - - location ~ \/admin|backup\/ { - deny all; - # allow YOUR_IP; - } - # Deny folder (Sec. lvl1) - location ~ \/(cache|log|attach_mod|config|includes|language|triggers)\/ { - deny all; - } - - # deny access to .htaccess files, if Apache's document root - # concurs with nginx's one - # deny sql,tpl,db,inc,log - location ~ /\.ht { - deny all; - } - location ~ \.(.*sql|tpl|db|inc|log)$ { - deny all; - } - } +user www www; +worker_processes 4; + +#error_log /var/log/nginx/error.log; +#error_log /var/log/nginx/error.log notice; +#error_log /var/log/nginx/error.log info; + +pid /var/run/nginx.pid; + +worker_rlimit_nofile 1024; +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] $request ' + # '"$status" $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #log_format IP .$remote_addr.; + + access_log off; + + server_tokens off; + reset_timedout_connection on; + + sendfile on; + + # http://en.wikipedia.org/wiki/Asynchronous_I/O + # aio sendfile; + + output_buffers 1 64k; + + tcp_nopush on; + tcp_nodelay on; + send_lowat 12000; + log_not_found off; + + keepalive_timeout 65; + + limit_req_zone $binary_remote_addr zone=one:16m rate=5r/s; + + gzip on; + gzip_vary on; + gzip_min_length 2048; + gzip_comp_level 5; + gzip_http_version 1.0; + gzip_proxied any; + gzip_disable "msie6"; + gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; + + client_max_body_size 10m; + large_client_header_buffers 4 8k; + client_body_temp_path /tmp/nginx/client_temp 1 2; + + server { + #listen 80 default sndbuf=32k rcvbuf=8k accept_filter=httpready; + #listen [::]:80 default sndbuf=32k rcvbuf=8k accept_filter=httpready; + + listen 80 default sndbuf=32k rcvbuf=8k; + server_name sitedomain.ru; + + charset utf8; + + access_log off; + + location / { + root /var/www; + index index.html index.htm index.php; + } + + error_page 404 /404.html; + error_page 500 502 503 504 /50x.html; + + # pass the PHP scripts to FastCGI server listening on /tmp/php.sock; + # + location ~ \.php$ { + #limit_req zone=one burst=20 nodelay; + #limit_req_log_level info; + + root /var/www; + fastcgi_index index.php; + fastcgi_pass unix:/tmp/php.sock; # 127.0.0.1:9000; + fastcgi_intercept_errors on; + + # FreeBSD Optimization + fastcgi_pass_request_body off; + client_body_in_file_only clean; + fastcgi_param REQUEST_BODY_FILE $request_body_file; + + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name; + + include fastcgi_params; + } + + # Old XBTT config +# location ^~ /bt/ { +# access_log off; +# if ( $query_string ~ "^uk=([^&?]{10})[&?]+(.*)$" ) { +# set $uk $1; +# set $qs $2&ip=$remote_addr; +# } +# if ( $query_string ~ "^uk=([^&?]{10})[&?]+((.*&|)ip=.*)$" ) { +# set $uk $1; +# set $qs $2; +# } +# if ( $qs ) { +# rewrite ^.*/([a-z]+)(\.php|)$ /$uk/$1?$qs break; +# } +# rewrite ^/?(.*)$ /$1?ip=$remote_addr&$query_string break; +# proxy_pass http://127.0.0.1:2710/; +# } + + # Cached Images + location ~* \.(jpg|jpeg|gif|png|css|js|ico)$ { + root /var/www; + access_log off; + expires 30d; + add_header Cache-Control public; + } + + location ~ \/admin|backup\/ { + deny all; + # allow YOUR_IP; + } + # Deny folder (Sec. lvl1) + location ~ \/(cache|log|attach_mod|config|includes|language|triggers)\/ { + deny all; + } + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # deny sql,tpl,db,inc,log + location ~ /\.ht { + deny all; + } + location ~ \.(.*sql|tpl|db|inc|log)$ { + deny all; + } + } } \ No newline at end of file diff --git a/install/sphinx/sphinx.conf b/install/sphinx/sphinx.conf index be2360d8d..d29033d81 100644 --- a/install/sphinx/sphinx.conf +++ b/install/sphinx/sphinx.conf @@ -1,104 +1,104 @@ -source torrentpier -{ - type = mysql - sql_host = localhost - sql_user = user - sql_pass = pass - sql_db = dbase - sql_query_pre = SET NAMES utf8 - sql_query_pre = SET CHARACTER_SET_RESULTS=utf8 - sql_query_pre = SET CHARACTER_SET_CLIENT=utf8 -} - -source topics: torrentpier -{ - sql_query = \ - SELECT topic_id, forum_id, topic_title \ - FROM bb_topics \ - WHERE topic_id BETWEEN $start AND $end - - sql_query_range = SELECT MIN(topic_id), MAX(topic_id) FROM bb_topics - sql_range_step = 100000 - - sql_attr_uint = forum_id - sql_ranged_throttle = 50 - sql_query_info = SELECT * FROM bb_topics WHERE topic_id = $id -} - -source posts: torrentpier -{ - sql_query = \ - SELECT pt.post_id, pt.post_text, t.topic_title, t.topic_id, t.forum_id \ - FROM bb_posts_text pt \ - LEFT JOIN bb_topics t on pt.post_id = t.topic_first_post_id \ - WHERE pt.post_id BETWEEN $start AND $end - - sql_query_range = SELECT MIN(post_id), MAX(post_id) FROM bb_posts_text - sql_range_step = 100000 - - sql_attr_uint = topic_id - sql_attr_uint = forum_id - sql_ranged_throttle = 50 - sql_query_info = SELECT * FROM bb_posts_text WHERE post_id = $id -} - -source users: torrentpier -{ - sql_query = \ - SELECT user_id, username \ - FROM bb_users \ - WHERE user_id BETWEEN $start AND $end - - sql_query_range = SELECT 1, MAX(user_id) FROM bb_users - sql_range_step = 1000 - sql_query_info = SELECT * FROM bb_users WHERE user_id = $id -} - -index topics -{ - docinfo = extern - morphology = stem_enru - charset_type = utf-8 - charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42C->U+430..U+44C, U+42E..U+42F->U+44E..U+44F, U+430..U+44C, U+44E..U+44F, U+0401->U+0435, U+0451->U+0435, U+042D->U+0435, U+044D->U+0435 - min_prefix_len = 0 - min_infix_len = 0 - min_word_len = 1 - min_stemming_len = 4 - enable_star = 1 - phrase_boundary = :, - , . , $ - phrase_boundary_step = 1 - html_strip = 1 - path = ./sphinx/data/topics - source = topics -} - -index posts: topics -{ - path = ./sphinx/data/posts - source = posts -} - -index users: topics -{ - path = ./sphinx/data/users - source = users -} - -indexer -{ - mem_limit = 256M -} - -searchd -{ - listen = 127.0.0.1:3312 - log = ./sphinx/log/searchd.log - query_log = ./sphinx/log/query.log - read_timeout = 5 - max_children = 15 - max_matches = 5000 - seamless_rotate = 1 - preopen_indexes = 0 - unlink_old = 1 - pid_file = ./sphinx/searchd.pid +source torrentpier +{ + type = mysql + sql_host = localhost + sql_user = user + sql_pass = pass + sql_db = dbase + sql_query_pre = SET NAMES utf8 + sql_query_pre = SET CHARACTER_SET_RESULTS=utf8 + sql_query_pre = SET CHARACTER_SET_CLIENT=utf8 +} + +source topics: torrentpier +{ + sql_query = \ + SELECT topic_id, forum_id, topic_title \ + FROM bb_topics \ + WHERE topic_id BETWEEN $start AND $end + + sql_query_range = SELECT MIN(topic_id), MAX(topic_id) FROM bb_topics + sql_range_step = 100000 + + sql_attr_uint = forum_id + sql_ranged_throttle = 50 + sql_query_info = SELECT * FROM bb_topics WHERE topic_id = $id +} + +source posts: torrentpier +{ + sql_query = \ + SELECT pt.post_id, pt.post_text, t.topic_title, t.topic_id, t.forum_id \ + FROM bb_posts_text pt \ + LEFT JOIN bb_topics t on pt.post_id = t.topic_first_post_id \ + WHERE pt.post_id BETWEEN $start AND $end + + sql_query_range = SELECT MIN(post_id), MAX(post_id) FROM bb_posts_text + sql_range_step = 100000 + + sql_attr_uint = topic_id + sql_attr_uint = forum_id + sql_ranged_throttle = 50 + sql_query_info = SELECT * FROM bb_posts_text WHERE post_id = $id +} + +source users: torrentpier +{ + sql_query = \ + SELECT user_id, username \ + FROM bb_users \ + WHERE user_id BETWEEN $start AND $end + + sql_query_range = SELECT 1, MAX(user_id) FROM bb_users + sql_range_step = 1000 + sql_query_info = SELECT * FROM bb_users WHERE user_id = $id +} + +index topics +{ + docinfo = extern + morphology = stem_enru + charset_type = utf-8 + charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42C->U+430..U+44C, U+42E..U+42F->U+44E..U+44F, U+430..U+44C, U+44E..U+44F, U+0401->U+0435, U+0451->U+0435, U+042D->U+0435, U+044D->U+0435 + min_prefix_len = 0 + min_infix_len = 0 + min_word_len = 1 + min_stemming_len = 4 + enable_star = 1 + phrase_boundary = :, - , . , $ + phrase_boundary_step = 1 + html_strip = 1 + path = ./sphinx/data/topics + source = topics +} + +index posts: topics +{ + path = ./sphinx/data/posts + source = posts +} + +index users: topics +{ + path = ./sphinx/data/users + source = users +} + +indexer +{ + mem_limit = 256M +} + +searchd +{ + listen = 127.0.0.1:3312 + log = ./sphinx/log/searchd.log + query_log = ./sphinx/log/query.log + read_timeout = 5 + max_children = 15 + max_matches = 5000 + seamless_rotate = 1 + preopen_indexes = 0 + unlink_old = 1 + pid_file = ./sphinx/searchd.pid } \ No newline at end of file diff --git a/other/converter/TBDevYSE_pre6/ReadMe.txt b/other/converter/TBDevYSE_pre6/ReadMe.txt index be2b8a36e..198424165 100644 --- a/other/converter/TBDevYSE_pre6/ReadMe.txt +++ b/other/converter/TBDevYSE_pre6/ReadMe.txt @@ -1,21 +1,21 @@ -TBDev Yuna Scatari Edition pre6 to TorrentPier 1.0.x converter. - -Quick guide: -1. Install and configure TorrentPier 1.0.0 or higher. -2. Import your TBDevYSE database into TorrentPier database (concretely 'comments', 'categories', 'torrents' and 'users' tables). -3. Put the contents of folder 'root' into your TorrentPier root. -4. Configure 'converter/settings.php' for optimal settings. -5. Run convert.php. -6. See 'converter/passwords.php' for new password to login under admin account. -7. Resychronize statistics using admin panel. -8. Make your new tracker popular! ----- -9. If you need to notify users for new passwords (which are needed to login in TorrentPier) via TBDevYSE PM system, - copy two files: automatically generated 'converter/passwords.php' and 'for_tbdev/pass.php' to your TBDevYSE root and run pass.php - (Don't forget to remove these files after completion). - You allow to change message text, see $msg in pass.php for this. -10. If you want to redirect peers from older announce to new announce everytime, replace original TBDev's announce.php with - 'for_tbdev/announce.php' - -Cheers, RoadTrain. +TBDev Yuna Scatari Edition pre6 to TorrentPier 1.0.x converter. + +Quick guide: +1. Install and configure TorrentPier 1.0.0 or higher. +2. Import your TBDevYSE database into TorrentPier database (concretely 'comments', 'categories', 'torrents' and 'users' tables). +3. Put the contents of folder 'root' into your TorrentPier root. +4. Configure 'converter/settings.php' for optimal settings. +5. Run convert.php. +6. See 'converter/passwords.php' for new password to login under admin account. +7. Resychronize statistics using admin panel. +8. Make your new tracker popular! +---- +9. If you need to notify users for new passwords (which are needed to login in TorrentPier) via TBDevYSE PM system, + copy two files: automatically generated 'converter/passwords.php' and 'for_tbdev/pass.php' to your TBDevYSE root and run pass.php + (Don't forget to remove these files after completion). + You allow to change message text, see $msg in pass.php for this. +10. If you want to redirect peers from older announce to new announce everytime, replace original TBDev's announce.php with + 'for_tbdev/announce.php' + +Cheers, RoadTrain. http://torrentpier.me/ \ No newline at end of file diff --git a/other/converter/TBDevYSE_pre6/for_tbdev/pass.php b/other/converter/TBDevYSE_pre6/for_tbdev/pass.php index 617242a18..b16622d6d 100644 --- a/other/converter/TBDevYSE_pre6/for_tbdev/pass.php +++ b/other/converter/TBDevYSE_pre6/for_tbdev/pass.php @@ -1,44 +1,44 @@ - -
        - - - -
        - '; -} -else -{ - if(!file_exists('passwords.php')) stderr($tracker_lang['error'], 'passwords.php not exists'); - - include('passwords.php'); - stdhead(); - foreach ($passwords as $user) - { - $msg_sql = sprintf($msg, $user['username'], $user['new_passwd']); - sql_query("INSERT INTO messages (receiver, added, subject, msg) VALUES({$user['tb_user_id']}, NOW(), ".sqlesc($subject).", ".sqlesc($msg_sql).")"); - } - stdmsg('OK', 'Mass PM succesful'); -} - + +
        +
        + +
        +
        + '; +} +else +{ + if(!file_exists('passwords.php')) stderr($tracker_lang['error'], 'passwords.php not exists'); + + include('passwords.php'); + stdhead(); + foreach ($passwords as $user) + { + $msg_sql = sprintf($msg, $user['username'], $user['new_passwd']); + sql_query("INSERT INTO messages (receiver, added, subject, msg) VALUES({$user['tb_user_id']}, NOW(), ".sqlesc($subject).", ".sqlesc($msg_sql).")"); + } + stdmsg('OK', 'Mass PM succesful'); +} + stdfoot(); \ No newline at end of file diff --git a/other/converter/TBDevYSE_pre6/root/convert.php b/other/converter/TBDevYSE_pre6/root/convert.php index bee3f2a4b..dec5874d0 100644 --- a/other/converter/TBDevYSE_pre6/root/convert.php +++ b/other/converter/TBDevYSE_pre6/root/convert.php @@ -1,262 +1,262 @@ -session_start(); - -if (!IS_ADMIN) die("Restricted access"); -while (@ob_end_flush()); -ob_implicit_flush(); - -error_reporting(E_ALL); -@ini_set('display_errors', 1); - -?> - - - - - - - - - - -
        -
        - -
        -
        - - '; - - exit; -} -else -{ - -@ini_set('memory_limit', '512M'); -@ini_set('max_execution_time', @ini_get('max_execution_time') + 1200); - -// Step 1: Converting Users -if (CONVERT_USERS) -{ - if (CLEAN) - { - tp_users_cleanup(); - print_ok ("Users cleared"); - } - - $max_uid = (int) get_max_val(BB_USERS, 'user_id'); - $max_uid = ($max_uid > 1) ? $max_uid : 1; - - $users_count = (int) get_count(TB_USERS_TABLE, 'id'); - $loops = (int) ceil($users_count / C_USERS_PER_ONCE); - $pass = array(); - - switch(TR_TYPE) - { - case 'yse': - $_sql = 'avatar, '; - break; - - default: - $_sql = ''; - break; - } - - for ($i = 0; $i < $loops; $i++) - { - $start = $i * C_USERS_PER_ONCE; - $offset = C_USERS_PER_ONCE; - - $sql = " - SELECT - id, username, email, status, UNIX_TIMESTAMP(added) AS added, UNIX_TIMESTAMP(last_access) AS last_access, - class, icq, msn, aim, yahoo, website, $_sql - uploaded, downloaded, enabled, language - FROM ". TB_USERS_TABLE ." - ORDER BY id - LIMIT $start, $offset"; - - $users = DB()->fetch_rowset($sql); - DB()->sql_freeresult(); - - foreach ($users as $user) - { - $user['id'] += $max_uid; - $user['password'] = make_rand_str(15); - convert_user($user); - $pass[] = array( - 'tb_user_id' => $user['id'] - $max_uid, - 'username' => $user['username'], - 'new_passwd' => $user['password'], - ); - } - } - $passf = fopen('./converter/passwords.php', 'w'); - $to_write = " $tr_cat_id, - "cat_title" => 'Tracker', - ); - tp_add_category($tp_cat_data); - set_auto_increment(BB_CATEGORIES, 'cat_id'); - unset($tp_cat_data); - - $cats = $db->fetch_rowset("SELECT id, sort, name FROM ". TB_CATEGORIES_TABLE); - DB()->sql_freeresult(); - - $max_forum_id = (int) get_max_val(BB_FORUMS, 'forum_id'); - - foreach ($cats as $cat) - { - $cat['id'] += $max_forum_id; - $cat['cat_id'] = $tr_cat_id; - convert_cat($cat); - } - set_auto_increment(BB_FORUMS, 'forum_id'); - print_ok ("Categories from TBDev converted"); - unset($cats); - - // Start of torrents converting - switch(TR_TYPE) - { - case 'yse': - $_sql = 'image1, image2, '; - break; - - case 'sky': - $_sql = 'poster, screenshot1, screenshot2, screenshot3, screenshot4, '; - break; - - default: - $_sql = ''; - break; - } - - $max_topic_id = (int) get_max_val(BB_TOPICS, 'topic_id'); - $max_post_id = (int) get_max_val(BB_POSTS, 'post_id'); - $max_attach_id = (int) get_max_val(BB_ATTACHMENTS, 'attach_id'); - - $torrents_count = (int) get_count(TB_TORRENTS_TABLE, 'id'); - $loops = (int) ceil($torrents_count / C_TORRENTS_PER_ONCE); - - for ($i = 0; $i < $loops; $i++) - { - $start = $i * C_TORRENTS_PER_ONCE; - $offset = C_TORRENTS_PER_ONCE; - $sql = " - SELECT - id, info_hash, name, filename, search_text, descr, $_sql - category, UNIX_TIMESTAMP(added) AS added, size, views, - UNIX_TIMESTAMP(last_action) AS lastseed, times_completed, owner, sticky - FROM ". TB_TORRENTS_TABLE ." - ORDER BY id - LIMIT $start, $offset"; - - $torrents = DB()->fetch_rowset($sql); - DB()->sql_freeresult(); - - foreach ($torrents as $torrent) - { - $torrent['topic_id'] = $torrent['id'] + $max_topic_id; - $torrent['post_id'] = $torrent['id'] + $max_post_id; - $torrent['attach_id'] = $torrent['id'] + $max_attach_id; - $torrent['owner'] += $max_uid; - $torrent['descr'] = append_images($torrent); - convert_torrent($torrent); - //print_r($torrent); - } - } - set_auto_increment(BB_TOPICS, 'topic_id'); - set_auto_increment(BB_POSTS, 'post_id'); - print_ok ("Total $torrents_count torrents from TBDev converted"); - unset($torrents); - - if (CONVERT_COMMENTS) - { - $max_post_id = (int) get_max_val(BB_POSTS, 'post_id'); - $max_topic_id = (int) get_max_val(BB_TOPICS, 'topic_id'); - $max_attach_id = (int) get_max_val(BB_ATTACHMENTS, 'attach_id'); - - $comments_count = (int) get_count(TB_COMMENTS_TABLE, 'id'); - $loops = (int) ceil($comments_count / C_COMMENTS_PER_ONCE); - - for ($i = 0; $i < $loops; $i++) - { - $start = $i * C_COMMENTS_PER_ONCE; - $offset = C_COMMENTS_PER_ONCE; - $sql = " - SELECT - c.id, c.user, c.torrent, c.text, tor.category, - UNIX_TIMESTAMP(c.added) AS added, UNIX_TIMESTAMP(c.editedat) AS editedat, c.ip - FROM ". TB_COMMENTS_TABLE ." c - LEFT JOIN ". TB_TORRENTS_TABLE ." tor ON(tor.id = c.torrent) - WHERE c.torrent <> 0 - ORDER BY c.id - LIMIT $start, $offset"; - - $comments = DB()->fetch_rowset($sql); - DB()->sql_freeresult(); - - foreach ($comments as $comment) - { - $comment['user'] += $max_uid; - $comment['id'] += $max_post_id; - convert_comment($comment); - } - } - unset($comments); - set_auto_increment(BB_POSTS, 'post_id'); - print_ok ("Total $comments_count comments from TBDev converted"); - } -} - -?> - -
        -Converting completed. - - +session_start(); + +if (!IS_ADMIN) die("Restricted access"); +while (@ob_end_flush()); +ob_implicit_flush(); + +error_reporting(E_ALL); +@ini_set('display_errors', 1); + +?> + + + + + + + + + + +
        +
        + +
        +
        + + '; + + exit; +} +else +{ + +@ini_set('memory_limit', '512M'); +@ini_set('max_execution_time', @ini_get('max_execution_time') + 1200); + +// Step 1: Converting Users +if (CONVERT_USERS) +{ + if (CLEAN) + { + tp_users_cleanup(); + print_ok ("Users cleared"); + } + + $max_uid = (int) get_max_val(BB_USERS, 'user_id'); + $max_uid = ($max_uid > 1) ? $max_uid : 1; + + $users_count = (int) get_count(TB_USERS_TABLE, 'id'); + $loops = (int) ceil($users_count / C_USERS_PER_ONCE); + $pass = array(); + + switch(TR_TYPE) + { + case 'yse': + $_sql = 'avatar, '; + break; + + default: + $_sql = ''; + break; + } + + for ($i = 0; $i < $loops; $i++) + { + $start = $i * C_USERS_PER_ONCE; + $offset = C_USERS_PER_ONCE; + + $sql = " + SELECT + id, username, email, status, UNIX_TIMESTAMP(added) AS added, UNIX_TIMESTAMP(last_access) AS last_access, + class, icq, msn, aim, yahoo, website, $_sql + uploaded, downloaded, enabled, language + FROM ". TB_USERS_TABLE ." + ORDER BY id + LIMIT $start, $offset"; + + $users = DB()->fetch_rowset($sql); + DB()->sql_freeresult(); + + foreach ($users as $user) + { + $user['id'] += $max_uid; + $user['password'] = make_rand_str(15); + convert_user($user); + $pass[] = array( + 'tb_user_id' => $user['id'] - $max_uid, + 'username' => $user['username'], + 'new_passwd' => $user['password'], + ); + } + } + $passf = fopen('./converter/passwords.php', 'w'); + $to_write = " $tr_cat_id, + "cat_title" => 'Tracker', + ); + tp_add_category($tp_cat_data); + set_auto_increment(BB_CATEGORIES, 'cat_id'); + unset($tp_cat_data); + + $cats = $db->fetch_rowset("SELECT id, sort, name FROM ". TB_CATEGORIES_TABLE); + DB()->sql_freeresult(); + + $max_forum_id = (int) get_max_val(BB_FORUMS, 'forum_id'); + + foreach ($cats as $cat) + { + $cat['id'] += $max_forum_id; + $cat['cat_id'] = $tr_cat_id; + convert_cat($cat); + } + set_auto_increment(BB_FORUMS, 'forum_id'); + print_ok ("Categories from TBDev converted"); + unset($cats); + + // Start of torrents converting + switch(TR_TYPE) + { + case 'yse': + $_sql = 'image1, image2, '; + break; + + case 'sky': + $_sql = 'poster, screenshot1, screenshot2, screenshot3, screenshot4, '; + break; + + default: + $_sql = ''; + break; + } + + $max_topic_id = (int) get_max_val(BB_TOPICS, 'topic_id'); + $max_post_id = (int) get_max_val(BB_POSTS, 'post_id'); + $max_attach_id = (int) get_max_val(BB_ATTACHMENTS, 'attach_id'); + + $torrents_count = (int) get_count(TB_TORRENTS_TABLE, 'id'); + $loops = (int) ceil($torrents_count / C_TORRENTS_PER_ONCE); + + for ($i = 0; $i < $loops; $i++) + { + $start = $i * C_TORRENTS_PER_ONCE; + $offset = C_TORRENTS_PER_ONCE; + $sql = " + SELECT + id, info_hash, name, filename, search_text, descr, $_sql + category, UNIX_TIMESTAMP(added) AS added, size, views, + UNIX_TIMESTAMP(last_action) AS lastseed, times_completed, owner, sticky + FROM ". TB_TORRENTS_TABLE ." + ORDER BY id + LIMIT $start, $offset"; + + $torrents = DB()->fetch_rowset($sql); + DB()->sql_freeresult(); + + foreach ($torrents as $torrent) + { + $torrent['topic_id'] = $torrent['id'] + $max_topic_id; + $torrent['post_id'] = $torrent['id'] + $max_post_id; + $torrent['attach_id'] = $torrent['id'] + $max_attach_id; + $torrent['owner'] += $max_uid; + $torrent['descr'] = append_images($torrent); + convert_torrent($torrent); + //print_r($torrent); + } + } + set_auto_increment(BB_TOPICS, 'topic_id'); + set_auto_increment(BB_POSTS, 'post_id'); + print_ok ("Total $torrents_count torrents from TBDev converted"); + unset($torrents); + + if (CONVERT_COMMENTS) + { + $max_post_id = (int) get_max_val(BB_POSTS, 'post_id'); + $max_topic_id = (int) get_max_val(BB_TOPICS, 'topic_id'); + $max_attach_id = (int) get_max_val(BB_ATTACHMENTS, 'attach_id'); + + $comments_count = (int) get_count(TB_COMMENTS_TABLE, 'id'); + $loops = (int) ceil($comments_count / C_COMMENTS_PER_ONCE); + + for ($i = 0; $i < $loops; $i++) + { + $start = $i * C_COMMENTS_PER_ONCE; + $offset = C_COMMENTS_PER_ONCE; + $sql = " + SELECT + c.id, c.user, c.torrent, c.text, tor.category, + UNIX_TIMESTAMP(c.added) AS added, UNIX_TIMESTAMP(c.editedat) AS editedat, c.ip + FROM ". TB_COMMENTS_TABLE ." c + LEFT JOIN ". TB_TORRENTS_TABLE ." tor ON(tor.id = c.torrent) + WHERE c.torrent <> 0 + ORDER BY c.id + LIMIT $start, $offset"; + + $comments = DB()->fetch_rowset($sql); + DB()->sql_freeresult(); + + foreach ($comments as $comment) + { + $comment['user'] += $max_uid; + $comment['id'] += $max_post_id; + convert_comment($comment); + } + } + unset($comments); + set_auto_increment(BB_POSTS, 'post_id'); + print_ok ("Total $comments_count comments from TBDev converted"); + } +} + +?> + +
        +Converting completed. + + \ No newline at end of file diff --git a/other/converter/TBDevYSE_pre6/root/converter/constants.php b/other/converter/TBDevYSE_pre6/root/converter/constants.php index 9fe8a9862..c1c7d0bd7 100644 --- a/other/converter/TBDevYSE_pre6/root/converter/constants.php +++ b/other/converter/TBDevYSE_pre6/root/converter/constants.php @@ -1,8 +1,8 @@ -session_start(); - -set_die_append_msg(); -if (!IS_SUPER_ADMIN) bb_die($lang['ONLY_FOR_SUPER_ADMIN']); - -$confirm = request_var('confirm', ''); - -if ($confirm) { - DB()->query(" - CREATE TABLE IF NOT EXISTS `bb_poll_users` ( - `topic_id` int(10) unsigned NOT NULL, - `user_id` int(11) NOT NULL, - `vote_ip` varchar(32) NOT NULL, - `vote_dt` int(11) NOT NULL DEFAULT '0', - PRIMARY KEY (`topic_id`,`user_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 - "); - - DB()->query(" - CREATE TABLE IF NOT EXISTS `bb_poll_votes` ( - `topic_id` int(10) unsigned NOT NULL, - `vote_id` tinyint(4) unsigned NOT NULL, - `vote_text` varchar(255) NOT NULL, - `vote_result` mediumint(8) unsigned NOT NULL, - PRIMARY KEY (`topic_id`,`vote_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 - "); - - DB()->query(" - INSERT IGNORE INTO bb_poll_votes - (topic_id, vote_id, vote_text, vote_result) - SELECT - topic_id, 0, vote_text, 0 - FROM bb_vote_desc; - "); - - DB()->query(" - INSERT IGNORE INTO bb_poll_votes - (topic_id, vote_id, vote_text, vote_result) - SELECT - d.topic_id, r.vote_option_id, r.vote_option_text, r.vote_result - FROM bb_vote_desc d, bb_vote_results r - WHERE - d.vote_id = r.vote_id; - "); - - DB()->query(" - INSERT IGNORE INTO bb_poll_users - (topic_id, user_id, vote_ip) - SELECT - d.topic_id, v.vote_user_id, v.vote_user_ip - FROM bb_vote_desc d, bb_vote_voters v - WHERE - d.vote_id = v.vote_id - AND v.vote_user_id > 0; - "); - - DB()->query("DROP TABLE IF EXISTS bb_vote_desc"); - DB()->query("DROP TABLE IF EXISTS bb_vote_results"); - DB()->query("DROP TABLE IF EXISTS bb_vote_voters"); - - bb_die('

        База данных обновлена

        '); -} else { - $msg = '
        '; - $msg .= '

        !!! Перед тем как нажать на кнопку, сделайте бекап базы данных !!!


        '; - $msg .= ''; - $msg .= '
        '; - - bb_die($msg); +session_start(); + +set_die_append_msg(); +if (!IS_SUPER_ADMIN) bb_die($lang['ONLY_FOR_SUPER_ADMIN']); + +$confirm = request_var('confirm', ''); + +if ($confirm) { + DB()->query(" + CREATE TABLE IF NOT EXISTS `bb_poll_users` ( + `topic_id` int(10) unsigned NOT NULL, + `user_id` int(11) NOT NULL, + `vote_ip` varchar(32) NOT NULL, + `vote_dt` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`topic_id`,`user_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 + "); + + DB()->query(" + CREATE TABLE IF NOT EXISTS `bb_poll_votes` ( + `topic_id` int(10) unsigned NOT NULL, + `vote_id` tinyint(4) unsigned NOT NULL, + `vote_text` varchar(255) NOT NULL, + `vote_result` mediumint(8) unsigned NOT NULL, + PRIMARY KEY (`topic_id`,`vote_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 + "); + + DB()->query(" + INSERT IGNORE INTO bb_poll_votes + (topic_id, vote_id, vote_text, vote_result) + SELECT + topic_id, 0, vote_text, 0 + FROM bb_vote_desc; + "); + + DB()->query(" + INSERT IGNORE INTO bb_poll_votes + (topic_id, vote_id, vote_text, vote_result) + SELECT + d.topic_id, r.vote_option_id, r.vote_option_text, r.vote_result + FROM bb_vote_desc d, bb_vote_results r + WHERE + d.vote_id = r.vote_id; + "); + + DB()->query(" + INSERT IGNORE INTO bb_poll_users + (topic_id, user_id, vote_ip) + SELECT + d.topic_id, v.vote_user_id, v.vote_user_ip + FROM bb_vote_desc d, bb_vote_voters v + WHERE + d.vote_id = v.vote_id + AND v.vote_user_id > 0; + "); + + DB()->query("DROP TABLE IF EXISTS bb_vote_desc"); + DB()->query("DROP TABLE IF EXISTS bb_vote_results"); + DB()->query("DROP TABLE IF EXISTS bb_vote_voters"); + + bb_die('

        База данных обновлена

        '); +} else { + $msg = '
        '; + $msg .= '

        !!! Перед тем как нажать на кнопку, сделайте бекап базы данных !!!


        '; + $msg .= ''; + $msg .= '
        '; + + bb_die($msg); } \ No newline at end of file diff --git a/upload/.htaccess b/upload/.htaccess index 19caff91d..dd1ef258a 100644 --- a/upload/.htaccess +++ b/upload/.htaccess @@ -1,9 +1,9 @@ -## Set charset server -AddDefaultCharset UTF-8 - -## Access control -Options All -Indexes - - -deny from all +## Set charset server +AddDefaultCharset UTF-8 + +## Access control +Options All -Indexes + + +deny from all \ No newline at end of file diff --git a/upload/admin/admin_attach_cp.php b/upload/admin/admin_attach_cp.php index 81cbc3147..c73e47d02 100644 --- a/upload/admin/admin_attach_cp.php +++ b/upload/admin/admin_attach_cp.php @@ -1,558 +1,558 @@ -'; - -for($i = 0; $i < count($view_types_text); $i++) -{ - $selected = ($view == $view_types[$i]) ? ' selected="selected"' : ''; - $select_view .= ''; -} -$select_view .= ''; - -if (count($mode_types_text) > 0) -{ - $select_sort_mode = ''; -} - -$select_sort_order = ''; - -$submit_change = ( isset($_POST['submit_change']) ) ? TRUE : FALSE; -$delete = ( isset($_POST['delete']) ) ? TRUE : FALSE; -$delete_id_list = get_var('delete_id_list', array(0)); - -$confirm = isset($_POST['confirm']); - -if ($confirm && sizeof($delete_id_list) > 0) -{ - $attachments = array(); - - delete_attachment(0, $delete_id_list); -} -else if ($delete && sizeof($delete_id_list) > 0) -{ - // Not confirmed, show confirmation message - $hidden_fields = ''; - $hidden_fields .= ''; - $hidden_fields .= ''; - $hidden_fields .= ''; - $hidden_fields .= ''; - - for ($i = 0; $i < sizeof($delete_id_list); $i++) - { - $hidden_fields .= ''; - } - - print_confirmation(array( - 'FORM_ACTION' => "admin_attach_cp.php", - 'HIDDEN_FIELDS' => $hidden_fields, - )); -} - -// Assign Default Template Vars -$template->assign_vars(array( - 'S_VIEW_SELECT' => $select_view, - 'S_MODE_ACTION' => 'admin_attach_cp.php', -)); - -if ($submit_change && $view == 'attachments') -{ - $attach_change_list = get_var('attach_id_list', array(0)); - $attach_comment_list = get_var('attach_comment_list', array('')); - $attach_download_count_list = get_var('attach_count_list', array(0)); - - // Generate correct Change List - $attachments = array(); - - for ($i = 0; $i < count($attach_change_list); $i++) - { - $attachments['_' . $attach_change_list[$i]]['comment'] = $attach_comment_list[$i]; - $attachments['_' . $attach_change_list[$i]]['download_count'] = $attach_download_count_list[$i]; - } - - $sql = 'SELECT * - FROM ' . BB_ATTACHMENTS_DESC . ' - ORDER BY attach_id'; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get attachment informations'); - } - - while ( $attachrow = DB()->sql_fetchrow($result) ) - { - if ( isset($attachments['_' . $attachrow['attach_id']]) ) - { - if ($attachrow['comment'] != $attachments['_' . $attachrow['attach_id']]['comment'] || $attachrow['download_count'] != $attachments['_' . $attachrow['attach_id']]['download_count']) - { - $sql = "UPDATE " . BB_ATTACHMENTS_DESC . " - SET comment = '" . attach_mod_sql_escape($attachments['_' . $attachrow['attach_id']]['comment']) . "', download_count = " . (int) $attachments['_' . $attachrow['attach_id']]['download_count'] . " - WHERE attach_id = " . (int) $attachrow['attach_id']; - - if (!DB()->sql_query($sql)) - { - bb_die('Could not update attachments informations'); - } - } - } - } - DB()->sql_freeresult($result); -} - -// Statistics -if ($view == 'stats') -{ - $upload_dir_size = get_formatted_dirsize(); - - $attachment_quota = humn_size($attach_config['attachment_quota']); - - // number_of_attachments - $row = DB()->fetch_row(" - SELECT COUNT(*) AS total FROM ". BB_ATTACHMENTS_DESC ." - "); - $number_of_attachments = $number_of_posts = $row['total']; - - $number_of_pms = 0; - - // number_of_topics - $row = DB()->fetch_row(" - SELECT COUNT(*) AS topics FROM ". BB_TOPICS ." WHERE topic_attachment = 1 - "); - $number_of_topics = $row['topics']; - - // number_of_users - $row = DB()->fetch_row(" - SELECT COUNT(DISTINCT user_id_1) AS users FROM ". BB_ATTACHMENTS ." WHERE post_id != 0 - "); - $number_of_users = $row['users']; - - $template->assign_vars(array( - 'TPL_ATTACH_STATISTICS' => true, - 'TOTAL_FILESIZE' => $upload_dir_size, - 'ATTACH_QUOTA' => $attachment_quota, - 'NUMBER_OF_ATTACHMENTS' => $number_of_attachments, - 'NUMBER_OF_POSTS' => $number_of_posts, - 'NUMBER_OF_PMS' => $number_of_pms, - 'NUMBER_OF_TOPICS' => $number_of_topics, - 'NUMBER_OF_USERS' => $number_of_users, - )); - -} - -// Search -if ($view == 'search') -{ - // Get Forums and Categories - //sf - add [, f.forum_parent] - $sql = "SELECT c.cat_title, c.cat_id, f.forum_name, f.forum_id, f.forum_parent - FROM " . BB_CATEGORIES . " c, " . BB_FORUMS . " f - WHERE f.cat_id = c.cat_id - ORDER BY c.cat_id, f.forum_order"; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not obtain forum_name / forum_id'); - } - - $s_forums = ''; - while ($row = DB()->sql_fetchrow($result)) - { //sf - $s_forums .= ''; - - if( empty($list_cat[$row['cat_id']]) ) - { - $list_cat[$row['cat_id']] = $row['cat_title']; - } - } - - if( $s_forums != '' ) - { - $s_forums = '' . $s_forums; - - // Category to search - $s_categories = ''; - - foreach ($list_cat as $cat_id => $cat_title) - { - $s_categories .= ''; - } - } - else - { - bb_die($lang['NO_SEARCHABLE_FORUMS']); - } - - $template->assign_vars(array( - 'TPL_ATTACH_SEARCH' => true, - 'S_FORUM_OPTIONS' => $s_forums, - 'S_CATEGORY_OPTIONS' => $s_categories, - 'S_SORT_OPTIONS' => $select_sort_mode, - 'S_SORT_ORDER' => $select_sort_order, - )); -} - -// Username -if ($view == 'username') -{ - $template->assign_vars(array( - 'TPL_ATTACH_USER' => true, - 'S_MODE_SELECT' => $select_sort_mode, - 'S_ORDER_SELECT' => $select_sort_order, - )); - $total_rows = 0; - bb_die('removed'); -} - -// Attachments -if ($view == 'attachments') -{ - $user_based = ($uid) ? TRUE : FALSE; - $search_based = (isset($_POST['search']) && $_POST['search']) ? TRUE : FALSE; - - $hidden_fields = ''; - - $template->assign_vars(array( - 'TPL_ATTACH_ATTACHMENTS' => true, - 'S_MODE_SELECT' => $select_sort_mode, - 'S_ORDER_SELECT' => $select_sort_order, - )); - - $total_rows = 0; - - // Are we called from Username ? - if ($user_based) - { - $sql = "SELECT username FROM " . BB_USERS . " WHERE user_id = " . intval($uid); - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Error getting username'); - } - - $row = DB()->sql_fetchrow($result); - DB()->sql_freeresult($result); - $username = $row['username']; - - $s_hidden = ''; - - $template->assign_block_vars('switch_user_based', array()); - - $template->assign_vars(array( - 'S_USER_HIDDEN' => $s_hidden, - 'L_STATISTICS_FOR_USER' => sprintf($lang['STATISTICS_FOR_USER'], $username), - )); - - $sql = "SELECT attach_id - FROM " . BB_ATTACHMENTS . " - WHERE user_id_1 = " . intval($uid) . " - GROUP BY attach_id"; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not query attachments #1'); - } - - $attach_ids = DB()->sql_fetchrowset($result); - $num_attach_ids = DB()->num_rows($result); - DB()->sql_freeresult($result); - - if ($num_attach_ids == 0) - { - bb_die('For some reason no attachments are assigned to the user ' . $username); - } - - $total_rows = $num_attach_ids; - - $attach_id = array(); - - for ($j = 0; $j < $num_attach_ids; $j++) - { - $attach_id[] = intval($attach_ids[$j]['attach_id']); - } - - $sql = "SELECT a.* - FROM " . BB_ATTACHMENTS_DESC . " a - WHERE a.attach_id IN (" . implode(', ', $attach_id) . ") " . - $order_by; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not query attachments #2'); - } - - $attachments = DB()->sql_fetchrowset($result); - $num_attach = DB()->num_rows($result); - DB()->sql_freeresult($result); - } - else - { - // we are called from search - $attachments = search_attachments($order_by, $total_rows); - } - - if (sizeof($attachments) > 0) - { - for ($i = 0; $i < sizeof($attachments); $i++) - { - $delete_box = ''; - - for ($j = 0; $j < count($delete_id_list); $j++) - { - if ($delete_id_list[$j] == $attachments[$i]['attach_id']) - { - $delete_box = ''; - break; - } - } - - $row_class = !($i % 2) ? 'row1' : 'row2'; - - // Is the Attachment assigned to more than one post ? - // If it's not assigned to any post, it's an private message thingy. ;) - $post_titles = array(); - - $sql = "SELECT * - FROM " . BB_ATTACHMENTS . " - WHERE attach_id = " . intval($attachments[$i]['attach_id']); - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not query attachments #3'); - } - - $ids = DB()->sql_fetchrowset($result); - $num_ids = DB()->num_rows($result); - DB()->sql_freeresult($result); - - for ($j = 0; $j < $num_ids; $j++) - { - if ($ids[$j]['post_id'] != 0) - { - $sql = "SELECT t.topic_title - FROM " . BB_TOPICS . " t, " . BB_POSTS . " p - WHERE p.post_id = " . intval($ids[$j]['post_id']) . " AND p.topic_id = t.topic_id - GROUP BY t.topic_id, t.topic_title"; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not query topic'); - } - - $row = DB()->sql_fetchrow($result); - DB()->sql_freeresult($result); - $post_title = $row['topic_title']; - - if (strlen($post_title) > 32) - { - $post_title = str_short($post_title, 30); - } - - $view_topic = BB_ROOT . 'viewtopic.php?' . POST_POST_URL . '=' . $ids[$j]['post_id'] . '#' . $ids[$j]['post_id']; - - $post_titles[] = '' . $post_title . ''; - } - else - { - $post_titles[] = $lang['PRIVATE_MESSAGE']; - } - } - - $post_titles = implode('
        ', $post_titles); - - $hidden_field = ''; - - $template->assign_block_vars('attachrow', array( - 'ROW_NUMBER' => $i + ( @$_GET['start'] + 1 ), - 'ROW_CLASS' => $row_class, - - 'FILENAME' => htmlspecialchars($attachments[$i]['real_filename']), - 'COMMENT' => htmlspecialchars($attachments[$i]['comment']), - 'EXTENSION' => $attachments[$i]['extension'], - 'SIZE' => round(($attachments[$i]['filesize'] / 1024), 2), - 'DOWNLOAD_COUNT' => $attachments[$i]['download_count'], - 'POST_TIME' => bb_date($attachments[$i]['filetime']), - 'POST_TITLE' => $post_titles, - - 'S_DELETE_BOX' => $delete_box, - 'S_HIDDEN' => $hidden_field, - 'U_VIEW_ATTACHMENT' => BB_ROOT . 'download.php?id=' . $attachments[$i]['attach_id'], - )); - - } - } - - if (!$search_based && !$user_based) - { - if ($total_attachments == 0) - { - $sql = "SELECT attach_id FROM " . BB_ATTACHMENTS_DESC; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not query attachment description table'); - } - - $total_rows = DB()->num_rows($result); - DB()->sql_freeresult($result); - } - } -} - -// Generate Pagination -if ($do_pagination && $total_rows > $bb_cfg['topics_per_page']) -{ - generate_pagination('admin_attach_cp.php?view=' . $view . '&mode=' . $mode . '&order=' . $sort_order . '&uid=' . $uid, $total_rows, $bb_cfg['topics_per_page'], $start).' '; -} - +'; + +for($i = 0; $i < count($view_types_text); $i++) +{ + $selected = ($view == $view_types[$i]) ? ' selected="selected"' : ''; + $select_view .= ''; +} +$select_view .= ''; + +if (count($mode_types_text) > 0) +{ + $select_sort_mode = ''; +} + +$select_sort_order = ''; + +$submit_change = ( isset($_POST['submit_change']) ) ? TRUE : FALSE; +$delete = ( isset($_POST['delete']) ) ? TRUE : FALSE; +$delete_id_list = get_var('delete_id_list', array(0)); + +$confirm = isset($_POST['confirm']); + +if ($confirm && sizeof($delete_id_list) > 0) +{ + $attachments = array(); + + delete_attachment(0, $delete_id_list); +} +else if ($delete && sizeof($delete_id_list) > 0) +{ + // Not confirmed, show confirmation message + $hidden_fields = ''; + $hidden_fields .= ''; + $hidden_fields .= ''; + $hidden_fields .= ''; + $hidden_fields .= ''; + + for ($i = 0; $i < sizeof($delete_id_list); $i++) + { + $hidden_fields .= ''; + } + + print_confirmation(array( + 'FORM_ACTION' => "admin_attach_cp.php", + 'HIDDEN_FIELDS' => $hidden_fields, + )); +} + +// Assign Default Template Vars +$template->assign_vars(array( + 'S_VIEW_SELECT' => $select_view, + 'S_MODE_ACTION' => 'admin_attach_cp.php', +)); + +if ($submit_change && $view == 'attachments') +{ + $attach_change_list = get_var('attach_id_list', array(0)); + $attach_comment_list = get_var('attach_comment_list', array('')); + $attach_download_count_list = get_var('attach_count_list', array(0)); + + // Generate correct Change List + $attachments = array(); + + for ($i = 0; $i < count($attach_change_list); $i++) + { + $attachments['_' . $attach_change_list[$i]]['comment'] = $attach_comment_list[$i]; + $attachments['_' . $attach_change_list[$i]]['download_count'] = $attach_download_count_list[$i]; + } + + $sql = 'SELECT * + FROM ' . BB_ATTACHMENTS_DESC . ' + ORDER BY attach_id'; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get attachment informations'); + } + + while ( $attachrow = DB()->sql_fetchrow($result) ) + { + if ( isset($attachments['_' . $attachrow['attach_id']]) ) + { + if ($attachrow['comment'] != $attachments['_' . $attachrow['attach_id']]['comment'] || $attachrow['download_count'] != $attachments['_' . $attachrow['attach_id']]['download_count']) + { + $sql = "UPDATE " . BB_ATTACHMENTS_DESC . " + SET comment = '" . attach_mod_sql_escape($attachments['_' . $attachrow['attach_id']]['comment']) . "', download_count = " . (int) $attachments['_' . $attachrow['attach_id']]['download_count'] . " + WHERE attach_id = " . (int) $attachrow['attach_id']; + + if (!DB()->sql_query($sql)) + { + bb_die('Could not update attachments informations'); + } + } + } + } + DB()->sql_freeresult($result); +} + +// Statistics +if ($view == 'stats') +{ + $upload_dir_size = get_formatted_dirsize(); + + $attachment_quota = humn_size($attach_config['attachment_quota']); + + // number_of_attachments + $row = DB()->fetch_row(" + SELECT COUNT(*) AS total FROM ". BB_ATTACHMENTS_DESC ." + "); + $number_of_attachments = $number_of_posts = $row['total']; + + $number_of_pms = 0; + + // number_of_topics + $row = DB()->fetch_row(" + SELECT COUNT(*) AS topics FROM ". BB_TOPICS ." WHERE topic_attachment = 1 + "); + $number_of_topics = $row['topics']; + + // number_of_users + $row = DB()->fetch_row(" + SELECT COUNT(DISTINCT user_id_1) AS users FROM ". BB_ATTACHMENTS ." WHERE post_id != 0 + "); + $number_of_users = $row['users']; + + $template->assign_vars(array( + 'TPL_ATTACH_STATISTICS' => true, + 'TOTAL_FILESIZE' => $upload_dir_size, + 'ATTACH_QUOTA' => $attachment_quota, + 'NUMBER_OF_ATTACHMENTS' => $number_of_attachments, + 'NUMBER_OF_POSTS' => $number_of_posts, + 'NUMBER_OF_PMS' => $number_of_pms, + 'NUMBER_OF_TOPICS' => $number_of_topics, + 'NUMBER_OF_USERS' => $number_of_users, + )); + +} + +// Search +if ($view == 'search') +{ + // Get Forums and Categories + //sf - add [, f.forum_parent] + $sql = "SELECT c.cat_title, c.cat_id, f.forum_name, f.forum_id, f.forum_parent + FROM " . BB_CATEGORIES . " c, " . BB_FORUMS . " f + WHERE f.cat_id = c.cat_id + ORDER BY c.cat_id, f.forum_order"; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not obtain forum_name / forum_id'); + } + + $s_forums = ''; + while ($row = DB()->sql_fetchrow($result)) + { //sf + $s_forums .= ''; + + if( empty($list_cat[$row['cat_id']]) ) + { + $list_cat[$row['cat_id']] = $row['cat_title']; + } + } + + if( $s_forums != '' ) + { + $s_forums = '' . $s_forums; + + // Category to search + $s_categories = ''; + + foreach ($list_cat as $cat_id => $cat_title) + { + $s_categories .= ''; + } + } + else + { + bb_die($lang['NO_SEARCHABLE_FORUMS']); + } + + $template->assign_vars(array( + 'TPL_ATTACH_SEARCH' => true, + 'S_FORUM_OPTIONS' => $s_forums, + 'S_CATEGORY_OPTIONS' => $s_categories, + 'S_SORT_OPTIONS' => $select_sort_mode, + 'S_SORT_ORDER' => $select_sort_order, + )); +} + +// Username +if ($view == 'username') +{ + $template->assign_vars(array( + 'TPL_ATTACH_USER' => true, + 'S_MODE_SELECT' => $select_sort_mode, + 'S_ORDER_SELECT' => $select_sort_order, + )); + $total_rows = 0; + bb_die('removed'); +} + +// Attachments +if ($view == 'attachments') +{ + $user_based = ($uid) ? TRUE : FALSE; + $search_based = (isset($_POST['search']) && $_POST['search']) ? TRUE : FALSE; + + $hidden_fields = ''; + + $template->assign_vars(array( + 'TPL_ATTACH_ATTACHMENTS' => true, + 'S_MODE_SELECT' => $select_sort_mode, + 'S_ORDER_SELECT' => $select_sort_order, + )); + + $total_rows = 0; + + // Are we called from Username ? + if ($user_based) + { + $sql = "SELECT username FROM " . BB_USERS . " WHERE user_id = " . intval($uid); + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Error getting username'); + } + + $row = DB()->sql_fetchrow($result); + DB()->sql_freeresult($result); + $username = $row['username']; + + $s_hidden = ''; + + $template->assign_block_vars('switch_user_based', array()); + + $template->assign_vars(array( + 'S_USER_HIDDEN' => $s_hidden, + 'L_STATISTICS_FOR_USER' => sprintf($lang['STATISTICS_FOR_USER'], $username), + )); + + $sql = "SELECT attach_id + FROM " . BB_ATTACHMENTS . " + WHERE user_id_1 = " . intval($uid) . " + GROUP BY attach_id"; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not query attachments #1'); + } + + $attach_ids = DB()->sql_fetchrowset($result); + $num_attach_ids = DB()->num_rows($result); + DB()->sql_freeresult($result); + + if ($num_attach_ids == 0) + { + bb_die('For some reason no attachments are assigned to the user ' . $username); + } + + $total_rows = $num_attach_ids; + + $attach_id = array(); + + for ($j = 0; $j < $num_attach_ids; $j++) + { + $attach_id[] = intval($attach_ids[$j]['attach_id']); + } + + $sql = "SELECT a.* + FROM " . BB_ATTACHMENTS_DESC . " a + WHERE a.attach_id IN (" . implode(', ', $attach_id) . ") " . + $order_by; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not query attachments #2'); + } + + $attachments = DB()->sql_fetchrowset($result); + $num_attach = DB()->num_rows($result); + DB()->sql_freeresult($result); + } + else + { + // we are called from search + $attachments = search_attachments($order_by, $total_rows); + } + + if (sizeof($attachments) > 0) + { + for ($i = 0; $i < sizeof($attachments); $i++) + { + $delete_box = ''; + + for ($j = 0; $j < count($delete_id_list); $j++) + { + if ($delete_id_list[$j] == $attachments[$i]['attach_id']) + { + $delete_box = ''; + break; + } + } + + $row_class = !($i % 2) ? 'row1' : 'row2'; + + // Is the Attachment assigned to more than one post ? + // If it's not assigned to any post, it's an private message thingy. ;) + $post_titles = array(); + + $sql = "SELECT * + FROM " . BB_ATTACHMENTS . " + WHERE attach_id = " . intval($attachments[$i]['attach_id']); + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not query attachments #3'); + } + + $ids = DB()->sql_fetchrowset($result); + $num_ids = DB()->num_rows($result); + DB()->sql_freeresult($result); + + for ($j = 0; $j < $num_ids; $j++) + { + if ($ids[$j]['post_id'] != 0) + { + $sql = "SELECT t.topic_title + FROM " . BB_TOPICS . " t, " . BB_POSTS . " p + WHERE p.post_id = " . intval($ids[$j]['post_id']) . " AND p.topic_id = t.topic_id + GROUP BY t.topic_id, t.topic_title"; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not query topic'); + } + + $row = DB()->sql_fetchrow($result); + DB()->sql_freeresult($result); + $post_title = $row['topic_title']; + + if (strlen($post_title) > 32) + { + $post_title = str_short($post_title, 30); + } + + $view_topic = BB_ROOT . 'viewtopic.php?' . POST_POST_URL . '=' . $ids[$j]['post_id'] . '#' . $ids[$j]['post_id']; + + $post_titles[] = '' . $post_title . ''; + } + else + { + $post_titles[] = $lang['PRIVATE_MESSAGE']; + } + } + + $post_titles = implode('
        ', $post_titles); + + $hidden_field = ''; + + $template->assign_block_vars('attachrow', array( + 'ROW_NUMBER' => $i + ( @$_GET['start'] + 1 ), + 'ROW_CLASS' => $row_class, + + 'FILENAME' => htmlspecialchars($attachments[$i]['real_filename']), + 'COMMENT' => htmlspecialchars($attachments[$i]['comment']), + 'EXTENSION' => $attachments[$i]['extension'], + 'SIZE' => round(($attachments[$i]['filesize'] / 1024), 2), + 'DOWNLOAD_COUNT' => $attachments[$i]['download_count'], + 'POST_TIME' => bb_date($attachments[$i]['filetime']), + 'POST_TITLE' => $post_titles, + + 'S_DELETE_BOX' => $delete_box, + 'S_HIDDEN' => $hidden_field, + 'U_VIEW_ATTACHMENT' => BB_ROOT . 'download.php?id=' . $attachments[$i]['attach_id'], + )); + + } + } + + if (!$search_based && !$user_based) + { + if ($total_attachments == 0) + { + $sql = "SELECT attach_id FROM " . BB_ATTACHMENTS_DESC; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not query attachment description table'); + } + + $total_rows = DB()->num_rows($result); + DB()->sql_freeresult($result); + } + } +} + +// Generate Pagination +if ($do_pagination && $total_rows > $bb_cfg['topics_per_page']) +{ + generate_pagination('admin_attach_cp.php?view=' . $view . '&mode=' . $mode . '&order=' . $sort_order . '&uid=' . $uid, $total_rows, $bb_cfg['topics_per_page'], $start).' '; +} + print_page('admin_attach_cp.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_attachments.php b/upload/admin/admin_attachments.php index 5cd8fb47d..9550e5db6 100644 --- a/upload/admin/admin_attachments.php +++ b/upload/admin/admin_attachments.php @@ -1,721 +1,721 @@ -sql_query($sql)) -{ - bb_die('Could not find attachment config table #1'); -} - -while ($row = DB()->sql_fetchrow($result)) -{ - $config_name = $row['config_name']; - $config_value = $row['config_value']; - - $new_attach[$config_name] = get_var($config_name, trim($attach_config[$config_name])); - - if (!$size && !$submit && $config_name == 'max_filesize') - { - $size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b'); - } - - if (!$quota_size && !$submit && $config_name == 'attachment_quota') - { - $quota_size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b'); - } - - if (!$pm_size && !$submit && $config_name == 'max_filesize_pm') - { - $pm_size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b'); - } - - if (!$submit && ($config_name == 'max_filesize' || $config_name == 'attachment_quota' || $config_name == 'max_filesize_pm')) - { - if ($new_attach[$config_name] >= 1048576) - { - $new_attach[$config_name] = round($new_attach[$config_name] / 1048576 * 100) / 100; - } - else if ($new_attach[$config_name] >= 1024) - { - $new_attach[$config_name] = round($new_attach[$config_name] / 1024 * 100) / 100; - } - } - - if ( $submit && ( $mode == 'manage' || $mode == 'cats') ) - { - if ($config_name == 'max_filesize') - { - $old = $new_attach[$config_name]; - $new_attach[$config_name] = ( $size == 'kb' ) ? round($new_attach[$config_name] * 1024) : ( ($size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name] ); - } - - if ($config_name == 'attachment_quota') - { - $old = $new_attach[$config_name]; - $new_attach[$config_name] = ( $quota_size == 'kb' ) ? round($new_attach[$config_name] * 1024) : ( ($quota_size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name] ); - } - - if ($config_name == 'max_filesize_pm') - { - $old = $new_attach[$config_name]; - $new_attach[$config_name] = ( $pm_size == 'kb' ) ? round($new_attach[$config_name] * 1024) : ( ($pm_size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name] ); - } - - if ($config_name == 'max_filesize') - { - $old_size = $attach_config[$config_name]; - $new_size = $new_attach[$config_name]; - - if ($old_size != $new_size) - { - // See, if we have a similar value of old_size in Mime Groups. If so, update these values. - $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . ' - SET max_filesize = ' . (int) $new_size . ' - WHERE max_filesize = ' . (int) $old_size; - - if (!($result_2 = DB()->sql_query($sql))) - { - bb_die('Could not update extension group information'); - } - - } - - $sql = "UPDATE " . BB_ATTACH_CONFIG . " - SET config_value = '" . attach_mod_sql_escape($new_attach[$config_name]) . "' - WHERE config_name = '" . attach_mod_sql_escape($config_name) . "'"; - } - else - { - $sql = "UPDATE " . BB_ATTACH_CONFIG . " - SET config_value = '" . attach_mod_sql_escape($new_attach[$config_name]) . "' - WHERE config_name = '" . attach_mod_sql_escape($config_name) . "'"; - } - - if (!DB()->sql_query($sql)) - { - bb_die('Failed to update attachment configuration for ' . $config_name); - } - - if ($config_name == 'max_filesize' || $config_name == 'attachment_quota' || $config_name == 'max_filesize_pm') - { - $new_attach[$config_name] = $old; - } - } -} -DB()->sql_freeresult($result); - -// Clear cached config -CACHE('bb_cache')->rm('attach_config'); - -$select_size_mode = size_select('size', $size); -$select_quota_size_mode = size_select('quota_size', $quota_size); -$select_pm_size_mode = size_select('pm_size', $pm_size); - -// Search Imagick -if ($search_imagick) -{ - $imagick = ''; - - if (preg_match('/convert/i', $imagick)) - { - return true; - } - else if ($imagick != 'none') - { - if (!preg_match('/WIN/i', PHP_OS)) - { - $retval = @exec('whereis convert'); - $paths = explode(' ', $retval); - - if (is_array($paths)) - { - for ( $i=0; $i < sizeof($paths); $i++) - { - $path = basename($paths[$i]); - - if ($path == 'convert') - { - $imagick = $paths[$i]; - } - } - } - } - else if (preg_match('/WIN/i', PHP_OS)) - { - $path = 'c:/imagemagick/convert.exe'; - - if ( !@file_exists(@amod_realpath($path))) - { - $imagick = $path; - } - } - } - - if ( !@file_exists(@amod_realpath(trim($imagick)))) - { - $new_attach['img_imagick'] = trim($imagick); - } - else - { - $new_attach['img_imagick'] = ''; - } -} - -// Check Settings -if ($check_upload) -{ - // Some tests... - $attach_config = array(); - - $sql = 'SELECT * FROM ' . BB_ATTACH_CONFIG; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not find attachment config table #2'); - } - - $row = DB()->sql_fetchrowset($result); - $num_rows = DB()->num_rows($result); - DB()->sql_freeresult($result); - - for ($i = 0; $i < $num_rows; $i++) - { - $attach_config[$row[$i]['config_name']] = trim($row[$i]['config_value']); - } - - if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':')) - { - $upload_dir = $attach_config['upload_dir']; - } - else - { - $upload_dir = BB_ROOT . $attach_config['upload_dir']; - } - - $error = false; - - // Does the target directory exist, is it a directory and writeable - if ( !@file_exists(@amod_realpath($upload_dir)) ) - { - $error = true; - $error_msg = sprintf($lang['DIRECTORY_DOES_NOT_EXIST'], $attach_config['upload_dir']) . '
        '; - } - - if (!$error && !is_dir($upload_dir)) - { - $error = TRUE; - $error_msg = sprintf($lang['DIRECTORY_IS_NOT_A_DIR'], $attach_config['upload_dir']) . '
        '; - } - - if (!$error) - { - if ( !($fp = @fopen($upload_dir . '/0_000000.000', 'w')) ) - { - $error = TRUE; - $error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $attach_config['upload_dir']) . '
        '; - } - else - { - @fclose($fp); - unlink_attach($upload_dir . '/0_000000.000'); - } - } - - if (!$error) - { - bb_die($lang['TEST_SETTINGS_SUCCESSFUL'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - } -} - -// Management -if ($submit && $mode == 'manage') -{ - if (!$error) - { - bb_die($lang['ATTACH_CONFIG_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - } -} - -if ($mode == 'manage') -{ - $yes_no_switches = array('disable_mod', 'allow_pm_attach', 'display_order'); - - for ($i = 0; $i < sizeof($yes_no_switches); $i++) - { - eval("\$" . $yes_no_switches[$i] . "_yes = ( \$new_attach['" . $yes_no_switches[$i] . "'] != '0' ) ? 'checked=\"checked\"' : '';"); - eval("\$" . $yes_no_switches[$i] . "_no = ( \$new_attach['" . $yes_no_switches[$i] . "'] == '0' ) ? 'checked=\"checked\"' : '';"); - } - - $template->assign_vars(array( - 'TPL_ATTACH_MANAGE' => true, - 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=manage', - 'S_FILESIZE' => $select_size_mode, - 'S_FILESIZE_QUOTA' => $select_quota_size_mode, - 'S_FILESIZE_PM' => $select_pm_size_mode, - 'S_DEFAULT_UPLOAD_LIMIT' => default_quota_limit_select('default_upload_quota', intval(trim($new_attach['default_upload_quota']))), - 'S_DEFAULT_PM_LIMIT' => default_quota_limit_select('default_pm_quota', intval(trim($new_attach['default_pm_quota']))), - - 'UPLOAD_DIR' => $new_attach['upload_dir'], - 'ATTACHMENT_IMG_PATH' => $new_attach['upload_img'], - 'TOPIC_ICON' => $new_attach['topic_icon'], - 'MAX_FILESIZE' => $new_attach['max_filesize'], - 'ATTACHMENT_QUOTA' => $new_attach['attachment_quota'], - 'MAX_FILESIZE_PM' => $new_attach['max_filesize_pm'], - 'MAX_ATTACHMENTS' => $new_attach['max_attachments'], - 'MAX_ATTACHMENTS_PM' => $new_attach['max_attachments_pm'], - 'DISABLE_MOD_YES' => $disable_mod_yes, - 'DISABLE_MOD_NO' => $disable_mod_no, - 'PM_ATTACH_YES' => $allow_pm_attach_yes, - 'PM_ATTACH_NO' => $allow_pm_attach_no, - 'DISPLAY_ORDER_ASC' => $display_order_yes, - 'DISPLAY_ORDER_DESC' => $display_order_no, - )); -} - -if ($submit && $mode == 'cats') -{ - if (!$error) - { - bb_die($lang['ATTACH_CONFIG_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - } -} - -if ($mode == 'cats') -{ - $s_assigned_group_images = $lang['NONE']; - - $sql = 'SELECT group_name, cat_id FROM ' . BB_EXTENSION_GROUPS . ' WHERE cat_id > 0 ORDER BY cat_id'; - - $s_assigned_group_images = array(); - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get group names from ' . BB_EXTENSION_GROUPS); - } - - $row = DB()->sql_fetchrowset($result); - DB()->sql_freeresult($result); - - for ($i = 0; $i < sizeof($row); $i++) - { - if ($row[$i]['cat_id'] == IMAGE_CAT) - { - $s_assigned_group_images[] = $row[$i]['group_name']; - } - } - - $display_inlined_yes = ( $new_attach['img_display_inlined'] != '0' ) ? 'checked="checked"' : ''; - $display_inlined_no = ( $new_attach['img_display_inlined'] == '0' ) ? 'checked="checked"' : ''; - - $create_thumbnail_yes = ( $new_attach['img_create_thumbnail'] != '0' ) ? 'checked="checked"' : ''; - $create_thumbnail_no = ( $new_attach['img_create_thumbnail'] == '0' ) ? 'checked="checked"' : ''; - - $use_gd2_yes = ( $new_attach['use_gd2'] != '0' ) ? 'checked="checked"' : ''; - $use_gd2_no = ( $new_attach['use_gd2'] == '0' ) ? 'checked="checked"' : ''; - - // Check Thumbnail Support - if (!is_imagick() && !@extension_loaded('gd')) - { - $new_attach['img_create_thumbnail'] = '0'; - } - else - { - $template->assign_block_vars('switch_thumbnail_support', array()); - } - - $template->assign_vars(array( - 'TPL_ATTACH_SPECIAL_CATEGORIES' => true, - 'IMAGE_MAX_HEIGHT' => $new_attach['img_max_height'], - 'IMAGE_MAX_WIDTH' => $new_attach['img_max_width'], - 'IMAGE_LINK_HEIGHT' => $new_attach['img_link_height'], - 'IMAGE_LINK_WIDTH' => $new_attach['img_link_width'], - 'IMAGE_MIN_THUMB_FILESIZE' => $new_attach['img_min_thumb_filesize'], - 'IMAGE_IMAGICK_PATH' => $new_attach['img_imagick'], - 'DISPLAY_INLINED_YES' => $display_inlined_yes, - 'DISPLAY_INLINED_NO' => $display_inlined_no, - 'CREATE_THUMBNAIL_YES' => $create_thumbnail_yes, - 'CREATE_THUMBNAIL_NO' => $create_thumbnail_no, - 'USE_GD2_YES' => $use_gd2_yes, - 'USE_GD2_NO' => $use_gd2_no, - 'S_ASSIGNED_GROUP_IMAGES' => implode(', ', $s_assigned_group_images), - 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=cats', - )); -} - -// Check Cat Settings -if ($check_image_cat) -{ - // Some tests... - $attach_config = array(); - - $sql = 'SELECT * FROM ' . BB_ATTACH_CONFIG; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not find attachment config table #3'); - } - - $row = DB()->sql_fetchrowset($result); - $num_rows = DB()->num_rows($result); - DB()->sql_freeresult($result); - - for ($i = 0; $i < $num_rows; $i++) - { - $attach_config[$row[$i]['config_name']] = trim($row[$i]['config_value']); - } - - if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':')) - { - $upload_dir = $attach_config['upload_dir']; - } - else - { - $upload_dir = BB_ROOT . $attach_config['upload_dir']; - } - - $upload_dir = $upload_dir . '/' . THUMB_DIR; - - $error = false; - - // Does the target directory exist, is it a directory and writeable - if ( !@file_exists(@amod_realpath($upload_dir)) ) - { - @mkdir($upload_dir, 0755); - @chmod($upload_dir, 0777); - - if ( !@file_exists(@amod_realpath($upload_dir)) ) - { - $error = TRUE; - $error_msg = sprintf($lang['DIRECTORY_DOES_NOT_EXIST'], $upload_dir) . '
        '; - } - } - - if (!$error && !is_dir($upload_dir)) - { - $error = TRUE; - $error_msg = sprintf($lang['DIRECTORY_IS_NOT_A_DIR'], $upload_dir) . '
        '; - } - - if (!$error) - { - if ( !($fp = @fopen($upload_dir . '/0_000000.000', 'w')) ) - { - $error = TRUE; - $error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $upload_dir) . '
        '; - } - else - { - @fclose($fp); - @unlink($upload_dir . '/0_000000.000'); - } - } - - if (!$error) - { - bb_die($lang['TEST_SETTINGS_SUCCESSFUL'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - } -} - -// Quota Limit Settings -if ($submit && $mode == 'quota') -{ - // Change Quota Limit - $quota_change_list = get_var('quota_change_list', array(0)); - $quota_desc_list = get_var('quota_desc_list', array('')); - $filesize_list = get_var('max_filesize_list', array(0)); - $size_select_list = get_var('size_select_list', array('')); - - $allowed_list = array(); - - for ($i = 0; $i < sizeof($quota_change_list); $i++) - { - $filesize_list[$i] = ( $size_select_list[$i] == 'kb' ) ? round($filesize_list[$i] * 1024) : ( ($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i] ); - - $sql = 'UPDATE ' . BB_QUOTA_LIMITS . " - SET quota_desc = '" . attach_mod_sql_escape($quota_desc_list[$i]) . "', quota_limit = " . (int) $filesize_list[$i] . " - WHERE quota_limit_id = " . (int) $quota_change_list[$i]; - - if (!(DB()->sql_query($sql))) - { - bb_die('Could not update quota limits'); - } - } - - // Delete Quota Limits - $quota_id_list = get_var('quota_id_list', array(0)); - - $quota_id_sql = implode(', ', $quota_id_list); - - if ($quota_id_sql != '') - { - $sql = 'DELETE FROM ' . BB_QUOTA_LIMITS . ' WHERE quota_limit_id IN (' . $quota_id_sql . ')'; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not delete quota limits'); - } - - // Delete Quotas linked to this setting - $sql = 'DELETE FROM ' . BB_QUOTA . ' WHERE quota_limit_id IN (' . $quota_id_sql . ')'; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not delete quotas'); - } - } - - // Add Quota Limit ? - $quota_desc = get_var('quota_description', ''); - $filesize = get_var('add_max_filesize', 0); - $size_select = get_var('add_size_select', ''); - $add = ( isset($_POST['add_quota_check']) ) ? TRUE : FALSE; - - if ($quota_desc != '' && $add) - { - // check Quota Description - $sql = 'SELECT quota_desc FROM ' . BB_QUOTA_LIMITS; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not query quota limits table'); - } - - $row = DB()->sql_fetchrowset($result); - $num_rows = DB()->num_rows($result); - DB()->sql_freeresult($result); - - if ( $num_rows > 0 ) - { - for ($i = 0; $i < $num_rows; $i++) - { - if ($row[$i]['quota_desc'] == $quota_desc) - { - $error = TRUE; - if( isset($error_msg) ) - { - $error_msg .= '
        '; - } - $error_msg .= sprintf($lang['QUOTA_LIMIT_EXIST'], $extension_group); - } - } - } - - if (!$error) - { - $filesize = ( $size_select == 'kb' ) ? round($filesize * 1024) : ( ($size_select == 'mb') ? round($filesize * 1048576) : $filesize ); - - $sql = "INSERT INTO " . BB_QUOTA_LIMITS . " (quota_desc, quota_limit) - VALUES ('" . attach_mod_sql_escape($quota_desc) . "', " . (int) $filesize . ")"; - - if (!(DB()->sql_query($sql))) - { - bb_die('Could not add quota limit'); - } - } - - } - - if (!$error) - { - bb_die($lang['ATTACH_CONFIG_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - } - -} - -if ($mode == 'quota') -{ - $max_add_filesize = $attach_config['max_filesize']; - $size = ($max_add_filesize >= 1048576) ? 'mb' : ( ($max_add_filesize >= 1024) ? 'kb' : 'b' ); - - if ($max_add_filesize >= 1048576) - { - $max_add_filesize = round($max_add_filesize / 1048576 * 100) / 100; - } - else if ( $max_add_filesize >= 1024) - { - $max_add_filesize = round($max_add_filesize / 1024 * 100) / 100; - } - - $template->assign_vars(array( - 'TPL_ATTACH_QUOTA' => true, - 'MAX_FILESIZE' => $max_add_filesize, - 'S_FILESIZE' => size_select('add_size_select', $size), - 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=quota', - )); - - $sql = "SELECT * FROM " . BB_QUOTA_LIMITS . " ORDER BY quota_limit DESC"; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get quota limits #1'); - } - - $rows = DB()->sql_fetchrowset($result); - DB()->sql_freeresult($result); - - for ($i = 0; $i < sizeof($rows); $i++) - { - $size_format = ($rows[$i]['quota_limit'] >= 1048576) ? 'mb' : ( ($rows[$i]['quota_limit'] >= 1024) ? 'kb' : 'b' ); - - if ( $rows[$i]['quota_limit'] >= 1048576) - { - $rows[$i]['quota_limit'] = round($rows[$i]['quota_limit'] / 1048576 * 100) / 100; - } - else if($rows[$i]['quota_limit'] >= 1024) - { - $rows[$i]['quota_limit'] = round($rows[$i]['quota_limit'] / 1024 * 100) / 100; - } - - $template->assign_block_vars('limit_row', array( - 'QUOTA_NAME' => $rows[$i]['quota_desc'], - 'QUOTA_ID' => $rows[$i]['quota_limit_id'], - 'S_FILESIZE' => size_select('size_select_list[]', $size_format), - 'U_VIEW' => "admin_attachments.php?mode=$mode&e_mode=view_quota&quota_id=" . $rows[$i]['quota_limit_id'], - 'MAX_FILESIZE' => $rows[$i]['quota_limit'], - )); - } -} - -if ($mode == 'quota' && $e_mode == 'view_quota') -{ - $quota_id = get_var('quota_id', 0); - - if (!$quota_id) - { - bb_die('Invalid call'); - } - - $template->assign_block_vars('switch_quota_limit_desc', array()); - - $sql = "SELECT * FROM " . BB_QUOTA_LIMITS . " WHERE quota_limit_id = " . (int) $quota_id . " LIMIT 1"; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get quota limits #2'); - } - - $row = DB()->sql_fetchrow($result); - DB()->sql_freeresult($result); - - $template->assign_vars(array( - 'L_QUOTA_LIMIT_DESC' => $row['quota_desc'], - )); - - $sql = 'SELECT q.user_id, u.username, q.quota_type - FROM ' . BB_QUOTA . ' q, ' . BB_USERS . ' u - WHERE q.quota_limit_id = ' . (int) $quota_id . ' - AND q.user_id <> 0 - AND q.user_id = u.user_id'; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get quota limits #3'); - } - - $rows = DB()->sql_fetchrowset($result); - $num_rows = DB()->num_rows($result); - DB()->sql_freeresult($result); - - for ($i = 0; $i < $num_rows; $i++) - { - if ($rows[$i]['quota_type'] == QUOTA_UPLOAD_LIMIT) - { - $template->assign_block_vars('users_upload_row', array( - 'USER_ID' => $rows[$i]['user_id'], - 'USERNAME' => $rows[$i]['username'], - )); - } - else if ($rows[$i]['quota_type'] == QUOTA_PM_LIMIT) - { - $template->assign_block_vars('users_pm_row', array( - 'USER_ID' => $rows[$i]['user_id'], - 'USERNAME' => $rows[$i]['username'], - )); - } - } - - $sql = 'SELECT q.group_id, g.group_name, q.quota_type - FROM ' . BB_QUOTA . ' q, ' . BB_GROUPS . ' g - WHERE q.quota_limit_id = ' . (int) $quota_id . ' - AND q.group_id <> 0 - AND q.group_id = g.group_id'; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get quota limits #4'); - } - - $rows = DB()->sql_fetchrowset($result); - $num_rows = DB()->num_rows($result); - DB()->sql_freeresult($result); - - for ($i = 0; $i < $num_rows; $i++) - { - if ($rows[$i]['quota_type'] == QUOTA_UPLOAD_LIMIT) - { - $template->assign_block_vars('groups_upload_row', array( - 'GROUP_ID' => $rows[$i]['group_id'], - 'GROUPNAME' => $rows[$i]['group_name'], - )); - } - else if ($rows[$i]['quota_type'] == QUOTA_PM_LIMIT) - { - $template->assign_block_vars('groups_pm_row', array( - 'GROUP_ID' => $rows[$i]['group_id'], - 'GROUPNAME' => $rows[$i]['group_name'], - )); - } - } -} - -if ($error) -{ - $template->assign_vars(array('ERROR_MESSAGE' => $error_msg)); -} - +sql_query($sql)) +{ + bb_die('Could not find attachment config table #1'); +} + +while ($row = DB()->sql_fetchrow($result)) +{ + $config_name = $row['config_name']; + $config_value = $row['config_value']; + + $new_attach[$config_name] = get_var($config_name, trim($attach_config[$config_name])); + + if (!$size && !$submit && $config_name == 'max_filesize') + { + $size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b'); + } + + if (!$quota_size && !$submit && $config_name == 'attachment_quota') + { + $quota_size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b'); + } + + if (!$pm_size && !$submit && $config_name == 'max_filesize_pm') + { + $pm_size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b'); + } + + if (!$submit && ($config_name == 'max_filesize' || $config_name == 'attachment_quota' || $config_name == 'max_filesize_pm')) + { + if ($new_attach[$config_name] >= 1048576) + { + $new_attach[$config_name] = round($new_attach[$config_name] / 1048576 * 100) / 100; + } + else if ($new_attach[$config_name] >= 1024) + { + $new_attach[$config_name] = round($new_attach[$config_name] / 1024 * 100) / 100; + } + } + + if ( $submit && ( $mode == 'manage' || $mode == 'cats') ) + { + if ($config_name == 'max_filesize') + { + $old = $new_attach[$config_name]; + $new_attach[$config_name] = ( $size == 'kb' ) ? round($new_attach[$config_name] * 1024) : ( ($size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name] ); + } + + if ($config_name == 'attachment_quota') + { + $old = $new_attach[$config_name]; + $new_attach[$config_name] = ( $quota_size == 'kb' ) ? round($new_attach[$config_name] * 1024) : ( ($quota_size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name] ); + } + + if ($config_name == 'max_filesize_pm') + { + $old = $new_attach[$config_name]; + $new_attach[$config_name] = ( $pm_size == 'kb' ) ? round($new_attach[$config_name] * 1024) : ( ($pm_size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name] ); + } + + if ($config_name == 'max_filesize') + { + $old_size = $attach_config[$config_name]; + $new_size = $new_attach[$config_name]; + + if ($old_size != $new_size) + { + // See, if we have a similar value of old_size in Mime Groups. If so, update these values. + $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . ' + SET max_filesize = ' . (int) $new_size . ' + WHERE max_filesize = ' . (int) $old_size; + + if (!($result_2 = DB()->sql_query($sql))) + { + bb_die('Could not update extension group information'); + } + + } + + $sql = "UPDATE " . BB_ATTACH_CONFIG . " + SET config_value = '" . attach_mod_sql_escape($new_attach[$config_name]) . "' + WHERE config_name = '" . attach_mod_sql_escape($config_name) . "'"; + } + else + { + $sql = "UPDATE " . BB_ATTACH_CONFIG . " + SET config_value = '" . attach_mod_sql_escape($new_attach[$config_name]) . "' + WHERE config_name = '" . attach_mod_sql_escape($config_name) . "'"; + } + + if (!DB()->sql_query($sql)) + { + bb_die('Failed to update attachment configuration for ' . $config_name); + } + + if ($config_name == 'max_filesize' || $config_name == 'attachment_quota' || $config_name == 'max_filesize_pm') + { + $new_attach[$config_name] = $old; + } + } +} +DB()->sql_freeresult($result); + +// Clear cached config +CACHE('bb_cache')->rm('attach_config'); + +$select_size_mode = size_select('size', $size); +$select_quota_size_mode = size_select('quota_size', $quota_size); +$select_pm_size_mode = size_select('pm_size', $pm_size); + +// Search Imagick +if ($search_imagick) +{ + $imagick = ''; + + if (preg_match('/convert/i', $imagick)) + { + return true; + } + else if ($imagick != 'none') + { + if (!preg_match('/WIN/i', PHP_OS)) + { + $retval = @exec('whereis convert'); + $paths = explode(' ', $retval); + + if (is_array($paths)) + { + for ( $i=0; $i < sizeof($paths); $i++) + { + $path = basename($paths[$i]); + + if ($path == 'convert') + { + $imagick = $paths[$i]; + } + } + } + } + else if (preg_match('/WIN/i', PHP_OS)) + { + $path = 'c:/imagemagick/convert.exe'; + + if ( !@file_exists(@amod_realpath($path))) + { + $imagick = $path; + } + } + } + + if ( !@file_exists(@amod_realpath(trim($imagick)))) + { + $new_attach['img_imagick'] = trim($imagick); + } + else + { + $new_attach['img_imagick'] = ''; + } +} + +// Check Settings +if ($check_upload) +{ + // Some tests... + $attach_config = array(); + + $sql = 'SELECT * FROM ' . BB_ATTACH_CONFIG; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not find attachment config table #2'); + } + + $row = DB()->sql_fetchrowset($result); + $num_rows = DB()->num_rows($result); + DB()->sql_freeresult($result); + + for ($i = 0; $i < $num_rows; $i++) + { + $attach_config[$row[$i]['config_name']] = trim($row[$i]['config_value']); + } + + if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':')) + { + $upload_dir = $attach_config['upload_dir']; + } + else + { + $upload_dir = BB_ROOT . $attach_config['upload_dir']; + } + + $error = false; + + // Does the target directory exist, is it a directory and writeable + if ( !@file_exists(@amod_realpath($upload_dir)) ) + { + $error = true; + $error_msg = sprintf($lang['DIRECTORY_DOES_NOT_EXIST'], $attach_config['upload_dir']) . '
        '; + } + + if (!$error && !is_dir($upload_dir)) + { + $error = TRUE; + $error_msg = sprintf($lang['DIRECTORY_IS_NOT_A_DIR'], $attach_config['upload_dir']) . '
        '; + } + + if (!$error) + { + if ( !($fp = @fopen($upload_dir . '/0_000000.000', 'w')) ) + { + $error = TRUE; + $error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $attach_config['upload_dir']) . '
        '; + } + else + { + @fclose($fp); + unlink_attach($upload_dir . '/0_000000.000'); + } + } + + if (!$error) + { + bb_die($lang['TEST_SETTINGS_SUCCESSFUL'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + } +} + +// Management +if ($submit && $mode == 'manage') +{ + if (!$error) + { + bb_die($lang['ATTACH_CONFIG_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + } +} + +if ($mode == 'manage') +{ + $yes_no_switches = array('disable_mod', 'allow_pm_attach', 'display_order'); + + for ($i = 0; $i < sizeof($yes_no_switches); $i++) + { + eval("\$" . $yes_no_switches[$i] . "_yes = ( \$new_attach['" . $yes_no_switches[$i] . "'] != '0' ) ? 'checked=\"checked\"' : '';"); + eval("\$" . $yes_no_switches[$i] . "_no = ( \$new_attach['" . $yes_no_switches[$i] . "'] == '0' ) ? 'checked=\"checked\"' : '';"); + } + + $template->assign_vars(array( + 'TPL_ATTACH_MANAGE' => true, + 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=manage', + 'S_FILESIZE' => $select_size_mode, + 'S_FILESIZE_QUOTA' => $select_quota_size_mode, + 'S_FILESIZE_PM' => $select_pm_size_mode, + 'S_DEFAULT_UPLOAD_LIMIT' => default_quota_limit_select('default_upload_quota', intval(trim($new_attach['default_upload_quota']))), + 'S_DEFAULT_PM_LIMIT' => default_quota_limit_select('default_pm_quota', intval(trim($new_attach['default_pm_quota']))), + + 'UPLOAD_DIR' => $new_attach['upload_dir'], + 'ATTACHMENT_IMG_PATH' => $new_attach['upload_img'], + 'TOPIC_ICON' => $new_attach['topic_icon'], + 'MAX_FILESIZE' => $new_attach['max_filesize'], + 'ATTACHMENT_QUOTA' => $new_attach['attachment_quota'], + 'MAX_FILESIZE_PM' => $new_attach['max_filesize_pm'], + 'MAX_ATTACHMENTS' => $new_attach['max_attachments'], + 'MAX_ATTACHMENTS_PM' => $new_attach['max_attachments_pm'], + 'DISABLE_MOD_YES' => $disable_mod_yes, + 'DISABLE_MOD_NO' => $disable_mod_no, + 'PM_ATTACH_YES' => $allow_pm_attach_yes, + 'PM_ATTACH_NO' => $allow_pm_attach_no, + 'DISPLAY_ORDER_ASC' => $display_order_yes, + 'DISPLAY_ORDER_DESC' => $display_order_no, + )); +} + +if ($submit && $mode == 'cats') +{ + if (!$error) + { + bb_die($lang['ATTACH_CONFIG_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + } +} + +if ($mode == 'cats') +{ + $s_assigned_group_images = $lang['NONE']; + + $sql = 'SELECT group_name, cat_id FROM ' . BB_EXTENSION_GROUPS . ' WHERE cat_id > 0 ORDER BY cat_id'; + + $s_assigned_group_images = array(); + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get group names from ' . BB_EXTENSION_GROUPS); + } + + $row = DB()->sql_fetchrowset($result); + DB()->sql_freeresult($result); + + for ($i = 0; $i < sizeof($row); $i++) + { + if ($row[$i]['cat_id'] == IMAGE_CAT) + { + $s_assigned_group_images[] = $row[$i]['group_name']; + } + } + + $display_inlined_yes = ( $new_attach['img_display_inlined'] != '0' ) ? 'checked="checked"' : ''; + $display_inlined_no = ( $new_attach['img_display_inlined'] == '0' ) ? 'checked="checked"' : ''; + + $create_thumbnail_yes = ( $new_attach['img_create_thumbnail'] != '0' ) ? 'checked="checked"' : ''; + $create_thumbnail_no = ( $new_attach['img_create_thumbnail'] == '0' ) ? 'checked="checked"' : ''; + + $use_gd2_yes = ( $new_attach['use_gd2'] != '0' ) ? 'checked="checked"' : ''; + $use_gd2_no = ( $new_attach['use_gd2'] == '0' ) ? 'checked="checked"' : ''; + + // Check Thumbnail Support + if (!is_imagick() && !@extension_loaded('gd')) + { + $new_attach['img_create_thumbnail'] = '0'; + } + else + { + $template->assign_block_vars('switch_thumbnail_support', array()); + } + + $template->assign_vars(array( + 'TPL_ATTACH_SPECIAL_CATEGORIES' => true, + 'IMAGE_MAX_HEIGHT' => $new_attach['img_max_height'], + 'IMAGE_MAX_WIDTH' => $new_attach['img_max_width'], + 'IMAGE_LINK_HEIGHT' => $new_attach['img_link_height'], + 'IMAGE_LINK_WIDTH' => $new_attach['img_link_width'], + 'IMAGE_MIN_THUMB_FILESIZE' => $new_attach['img_min_thumb_filesize'], + 'IMAGE_IMAGICK_PATH' => $new_attach['img_imagick'], + 'DISPLAY_INLINED_YES' => $display_inlined_yes, + 'DISPLAY_INLINED_NO' => $display_inlined_no, + 'CREATE_THUMBNAIL_YES' => $create_thumbnail_yes, + 'CREATE_THUMBNAIL_NO' => $create_thumbnail_no, + 'USE_GD2_YES' => $use_gd2_yes, + 'USE_GD2_NO' => $use_gd2_no, + 'S_ASSIGNED_GROUP_IMAGES' => implode(', ', $s_assigned_group_images), + 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=cats', + )); +} + +// Check Cat Settings +if ($check_image_cat) +{ + // Some tests... + $attach_config = array(); + + $sql = 'SELECT * FROM ' . BB_ATTACH_CONFIG; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not find attachment config table #3'); + } + + $row = DB()->sql_fetchrowset($result); + $num_rows = DB()->num_rows($result); + DB()->sql_freeresult($result); + + for ($i = 0; $i < $num_rows; $i++) + { + $attach_config[$row[$i]['config_name']] = trim($row[$i]['config_value']); + } + + if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':')) + { + $upload_dir = $attach_config['upload_dir']; + } + else + { + $upload_dir = BB_ROOT . $attach_config['upload_dir']; + } + + $upload_dir = $upload_dir . '/' . THUMB_DIR; + + $error = false; + + // Does the target directory exist, is it a directory and writeable + if ( !@file_exists(@amod_realpath($upload_dir)) ) + { + @mkdir($upload_dir, 0755); + @chmod($upload_dir, 0777); + + if ( !@file_exists(@amod_realpath($upload_dir)) ) + { + $error = TRUE; + $error_msg = sprintf($lang['DIRECTORY_DOES_NOT_EXIST'], $upload_dir) . '
        '; + } + } + + if (!$error && !is_dir($upload_dir)) + { + $error = TRUE; + $error_msg = sprintf($lang['DIRECTORY_IS_NOT_A_DIR'], $upload_dir) . '
        '; + } + + if (!$error) + { + if ( !($fp = @fopen($upload_dir . '/0_000000.000', 'w')) ) + { + $error = TRUE; + $error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $upload_dir) . '
        '; + } + else + { + @fclose($fp); + @unlink($upload_dir . '/0_000000.000'); + } + } + + if (!$error) + { + bb_die($lang['TEST_SETTINGS_SUCCESSFUL'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + } +} + +// Quota Limit Settings +if ($submit && $mode == 'quota') +{ + // Change Quota Limit + $quota_change_list = get_var('quota_change_list', array(0)); + $quota_desc_list = get_var('quota_desc_list', array('')); + $filesize_list = get_var('max_filesize_list', array(0)); + $size_select_list = get_var('size_select_list', array('')); + + $allowed_list = array(); + + for ($i = 0; $i < sizeof($quota_change_list); $i++) + { + $filesize_list[$i] = ( $size_select_list[$i] == 'kb' ) ? round($filesize_list[$i] * 1024) : ( ($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i] ); + + $sql = 'UPDATE ' . BB_QUOTA_LIMITS . " + SET quota_desc = '" . attach_mod_sql_escape($quota_desc_list[$i]) . "', quota_limit = " . (int) $filesize_list[$i] . " + WHERE quota_limit_id = " . (int) $quota_change_list[$i]; + + if (!(DB()->sql_query($sql))) + { + bb_die('Could not update quota limits'); + } + } + + // Delete Quota Limits + $quota_id_list = get_var('quota_id_list', array(0)); + + $quota_id_sql = implode(', ', $quota_id_list); + + if ($quota_id_sql != '') + { + $sql = 'DELETE FROM ' . BB_QUOTA_LIMITS . ' WHERE quota_limit_id IN (' . $quota_id_sql . ')'; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not delete quota limits'); + } + + // Delete Quotas linked to this setting + $sql = 'DELETE FROM ' . BB_QUOTA . ' WHERE quota_limit_id IN (' . $quota_id_sql . ')'; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not delete quotas'); + } + } + + // Add Quota Limit ? + $quota_desc = get_var('quota_description', ''); + $filesize = get_var('add_max_filesize', 0); + $size_select = get_var('add_size_select', ''); + $add = ( isset($_POST['add_quota_check']) ) ? TRUE : FALSE; + + if ($quota_desc != '' && $add) + { + // check Quota Description + $sql = 'SELECT quota_desc FROM ' . BB_QUOTA_LIMITS; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not query quota limits table'); + } + + $row = DB()->sql_fetchrowset($result); + $num_rows = DB()->num_rows($result); + DB()->sql_freeresult($result); + + if ( $num_rows > 0 ) + { + for ($i = 0; $i < $num_rows; $i++) + { + if ($row[$i]['quota_desc'] == $quota_desc) + { + $error = TRUE; + if( isset($error_msg) ) + { + $error_msg .= '
        '; + } + $error_msg .= sprintf($lang['QUOTA_LIMIT_EXIST'], $extension_group); + } + } + } + + if (!$error) + { + $filesize = ( $size_select == 'kb' ) ? round($filesize * 1024) : ( ($size_select == 'mb') ? round($filesize * 1048576) : $filesize ); + + $sql = "INSERT INTO " . BB_QUOTA_LIMITS . " (quota_desc, quota_limit) + VALUES ('" . attach_mod_sql_escape($quota_desc) . "', " . (int) $filesize . ")"; + + if (!(DB()->sql_query($sql))) + { + bb_die('Could not add quota limit'); + } + } + + } + + if (!$error) + { + bb_die($lang['ATTACH_CONFIG_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + } + +} + +if ($mode == 'quota') +{ + $max_add_filesize = $attach_config['max_filesize']; + $size = ($max_add_filesize >= 1048576) ? 'mb' : ( ($max_add_filesize >= 1024) ? 'kb' : 'b' ); + + if ($max_add_filesize >= 1048576) + { + $max_add_filesize = round($max_add_filesize / 1048576 * 100) / 100; + } + else if ( $max_add_filesize >= 1024) + { + $max_add_filesize = round($max_add_filesize / 1024 * 100) / 100; + } + + $template->assign_vars(array( + 'TPL_ATTACH_QUOTA' => true, + 'MAX_FILESIZE' => $max_add_filesize, + 'S_FILESIZE' => size_select('add_size_select', $size), + 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=quota', + )); + + $sql = "SELECT * FROM " . BB_QUOTA_LIMITS . " ORDER BY quota_limit DESC"; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get quota limits #1'); + } + + $rows = DB()->sql_fetchrowset($result); + DB()->sql_freeresult($result); + + for ($i = 0; $i < sizeof($rows); $i++) + { + $size_format = ($rows[$i]['quota_limit'] >= 1048576) ? 'mb' : ( ($rows[$i]['quota_limit'] >= 1024) ? 'kb' : 'b' ); + + if ( $rows[$i]['quota_limit'] >= 1048576) + { + $rows[$i]['quota_limit'] = round($rows[$i]['quota_limit'] / 1048576 * 100) / 100; + } + else if($rows[$i]['quota_limit'] >= 1024) + { + $rows[$i]['quota_limit'] = round($rows[$i]['quota_limit'] / 1024 * 100) / 100; + } + + $template->assign_block_vars('limit_row', array( + 'QUOTA_NAME' => $rows[$i]['quota_desc'], + 'QUOTA_ID' => $rows[$i]['quota_limit_id'], + 'S_FILESIZE' => size_select('size_select_list[]', $size_format), + 'U_VIEW' => "admin_attachments.php?mode=$mode&e_mode=view_quota&quota_id=" . $rows[$i]['quota_limit_id'], + 'MAX_FILESIZE' => $rows[$i]['quota_limit'], + )); + } +} + +if ($mode == 'quota' && $e_mode == 'view_quota') +{ + $quota_id = get_var('quota_id', 0); + + if (!$quota_id) + { + bb_die('Invalid call'); + } + + $template->assign_block_vars('switch_quota_limit_desc', array()); + + $sql = "SELECT * FROM " . BB_QUOTA_LIMITS . " WHERE quota_limit_id = " . (int) $quota_id . " LIMIT 1"; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get quota limits #2'); + } + + $row = DB()->sql_fetchrow($result); + DB()->sql_freeresult($result); + + $template->assign_vars(array( + 'L_QUOTA_LIMIT_DESC' => $row['quota_desc'], + )); + + $sql = 'SELECT q.user_id, u.username, q.quota_type + FROM ' . BB_QUOTA . ' q, ' . BB_USERS . ' u + WHERE q.quota_limit_id = ' . (int) $quota_id . ' + AND q.user_id <> 0 + AND q.user_id = u.user_id'; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get quota limits #3'); + } + + $rows = DB()->sql_fetchrowset($result); + $num_rows = DB()->num_rows($result); + DB()->sql_freeresult($result); + + for ($i = 0; $i < $num_rows; $i++) + { + if ($rows[$i]['quota_type'] == QUOTA_UPLOAD_LIMIT) + { + $template->assign_block_vars('users_upload_row', array( + 'USER_ID' => $rows[$i]['user_id'], + 'USERNAME' => $rows[$i]['username'], + )); + } + else if ($rows[$i]['quota_type'] == QUOTA_PM_LIMIT) + { + $template->assign_block_vars('users_pm_row', array( + 'USER_ID' => $rows[$i]['user_id'], + 'USERNAME' => $rows[$i]['username'], + )); + } + } + + $sql = 'SELECT q.group_id, g.group_name, q.quota_type + FROM ' . BB_QUOTA . ' q, ' . BB_GROUPS . ' g + WHERE q.quota_limit_id = ' . (int) $quota_id . ' + AND q.group_id <> 0 + AND q.group_id = g.group_id'; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get quota limits #4'); + } + + $rows = DB()->sql_fetchrowset($result); + $num_rows = DB()->num_rows($result); + DB()->sql_freeresult($result); + + for ($i = 0; $i < $num_rows; $i++) + { + if ($rows[$i]['quota_type'] == QUOTA_UPLOAD_LIMIT) + { + $template->assign_block_vars('groups_upload_row', array( + 'GROUP_ID' => $rows[$i]['group_id'], + 'GROUPNAME' => $rows[$i]['group_name'], + )); + } + else if ($rows[$i]['quota_type'] == QUOTA_PM_LIMIT) + { + $template->assign_block_vars('groups_pm_row', array( + 'GROUP_ID' => $rows[$i]['group_id'], + 'GROUPNAME' => $rows[$i]['group_name'], + )); + } + } +} + +if ($error) +{ + $template->assign_vars(array('ERROR_MESSAGE' => $error_msg)); +} + print_page('admin_attachments.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_board.php b/upload/admin/admin_board.php index 4fc393b3f..32761b3d4 100644 --- a/upload/admin/admin_board.php +++ b/upload/admin/admin_board.php @@ -1,152 +1,152 @@ - '

        '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''), - 'config' => '

        '. sprintf($lang['CLICK_RETURN_CONFIG'], '', ''), - 'config_mods' => '

        '. sprintf($lang['CLICK_RETURN_CONFIG_MODS'], '', '') -); - -// -// Pull all config data -// -$sql = "SELECT * FROM " . BB_CONFIG; -if(!$result = DB()->sql_query($sql)) -{ - bb_die('Could not query config information in admin_board'); -} -else -{ - while( $row = DB()->sql_fetchrow($result) ) - { - $config_name = $row['config_name']; - $config_value = $row['config_value']; - $default_config[$config_name] = $config_value; - - $new[$config_name] = isset($_POST[$config_name]) ? $_POST[$config_name] : $default_config[$config_name]; - - if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name]) - { - if ($config_name == ('seed_bonus_points' || 'seed_bonus_release' || 'bonus_upload' || 'bonus_upload_price')) $new[$config_name] = serialize(str_replace(',', '.', $new[$config_name])); - bb_update_config(array($config_name => $new[$config_name])); - } - } - - if (isset($_POST['submit'])) - { - bb_die($lang['CONFIG_UPDATED'] . $return_links[$mode] . $return_links['index']); - } -} - -switch($mode) -{ - case 'config_mods': - $template->assign_vars(array( - 'S_CONFIG_ACTION' => 'admin_board.php?mode=config_mods', - 'CONFIG_MODS' => true, - - 'REPORTS_ENABLED' => $new['reports_enabled'], - 'MAGNET_LINKS_ENABLED' => $new['magnet_links_enabled'], - 'GENDER' => $new['gender'], - 'CALLSEED' => $new['callseed'], - 'TOR_STATS' => $new['tor_stats'], - 'SHOW_LATEST_NEWS' => $new['show_latest_news'], - 'MAX_NEWS_TITLE' => $new['max_news_title'], - 'LATEST_NEWS_COUNT' => $new['latest_news_count'], - 'LATEST_NEWS_FORUM_ID' => $new['latest_news_forum_id'], - 'SHOW_NETWORK_NEWS' => $new['show_network_news'], - 'MAX_NET_TITLE' => $new['max_net_title'], - 'NETWORK_NEWS_COUNT' => $new['network_news_count'], - 'NETWORK_NEWS_FORUM_ID' => $new['network_news_forum_id'], - 'WHOIS_INFO' => $new['whois_info'], - 'SHOW_MOD_INDEX' => $new['show_mod_index'], - 'BIRTHDAY_ENABLED' => $new['birthday_enabled'], - 'BIRTHDAY_MAX_AGE' => $new['birthday_max_age'], - 'BIRTHDAY_MIN_AGE' => $new['birthday_min_age'], - 'BIRTHDAY_CHECK_DAY' => $new['birthday_check_day'], - 'PREMOD' => $new['premod'], - 'TOR_COMMENT' => $new['tor_comment'], - 'NEW_TPLS' => $new['new_tpls'], - 'SEED_BONUS_ENABLED' => $new['seed_bonus_enabled'], - 'SEED_BONUS_TOR_SIZE' => $new['seed_bonus_tor_size'], - 'SEED_BONUS_USER_REGDATE' => $new['seed_bonus_user_regdate'], - )); - - if ($new['seed_bonus_points'] && $new['seed_bonus_release']) - { - $seed_bonus = unserialize($new['seed_bonus_points']); - $seed_release = unserialize($new['seed_bonus_release']); - - foreach ($seed_bonus as $i => $row) - { - if (!$row || !$seed_release[$i]) continue; - - $template->assign_block_vars('seed_bonus', array( - 'RELEASE' => $seed_release[$i], - 'POINTS' => $row, - )); - } - } - - if ($new['bonus_upload'] && $new['bonus_upload_price']) - { - $upload_row = unserialize($new['bonus_upload']); - $price_row = unserialize($new['bonus_upload_price']); - - foreach ($upload_row as $i => $row) - { - if (!$row || !$price_row[$i]) continue; - - $template->assign_block_vars('bonus_upload', array( - 'UP' => $row, - 'PRICE' => $price_row[$i], - )); - } - } - break; - - default: - $template->assign_vars(array( - 'S_CONFIG_ACTION' => 'admin_board.php?mode=config', - 'CONFIG' => true, - - 'SITENAME' => htmlCHR($new['sitename']), - 'CONFIG_SITE_DESCRIPTION' => htmlCHR($new['site_desc']), - 'DISABLE_BOARD' => ($new['board_disable']) ? true : false, - 'ALLOW_AUTOLOGIN' => ($new['allow_autologin']) ? true : false, - 'AUTOLOGIN_TIME' => (int) $new['max_autologin_time'], - 'MAX_POLL_OPTIONS' => $new['max_poll_options'], - 'FLOOD_INTERVAL' => $new['flood_interval'], - 'TOPICS_PER_PAGE' => $new['topics_per_page'], - 'POSTS_PER_PAGE' => $new['posts_per_page'], - 'HOT_TOPIC' => $new['hot_threshold'], - 'DEFAULT_DATEFORMAT' => $new['default_dateformat'], - 'LANG_SELECT' => language_select($new['default_lang'], 'default_lang'), - 'TIMEZONE_SELECT' => tz_select($new['board_timezone'], 'board_timezone'), - 'MAX_LOGIN_ATTEMPTS' => $new['max_login_attempts'], - 'LOGIN_RESET_TIME' => $new['login_reset_time'], - 'PRUNE_ENABLE' => ($new['prune_enable']) ? true : false, - 'ALLOW_BBCODE' => ($new['allow_bbcode']) ? true : false, - 'ALLOW_SMILIES' => ($new['allow_smilies']) ? true : false, - 'ALLOW_SIG' => ($new['allow_sig']) ? true : false, - 'SIG_SIZE' => $new['max_sig_chars'], - 'ALLOW_NAMECHANGE' => ($new['allow_namechange']) ? true : false, - 'SMILIES_PATH' => $new['smilies_path'], - )); - break; -} - + '

        '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''), + 'config' => '

        '. sprintf($lang['CLICK_RETURN_CONFIG'], '', ''), + 'config_mods' => '

        '. sprintf($lang['CLICK_RETURN_CONFIG_MODS'], '', '') +); + +// +// Pull all config data +// +$sql = "SELECT * FROM " . BB_CONFIG; +if(!$result = DB()->sql_query($sql)) +{ + bb_die('Could not query config information in admin_board'); +} +else +{ + while( $row = DB()->sql_fetchrow($result) ) + { + $config_name = $row['config_name']; + $config_value = $row['config_value']; + $default_config[$config_name] = $config_value; + + $new[$config_name] = isset($_POST[$config_name]) ? $_POST[$config_name] : $default_config[$config_name]; + + if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name]) + { + if ($config_name == ('seed_bonus_points' || 'seed_bonus_release' || 'bonus_upload' || 'bonus_upload_price')) $new[$config_name] = serialize(str_replace(',', '.', $new[$config_name])); + bb_update_config(array($config_name => $new[$config_name])); + } + } + + if (isset($_POST['submit'])) + { + bb_die($lang['CONFIG_UPDATED'] . $return_links[$mode] . $return_links['index']); + } +} + +switch($mode) +{ + case 'config_mods': + $template->assign_vars(array( + 'S_CONFIG_ACTION' => 'admin_board.php?mode=config_mods', + 'CONFIG_MODS' => true, + + 'REPORTS_ENABLED' => $new['reports_enabled'], + 'MAGNET_LINKS_ENABLED' => $new['magnet_links_enabled'], + 'GENDER' => $new['gender'], + 'CALLSEED' => $new['callseed'], + 'TOR_STATS' => $new['tor_stats'], + 'SHOW_LATEST_NEWS' => $new['show_latest_news'], + 'MAX_NEWS_TITLE' => $new['max_news_title'], + 'LATEST_NEWS_COUNT' => $new['latest_news_count'], + 'LATEST_NEWS_FORUM_ID' => $new['latest_news_forum_id'], + 'SHOW_NETWORK_NEWS' => $new['show_network_news'], + 'MAX_NET_TITLE' => $new['max_net_title'], + 'NETWORK_NEWS_COUNT' => $new['network_news_count'], + 'NETWORK_NEWS_FORUM_ID' => $new['network_news_forum_id'], + 'WHOIS_INFO' => $new['whois_info'], + 'SHOW_MOD_INDEX' => $new['show_mod_index'], + 'BIRTHDAY_ENABLED' => $new['birthday_enabled'], + 'BIRTHDAY_MAX_AGE' => $new['birthday_max_age'], + 'BIRTHDAY_MIN_AGE' => $new['birthday_min_age'], + 'BIRTHDAY_CHECK_DAY' => $new['birthday_check_day'], + 'PREMOD' => $new['premod'], + 'TOR_COMMENT' => $new['tor_comment'], + 'NEW_TPLS' => $new['new_tpls'], + 'SEED_BONUS_ENABLED' => $new['seed_bonus_enabled'], + 'SEED_BONUS_TOR_SIZE' => $new['seed_bonus_tor_size'], + 'SEED_BONUS_USER_REGDATE' => $new['seed_bonus_user_regdate'], + )); + + if ($new['seed_bonus_points'] && $new['seed_bonus_release']) + { + $seed_bonus = unserialize($new['seed_bonus_points']); + $seed_release = unserialize($new['seed_bonus_release']); + + foreach ($seed_bonus as $i => $row) + { + if (!$row || !$seed_release[$i]) continue; + + $template->assign_block_vars('seed_bonus', array( + 'RELEASE' => $seed_release[$i], + 'POINTS' => $row, + )); + } + } + + if ($new['bonus_upload'] && $new['bonus_upload_price']) + { + $upload_row = unserialize($new['bonus_upload']); + $price_row = unserialize($new['bonus_upload_price']); + + foreach ($upload_row as $i => $row) + { + if (!$row || !$price_row[$i]) continue; + + $template->assign_block_vars('bonus_upload', array( + 'UP' => $row, + 'PRICE' => $price_row[$i], + )); + } + } + break; + + default: + $template->assign_vars(array( + 'S_CONFIG_ACTION' => 'admin_board.php?mode=config', + 'CONFIG' => true, + + 'SITENAME' => htmlCHR($new['sitename']), + 'CONFIG_SITE_DESCRIPTION' => htmlCHR($new['site_desc']), + 'DISABLE_BOARD' => ($new['board_disable']) ? true : false, + 'ALLOW_AUTOLOGIN' => ($new['allow_autologin']) ? true : false, + 'AUTOLOGIN_TIME' => (int) $new['max_autologin_time'], + 'MAX_POLL_OPTIONS' => $new['max_poll_options'], + 'FLOOD_INTERVAL' => $new['flood_interval'], + 'TOPICS_PER_PAGE' => $new['topics_per_page'], + 'POSTS_PER_PAGE' => $new['posts_per_page'], + 'HOT_TOPIC' => $new['hot_threshold'], + 'DEFAULT_DATEFORMAT' => $new['default_dateformat'], + 'LANG_SELECT' => language_select($new['default_lang'], 'default_lang'), + 'TIMEZONE_SELECT' => tz_select($new['board_timezone'], 'board_timezone'), + 'MAX_LOGIN_ATTEMPTS' => $new['max_login_attempts'], + 'LOGIN_RESET_TIME' => $new['login_reset_time'], + 'PRUNE_ENABLE' => ($new['prune_enable']) ? true : false, + 'ALLOW_BBCODE' => ($new['allow_bbcode']) ? true : false, + 'ALLOW_SMILIES' => ($new['allow_smilies']) ? true : false, + 'ALLOW_SIG' => ($new['allow_sig']) ? true : false, + 'SIG_SIZE' => $new['max_sig_chars'], + 'ALLOW_NAMECHANGE' => ($new['allow_namechange']) ? true : false, + 'SMILIES_PATH' => $new['smilies_path'], + )); + break; +} + print_page('admin_board.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_bt_forum_cfg.php b/upload/admin/admin_bt_forum_cfg.php index f87a0c09b..3aab8b5b9 100644 --- a/upload/admin/admin_bt_forum_cfg.php +++ b/upload/admin/admin_bt_forum_cfg.php @@ -1,152 +1,152 @@ - 'http://demo.torrentpier.me/bt/', -); - -$default_cfg_bool = array( - 'bt_disable_dht' => 1, - 'bt_show_peers' => 1, - 'bt_add_auth_key' => 1, - 'bt_show_dl_list' => 0, - 'bt_dl_list_only_1st_page' => 1, - 'bt_dl_list_only_count' => 1, - 'bt_replace_ann_url' => 1, - 'bt_show_ip_only_moder' => 1, - 'bt_show_port_only_moder' => 1, - 'bt_check_announce_url' => 0, - 'bt_show_dl_list_buttons' => 1, - 'bt_show_dl_but_will' => 1, - 'bt_show_dl_but_down' => 0, - 'bt_show_dl_but_compl' => 1, - 'bt_show_dl_but_cancel' => 1, - 'bt_show_dl_stat_on_index' => 1, - 'bt_newtopic_auto_reg' => 1, - 'bt_tor_browse_only_reg' => 1, - 'bt_search_bool_mode' => 1, - 'bt_allow_spmode_change' => 1, - 'bt_del_addit_ann_urls' => 1, - 'bt_set_dltype_on_tor_reg' => 1, - 'bt_unset_dltype_on_tor_unreg' => 1, -); - -$default_cfg_num = array( - 'bt_show_peers_mode' => SHOW_PEERS_COUNT, -); - -$default_cfg = array_merge($default_cfg_str, $default_cfg_bool, $default_cfg_num); - -$db_fields_bool = array( - 'allow_reg_tracker' => 0, // Allowed forums for registering torrents on tracker - 'allow_porno_topic' => 0, // Allowed forums for porno topics - 'self_moderated' => 0, // Users can move theirs topic to another forum -); - -// Get config -$cfg = bb_get_config(BB_CONFIG, true, false); - -// Submit new config -if ($submit && $confirm) -{ - foreach ($db_fields_bool as $field_name => $field_def_val) - { - update_table_bool(BB_FORUMS, 'forum_id', $field_name, $field_def_val); - } - - update_config_table(BB_CONFIG, $default_cfg_str, $cfg, 'str'); - update_config_table(BB_CONFIG, $default_cfg_bool, $cfg, 'bool'); - update_config_table(BB_CONFIG, $default_cfg_num, $cfg, 'num'); - - $datastore->update('cat_forums'); - - bb_die($lang['CONFIG_UPD'] .'

        '. sprintf($lang['RETURN_CONFIG'], '', '') .'

        '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); -} - -// Set template vars -set_tpl_vars ($default_cfg_str, $cfg); -set_tpl_vars_lang ($default_cfg_str); - -set_tpl_vars_bool ($default_cfg_bool, $cfg); -set_tpl_vars_lang ($default_cfg_bool); - -set_tpl_vars ($default_cfg_num, $cfg); -set_tpl_vars_lang ($default_cfg_num); - -set_tpl_vars_lang ($db_fields_bool); - -// Get Forums list -$sql = "SELECT f.* - FROM ". BB_CATEGORIES ." c, ". BB_FORUMS ." f - WHERE f.cat_id = c.cat_id - ORDER BY c.cat_order, f.forum_order"; - -if (!$result = DB()->sql_query($sql)) -{ - bb_die('Could not obtain forum names'); -} - -$rowset = DB()->sql_fetchrowset($result); -$forum_rows = min($max_forum_rows, count($rowset)); - -foreach ($db_fields_bool as $field_name => $field_def_val) -{ - $$field_name = ''; -} - -foreach ($rowset as $rid => $forum) -{ - foreach ($db_fields_bool as $field_name => $field_def_val) - { - $forum_name = $forum['forum_name']; - $selected = ($forum[$field_name]) ? ' selected="selected"' : ''; - - $forum_name = str_short($forum_name, $max_forum_name_len); - - $$field_name .= '\n"; - } -} - -foreach ($db_fields_bool as $field_name => $field_def_val) -{ - $$field_name = ''; - $template->assign_vars(array('S_'. strtoupper($field_name) => $$field_name)); -} - -$template->assign_vars(array( - 'L_BT_SHOW_PEERS_MODE_COUNT' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_COUNT) ? ''. $lang['BT_SHOW_PEERS_MODE_COUNT'] .'' : $lang['BT_SHOW_PEERS_MODE_COUNT'], - 'L_BT_SHOW_PEERS_MODE_NAMES' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_NAMES) ? ''. $lang['BT_SHOW_PEERS_MODE_NAMES'] .'' : $lang['BT_SHOW_PEERS_MODE_NAMES'], - 'L_BT_SHOW_PEERS_MODE_FULL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_FULL) ? ''. $lang['BT_SHOW_PEERS_MODE_FULL'] .'' : $lang['BT_SHOW_PEERS_MODE_FULL'], - - 'BT_SHOW_PEERS_MODE_COUNT_VAL' => SHOW_PEERS_COUNT, - 'BT_SHOW_PEERS_MODE_NAMES_VAL' => SHOW_PEERS_NAMES, - 'BT_SHOW_PEERS_MODE_FULL_VAL' => SHOW_PEERS_FULL, - - 'BT_SHOW_PEERS_MODE_COUNT_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_COUNT) ? HTML_CHECKED : '', - 'BT_SHOW_PEERS_MODE_NAMES_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_NAMES) ? HTML_CHECKED : '', - 'BT_SHOW_PEERS_MODE_FULL_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_FULL) ? HTML_CHECKED : '', - - 'S_HIDDEN_FIELDS' => '', - 'S_CONFIG_ACTION' => 'admin_bt_forum_cfg.php', -)); - + 'http://demo.torrentpier.me/bt/', +); + +$default_cfg_bool = array( + 'bt_disable_dht' => 1, + 'bt_show_peers' => 1, + 'bt_add_auth_key' => 1, + 'bt_show_dl_list' => 0, + 'bt_dl_list_only_1st_page' => 1, + 'bt_dl_list_only_count' => 1, + 'bt_replace_ann_url' => 1, + 'bt_show_ip_only_moder' => 1, + 'bt_show_port_only_moder' => 1, + 'bt_check_announce_url' => 0, + 'bt_show_dl_list_buttons' => 1, + 'bt_show_dl_but_will' => 1, + 'bt_show_dl_but_down' => 0, + 'bt_show_dl_but_compl' => 1, + 'bt_show_dl_but_cancel' => 1, + 'bt_show_dl_stat_on_index' => 1, + 'bt_newtopic_auto_reg' => 1, + 'bt_tor_browse_only_reg' => 1, + 'bt_search_bool_mode' => 1, + 'bt_allow_spmode_change' => 1, + 'bt_del_addit_ann_urls' => 1, + 'bt_set_dltype_on_tor_reg' => 1, + 'bt_unset_dltype_on_tor_unreg' => 1, +); + +$default_cfg_num = array( + 'bt_show_peers_mode' => SHOW_PEERS_COUNT, +); + +$default_cfg = array_merge($default_cfg_str, $default_cfg_bool, $default_cfg_num); + +$db_fields_bool = array( + 'allow_reg_tracker' => 0, // Allowed forums for registering torrents on tracker + 'allow_porno_topic' => 0, // Allowed forums for porno topics + 'self_moderated' => 0, // Users can move theirs topic to another forum +); + +// Get config +$cfg = bb_get_config(BB_CONFIG, true, false); + +// Submit new config +if ($submit && $confirm) +{ + foreach ($db_fields_bool as $field_name => $field_def_val) + { + update_table_bool(BB_FORUMS, 'forum_id', $field_name, $field_def_val); + } + + update_config_table(BB_CONFIG, $default_cfg_str, $cfg, 'str'); + update_config_table(BB_CONFIG, $default_cfg_bool, $cfg, 'bool'); + update_config_table(BB_CONFIG, $default_cfg_num, $cfg, 'num'); + + $datastore->update('cat_forums'); + + bb_die($lang['CONFIG_UPD'] .'

        '. sprintf($lang['RETURN_CONFIG'], '', '') .'

        '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); +} + +// Set template vars +set_tpl_vars ($default_cfg_str, $cfg); +set_tpl_vars_lang ($default_cfg_str); + +set_tpl_vars_bool ($default_cfg_bool, $cfg); +set_tpl_vars_lang ($default_cfg_bool); + +set_tpl_vars ($default_cfg_num, $cfg); +set_tpl_vars_lang ($default_cfg_num); + +set_tpl_vars_lang ($db_fields_bool); + +// Get Forums list +$sql = "SELECT f.* + FROM ". BB_CATEGORIES ." c, ". BB_FORUMS ." f + WHERE f.cat_id = c.cat_id + ORDER BY c.cat_order, f.forum_order"; + +if (!$result = DB()->sql_query($sql)) +{ + bb_die('Could not obtain forum names'); +} + +$rowset = DB()->sql_fetchrowset($result); +$forum_rows = min($max_forum_rows, count($rowset)); + +foreach ($db_fields_bool as $field_name => $field_def_val) +{ + $$field_name = ''; +} + +foreach ($rowset as $rid => $forum) +{ + foreach ($db_fields_bool as $field_name => $field_def_val) + { + $forum_name = $forum['forum_name']; + $selected = ($forum[$field_name]) ? ' selected="selected"' : ''; + + $forum_name = str_short($forum_name, $max_forum_name_len); + + $$field_name .= '\n"; + } +} + +foreach ($db_fields_bool as $field_name => $field_def_val) +{ + $$field_name = ''; + $template->assign_vars(array('S_'. strtoupper($field_name) => $$field_name)); +} + +$template->assign_vars(array( + 'L_BT_SHOW_PEERS_MODE_COUNT' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_COUNT) ? ''. $lang['BT_SHOW_PEERS_MODE_COUNT'] .'' : $lang['BT_SHOW_PEERS_MODE_COUNT'], + 'L_BT_SHOW_PEERS_MODE_NAMES' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_NAMES) ? ''. $lang['BT_SHOW_PEERS_MODE_NAMES'] .'' : $lang['BT_SHOW_PEERS_MODE_NAMES'], + 'L_BT_SHOW_PEERS_MODE_FULL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_FULL) ? ''. $lang['BT_SHOW_PEERS_MODE_FULL'] .'' : $lang['BT_SHOW_PEERS_MODE_FULL'], + + 'BT_SHOW_PEERS_MODE_COUNT_VAL' => SHOW_PEERS_COUNT, + 'BT_SHOW_PEERS_MODE_NAMES_VAL' => SHOW_PEERS_NAMES, + 'BT_SHOW_PEERS_MODE_FULL_VAL' => SHOW_PEERS_FULL, + + 'BT_SHOW_PEERS_MODE_COUNT_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_COUNT) ? HTML_CHECKED : '', + 'BT_SHOW_PEERS_MODE_NAMES_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_NAMES) ? HTML_CHECKED : '', + 'BT_SHOW_PEERS_MODE_FULL_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_FULL) ? HTML_CHECKED : '', + + 'S_HIDDEN_FIELDS' => '', + 'S_CONFIG_ACTION' => 'admin_bt_forum_cfg.php', +)); + print_page('admin_bt_forum_cfg.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_bt_tracker_cfg.php b/upload/admin/admin_bt_tracker_cfg.php index ec8034372..34ac6bae1 100644 --- a/upload/admin/admin_bt_tracker_cfg.php +++ b/upload/admin/admin_bt_tracker_cfg.php @@ -1,66 +1,66 @@ - 'Tracker is disabled', - 'browser_redirect_url' => 'http://demo.torrentpier.me/', -); - -$default_cfg_bool = array( - 'autoclean' => 1, - 'off' => 0, - 'compact_mode' => 1, - 'update_dlstat' => 1, - 'limit_active_tor' => 0, - 'limit_concurrent_ips' => 0, -); - -$default_cfg_num = array( - 'numwant' => 50, - 'expire_factor' => 4, - 'limit_seed_count' => 20, - 'limit_leech_count' => 4, - 'leech_expire_factor' => 60, - 'limit_seed_ips' => 0, - 'limit_leech_ips' => 0, -); - -// Set template vars -set_tpl_vars ($default_cfg_str, $tr_cfg); -set_tpl_vars_lang ($default_cfg_str); - -set_tpl_vars_bool ($default_cfg_bool, $tr_cfg); -set_tpl_vars_lang ($default_cfg_bool); - -set_tpl_vars ($default_cfg_num, $tr_cfg); -set_tpl_vars_lang ($default_cfg_num); - -$template->assign_vars(array( - 'IGNORE_REPORTED_IP' => $bb_cfg['ignore_reported_ip'], - 'ANNOUNCE_INTERVAL' => $bb_cfg['announce_interval'], - 'PASSKEY_KEY' => $bb_cfg['passkey_key'], - 'GOLD_SILVER_ENABLED' => $tr_cfg['gold_silver_enabled'], - 'DISABLE_SUBMIT' => true, - - 'S_HIDDEN_FIELDS' => '', - 'S_CONFIG_ACTION' => 'admin_bt_tracker_cfg.php', -)); - + 'Tracker is disabled', + 'browser_redirect_url' => 'http://demo.torrentpier.me/', +); + +$default_cfg_bool = array( + 'autoclean' => 1, + 'off' => 0, + 'compact_mode' => 1, + 'update_dlstat' => 1, + 'limit_active_tor' => 0, + 'limit_concurrent_ips' => 0, +); + +$default_cfg_num = array( + 'numwant' => 50, + 'expire_factor' => 4, + 'limit_seed_count' => 20, + 'limit_leech_count' => 4, + 'leech_expire_factor' => 60, + 'limit_seed_ips' => 0, + 'limit_leech_ips' => 0, +); + +// Set template vars +set_tpl_vars ($default_cfg_str, $tr_cfg); +set_tpl_vars_lang ($default_cfg_str); + +set_tpl_vars_bool ($default_cfg_bool, $tr_cfg); +set_tpl_vars_lang ($default_cfg_bool); + +set_tpl_vars ($default_cfg_num, $tr_cfg); +set_tpl_vars_lang ($default_cfg_num); + +$template->assign_vars(array( + 'IGNORE_REPORTED_IP' => $bb_cfg['ignore_reported_ip'], + 'ANNOUNCE_INTERVAL' => $bb_cfg['announce_interval'], + 'PASSKEY_KEY' => $bb_cfg['passkey_key'], + 'GOLD_SILVER_ENABLED' => $tr_cfg['gold_silver_enabled'], + 'DISABLE_SUBMIT' => true, + + 'S_HIDDEN_FIELDS' => '', + 'S_CONFIG_ACTION' => 'admin_bt_tracker_cfg.php', +)); + print_page('admin_bt_tracker_cfg.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_disallow.php b/upload/admin/admin_disallow.php index a025ca965..fa75c2c0c 100644 --- a/upload/admin/admin_disallow.php +++ b/upload/admin/admin_disallow.php @@ -1,97 +1,97 @@ -escape($disallowed_user) . "')"; - $result = DB()->sql_query( $sql ); - if (!$result) - { - bb_die('Could not add disallowed user'); - } - $message = $lang['DISALLOW_SUCCESSFUL']; - } - - $message .= '

        '. sprintf($lang['CLICK_RETURN_DISALLOWADMIN'], '', '') . '

        '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); - - bb_die($message); -} -elseif (isset($_POST['delete_name'])) -{ - $disallowed_id = (isset($_POST['disallowed_id']) ) ? intval( $_POST['disallowed_id'] ) : intval( $_GET['disallowed_id']); - - $sql = "DELETE FROM " . BB_DISALLOW . " WHERE disallow_id = $disallowed_id"; - $result = DB()->sql_query($sql); - if (!$result) - { - bb_die('Could not removed disallowed user'); - } - - $message .= $lang['DISALLOWED_DELETED'] .'

        '. sprintf($lang['CLICK_RETURN_DISALLOWADMIN'], '', '') .'

        '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); - - bb_die($message); - -} - -// -// Grab the current list of disallowed usernames... -// -$sql = "SELECT * FROM " . BB_DISALLOW; -$result = DB()->sql_query($sql); -if (!$result) -{ - bb_die('Could not get disallowed users'); -} - -$disallowed = DB()->sql_fetchrowset($result); - -// -// Ok now generate the info for the template, which will be put out no matter -// what mode we are in. -// -$disallow_select = ''; - -$template->assign_vars(array( - 'S_DISALLOW_SELECT' => $disallow_select, - 'S_FORM_ACTION' => 'admin_disallow.php', -)); - +escape($disallowed_user) . "')"; + $result = DB()->sql_query( $sql ); + if (!$result) + { + bb_die('Could not add disallowed user'); + } + $message = $lang['DISALLOW_SUCCESSFUL']; + } + + $message .= '

        '. sprintf($lang['CLICK_RETURN_DISALLOWADMIN'], '', '') . '

        '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); + + bb_die($message); +} +elseif (isset($_POST['delete_name'])) +{ + $disallowed_id = (isset($_POST['disallowed_id']) ) ? intval( $_POST['disallowed_id'] ) : intval( $_GET['disallowed_id']); + + $sql = "DELETE FROM " . BB_DISALLOW . " WHERE disallow_id = $disallowed_id"; + $result = DB()->sql_query($sql); + if (!$result) + { + bb_die('Could not removed disallowed user'); + } + + $message .= $lang['DISALLOWED_DELETED'] .'

        '. sprintf($lang['CLICK_RETURN_DISALLOWADMIN'], '', '') .'

        '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); + + bb_die($message); + +} + +// +// Grab the current list of disallowed usernames... +// +$sql = "SELECT * FROM " . BB_DISALLOW; +$result = DB()->sql_query($sql); +if (!$result) +{ + bb_die('Could not get disallowed users'); +} + +$disallowed = DB()->sql_fetchrowset($result); + +// +// Ok now generate the info for the template, which will be put out no matter +// what mode we are in. +// +$disallow_select = ''; + +$template->assign_vars(array( + 'S_DISALLOW_SELECT' => $disallow_select, + 'S_FORM_ACTION' => 'admin_disallow.php', +)); + print_page('admin_disallow.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_extensions.php b/upload/admin/admin_extensions.php index a9c1524d4..d894660d9 100644 --- a/upload/admin/admin_extensions.php +++ b/upload/admin/admin_extensions.php @@ -1,783 +1,783 @@ -update('attach_extensions'); -} -register_shutdown_function('update_attach_extensions'); - -require('./pagestart.php'); -// ACP Header - END - -if ( ($attach_config['upload_dir'][0] == '/') || ( ($attach_config['upload_dir'][0] != '/') && ($attach_config['upload_dir'][1] == ':') ) ) -{ - $upload_dir = $attach_config['upload_dir']; -} -else -{ - $upload_dir = BB_ROOT . $attach_config['upload_dir']; -} - -include(BB_ROOT .'attach_mod/includes/functions_selects.php'); - -// Check if the language got included -if (!isset($lang['TEST_SETTINGS_SUCCESSFUL'])) -{ - // include_once is used within the function - include_attach_lang(); -} - -// Init Vars -$types_download = array(INLINE_LINK, PHYSICAL_LINK); -$modes_download = array('inline', 'physical'); - -$types_category = array(IMAGE_CAT); -$modes_category = array($lang['CATEGORY_IMAGES']); - -$size = get_var('size', ''); -$mode = get_var('mode', ''); -$e_mode = get_var('e_mode', ''); - -$submit = (isset($_POST['submit'])) ? TRUE : FALSE; - -// Get Attachment Config -$attach_config = array(); - -$sql = 'SELECT * FROM '. BB_ATTACH_CONFIG; - -if (!($result = DB()->sql_query($sql))) -{ - bb_die('Could not query attachment information'); -} - -while ($row = DB()->sql_fetchrow($result)) -{ - $attach_config[$row['config_name']] = trim($row['config_value']); -} -DB()->sql_freeresult($result); - -// Extension Management -if ($submit && $mode == 'extensions') -{ - // Change Extensions ? - $extension_change_list = get_var('extension_change_list', array(0)); - $extension_explain_list = get_var('extension_explain_list', array('')); - $group_select_list = get_var('group_select', array(0)); - - // Generate correct Change List - $extensions = array(); - - for ($i = 0; $i < sizeof($extension_change_list); $i++) - { - $extensions['_' . $extension_change_list[$i]]['comment'] = $extension_explain_list[$i]; - $extensions['_' . $extension_change_list[$i]]['group_id'] = intval($group_select_list[$i]); - } - - $sql = 'SELECT * FROM ' . BB_EXTENSIONS . ' ORDER BY ext_id'; - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get extension informations #1'); - } - - $num_rows = DB()->num_rows($result); - $extension_row = DB()->sql_fetchrowset($result); - DB()->sql_freeresult($result); - - if ($num_rows > 0) - { - for ($i = 0; $i < sizeof($extension_row); $i++) - { - if ($extension_row[$i]['comment'] != $extensions['_' . $extension_row[$i]['ext_id']]['comment'] || intval($extension_row[$i]['group_id']) != intval($extensions['_' . $extension_row[$i]['ext_id']]['group_id'])) - { - $sql_ary = array( - 'comment' => (string) $extensions['_' . $extension_row[$i]['ext_id']]['comment'], - 'group_id' => (int) $extensions['_' . $extension_row[$i]['ext_id']]['group_id'] - ); - - $sql = 'UPDATE ' . BB_EXTENSIONS . ' SET ' . attach_mod_sql_build_array('UPDATE', $sql_ary) . ' - WHERE ext_id = ' . (int) $extension_row[$i]['ext_id']; - - if (!DB()->sql_query($sql)) - { - bb_die('Could not update extension informations'); - } - } - } - } - - // Delete Extension? - $extension_id_list = get_var('extension_id_list', array(0)); - - $extension_id_sql = implode(', ', $extension_id_list); - - if ($extension_id_sql != '') - { - $sql = 'DELETE FROM ' . BB_EXTENSIONS . ' WHERE ext_id IN (' . $extension_id_sql . ')'; - - if( !$result = DB()->sql_query($sql) ) - { - bb_die('Could not delete extensions'); - } - } - - // Add Extension ? - $extension = get_var('add_extension', ''); - $extension_explain = get_var('add_extension_explain', ''); - $extension_group = get_var('add_group_select', 0); - $add = ( isset($_POST['add_extension_check']) ) ? TRUE : FALSE; - - if ($extension != '' && $add) - { - $template->assign_vars(array( - 'ADD_EXTENSION' => $extension, - 'ADD_EXTENSION_EXPLAIN' => $extension_explain, - )); - - if (!@$error) - { - // check extension - $sql = 'SELECT extension FROM ' . BB_EXTENSIONS; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not query extensions'); - } - - $row = DB()->sql_fetchrowset($result); - $num_rows = DB()->num_rows($result); - DB()->sql_freeresult($result); - - if ($num_rows > 0) - { - for ($i = 0; $i < $num_rows; $i++) - { - if (strtolower(trim($row[$i]['extension'])) == strtolower(trim($extension))) - { - $error = TRUE; - if( isset($error_msg) ) - { - $error_msg .= '
        '; - } - $error_msg .= sprintf($lang['EXTENSION_EXIST'], strtolower(trim($extension))); - } - } - } - - if (!@$error) - { - $sql_ary = array( - 'group_id' => (int) $extension_group, - 'extension' => (string) strtolower($extension), - 'comment' => (string) $extension_explain - ); - - $sql = 'INSERT INTO ' . BB_EXTENSIONS . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary); - - if (!DB()->sql_query($sql)) - { - bb_die('Could not add extension'); - } - - } - } - } - - if (!@$error) - { - bb_die($lang['ATTACH_CONFIG_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - } -} - -if ($mode == 'extensions') -{ - // Extensions - $template->assign_vars(array( - 'TPL_ATTACH_EXTENSIONS' => true, - 'S_CANCEL_ACTION' => 'admin_extensions.php?mode=extensions', - 'S_ATTACH_ACTION' => 'admin_extensions.php?mode=extensions', - )); - - if ($submit) - { - $template->assign_vars(array( - 'S_ADD_GROUP_SELECT' => group_select('add_group_select', $extension_group)) - ); - } - else - { - $template->assign_vars(array( - 'S_ADD_GROUP_SELECT' => group_select('add_group_select')) - ); - } - - $sql = 'SELECT * FROM ' . BB_EXTENSIONS . ' ORDER BY group_id'; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get extension informations #2'); - } - - $extension_row = DB()->sql_fetchrowset($result); - $num_extension_row = DB()->num_rows($result); - DB()->sql_freeresult($result); - - if ($num_extension_row > 0) - { - $extension_row = sort_multi_array($extension_row, 'group_name', 'ASC'); - - for ($i = 0; $i < $num_extension_row; $i++) - { - if ($submit) - { - $template->assign_block_vars('extension_row', array( - 'EXT_ID' => $extension_row[$i]['ext_id'], - 'EXTENSION' => $extension_row[$i]['extension'], - 'EXTENSION_EXPLAIN' => $extension_explain_list[$i], - 'S_GROUP_SELECT' => group_select('group_select[]', $group_select_list[$i])) - ); - } - else - { - $template->assign_block_vars('extension_row', array( - 'EXT_ID' => $extension_row[$i]['ext_id'], - 'EXTENSION' => $extension_row[$i]['extension'], - 'EXTENSION_EXPLAIN' => $extension_row[$i]['comment'], - 'S_GROUP_SELECT' => group_select('group_select[]', $extension_row[$i]['group_id'])) - ); - } - } - } - -} - -// Extension Groups -if ($submit && $mode == 'groups') -{ - // Change Extension Groups ? - $group_change_list = get_var('group_change_list', array(0)); - $extension_group_list = get_var('extension_group_list', array('')); - $group_allowed_list = get_var('allowed_list', array(0)); - $download_mode_list = get_var('download_mode_list', array(0)); - $category_list = get_var('category_list', array(0)); - $upload_icon_list = get_var('upload_icon_list', array('')); - $filesize_list = get_var('max_filesize_list', array(0)); - $size_select_list = get_var('size_select_list', array('')); - - $allowed_list = array(); - - for ($i = 0; $i < sizeof($group_allowed_list); $i++) - { - for ($j = 0; $j < sizeof($group_change_list); $j++) - { - if ($group_allowed_list[$i] == $group_change_list[$j]) - { - $allowed_list[$j] = 1; - } - } - } - - for ($i = 0; $i < sizeof($group_change_list); $i++) - { - $allowed = (isset($allowed_list[$i])) ? 1 : 0; - - $filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : ( ($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i] ); - - $sql_ary = array( - 'group_name' => (string) $extension_group_list[$i], - 'cat_id' => (int) $category_list[$i], - 'allow_group' => (int) $allowed, - 'download_mode' => (int) $download_mode_list[$i], - 'upload_icon' => (string) $upload_icon_list[$i], - 'max_filesize' => (int) $filesize_list[$i] - ); - - $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . ' SET ' . attach_mod_sql_build_array('UPDATE', $sql_ary) . ' - WHERE group_id = ' . (int) $group_change_list[$i]; - - if (!(DB()->sql_query($sql))) - { - bb_die('Could not update extension groups informations'); - } - } - - // Delete Extension Groups - $group_id_list = get_var('group_id_list', array(0)); - - $group_id_sql = implode(', ', $group_id_list); - - if ($group_id_sql != '') - { - $sql = 'DELETE - FROM ' . BB_EXTENSION_GROUPS . ' - WHERE group_id IN (' . $group_id_sql . ')'; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not delete extension groups'); - } - - // Set corresponding Extensions to a pending Group - $sql = 'UPDATE ' . BB_EXTENSIONS . ' - SET group_id = 0 - WHERE group_id IN (' . $group_id_sql . ')'; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not assign extensions to pending group'); - } - } - - // Add Extensions? - $extension_group = get_var('add_extension_group', ''); - $download_mode = get_var('add_download_mode', 0); - $cat_id = get_var('add_category', 0); - $upload_icon = get_var('add_upload_icon', ''); - $filesize = get_var('add_max_filesize', 0); - $size_select = get_var('add_size_select', ''); - - $is_allowed = (isset($_POST['add_allowed'])) ? 1 : 0; - $add = ( isset($_POST['add_extension_group_check']) ) ? TRUE : FALSE; - - if ($extension_group != '' && $add) - { - // check Extension Group - $sql = 'SELECT group_name FROM ' . BB_EXTENSION_GROUPS; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not query extension groups table'); - } - - $row = DB()->sql_fetchrowset($result); - $num_rows = DB()->num_rows($result); - DB()->sql_freeresult($result); - - if ($num_rows > 0) - { - for ($i = 0; $i < $num_rows; $i++) - { - if ($row[$i]['group_name'] == $extension_group) - { - $error = TRUE; - if( isset($error_msg) ) - { - $error_msg .= '
        '; - } - $error_msg .= sprintf($lang['EXTENSION_GROUP_EXIST'], $extension_group); - } - } - } - - if (!@$error) - { - $filesize = ($size_select == 'kb') ? round($filesize * 1024) : ( ($size_select == 'mb') ? round($filesize * 1048576) : $filesize ); - - $sql_ary = array( - 'group_name' => (string) $extension_group, - 'cat_id' => (int) $cat_id, - 'allow_group' => (int) $is_allowed, - 'download_mode' => (int) $download_mode, - 'upload_icon' => (string) $upload_icon, - 'max_filesize' => (int) $filesize, - 'forum_permissions' => '' - ); - - $sql = 'INSERT INTO ' . BB_EXTENSION_GROUPS . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary); - - if (!(DB()->sql_query($sql))) - { - bb_die('Could not add extension group'); - } - } - - } - - if (!@$error) - { - bb_die($lang['ATTACH_CONFIG_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - } -} - -if ($mode == 'groups') -{ - // Extension Groups - if (!$size && !$submit) - { - $max_add_filesize = $attach_config['max_filesize']; - - $size = ($max_add_filesize >= 1048576) ? 'mb' : ( ($max_add_filesize >= 1024) ? 'kb' : 'b' ); - } - - if ($max_add_filesize >= 1048576) - { - $max_add_filesize = round($max_add_filesize / 1048576 * 100) / 100; - } - else if ( $max_add_filesize >= 1024) - { - $max_add_filesize = round($max_add_filesize / 1024 * 100) / 100; - } - - $viewgroup = get_var(POST_GROUPS_URL, 0); - - $template->assign_vars(array( - 'TPL_ATTACH_EXTENSION_GROUPS' => true, - 'ADD_GROUP_NAME' => ( isset($submit) ) ? @$extension_group : '', - 'MAX_FILESIZE' => $max_add_filesize, - 'S_FILESIZE' => size_select('add_size_select', $size), - 'S_ADD_DOWNLOAD_MODE' => download_select('add_download_mode'), - 'S_SELECT_CAT' => category_select('add_category'), - 'S_CANCEL_ACTION' => "admin_extensions.php?mode=groups", - 'S_ATTACH_ACTION' => "admin_extensions.php?mode=groups") - ); - - $sql = 'SELECT * FROM ' . BB_EXTENSION_GROUPS; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get extension group informations'); - } - - $extension_group = DB()->sql_fetchrowset($result); - $num_extension_group = DB()->num_rows($result); - DB()->sql_freeresult($result); - - for ($i = 0; $i < $num_extension_group; $i++) - { - // Format the filesize - if (!$extension_group[$i]['max_filesize']) - { - $extension_group[$i]['max_filesize'] = $attach_config['max_filesize']; - } - - $size_format = ($extension_group[$i]['max_filesize'] >= 1048576) ? 'mb' : ( ($extension_group[$i]['max_filesize'] >= 1024) ? 'kb' : 'b' ); - - if ( $extension_group[$i]['max_filesize'] >= 1048576) - { - $extension_group[$i]['max_filesize'] = round($extension_group[$i]['max_filesize'] / 1048576 * 100) / 100; - } - else if($extension_group[$i]['max_filesize'] >= 1024) - { - $extension_group[$i]['max_filesize'] = round($extension_group[$i]['max_filesize'] / 1024 * 100) / 100; - } - - $s_allowed = ($extension_group[$i]['allow_group'] == 1) ? 'checked="checked"' : ''; - - $template->assign_block_vars('grouprow', array( - 'GROUP_ID' => $extension_group[$i]['group_id'], - 'EXTENSION_GROUP' => $extension_group[$i]['group_name'], - 'UPLOAD_ICON' => $extension_group[$i]['upload_icon'], - - 'S_ALLOW_SELECTED' => $s_allowed, - 'S_SELECT_CAT' => category_select('category_list[]', $extension_group[$i]['group_id']), - 'S_DOWNLOAD_MODE' => download_select('download_mode_list[]', $extension_group[$i]['group_id']), - 'S_FILESIZE' => size_select('size_select_list[]', $size_format), - - 'MAX_FILESIZE' => $extension_group[$i]['max_filesize'], - 'CAT_BOX' => ( $viewgroup == $extension_group[$i]['group_id'] ) ? '+' : '-', - 'U_VIEWGROUP' => ( $viewgroup == $extension_group[$i]['group_id'] ) ? "admin_extensions.php?mode=groups" : "admin_extensions.php?mode=groups&" . POST_GROUPS_URL . "=" . $extension_group[$i]['group_id'], - 'U_FORUM_PERMISSIONS' => "admin_extensions.php?mode=$mode&e_mode=perm&e_group=" . $extension_group[$i]['group_id']) - ); - - if ($viewgroup && $viewgroup == $extension_group[$i]['group_id']) - { - $sql = 'SELECT comment, extension FROM ' . BB_EXTENSIONS . ' WHERE group_id = ' . (int) $viewgroup; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not get extension informations #3'); - } - - $extension = DB()->sql_fetchrowset($result); - $num_extension = DB()->num_rows($result); - DB()->sql_freeresult($result); - - for ($j = 0; $j < $num_extension; $j++) - { - $template->assign_block_vars('grouprow.extensionrow', array( - 'EXPLANATION' => $extension[$j]['comment'], - 'EXTENSION' => $extension[$j]['extension']) - ); - } - } - } -} - -if ($e_mode == 'perm') -{ - $group = get_var('e_group', 0); - - $add_forum = (isset($_POST['add_forum'])) ? TRUE : FALSE; - $delete_forum = (isset($_POST['del_forum'])) ? TRUE : FALSE; - - if (isset($_POST['close_perm'])) - { - $e_mode = ''; - } -} - -// Add Forums -if (@$add_forum && $e_mode == 'perm' && $group) -{ - $add_forums_list = get_var('entries', array(0)); - $add_all_forums = FALSE; - - for ($i = 0; $i < sizeof($add_forums_list); $i++) - { - if ($add_forums_list[$i] == 0) - { - $add_all_forums = TRUE; - } - } - - // If we add ALL FORUMS, we are able to overwrite the Permissions - if ($add_all_forums) - { - $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '' WHERE group_id = " . (int) $group; - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not update permissions #1'); - } - } - - // Else we have to add Permissions - if (!$add_all_forums) - { - $sql = 'SELECT forum_permissions - FROM ' . BB_EXTENSION_GROUPS . ' - WHERE group_id = ' . intval($group) . ' - LIMIT 1'; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get group permissions from ' . BB_EXTENSION_GROUPS); - } - - $row = DB()->sql_fetchrow($result); - DB()->sql_freeresult($result); - - if (trim($row['forum_permissions']) == '') - { - $auth_p = array(); - } - else - { - $auth_p = auth_unpack($row['forum_permissions']); - } - - // Generate array for Auth_Pack, do not add doubled forums - for ($i = 0; $i < sizeof($add_forums_list); $i++) - { - if (!in_array($add_forums_list[$i], $auth_p)) - { - $auth_p[] = $add_forums_list[$i]; - } - } - - $auth_bitstream = auth_pack($auth_p); - - $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '" . attach_mod_sql_escape($auth_bitstream) . "' WHERE group_id = " . (int) $group; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not update permissions #2'); - } - } - -} - -// Delete Forums -if (@$delete_forum && $e_mode == 'perm' && $group) -{ - $delete_forums_list = get_var('entries', array(0)); - - // Get the current Forums - $sql = 'SELECT forum_permissions - FROM ' . BB_EXTENSION_GROUPS . ' - WHERE group_id = ' . intval($group) . ' - LIMIT 1'; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get group permissions from ' . BB_EXTENSION_GROUPS); - } - - $row = DB()->sql_fetchrow($result); - DB()->sql_freeresult($result); - - $auth_p2 = auth_unpack(trim($row['forum_permissions'])); - $auth_p = array(); - - // Generate array for Auth_Pack, delete the chosen ones - for ($i = 0; $i < sizeof($auth_p2); $i++) - { - if (!in_array($auth_p2[$i], $delete_forums_list)) - { - $auth_p[] = $auth_p2[$i]; - } - } - - $auth_bitstream = (sizeof($auth_p) > 0) ? auth_pack($auth_p) : ''; - - $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '" . attach_mod_sql_escape($auth_bitstream) . "' WHERE group_id = " . (int) $group; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not update permissions #3'); - } -} - -// Display the Group Permissions Box for configuring it -if ($e_mode == 'perm' && $group) -{ - $sql = 'SELECT group_name, forum_permissions - FROM ' . BB_EXTENSION_GROUPS . ' - WHERE group_id = ' . intval($group) . ' - LIMIT 1'; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get group name from ' . BB_EXTENSION_GROUPS); - } - - $row = DB()->sql_fetchrow($result); - DB()->sql_freeresult($result); - - $group_name = $row['group_name']; - $allowed_forums = trim($row['forum_permissions']); - - $forum_perm = array(); - - if ($allowed_forums == '') - { - $forum_perm[0]['forum_id'] = 0; - $forum_perm[0]['forum_name'] = $lang['PERM_ALL_FORUMS']; - } - else - { - $forum_p = array(); - $act_id = 0; - $forum_p = auth_unpack($allowed_forums); - $sql = "SELECT forum_id, forum_name FROM " . BB_FORUMS . " WHERE forum_id IN (" . implode(', ', $forum_p) . ")"; - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get forum names'); - } - - while ($row = DB()->sql_fetchrow($result)) - { - $forum_perm[$act_id]['forum_id'] = $row['forum_id']; - $forum_perm[$act_id]['forum_name'] = $row['forum_name']; - $act_id++; - } - } - - for ($i = 0; $i < sizeof($forum_perm); $i++) - { - $template->assign_block_vars('allow_option_values', array( - 'VALUE' => $forum_perm[$i]['forum_id'], - 'OPTION' => htmlCHR($forum_perm[$i]['forum_name'])) - ); - } - - $template->assign_vars(array( - 'TPL_ATTACH_EXTENSION_GROUPS_PERMISSIONS' => true, - 'L_GROUP_PERMISSIONS_TITLE' => sprintf($lang['GROUP_PERMISSIONS_TITLE_ADMIN'], trim($group_name)), - 'A_PERM_ACTION' => "admin_extensions.php?mode=groups&e_mode=perm&e_group=$group") - ); - - $forum_option_values = array(0 => $lang['PERM_ALL_FORUMS']); - - $sql = "SELECT forum_id, forum_name FROM " . BB_FORUMS; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not get forums #1'); - } - - while ($row = DB()->sql_fetchrow($result)) - { - $forum_option_values[intval($row['forum_id'])] = $row['forum_name']; - } - DB()->sql_freeresult($result); - - foreach ($forum_option_values as $value => $option) - { - $template->assign_block_vars('forum_option_values', array( - 'VALUE' => $value, - 'OPTION' => htmlCHR($option)) - ); - } - - $empty_perm_forums = array(); - - $sql = "SELECT forum_id, forum_name FROM " . BB_FORUMS . " WHERE auth_attachments < " . AUTH_ADMIN; - - if (!($f_result = DB()->sql_query($sql))) - { - bb_die('Could not get forums #2'); - } - - while ($row = DB()->sql_fetchrow($f_result)) - { - $forum_id = $row['forum_id']; - - $sql = "SELECT forum_permissions - FROM " . BB_EXTENSION_GROUPS . " - WHERE allow_group = 1 - ORDER BY group_name ASC"; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not query extension groups'); - } - - $rows = DB()->sql_fetchrowset($result); - $num_rows = DB()->num_rows($result); - DB()->sql_freeresult($result); - - $found_forum = FALSE; - - for ($i = 0; $i < $num_rows; $i++) - { - $allowed_forums = auth_unpack(trim($rows[$i]['forum_permissions'])); - if (in_array($forum_id, $allowed_forums) || trim($rows[$i]['forum_permissions']) == '') - { - $found_forum = TRUE; - break; - } - } - - if (!$found_forum) - { - $empty_perm_forums[$forum_id] = $row['forum_name']; - } - } - DB()->sql_freeresult($f_result); - - $message = ''; - - foreach ($empty_perm_forums as $forum_id => $forum_name) - { - $message .= ( $message == '' ) ? $forum_name : '
        ' . $forum_name; - } - - if (sizeof($empty_perm_forums) > 0) - { - $template->assign_vars(array('ERROR_MESSAGE' => $lang['NOTE_ADMIN_EMPTY_GROUP_PERMISSIONS'] . $message)); - } -} - -if (@$error) -{ - $template->assign_vars(array('ERROR_MESSAGE' => $error_msg)); -} - +update('attach_extensions'); +} +register_shutdown_function('update_attach_extensions'); + +require('./pagestart.php'); +// ACP Header - END + +if ( ($attach_config['upload_dir'][0] == '/') || ( ($attach_config['upload_dir'][0] != '/') && ($attach_config['upload_dir'][1] == ':') ) ) +{ + $upload_dir = $attach_config['upload_dir']; +} +else +{ + $upload_dir = BB_ROOT . $attach_config['upload_dir']; +} + +include(BB_ROOT .'attach_mod/includes/functions_selects.php'); + +// Check if the language got included +if (!isset($lang['TEST_SETTINGS_SUCCESSFUL'])) +{ + // include_once is used within the function + include_attach_lang(); +} + +// Init Vars +$types_download = array(INLINE_LINK, PHYSICAL_LINK); +$modes_download = array('inline', 'physical'); + +$types_category = array(IMAGE_CAT); +$modes_category = array($lang['CATEGORY_IMAGES']); + +$size = get_var('size', ''); +$mode = get_var('mode', ''); +$e_mode = get_var('e_mode', ''); + +$submit = (isset($_POST['submit'])) ? TRUE : FALSE; + +// Get Attachment Config +$attach_config = array(); + +$sql = 'SELECT * FROM '. BB_ATTACH_CONFIG; + +if (!($result = DB()->sql_query($sql))) +{ + bb_die('Could not query attachment information'); +} + +while ($row = DB()->sql_fetchrow($result)) +{ + $attach_config[$row['config_name']] = trim($row['config_value']); +} +DB()->sql_freeresult($result); + +// Extension Management +if ($submit && $mode == 'extensions') +{ + // Change Extensions ? + $extension_change_list = get_var('extension_change_list', array(0)); + $extension_explain_list = get_var('extension_explain_list', array('')); + $group_select_list = get_var('group_select', array(0)); + + // Generate correct Change List + $extensions = array(); + + for ($i = 0; $i < sizeof($extension_change_list); $i++) + { + $extensions['_' . $extension_change_list[$i]]['comment'] = $extension_explain_list[$i]; + $extensions['_' . $extension_change_list[$i]]['group_id'] = intval($group_select_list[$i]); + } + + $sql = 'SELECT * FROM ' . BB_EXTENSIONS . ' ORDER BY ext_id'; + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get extension informations #1'); + } + + $num_rows = DB()->num_rows($result); + $extension_row = DB()->sql_fetchrowset($result); + DB()->sql_freeresult($result); + + if ($num_rows > 0) + { + for ($i = 0; $i < sizeof($extension_row); $i++) + { + if ($extension_row[$i]['comment'] != $extensions['_' . $extension_row[$i]['ext_id']]['comment'] || intval($extension_row[$i]['group_id']) != intval($extensions['_' . $extension_row[$i]['ext_id']]['group_id'])) + { + $sql_ary = array( + 'comment' => (string) $extensions['_' . $extension_row[$i]['ext_id']]['comment'], + 'group_id' => (int) $extensions['_' . $extension_row[$i]['ext_id']]['group_id'] + ); + + $sql = 'UPDATE ' . BB_EXTENSIONS . ' SET ' . attach_mod_sql_build_array('UPDATE', $sql_ary) . ' + WHERE ext_id = ' . (int) $extension_row[$i]['ext_id']; + + if (!DB()->sql_query($sql)) + { + bb_die('Could not update extension informations'); + } + } + } + } + + // Delete Extension? + $extension_id_list = get_var('extension_id_list', array(0)); + + $extension_id_sql = implode(', ', $extension_id_list); + + if ($extension_id_sql != '') + { + $sql = 'DELETE FROM ' . BB_EXTENSIONS . ' WHERE ext_id IN (' . $extension_id_sql . ')'; + + if( !$result = DB()->sql_query($sql) ) + { + bb_die('Could not delete extensions'); + } + } + + // Add Extension ? + $extension = get_var('add_extension', ''); + $extension_explain = get_var('add_extension_explain', ''); + $extension_group = get_var('add_group_select', 0); + $add = ( isset($_POST['add_extension_check']) ) ? TRUE : FALSE; + + if ($extension != '' && $add) + { + $template->assign_vars(array( + 'ADD_EXTENSION' => $extension, + 'ADD_EXTENSION_EXPLAIN' => $extension_explain, + )); + + if (!@$error) + { + // check extension + $sql = 'SELECT extension FROM ' . BB_EXTENSIONS; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not query extensions'); + } + + $row = DB()->sql_fetchrowset($result); + $num_rows = DB()->num_rows($result); + DB()->sql_freeresult($result); + + if ($num_rows > 0) + { + for ($i = 0; $i < $num_rows; $i++) + { + if (strtolower(trim($row[$i]['extension'])) == strtolower(trim($extension))) + { + $error = TRUE; + if( isset($error_msg) ) + { + $error_msg .= '
        '; + } + $error_msg .= sprintf($lang['EXTENSION_EXIST'], strtolower(trim($extension))); + } + } + } + + if (!@$error) + { + $sql_ary = array( + 'group_id' => (int) $extension_group, + 'extension' => (string) strtolower($extension), + 'comment' => (string) $extension_explain + ); + + $sql = 'INSERT INTO ' . BB_EXTENSIONS . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary); + + if (!DB()->sql_query($sql)) + { + bb_die('Could not add extension'); + } + + } + } + } + + if (!@$error) + { + bb_die($lang['ATTACH_CONFIG_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + } +} + +if ($mode == 'extensions') +{ + // Extensions + $template->assign_vars(array( + 'TPL_ATTACH_EXTENSIONS' => true, + 'S_CANCEL_ACTION' => 'admin_extensions.php?mode=extensions', + 'S_ATTACH_ACTION' => 'admin_extensions.php?mode=extensions', + )); + + if ($submit) + { + $template->assign_vars(array( + 'S_ADD_GROUP_SELECT' => group_select('add_group_select', $extension_group)) + ); + } + else + { + $template->assign_vars(array( + 'S_ADD_GROUP_SELECT' => group_select('add_group_select')) + ); + } + + $sql = 'SELECT * FROM ' . BB_EXTENSIONS . ' ORDER BY group_id'; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get extension informations #2'); + } + + $extension_row = DB()->sql_fetchrowset($result); + $num_extension_row = DB()->num_rows($result); + DB()->sql_freeresult($result); + + if ($num_extension_row > 0) + { + $extension_row = sort_multi_array($extension_row, 'group_name', 'ASC'); + + for ($i = 0; $i < $num_extension_row; $i++) + { + if ($submit) + { + $template->assign_block_vars('extension_row', array( + 'EXT_ID' => $extension_row[$i]['ext_id'], + 'EXTENSION' => $extension_row[$i]['extension'], + 'EXTENSION_EXPLAIN' => $extension_explain_list[$i], + 'S_GROUP_SELECT' => group_select('group_select[]', $group_select_list[$i])) + ); + } + else + { + $template->assign_block_vars('extension_row', array( + 'EXT_ID' => $extension_row[$i]['ext_id'], + 'EXTENSION' => $extension_row[$i]['extension'], + 'EXTENSION_EXPLAIN' => $extension_row[$i]['comment'], + 'S_GROUP_SELECT' => group_select('group_select[]', $extension_row[$i]['group_id'])) + ); + } + } + } + +} + +// Extension Groups +if ($submit && $mode == 'groups') +{ + // Change Extension Groups ? + $group_change_list = get_var('group_change_list', array(0)); + $extension_group_list = get_var('extension_group_list', array('')); + $group_allowed_list = get_var('allowed_list', array(0)); + $download_mode_list = get_var('download_mode_list', array(0)); + $category_list = get_var('category_list', array(0)); + $upload_icon_list = get_var('upload_icon_list', array('')); + $filesize_list = get_var('max_filesize_list', array(0)); + $size_select_list = get_var('size_select_list', array('')); + + $allowed_list = array(); + + for ($i = 0; $i < sizeof($group_allowed_list); $i++) + { + for ($j = 0; $j < sizeof($group_change_list); $j++) + { + if ($group_allowed_list[$i] == $group_change_list[$j]) + { + $allowed_list[$j] = 1; + } + } + } + + for ($i = 0; $i < sizeof($group_change_list); $i++) + { + $allowed = (isset($allowed_list[$i])) ? 1 : 0; + + $filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : ( ($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i] ); + + $sql_ary = array( + 'group_name' => (string) $extension_group_list[$i], + 'cat_id' => (int) $category_list[$i], + 'allow_group' => (int) $allowed, + 'download_mode' => (int) $download_mode_list[$i], + 'upload_icon' => (string) $upload_icon_list[$i], + 'max_filesize' => (int) $filesize_list[$i] + ); + + $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . ' SET ' . attach_mod_sql_build_array('UPDATE', $sql_ary) . ' + WHERE group_id = ' . (int) $group_change_list[$i]; + + if (!(DB()->sql_query($sql))) + { + bb_die('Could not update extension groups informations'); + } + } + + // Delete Extension Groups + $group_id_list = get_var('group_id_list', array(0)); + + $group_id_sql = implode(', ', $group_id_list); + + if ($group_id_sql != '') + { + $sql = 'DELETE + FROM ' . BB_EXTENSION_GROUPS . ' + WHERE group_id IN (' . $group_id_sql . ')'; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not delete extension groups'); + } + + // Set corresponding Extensions to a pending Group + $sql = 'UPDATE ' . BB_EXTENSIONS . ' + SET group_id = 0 + WHERE group_id IN (' . $group_id_sql . ')'; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not assign extensions to pending group'); + } + } + + // Add Extensions? + $extension_group = get_var('add_extension_group', ''); + $download_mode = get_var('add_download_mode', 0); + $cat_id = get_var('add_category', 0); + $upload_icon = get_var('add_upload_icon', ''); + $filesize = get_var('add_max_filesize', 0); + $size_select = get_var('add_size_select', ''); + + $is_allowed = (isset($_POST['add_allowed'])) ? 1 : 0; + $add = ( isset($_POST['add_extension_group_check']) ) ? TRUE : FALSE; + + if ($extension_group != '' && $add) + { + // check Extension Group + $sql = 'SELECT group_name FROM ' . BB_EXTENSION_GROUPS; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not query extension groups table'); + } + + $row = DB()->sql_fetchrowset($result); + $num_rows = DB()->num_rows($result); + DB()->sql_freeresult($result); + + if ($num_rows > 0) + { + for ($i = 0; $i < $num_rows; $i++) + { + if ($row[$i]['group_name'] == $extension_group) + { + $error = TRUE; + if( isset($error_msg) ) + { + $error_msg .= '
        '; + } + $error_msg .= sprintf($lang['EXTENSION_GROUP_EXIST'], $extension_group); + } + } + } + + if (!@$error) + { + $filesize = ($size_select == 'kb') ? round($filesize * 1024) : ( ($size_select == 'mb') ? round($filesize * 1048576) : $filesize ); + + $sql_ary = array( + 'group_name' => (string) $extension_group, + 'cat_id' => (int) $cat_id, + 'allow_group' => (int) $is_allowed, + 'download_mode' => (int) $download_mode, + 'upload_icon' => (string) $upload_icon, + 'max_filesize' => (int) $filesize, + 'forum_permissions' => '' + ); + + $sql = 'INSERT INTO ' . BB_EXTENSION_GROUPS . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary); + + if (!(DB()->sql_query($sql))) + { + bb_die('Could not add extension group'); + } + } + + } + + if (!@$error) + { + bb_die($lang['ATTACH_CONFIG_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + } +} + +if ($mode == 'groups') +{ + // Extension Groups + if (!$size && !$submit) + { + $max_add_filesize = $attach_config['max_filesize']; + + $size = ($max_add_filesize >= 1048576) ? 'mb' : ( ($max_add_filesize >= 1024) ? 'kb' : 'b' ); + } + + if ($max_add_filesize >= 1048576) + { + $max_add_filesize = round($max_add_filesize / 1048576 * 100) / 100; + } + else if ( $max_add_filesize >= 1024) + { + $max_add_filesize = round($max_add_filesize / 1024 * 100) / 100; + } + + $viewgroup = get_var(POST_GROUPS_URL, 0); + + $template->assign_vars(array( + 'TPL_ATTACH_EXTENSION_GROUPS' => true, + 'ADD_GROUP_NAME' => ( isset($submit) ) ? @$extension_group : '', + 'MAX_FILESIZE' => $max_add_filesize, + 'S_FILESIZE' => size_select('add_size_select', $size), + 'S_ADD_DOWNLOAD_MODE' => download_select('add_download_mode'), + 'S_SELECT_CAT' => category_select('add_category'), + 'S_CANCEL_ACTION' => "admin_extensions.php?mode=groups", + 'S_ATTACH_ACTION' => "admin_extensions.php?mode=groups") + ); + + $sql = 'SELECT * FROM ' . BB_EXTENSION_GROUPS; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get extension group informations'); + } + + $extension_group = DB()->sql_fetchrowset($result); + $num_extension_group = DB()->num_rows($result); + DB()->sql_freeresult($result); + + for ($i = 0; $i < $num_extension_group; $i++) + { + // Format the filesize + if (!$extension_group[$i]['max_filesize']) + { + $extension_group[$i]['max_filesize'] = $attach_config['max_filesize']; + } + + $size_format = ($extension_group[$i]['max_filesize'] >= 1048576) ? 'mb' : ( ($extension_group[$i]['max_filesize'] >= 1024) ? 'kb' : 'b' ); + + if ( $extension_group[$i]['max_filesize'] >= 1048576) + { + $extension_group[$i]['max_filesize'] = round($extension_group[$i]['max_filesize'] / 1048576 * 100) / 100; + } + else if($extension_group[$i]['max_filesize'] >= 1024) + { + $extension_group[$i]['max_filesize'] = round($extension_group[$i]['max_filesize'] / 1024 * 100) / 100; + } + + $s_allowed = ($extension_group[$i]['allow_group'] == 1) ? 'checked="checked"' : ''; + + $template->assign_block_vars('grouprow', array( + 'GROUP_ID' => $extension_group[$i]['group_id'], + 'EXTENSION_GROUP' => $extension_group[$i]['group_name'], + 'UPLOAD_ICON' => $extension_group[$i]['upload_icon'], + + 'S_ALLOW_SELECTED' => $s_allowed, + 'S_SELECT_CAT' => category_select('category_list[]', $extension_group[$i]['group_id']), + 'S_DOWNLOAD_MODE' => download_select('download_mode_list[]', $extension_group[$i]['group_id']), + 'S_FILESIZE' => size_select('size_select_list[]', $size_format), + + 'MAX_FILESIZE' => $extension_group[$i]['max_filesize'], + 'CAT_BOX' => ( $viewgroup == $extension_group[$i]['group_id'] ) ? '+' : '-', + 'U_VIEWGROUP' => ( $viewgroup == $extension_group[$i]['group_id'] ) ? "admin_extensions.php?mode=groups" : "admin_extensions.php?mode=groups&" . POST_GROUPS_URL . "=" . $extension_group[$i]['group_id'], + 'U_FORUM_PERMISSIONS' => "admin_extensions.php?mode=$mode&e_mode=perm&e_group=" . $extension_group[$i]['group_id']) + ); + + if ($viewgroup && $viewgroup == $extension_group[$i]['group_id']) + { + $sql = 'SELECT comment, extension FROM ' . BB_EXTENSIONS . ' WHERE group_id = ' . (int) $viewgroup; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not get extension informations #3'); + } + + $extension = DB()->sql_fetchrowset($result); + $num_extension = DB()->num_rows($result); + DB()->sql_freeresult($result); + + for ($j = 0; $j < $num_extension; $j++) + { + $template->assign_block_vars('grouprow.extensionrow', array( + 'EXPLANATION' => $extension[$j]['comment'], + 'EXTENSION' => $extension[$j]['extension']) + ); + } + } + } +} + +if ($e_mode == 'perm') +{ + $group = get_var('e_group', 0); + + $add_forum = (isset($_POST['add_forum'])) ? TRUE : FALSE; + $delete_forum = (isset($_POST['del_forum'])) ? TRUE : FALSE; + + if (isset($_POST['close_perm'])) + { + $e_mode = ''; + } +} + +// Add Forums +if (@$add_forum && $e_mode == 'perm' && $group) +{ + $add_forums_list = get_var('entries', array(0)); + $add_all_forums = FALSE; + + for ($i = 0; $i < sizeof($add_forums_list); $i++) + { + if ($add_forums_list[$i] == 0) + { + $add_all_forums = TRUE; + } + } + + // If we add ALL FORUMS, we are able to overwrite the Permissions + if ($add_all_forums) + { + $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '' WHERE group_id = " . (int) $group; + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not update permissions #1'); + } + } + + // Else we have to add Permissions + if (!$add_all_forums) + { + $sql = 'SELECT forum_permissions + FROM ' . BB_EXTENSION_GROUPS . ' + WHERE group_id = ' . intval($group) . ' + LIMIT 1'; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get group permissions from ' . BB_EXTENSION_GROUPS); + } + + $row = DB()->sql_fetchrow($result); + DB()->sql_freeresult($result); + + if (trim($row['forum_permissions']) == '') + { + $auth_p = array(); + } + else + { + $auth_p = auth_unpack($row['forum_permissions']); + } + + // Generate array for Auth_Pack, do not add doubled forums + for ($i = 0; $i < sizeof($add_forums_list); $i++) + { + if (!in_array($add_forums_list[$i], $auth_p)) + { + $auth_p[] = $add_forums_list[$i]; + } + } + + $auth_bitstream = auth_pack($auth_p); + + $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '" . attach_mod_sql_escape($auth_bitstream) . "' WHERE group_id = " . (int) $group; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not update permissions #2'); + } + } + +} + +// Delete Forums +if (@$delete_forum && $e_mode == 'perm' && $group) +{ + $delete_forums_list = get_var('entries', array(0)); + + // Get the current Forums + $sql = 'SELECT forum_permissions + FROM ' . BB_EXTENSION_GROUPS . ' + WHERE group_id = ' . intval($group) . ' + LIMIT 1'; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get group permissions from ' . BB_EXTENSION_GROUPS); + } + + $row = DB()->sql_fetchrow($result); + DB()->sql_freeresult($result); + + $auth_p2 = auth_unpack(trim($row['forum_permissions'])); + $auth_p = array(); + + // Generate array for Auth_Pack, delete the chosen ones + for ($i = 0; $i < sizeof($auth_p2); $i++) + { + if (!in_array($auth_p2[$i], $delete_forums_list)) + { + $auth_p[] = $auth_p2[$i]; + } + } + + $auth_bitstream = (sizeof($auth_p) > 0) ? auth_pack($auth_p) : ''; + + $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '" . attach_mod_sql_escape($auth_bitstream) . "' WHERE group_id = " . (int) $group; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not update permissions #3'); + } +} + +// Display the Group Permissions Box for configuring it +if ($e_mode == 'perm' && $group) +{ + $sql = 'SELECT group_name, forum_permissions + FROM ' . BB_EXTENSION_GROUPS . ' + WHERE group_id = ' . intval($group) . ' + LIMIT 1'; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get group name from ' . BB_EXTENSION_GROUPS); + } + + $row = DB()->sql_fetchrow($result); + DB()->sql_freeresult($result); + + $group_name = $row['group_name']; + $allowed_forums = trim($row['forum_permissions']); + + $forum_perm = array(); + + if ($allowed_forums == '') + { + $forum_perm[0]['forum_id'] = 0; + $forum_perm[0]['forum_name'] = $lang['PERM_ALL_FORUMS']; + } + else + { + $forum_p = array(); + $act_id = 0; + $forum_p = auth_unpack($allowed_forums); + $sql = "SELECT forum_id, forum_name FROM " . BB_FORUMS . " WHERE forum_id IN (" . implode(', ', $forum_p) . ")"; + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get forum names'); + } + + while ($row = DB()->sql_fetchrow($result)) + { + $forum_perm[$act_id]['forum_id'] = $row['forum_id']; + $forum_perm[$act_id]['forum_name'] = $row['forum_name']; + $act_id++; + } + } + + for ($i = 0; $i < sizeof($forum_perm); $i++) + { + $template->assign_block_vars('allow_option_values', array( + 'VALUE' => $forum_perm[$i]['forum_id'], + 'OPTION' => htmlCHR($forum_perm[$i]['forum_name'])) + ); + } + + $template->assign_vars(array( + 'TPL_ATTACH_EXTENSION_GROUPS_PERMISSIONS' => true, + 'L_GROUP_PERMISSIONS_TITLE' => sprintf($lang['GROUP_PERMISSIONS_TITLE_ADMIN'], trim($group_name)), + 'A_PERM_ACTION' => "admin_extensions.php?mode=groups&e_mode=perm&e_group=$group") + ); + + $forum_option_values = array(0 => $lang['PERM_ALL_FORUMS']); + + $sql = "SELECT forum_id, forum_name FROM " . BB_FORUMS; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not get forums #1'); + } + + while ($row = DB()->sql_fetchrow($result)) + { + $forum_option_values[intval($row['forum_id'])] = $row['forum_name']; + } + DB()->sql_freeresult($result); + + foreach ($forum_option_values as $value => $option) + { + $template->assign_block_vars('forum_option_values', array( + 'VALUE' => $value, + 'OPTION' => htmlCHR($option)) + ); + } + + $empty_perm_forums = array(); + + $sql = "SELECT forum_id, forum_name FROM " . BB_FORUMS . " WHERE auth_attachments < " . AUTH_ADMIN; + + if (!($f_result = DB()->sql_query($sql))) + { + bb_die('Could not get forums #2'); + } + + while ($row = DB()->sql_fetchrow($f_result)) + { + $forum_id = $row['forum_id']; + + $sql = "SELECT forum_permissions + FROM " . BB_EXTENSION_GROUPS . " + WHERE allow_group = 1 + ORDER BY group_name ASC"; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not query extension groups'); + } + + $rows = DB()->sql_fetchrowset($result); + $num_rows = DB()->num_rows($result); + DB()->sql_freeresult($result); + + $found_forum = FALSE; + + for ($i = 0; $i < $num_rows; $i++) + { + $allowed_forums = auth_unpack(trim($rows[$i]['forum_permissions'])); + if (in_array($forum_id, $allowed_forums) || trim($rows[$i]['forum_permissions']) == '') + { + $found_forum = TRUE; + break; + } + } + + if (!$found_forum) + { + $empty_perm_forums[$forum_id] = $row['forum_name']; + } + } + DB()->sql_freeresult($f_result); + + $message = ''; + + foreach ($empty_perm_forums as $forum_id => $forum_name) + { + $message .= ( $message == '' ) ? $forum_name : '
        ' . $forum_name; + } + + if (sizeof($empty_perm_forums) > 0) + { + $template->assign_vars(array('ERROR_MESSAGE' => $lang['NOTE_ADMIN_EMPTY_GROUP_PERMISSIONS'] . $message)); + } +} + +if (@$error) +{ + $template->assign_vars(array('ERROR_MESSAGE' => $error_msg)); +} + print_page('admin_extensions.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_forum_prune.php b/upload/admin/admin_forum_prune.php index f6d85a94b..65eb9f302 100644 --- a/upload/admin/admin_forum_prune.php +++ b/upload/admin/admin_forum_prune.php @@ -1,63 +1,63 @@ -fetch_rowset($sql) as $i => $row) - { - $pruned_topics = topic_delete('prune', $row['forum_id'], $prunetime, !empty($_POST['prune_all_topic_types'])); - $pruned_total += $pruned_topics; - $prune_performed = true; - - $template->assign_block_vars('pruned', array( - 'ROW_CLASS' => !($i % 2) ? 'row1' : 'row2', - 'FORUM_NAME' => htmlCHR($row['forum_name']), - 'PRUNED_TOPICS' => $pruned_topics, - )); - } - if (!$prune_performed) - { - bb_die($lang['NONE_SELECTED']); - } - if (!$pruned_total) - { - bb_die($lang['NO_SEARCH_MATCH']); - } -} - -$template->assign_vars(array( - 'PRUNED_TOTAL' => $pruned_total, - 'S_PRUNE_ACTION' => basename(__FILE__), - 'SEL_FORUM' => get_forum_select('admin', 'f[]', null, 65, 16, '', $all_forums), -)); - +fetch_rowset($sql) as $i => $row) + { + $pruned_topics = topic_delete('prune', $row['forum_id'], $prunetime, !empty($_POST['prune_all_topic_types'])); + $pruned_total += $pruned_topics; + $prune_performed = true; + + $template->assign_block_vars('pruned', array( + 'ROW_CLASS' => !($i % 2) ? 'row1' : 'row2', + 'FORUM_NAME' => htmlCHR($row['forum_name']), + 'PRUNED_TOPICS' => $pruned_topics, + )); + } + if (!$prune_performed) + { + bb_die($lang['NONE_SELECTED']); + } + if (!$pruned_total) + { + bb_die($lang['NO_SEARCH_MATCH']); + } +} + +$template->assign_vars(array( + 'PRUNED_TOTAL' => $pruned_total, + 'S_PRUNE_ACTION' => basename(__FILE__), + 'SEL_FORUM' => get_forum_select('admin', 'f[]', null, 65, 16, '', $all_forums), +)); + print_page('admin_forum_prune.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_forumauth.php b/upload/admin/admin_forumauth.php index 04b685659..b08f678aa 100644 --- a/upload/admin/admin_forumauth.php +++ b/upload/admin/admin_forumauth.php @@ -1,254 +1,254 @@ - array(AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_ALL, AUTH_ALL, AUTH_MOD, AUTH_MOD), // Public -/* Reg */ 1 => array(AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD), // Registered -/* Reg [Hid] */ 2 => array(AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD), // Registered [Hidden] -/* Priv */ 3 => array(AUTH_REG, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD), // Private -/* Priv [Hid] */ 4 => array(AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD), // Private [Hidden] -/* MOD */ 5 => array(AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators -/* MOD [Hid] */ 6 => array(AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators [Hidden] -); - -$simple_auth_types = array( - $lang['PUBLIC'], - $lang['REGISTERED'], - $lang['REGISTERED'] .' ['. $lang['HIDDEN'] .']', - $lang['PRIVATE'], - $lang['PRIVATE'] .' ['. $lang['HIDDEN'] .']', - $lang['MODERATORS'], - $lang['MODERATORS'] .' ['. $lang['HIDDEN'] .']', -); - -$field_names = array(); -foreach ($forum_auth_fields as $auth_type) -{ - $field_names[$auth_type] = $lang[strtoupper($auth_type)]; -} - -$forum_auth_levels = array('ALL', 'REG', 'PRIVATE', 'MOD', 'ADMIN'); -$forum_auth_const = array(AUTH_ALL, AUTH_REG, AUTH_ACL, AUTH_MOD, AUTH_ADMIN); - -if (@$_REQUEST[POST_FORUM_URL]) -{ - $forum_id = (int) $_REQUEST[POST_FORUM_URL]; - $forum_sql = "WHERE forum_id = $forum_id"; -} -else -{ - unset($forum_id); - $forum_sql = ''; -} - -if( isset($_GET['adv']) ) -{ - $adv = intval($_GET['adv']); -} -else -{ - unset($adv); -} - -// -// Start program proper -// -if( isset($_POST['submit']) ) -{ - $sql = ''; - - if(!empty($forum_id)) - { - if(isset($_POST['simpleauth'])) - { - $simple_ary = $simple_auth_ary[intval($_POST['simpleauth'])]; - - for($i = 0; $i < count($simple_ary); $i++) - { - $sql .= ( ( $sql != '' ) ? ', ' : '' ) . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i]; - } - - if (is_array($simple_ary)) - { - $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id"; - } - } - else - { - for ($i = 0; $i < count($forum_auth_fields); $i++) - { - $value = intval($_POST[$forum_auth_fields[$i]]); - - if ($forum_auth_fields[$i] == 'auth_vote') - { - if ($_POST['auth_vote'] == AUTH_ALL) - { - $value = AUTH_REG; - } - } - - $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value; - } - - $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id"; - } - - if ($sql != '') - { - if (!DB()->sql_query($sql)) - { - bb_die('Could not update auth table'); - } - } - - $forum_sql = ''; - $adv = 0; - } - - $datastore->update('cat_forums'); - bb_die($lang['FORUM_AUTH_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMAUTH'], '', "")); - -} // End of submit - -// -// Get required information, either all forums if -// no id was specified or just the requsted if it -// was -// -$forum_rows = DB()->fetch_rowset("SELECT * FROM ". BB_FORUMS ." $forum_sql"); - -if (empty($forum_id)) -{ - // Output the selection table if no forum id was specified - $template->assign_vars(array( - 'TPL_AUTH_SELECT_FORUM' => true, - 'S_AUTH_ACTION' => "admin_forumauth.php", - 'S_AUTH_SELECT' => get_forum_select('admin', 'f', null, 80), - )); - -} -else -{ - // Output the authorisation details if an id was specified - $forum_name = $forum_rows[0]['forum_name']; - - @reset($simple_auth_ary); - while (list($key, $auth_levels) = each($simple_auth_ary)) - { - $matched = 1; - for ($k = 0; $k < count($auth_levels); $k++) - { - $matched_type = $key; - - if ($forum_rows[0][$forum_auth_fields[$k]] != $auth_levels[$k]) - { - $matched = 0; - } - } - - if ( $matched ) - { - break; - } - } - - // - // If we didn't get a match above then we - // automatically switch into 'advanced' mode - // - if ( !isset($adv) && !$matched ) - { - $adv = 1; - } - - $s_column_span = 0; - - if (empty($adv)) - { - $simple_auth = ''; - - $template->assign_block_vars('forum_auth', array( - 'CELL_TITLE' => $lang['SIMPLE_MODE'], - 'S_AUTH_LEVELS_SELECT' => $simple_auth, - )); - - $s_column_span++; - } - else - { - // - // Output values of individual - // fields - // - for ($j = 0; $j < count($forum_auth_fields); $j++) - { - $custom_auth[$j] = '  '; - - $cell_title = $field_names[$forum_auth_fields[$j]]; - - $template->assign_block_vars('forum_auth', array( - 'CELL_TITLE' => $cell_title, - 'S_AUTH_LEVELS_SELECT' => $custom_auth[$j], - )); - - $s_column_span++; - } - } - - $adv_mode = ( empty($adv) ) ? '1' : '0'; - $switch_mode = "admin_forumauth.php?f=$forum_id&adv=$adv_mode"; - $switch_mode_text = ( empty($adv) ) ? $lang['ADVANCED_MODE'] : $lang['SIMPLE_MODE']; - $u_switch_mode = '' . $switch_mode_text . ''; - - $s_hidden_fields = ''; - - $template->assign_vars(array( - 'TPL_EDIT_FORUM_AUTH' => true, - 'FORUM_NAME' => htmlCHR($forum_name), - 'U_SWITCH_MODE' => $u_switch_mode, - 'S_FORUMAUTH_ACTION' => "admin_forumauth.php", - 'S_COLUMN_SPAN' => $s_column_span, - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - )); -} - + array(AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_ALL, AUTH_ALL, AUTH_MOD, AUTH_MOD), // Public +/* Reg */ 1 => array(AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD), // Registered +/* Reg [Hid] */ 2 => array(AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD), // Registered [Hidden] +/* Priv */ 3 => array(AUTH_REG, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD), // Private +/* Priv [Hid] */ 4 => array(AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD), // Private [Hidden] +/* MOD */ 5 => array(AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators +/* MOD [Hid] */ 6 => array(AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators [Hidden] +); + +$simple_auth_types = array( + $lang['PUBLIC'], + $lang['REGISTERED'], + $lang['REGISTERED'] .' ['. $lang['HIDDEN'] .']', + $lang['PRIVATE'], + $lang['PRIVATE'] .' ['. $lang['HIDDEN'] .']', + $lang['MODERATORS'], + $lang['MODERATORS'] .' ['. $lang['HIDDEN'] .']', +); + +$field_names = array(); +foreach ($forum_auth_fields as $auth_type) +{ + $field_names[$auth_type] = $lang[strtoupper($auth_type)]; +} + +$forum_auth_levels = array('ALL', 'REG', 'PRIVATE', 'MOD', 'ADMIN'); +$forum_auth_const = array(AUTH_ALL, AUTH_REG, AUTH_ACL, AUTH_MOD, AUTH_ADMIN); + +if (@$_REQUEST[POST_FORUM_URL]) +{ + $forum_id = (int) $_REQUEST[POST_FORUM_URL]; + $forum_sql = "WHERE forum_id = $forum_id"; +} +else +{ + unset($forum_id); + $forum_sql = ''; +} + +if( isset($_GET['adv']) ) +{ + $adv = intval($_GET['adv']); +} +else +{ + unset($adv); +} + +// +// Start program proper +// +if( isset($_POST['submit']) ) +{ + $sql = ''; + + if(!empty($forum_id)) + { + if(isset($_POST['simpleauth'])) + { + $simple_ary = $simple_auth_ary[intval($_POST['simpleauth'])]; + + for($i = 0; $i < count($simple_ary); $i++) + { + $sql .= ( ( $sql != '' ) ? ', ' : '' ) . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i]; + } + + if (is_array($simple_ary)) + { + $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id"; + } + } + else + { + for ($i = 0; $i < count($forum_auth_fields); $i++) + { + $value = intval($_POST[$forum_auth_fields[$i]]); + + if ($forum_auth_fields[$i] == 'auth_vote') + { + if ($_POST['auth_vote'] == AUTH_ALL) + { + $value = AUTH_REG; + } + } + + $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value; + } + + $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id"; + } + + if ($sql != '') + { + if (!DB()->sql_query($sql)) + { + bb_die('Could not update auth table'); + } + } + + $forum_sql = ''; + $adv = 0; + } + + $datastore->update('cat_forums'); + bb_die($lang['FORUM_AUTH_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMAUTH'], '', "")); + +} // End of submit + +// +// Get required information, either all forums if +// no id was specified or just the requsted if it +// was +// +$forum_rows = DB()->fetch_rowset("SELECT * FROM ". BB_FORUMS ." $forum_sql"); + +if (empty($forum_id)) +{ + // Output the selection table if no forum id was specified + $template->assign_vars(array( + 'TPL_AUTH_SELECT_FORUM' => true, + 'S_AUTH_ACTION' => "admin_forumauth.php", + 'S_AUTH_SELECT' => get_forum_select('admin', 'f', null, 80), + )); + +} +else +{ + // Output the authorisation details if an id was specified + $forum_name = $forum_rows[0]['forum_name']; + + @reset($simple_auth_ary); + while (list($key, $auth_levels) = each($simple_auth_ary)) + { + $matched = 1; + for ($k = 0; $k < count($auth_levels); $k++) + { + $matched_type = $key; + + if ($forum_rows[0][$forum_auth_fields[$k]] != $auth_levels[$k]) + { + $matched = 0; + } + } + + if ( $matched ) + { + break; + } + } + + // + // If we didn't get a match above then we + // automatically switch into 'advanced' mode + // + if ( !isset($adv) && !$matched ) + { + $adv = 1; + } + + $s_column_span = 0; + + if (empty($adv)) + { + $simple_auth = ''; + + $template->assign_block_vars('forum_auth', array( + 'CELL_TITLE' => $lang['SIMPLE_MODE'], + 'S_AUTH_LEVELS_SELECT' => $simple_auth, + )); + + $s_column_span++; + } + else + { + // + // Output values of individual + // fields + // + for ($j = 0; $j < count($forum_auth_fields); $j++) + { + $custom_auth[$j] = '  '; + + $cell_title = $field_names[$forum_auth_fields[$j]]; + + $template->assign_block_vars('forum_auth', array( + 'CELL_TITLE' => $cell_title, + 'S_AUTH_LEVELS_SELECT' => $custom_auth[$j], + )); + + $s_column_span++; + } + } + + $adv_mode = ( empty($adv) ) ? '1' : '0'; + $switch_mode = "admin_forumauth.php?f=$forum_id&adv=$adv_mode"; + $switch_mode_text = ( empty($adv) ) ? $lang['ADVANCED_MODE'] : $lang['SIMPLE_MODE']; + $u_switch_mode = '' . $switch_mode_text . ''; + + $s_hidden_fields = ''; + + $template->assign_vars(array( + 'TPL_EDIT_FORUM_AUTH' => true, + 'FORUM_NAME' => htmlCHR($forum_name), + 'U_SWITCH_MODE' => $u_switch_mode, + 'S_FORUMAUTH_ACTION' => "admin_forumauth.php", + 'S_COLUMN_SPAN' => $s_column_span, + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + )); +} + print_page('admin_forumauth.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_forumauth_list.php b/upload/admin/admin_forumauth_list.php index d809c410f..846805280 100644 --- a/upload/admin/admin_forumauth_list.php +++ b/upload/admin/admin_forumauth_list.php @@ -1,365 +1,365 @@ - array(AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_ALL), // Public -/* Reg */ 1 => array(AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG), // Registered -/* Reg [Hid] */ 2 => array(AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG), // Registered [Hidden] -/* Priv */ 3 => array(AUTH_REG, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL), // Private -/* Priv [Hid] */ 4 => array(AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL), // Private [Hidden] -/* MOD */ 5 => array(AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators -/* MOD [Hid] */ 6 => array(AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators [Hidden] -); - -$simple_auth_types = array( - $lang['PUBLIC'], - $lang['REGISTERED'], - $lang['REGISTERED'] .' ['. $lang['HIDDEN'] .']', - $lang['PRIVATE'], - $lang['PRIVATE'] .' ['. $lang['HIDDEN'] .']', - $lang['MODERATORS'], - $lang['MODERATORS'] .' ['. $lang['HIDDEN'] .']', -); - -$forum_auth_fields = array( - 'auth_view', - 'auth_read', - 'auth_reply', - 'auth_edit', - 'auth_delete', - 'auth_vote', - 'auth_pollcreate', - 'auth_attachments', - 'auth_download', - 'auth_post', - 'auth_sticky', - 'auth_announce', -); - -$field_names = array(); -foreach ($forum_auth_fields as $auth_type) -{ - $field_names[$auth_type] = $lang[strtoupper($auth_type)]; -} - -$forum_auth_levels = array('ALL', 'REG', 'PRIVATE', 'MOD', 'ADMIN'); -$forum_auth_const = array(AUTH_ALL, AUTH_REG, AUTH_ACL, AUTH_MOD, AUTH_ADMIN); - -if(isset($_GET[POST_FORUM_URL]) || isset($_POST[POST_FORUM_URL])) -{ - $forum_id = (isset($_POST[POST_FORUM_URL])) ? intval($_POST[POST_FORUM_URL]) : intval($_GET[POST_FORUM_URL]); - $forum_sql = "AND forum_id = $forum_id"; -} -else -{ - unset($forum_id); - $forum_sql = ''; -} - -if(isset($_GET[POST_CAT_URL]) || isset($_POST[POST_CAT_URL])) -{ - $cat_id = (isset($_POST[POST_CAT_URL])) ? intval($_POST[POST_CAT_URL]) : intval($_GET[POST_CAT_URL]); - $cat_sql = "AND c.cat_id = $cat_id"; -} -else -{ - unset($cat_id); - $cat_sql = ''; -} - -if( isset($_GET['adv']) ) -{ - $adv = intval($_GET['adv']); -} -else -{ - unset($adv); -} - -// -// Start program proper -// -if( isset($_POST['submit']) ) -{ - $sql = ''; - - if(!empty($forum_id)) - { - if(isset($_POST['simpleauth'])) - { - $simple_ary = $simple_auth_ary[intval($_POST['simpleauth'])]; - - for($i = 0; $i < count($simple_ary); $i++) - { - $sql .= ( ( $sql != '' ) ? ', ' : '' ) . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i]; - } - - if (is_array($simple_ary)) - { - $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id"; - } - } - else - { - for($i = 0; $i < count($forum_auth_fields); $i++) - { - $value = intval($_POST[$forum_auth_fields[$i]]); - - if ( $forum_auth_fields[$i] == 'auth_vote' ) - { - if ( $_POST['auth_vote'] == AUTH_ALL ) - { - $value = AUTH_REG; - } - } - - $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value; - } - - $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id"; - } - - if ($sql != '') - { - if (!DB()->sql_query($sql)) - { - bb_die('Could not update auth table #1'); - } - } - - $forum_sql = ''; - $adv = 0; - } - elseif (!empty($cat_id)) - { - for ($i = 0; $i < count($forum_auth_fields); $i++) - { - $value = intval($_POST[$forum_auth_fields[$i]]); - - if ($forum_auth_fields[$i] == 'auth_vote') - { - if ( $_POST['auth_vote'] == AUTH_ALL ) - { - $value = AUTH_REG; - } - } - - $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value; - } - - $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE cat_id = $cat_id"; - - if ($sql != '') - { - if (!DB()->sql_query($sql)) - { - bb_die('Could not update auth table #2'); - } - } - - $cat_sql = ''; - } - - $datastore->update('cat_forums'); - bb_die($lang['FORUM_AUTH_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMAUTH'], '', "")); - -} // End of submit - -// -// Get required information, either all forums if -// no id was specified or just the requsted forum -// or category if it was -// -$sql = "SELECT f.* - FROM " . BB_FORUMS . " f, " . BB_CATEGORIES . " c - WHERE c.cat_id = f.cat_id - $forum_sql $cat_sql - ORDER BY c.cat_order ASC, f.forum_order ASC"; -if (!($result = DB()->sql_query($sql))) -{ - bb_die('Could not obtain forum list'); -} - -$forum_rows = DB()->sql_fetchrowset($result); -DB()->sql_freeresult($result); - -if( empty($forum_id) && empty($cat_id) ) -{ - // - // Output the summary list if no forum id was - // specified - // - $template->assign_vars(array( - 'TPL_AUTH_FORUM_LIST' => true, - 'S_COLUMN_SPAN' => count($forum_auth_fields)+1, - )); - - for ($i = 0; $iassign_block_vars('forum_auth_titles', array( - 'CELL_TITLE' => $field_names[$forum_auth_fields[$i]], - )); - } - - // Obtain the category list - $sql = "SELECT c.cat_id, c.cat_title, c.cat_order - FROM " . BB_CATEGORIES . " c - ORDER BY c.cat_order"; - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not query categories list #1'); - } - - $category_rows = DB()->sql_fetchrowset($result); - $cat_count = count($category_rows); - - for ($i=0; $i<$cat_count; $i++) - { - $cat_id = $category_rows[$i]['cat_id']; - - $template->assign_block_vars('cat_row', array( - 'CAT_NAME' => htmlCHR($category_rows[$i]['cat_title']), - 'CAT_URL' => 'admin_forumauth_list.php'.'?'.POST_CAT_URL.'='.$category_rows[$i]['cat_id']) - ); - - for ($j=0; $jassign_block_vars('cat_row.forum_row', array( - 'ROW_CLASS' => !($j % 2) ? 'row4' : 'row5', - 'FORUM_NAME' => ''. htmlCHR($forum_rows[$j]['forum_name']) .'', - 'IS_SUBFORUM' => $forum_rows[$j]['forum_parent'], - )); - - for ($k=0; $kassign_block_vars('cat_row.forum_row.forum_auth_data', array( - 'CELL_VALUE' => $lang['FORUM_' . $item_auth_level], - 'AUTH_EXPLAIN' => sprintf($lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $forum_auth_fields[$k])], $lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $item_auth_level)])) - ); - } - } - } - } -} -else -{ - // - // output the authorisation details if an category id was - // specified - // - - // - // first display the current details for all forums - // in the category - // - for ($i = 0; $iassign_block_vars('forum_auth_titles', array( - 'CELL_TITLE' => $field_names[$forum_auth_fields[$i]], - )); - } - - // obtain the category list - $sql = "SELECT c.cat_id, c.cat_title, c.cat_order - FROM " . BB_CATEGORIES . " c - WHERE c.cat_id = $cat_id - ORDER BY c.cat_order"; - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not query categories list #2'); - } - - $category_rows = DB()->sql_fetchrowset($result); - - $cat_id = $category_rows[0]['cat_id']; - $cat_name = $category_rows[0]['cat_title']; - - $template->assign_block_vars('cat_row', array( - 'CAT_NAME' => htmlCHR($cat_name), - 'CAT_URL' => 'admin_forumauth_list.php?'. POST_CAT_URL .'='. $cat_id) - ); - - for ($j=0; $jassign_block_vars('cat_row.forum_row', array( - 'ROW_CLASS' => !($j % 2) ? 'row4' : 'row5', - 'FORUM_NAME' => ''. htmlCHR($forum_rows[$j]['forum_name']) .'', - 'IS_SUBFORUM' => $forum_rows[$j]['forum_parent'], - )); - - for ($k=0; $kassign_block_vars('cat_row.forum_row.forum_auth_data', array( - 'CELL_VALUE' => $lang['FORUM_' . $item_auth_level], - 'AUTH_EXPLAIN' => sprintf($lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $forum_auth_fields[$k])], $lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $item_auth_level)])) - ); - } - } - } - - // - // next generate the information to allow the permissions to be changed - // note: we always read from the first forum in the category - // - for($j = 0; $j < count($forum_auth_fields); $j++) - { - $custom_auth[$j] = ''; - - $template->assign_block_vars('forum_auth_data', array( - 'S_AUTH_LEVELS_SELECT' => $custom_auth[$j]) - ); - } - - // - // finally pass any remaining items to the template - // - $s_hidden_fields = ''; - - $template->assign_vars(array( - 'TPL_AUTH_CAT' => true, - 'CAT_NAME' => htmlCHR($cat_name), - 'S_FORUMAUTH_ACTION' => "admin_forumauth_list.php", - 'S_COLUMN_SPAN' => count($forum_auth_fields)+1, - 'S_HIDDEN_FIELDS' => $s_hidden_fields) - ); -} - + array(AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_ALL), // Public +/* Reg */ 1 => array(AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG), // Registered +/* Reg [Hid] */ 2 => array(AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG), // Registered [Hidden] +/* Priv */ 3 => array(AUTH_REG, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL), // Private +/* Priv [Hid] */ 4 => array(AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL), // Private [Hidden] +/* MOD */ 5 => array(AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators +/* MOD [Hid] */ 6 => array(AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators [Hidden] +); + +$simple_auth_types = array( + $lang['PUBLIC'], + $lang['REGISTERED'], + $lang['REGISTERED'] .' ['. $lang['HIDDEN'] .']', + $lang['PRIVATE'], + $lang['PRIVATE'] .' ['. $lang['HIDDEN'] .']', + $lang['MODERATORS'], + $lang['MODERATORS'] .' ['. $lang['HIDDEN'] .']', +); + +$forum_auth_fields = array( + 'auth_view', + 'auth_read', + 'auth_reply', + 'auth_edit', + 'auth_delete', + 'auth_vote', + 'auth_pollcreate', + 'auth_attachments', + 'auth_download', + 'auth_post', + 'auth_sticky', + 'auth_announce', +); + +$field_names = array(); +foreach ($forum_auth_fields as $auth_type) +{ + $field_names[$auth_type] = $lang[strtoupper($auth_type)]; +} + +$forum_auth_levels = array('ALL', 'REG', 'PRIVATE', 'MOD', 'ADMIN'); +$forum_auth_const = array(AUTH_ALL, AUTH_REG, AUTH_ACL, AUTH_MOD, AUTH_ADMIN); + +if(isset($_GET[POST_FORUM_URL]) || isset($_POST[POST_FORUM_URL])) +{ + $forum_id = (isset($_POST[POST_FORUM_URL])) ? intval($_POST[POST_FORUM_URL]) : intval($_GET[POST_FORUM_URL]); + $forum_sql = "AND forum_id = $forum_id"; +} +else +{ + unset($forum_id); + $forum_sql = ''; +} + +if(isset($_GET[POST_CAT_URL]) || isset($_POST[POST_CAT_URL])) +{ + $cat_id = (isset($_POST[POST_CAT_URL])) ? intval($_POST[POST_CAT_URL]) : intval($_GET[POST_CAT_URL]); + $cat_sql = "AND c.cat_id = $cat_id"; +} +else +{ + unset($cat_id); + $cat_sql = ''; +} + +if( isset($_GET['adv']) ) +{ + $adv = intval($_GET['adv']); +} +else +{ + unset($adv); +} + +// +// Start program proper +// +if( isset($_POST['submit']) ) +{ + $sql = ''; + + if(!empty($forum_id)) + { + if(isset($_POST['simpleauth'])) + { + $simple_ary = $simple_auth_ary[intval($_POST['simpleauth'])]; + + for($i = 0; $i < count($simple_ary); $i++) + { + $sql .= ( ( $sql != '' ) ? ', ' : '' ) . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i]; + } + + if (is_array($simple_ary)) + { + $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id"; + } + } + else + { + for($i = 0; $i < count($forum_auth_fields); $i++) + { + $value = intval($_POST[$forum_auth_fields[$i]]); + + if ( $forum_auth_fields[$i] == 'auth_vote' ) + { + if ( $_POST['auth_vote'] == AUTH_ALL ) + { + $value = AUTH_REG; + } + } + + $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value; + } + + $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id"; + } + + if ($sql != '') + { + if (!DB()->sql_query($sql)) + { + bb_die('Could not update auth table #1'); + } + } + + $forum_sql = ''; + $adv = 0; + } + elseif (!empty($cat_id)) + { + for ($i = 0; $i < count($forum_auth_fields); $i++) + { + $value = intval($_POST[$forum_auth_fields[$i]]); + + if ($forum_auth_fields[$i] == 'auth_vote') + { + if ( $_POST['auth_vote'] == AUTH_ALL ) + { + $value = AUTH_REG; + } + } + + $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value; + } + + $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE cat_id = $cat_id"; + + if ($sql != '') + { + if (!DB()->sql_query($sql)) + { + bb_die('Could not update auth table #2'); + } + } + + $cat_sql = ''; + } + + $datastore->update('cat_forums'); + bb_die($lang['FORUM_AUTH_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMAUTH'], '', "")); + +} // End of submit + +// +// Get required information, either all forums if +// no id was specified or just the requsted forum +// or category if it was +// +$sql = "SELECT f.* + FROM " . BB_FORUMS . " f, " . BB_CATEGORIES . " c + WHERE c.cat_id = f.cat_id + $forum_sql $cat_sql + ORDER BY c.cat_order ASC, f.forum_order ASC"; +if (!($result = DB()->sql_query($sql))) +{ + bb_die('Could not obtain forum list'); +} + +$forum_rows = DB()->sql_fetchrowset($result); +DB()->sql_freeresult($result); + +if( empty($forum_id) && empty($cat_id) ) +{ + // + // Output the summary list if no forum id was + // specified + // + $template->assign_vars(array( + 'TPL_AUTH_FORUM_LIST' => true, + 'S_COLUMN_SPAN' => count($forum_auth_fields)+1, + )); + + for ($i = 0; $iassign_block_vars('forum_auth_titles', array( + 'CELL_TITLE' => $field_names[$forum_auth_fields[$i]], + )); + } + + // Obtain the category list + $sql = "SELECT c.cat_id, c.cat_title, c.cat_order + FROM " . BB_CATEGORIES . " c + ORDER BY c.cat_order"; + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not query categories list #1'); + } + + $category_rows = DB()->sql_fetchrowset($result); + $cat_count = count($category_rows); + + for ($i=0; $i<$cat_count; $i++) + { + $cat_id = $category_rows[$i]['cat_id']; + + $template->assign_block_vars('cat_row', array( + 'CAT_NAME' => htmlCHR($category_rows[$i]['cat_title']), + 'CAT_URL' => 'admin_forumauth_list.php'.'?'.POST_CAT_URL.'='.$category_rows[$i]['cat_id']) + ); + + for ($j=0; $jassign_block_vars('cat_row.forum_row', array( + 'ROW_CLASS' => !($j % 2) ? 'row4' : 'row5', + 'FORUM_NAME' => ''. htmlCHR($forum_rows[$j]['forum_name']) .'', + 'IS_SUBFORUM' => $forum_rows[$j]['forum_parent'], + )); + + for ($k=0; $kassign_block_vars('cat_row.forum_row.forum_auth_data', array( + 'CELL_VALUE' => $lang['FORUM_' . $item_auth_level], + 'AUTH_EXPLAIN' => sprintf($lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $forum_auth_fields[$k])], $lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $item_auth_level)])) + ); + } + } + } + } +} +else +{ + // + // output the authorisation details if an category id was + // specified + // + + // + // first display the current details for all forums + // in the category + // + for ($i = 0; $iassign_block_vars('forum_auth_titles', array( + 'CELL_TITLE' => $field_names[$forum_auth_fields[$i]], + )); + } + + // obtain the category list + $sql = "SELECT c.cat_id, c.cat_title, c.cat_order + FROM " . BB_CATEGORIES . " c + WHERE c.cat_id = $cat_id + ORDER BY c.cat_order"; + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not query categories list #2'); + } + + $category_rows = DB()->sql_fetchrowset($result); + + $cat_id = $category_rows[0]['cat_id']; + $cat_name = $category_rows[0]['cat_title']; + + $template->assign_block_vars('cat_row', array( + 'CAT_NAME' => htmlCHR($cat_name), + 'CAT_URL' => 'admin_forumauth_list.php?'. POST_CAT_URL .'='. $cat_id) + ); + + for ($j=0; $jassign_block_vars('cat_row.forum_row', array( + 'ROW_CLASS' => !($j % 2) ? 'row4' : 'row5', + 'FORUM_NAME' => ''. htmlCHR($forum_rows[$j]['forum_name']) .'', + 'IS_SUBFORUM' => $forum_rows[$j]['forum_parent'], + )); + + for ($k=0; $kassign_block_vars('cat_row.forum_row.forum_auth_data', array( + 'CELL_VALUE' => $lang['FORUM_' . $item_auth_level], + 'AUTH_EXPLAIN' => sprintf($lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $forum_auth_fields[$k])], $lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $item_auth_level)])) + ); + } + } + } + + // + // next generate the information to allow the permissions to be changed + // note: we always read from the first forum in the category + // + for($j = 0; $j < count($forum_auth_fields); $j++) + { + $custom_auth[$j] = ''; + + $template->assign_block_vars('forum_auth_data', array( + 'S_AUTH_LEVELS_SELECT' => $custom_auth[$j]) + ); + } + + // + // finally pass any remaining items to the template + // + $s_hidden_fields = ''; + + $template->assign_vars(array( + 'TPL_AUTH_CAT' => true, + 'CAT_NAME' => htmlCHR($cat_name), + 'S_FORUMAUTH_ACTION' => "admin_forumauth_list.php", + 'S_COLUMN_SPAN' => count($forum_auth_fields)+1, + 'S_HIDDEN_FIELDS' => $s_hidden_fields) + ); +} + print_page('admin_forumauth_list.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_forums.php b/upload/admin/admin_forums.php index 1cfa56a58..c3264607f 100644 --- a/upload/admin/admin_forums.php +++ b/upload/admin/admin_forums.php @@ -1,1222 +1,1222 @@ - AUTH_ALL, - 'auth_read' => AUTH_ALL, - 'auth_post' => AUTH_REG, - 'auth_reply' => AUTH_REG, - 'auth_edit' => AUTH_REG, - 'auth_delete' => AUTH_REG, - 'auth_sticky' => AUTH_MOD, - 'auth_announce' => AUTH_MOD, - 'auth_vote' => AUTH_REG, - 'auth_pollcreate' => AUTH_REG, - 'auth_attachments' => AUTH_REG, - 'auth_download' => AUTH_REG, -); - -$mode = (@$_REQUEST['mode']) ? (string) $_REQUEST['mode'] : ''; - -$cat_forums = get_cat_forums(); - -if ($orphan_sf_sql = get_orphan_sf()) -{ - fix_orphan_sf($orphan_sf_sql, TRUE); -} -$forum_parent = $cat_id = 0; -$forumname = ''; - -if (isset($_REQUEST['addforum']) || isset($_REQUEST['addcategory'])) -{ - $mode = (isset($_REQUEST['addforum'])) ? "addforum" : "addcat"; - - if ($mode == 'addforum' && isset($_POST['addforum']) && isset($_POST['forumname']) && is_array($_POST['addforum'])) - { - $req_cat_id = array_keys($_POST['addforum']); - $cat_id = $req_cat_id[0]; - $forumname = stripslashes($_POST['forumname'][$cat_id]); - } -} - -$show_main_page = false; - -if ($mode) -{ - switch ($mode) - { - case 'addforum': - case 'editforum': - // - // Show form to create/modify a forum - // - if ($mode == 'editforum') - { - // $newmode determines if we are going to INSERT or UPDATE after posting? - - $l_title = $lang['EDIT_FORUM']; - $newmode = 'modforum'; - $buttonvalue = $lang['UPDATE']; - - $forum_id = intval($_GET[POST_FORUM_URL]); - - $row = get_info('forum', $forum_id); - - $cat_id = $row['cat_id']; - $forumname = $row['forum_name']; - $forumdesc = $row['forum_desc']; - $forumstatus = $row['forum_status']; - $forum_display_sort = $row['forum_display_sort']; - $forum_display_order = $row['forum_display_order']; - $forum_parent = $row['forum_parent']; - $show_on_index = $row['show_on_index']; - $prune_days = $row['prune_days']; - $forum_tpl_id = $row['forum_tpl_id']; - $allow_reg_tracker = $row['allow_reg_tracker']; - $allow_porno_topic = $row['allow_porno_topic']; - $self_moderated = $row['self_moderated']; - } - else - { - $l_title = $lang['CREATE_FORUM']; - $newmode = 'createforum'; - $buttonvalue = $lang['CREATE_FORUM']; - - $forumdesc = ''; - $forumstatus = FORUM_UNLOCKED; - $forum_display_sort = 0; - $forum_display_order = 0; - $forum_id = ''; - $show_on_index = 1; - $prune_days = 0; - $forum_tpl_id = 0; - $allow_reg_tracker = 0; - $allow_porno_topic = 0; - $self_moderated = 0; - } - - if (isset($_REQUEST['forum_parent'])) - { - $forum_parent = intval($_REQUEST['forum_parent']); - - if ($parent = get_forum_data($forum_parent)) - { - $cat_id = $parent['cat_id']; - } - } - else if (isset($_REQUEST['c'])) - { - $cat_id = (int) $_REQUEST['c']; - } - - $catlist = get_list('category', $cat_id, TRUE); - $forumlocked = $forumunlocked = ''; - - $forumstatus == ( FORUM_LOCKED ) ? $forumlocked = 'selected="selected"' : $forumunlocked = 'selected="selected"'; - - $statuslist = '\n'; - $statuslist .= '\n'; - - $forum_display_sort_list = get_forum_display_sort_option($forum_display_sort, 'list', 'sort'); - $forum_display_order_list = get_forum_display_sort_option($forum_display_order, 'list', 'order'); - - $s_hidden_fields = ''; - - $s_parent = '\n'; - $sel_forum = ($forum_parent && !isset($_REQUEST['forum_parent'])) ? $forum_id : $forum_parent; - $s_parent .= sf_get_list('forum', $forum_id, $sel_forum); - - $template->assign_vars(array( - 'TPL_EDIT_FORUM' => true, - - 'S_FORUM_DISPLAY_SORT_LIST' => $forum_display_sort_list, - 'S_FORUM_DISPLAY_ORDER_LIST' => $forum_display_order_list, - 'S_FORUM_ACTION' => 'admin_forums.php', - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - 'S_SUBMIT_VALUE' => $buttonvalue, - 'S_CAT_LIST' => $catlist, - 'S_STATUS_LIST' => $statuslist, - - 'SHOW_ON_INDEX' => $show_on_index, - 'S_PARENT_FORUM' => $s_parent, - 'CAT_LIST_CLASS' => ($forum_parent) ? 'hidden' : '', - 'SHOW_ON_INDEX_CLASS' => (!$forum_parent) ? 'hidden' : '', - 'TPL_SELECT' => get_select('forum_tpl', $forum_tpl_id, 'html', $lang['TEMPLATE_DISABLE']), - 'ALLOW_REG_TRACKER' => build_select('allow_reg_tracker', array($lang['DISALLOWED'] => 0, $lang['ALLOWED'] => 1), $allow_reg_tracker), - 'ALLOW_PORNO_TOPIC' => build_select('allow_porno_topic', array($lang['NONE'] => 0, $lang['YES'] => 1), $allow_porno_topic), - 'SELF_MODERATED' => build_select('self_moderated', array($lang['NONE'] => 0, $lang['YES'] => 1), $self_moderated), - - 'L_FORUM_TITLE' => $l_title, - - 'PRUNE_DAYS' => $prune_days, - 'FORUM_NAME' => htmlCHR($forumname), - 'DESCRIPTION' => htmlCHR($forumdesc), - )); - break; - - case 'createforum': - // - // Create a forum in the DB - // - $cat_id = intval($_POST[POST_CAT_URL]); - $forum_name = (string) $_POST['forumname']; - $forum_desc = (string) $_POST['forumdesc']; - $forum_status = intval($_POST['forumstatus']); - - $prune_days = intval($_POST['prune_days']); - - $forum_parent = ($_POST['forum_parent'] != -1) ? intval($_POST['forum_parent']) : 0; - $show_on_index = ($forum_parent) ? intval($_POST['show_on_index']) : 1; - - $forum_display_sort = intval($_POST['forum_display_sort']); - $forum_display_order = intval($_POST['forum_display_order']); - - $forum_tpl_id = (int) $_POST['forum_tpl_select']; - $allow_reg_tracker = (int) $_POST['allow_reg_tracker']; - $allow_porno_topic = (int) $_POST['allow_porno_topic']; - $self_moderated = (int) $_POST['self_moderated']; - - if (!$forum_name) - { - bb_die('Can not create a forum without a name'); - } - - if ($forum_parent) - { - if (!$parent = get_forum_data($forum_parent)) - { - bb_die('Parent forum with id '. $forum_parent .' not found'); - } - - $cat_id = $parent['cat_id']; - $forum_parent = ($parent['forum_parent']) ? $parent['forum_parent'] : $parent['forum_id']; - $forum_order = $parent['forum_order'] + 5; - } - else - { - $max_order = get_max_forum_order($cat_id); - $forum_order = $max_order + 5; - } - - // Default permissions of public forum - $field_sql = $value_sql = ''; - - foreach ($default_forum_auth as $field => $value) - { - $field_sql .= ", $field"; - $value_sql .= ", $value"; - } - - $forum_name_sql = DB()->escape($forum_name); - $forum_desc_sql = DB()->escape($forum_desc); - - $columns = ' forum_name, cat_id, forum_desc, forum_order, forum_status, prune_days, forum_parent, show_on_index, forum_display_sort, forum_display_order, forum_tpl_id, allow_reg_tracker, allow_porno_topic, self_moderated'. $field_sql; - $values = "'$forum_name_sql', $cat_id, '$forum_desc_sql', $forum_order, $forum_status, $prune_days, $forum_parent, $show_on_index, $forum_display_sort, $forum_display_order, $forum_tpl_id, $allow_reg_tracker, $allow_porno_topic, $self_moderated". $value_sql; - - DB()->query("INSERT INTO ". BB_FORUMS ." ($columns) VALUES ($values)"); - - renumber_order('forum', $cat_id); - $datastore->update('cat_forums'); - CACHE('bb_cache')->rm(); - - bb_die($lang['FORUMS_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - - break; - - case 'modforum': - // - // Modify a forum in the DB - // - $cat_id = intval($_POST[POST_CAT_URL]); - $forum_id = intval($_POST[POST_FORUM_URL]); - $forum_name = (string) $_POST['forumname']; - $forum_desc = (string) $_POST['forumdesc']; - $forum_status = intval($_POST['forumstatus']); - $prune_days = intval($_POST['prune_days']); - - $forum_parent = ($_POST['forum_parent'] != -1) ? intval($_POST['forum_parent']) : 0; - $show_on_index = ($forum_parent) ? intval($_POST['show_on_index']) : 1; - - $forum_display_order = intval($_POST['forum_display_order']); - $forum_display_sort = intval($_POST['forum_display_sort']); - $forum_tpl_id = (int) $_POST['forum_tpl_select']; - $allow_reg_tracker = (int) $_POST['allow_reg_tracker']; - $allow_porno_topic = (int) $_POST['allow_porno_topic']; - $self_moderated = (int) $_POST['self_moderated']; - - $forum_data = get_forum_data($forum_id); - $old_cat_id = $forum_data['cat_id']; - $forum_order = $forum_data['forum_order']; - - if (!$forum_name) - { - bb_die('Can not modify a forum without a name'); - } - - if ($forum_parent) - { - if (!$parent = get_forum_data($forum_parent)) - { - bb_die('Parent forum with id '. $forum_parent .' not found'); - } - - $cat_id = $parent['cat_id']; - $forum_parent = ($parent['forum_parent']) ? $parent['forum_parent'] : $parent['forum_id']; - $forum_order = $parent['forum_order'] + 5; - - if ($forum_id == $forum_parent) - { - bb_die('Ambiguous forum ID. Please select other parent forum'); - } - } - else if ($cat_id != $old_cat_id) - { - $max_order = get_max_forum_order($cat_id); - $forum_order = $max_order + 5; - } - else if ($forum_data['forum_parent']) - { - $old_parent = $forum_data['forum_parent']; - $forum_order = $cat_forums[$old_cat_id]['f'][$old_parent]['forum_order'] - 5; - } - - $forum_name_sql = DB()->escape($forum_name); - $forum_desc_sql = DB()->escape($forum_desc); - - DB()->query(" - UPDATE ". BB_FORUMS ." SET - forum_name = '$forum_name_sql', - cat_id = $cat_id, - forum_desc = '$forum_desc_sql', - forum_order = $forum_order, - forum_status = $forum_status, - prune_days = $prune_days, - forum_parent = $forum_parent, - show_on_index = $show_on_index, - forum_tpl_id = $forum_tpl_id, - allow_reg_tracker = $allow_reg_tracker, - allow_porno_topic = $allow_porno_topic, - self_moderated = $self_moderated, - forum_display_order = $forum_display_order, - forum_display_sort = $forum_display_sort - WHERE forum_id = $forum_id - "); - - if ($cat_id != $old_cat_id) - { - change_sf_cat($forum_id, $cat_id, $forum_order); - renumber_order('forum', $cat_id); - } - - renumber_order('forum', $old_cat_id); - - $cat_forums = get_cat_forums(); - $fix = fix_orphan_sf(); - $datastore->update('cat_forums'); - CACHE('bb_cache')->rm(); - - $message = $lang['FORUMS_UPDATED'] . '

        '; - $message .= ($fix) ? "$fix

        " : ''; - $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); - bb_die($message); - - break; - - case 'addcat': - // - // Create a category in the DB - // - if (!$new_cat_title = trim($_POST['categoryname'])) - { - bb_die('Category name is empty'); - } - - check_name_dup('cat', $new_cat_title); - - $order = DB()->fetch_row("SELECT MAX(cat_order) AS max_order FROM ". BB_CATEGORIES); - - $args = DB()->build_array('INSERT', array( - 'cat_title' => (string) $new_cat_title, - 'cat_order' => (int) $order['max_order'] + 10, - )); - - DB()->query("INSERT INTO ". BB_CATEGORIES . $args); - - $datastore->update('cat_forums'); - CACHE('bb_cache')->rm(); - - bb_die($lang['FORUMS_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - - break; - - case 'editcat': - // - // Show form to edit a category - // - $cat_id = (int) $_GET['c']; - $cat_info = get_info('category', $cat_id); - - $hidden_fields = array( - 'mode' => 'modcat', - 'c' => $cat_id, - ); - - $template->assign_vars(array( - 'TPL_EDIT_CATEGORY' => true, - 'CAT_TITLE' => htmlCHR($cat_info['cat_title']), - 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields), - 'S_SUBMIT_VALUE' => $lang['UPDATE'], - 'S_FORUM_ACTION' => "admin_forums.php", - )); - - break; - - case 'modcat': - // - // Modify a category in the DB - // - if (!$new_cat_title = trim($_POST['cat_title'])) - { - bb_die('Category name is empty'); - } - - $cat_id = (int) $_POST['c']; - - $row = get_info('category', $cat_id); - $cur_cat_title = $row['cat_title']; - - if ($cur_cat_title && $cur_cat_title !== $new_cat_title) - { - check_name_dup('cat', $new_cat_title); - - $new_cat_title_sql = DB()->escape($new_cat_title); - - DB()->query(" - UPDATE ". BB_CATEGORIES ." SET - cat_title = '$new_cat_title_sql' - WHERE cat_id = $cat_id - "); - } - - $datastore->update('cat_forums'); - CACHE('bb_cache')->rm(); - - bb_die($lang['FORUMS_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - - break; - - case 'deleteforum': - // - // Show form to delete a forum - // - $forum_id = (int) $_GET['f']; - - $move_to_options = ''; - $move_to_options .= sf_get_list('forum', $forum_id, 0); - - $foruminfo = get_info('forum', $forum_id); - - $hidden_fields = array( - 'mode' => 'movedelforum', - 'from_id' => $forum_id, - ); - - $template->assign_vars(array( - 'TPL_DELETE_FORUM' => true, - - 'WHAT_TO_DELETE' => htmlCHR($foruminfo['forum_name']), - 'DELETE_TITLE' => $lang['FORUM_DELETE'], - 'CAT_FORUM_NAME' => $lang['FORUM_NAME'], - - 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields), - 'S_FORUM_ACTION' => "admin_forums.php", - 'MOVE_TO_OPTIONS' => $move_to_options, - 'S_SUBMIT_VALUE' => $lang['MOVE_AND_DELETE'], - )); - - break; - - case 'movedelforum': - // - // Move or delete a forum in the DB - // - $from_id = (int) $_POST['from_id']; - $to_id = (int) $_POST['to_id']; - - if ($to_id == -1) - { - // Delete everything from forum - topic_delete('prune', $from_id, 0, true); - } - else - { - // Move all posts - $sql = "SELECT * FROM ". BB_FORUMS ." WHERE forum_id IN($from_id, $to_id)"; - $result = DB()->query($sql); - - if (DB()->num_rows($result) != 2) - { - bb_die('Ambiguous forum ID'); - } - - DB()->query("UPDATE ". BB_TOPICS ." SET forum_id = $to_id WHERE forum_id = $from_id"); - DB()->query("UPDATE ". BB_BT_TORRENTS ." SET forum_id = $to_id WHERE forum_id = $from_id"); - - $row = DB()->fetch_row("SELECT MIN(post_id) AS start_id, MAX(post_id) AS finish_id FROM ". BB_POSTS); - $start_id = (int) $row['start_id']; - $finish_id = (int) $row['finish_id']; - $per_cycle = 10000; - while (true) - { - set_time_limit(600); - $end_id = $start_id + $per_cycle - 1; - DB()->query(" - UPDATE ". BB_POSTS ." SET forum_id = $to_id WHERE post_id BETWEEN $start_id AND $end_id AND forum_id = $from_id - "); - if ($end_id > $finish_id) - { - break; - } - $start_id += $per_cycle; - } - - sync('forum', $to_id); - } - - DB()->query("DELETE FROM ". BB_FORUMS ." WHERE forum_id = $from_id"); - DB()->query("DELETE FROM ". BB_AUTH_ACCESS ." WHERE forum_id = $from_id"); - DB()->query("DELETE FROM ". BB_AUTH_ACCESS_SNAP ." WHERE forum_id = $from_id"); - - $cat_forums = get_cat_forums(); - fix_orphan_sf(); - update_user_level('all'); - $datastore->update('cat_forums'); - CACHE('bb_cache')->rm(); - - bb_die($lang['FORUMS_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - - break; - - case 'deletecat': - // Show form to delete a category - $cat_id = (int) $_GET['c']; - $catinfo = get_info('category', $cat_id); - $categories_count = $catinfo['number']; - - if ($categories_count == 1) - { - $row = DB()->fetch_row("SELECT COUNT(*) AS forums_count FROM ". BB_FORUMS); - - if ($row['forums_count'] > 0) - { - bb_die($lang['MUST_DELETE_FORUMS']); - } - else - { - $template->assign_var('NOWHERE_TO_MOVE', $lang['NOWHERE_TO_MOVE']); - } - } - - $hidden_fields = array( - 'mode' => 'movedelcat', - 'from_id' => $cat_id, - ); - - $template->assign_vars(array( - 'TPL_DELETE_FORUM' => true, - - 'WHAT_TO_DELETE' => htmlCHR($catinfo['cat_title']), - 'DELETE_TITLE' => $lang['CATEGORY_DELETE'], - 'CAT_FORUM_NAME' => $lang['CATEGORY'], - - 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields), - 'S_FORUM_ACTION' => "admin_forums.php", - 'MOVE_TO_OPTIONS' => get_list('category', $cat_id, 0), - 'S_SUBMIT_VALUE' => $lang['MOVE_AND_DELETE'], - )); - - break; - - case 'movedelcat': - // Move or delete a category in the DB - $from_id = (int) $_POST['from_id']; - $to_id = (int) $_POST['to_id']; - - if ($from_id == $to_id || !cat_exists($from_id) || !cat_exists($to_id)) - { - bb_die('Bad input'); - } - - $order_shear = get_max_forum_order($to_id) + 10; - - DB()->query(" - UPDATE ". BB_FORUMS ." SET - cat_id = $to_id, - forum_order = forum_order + $order_shear - WHERE cat_id = $from_id - "); - - DB()->query("DELETE FROM ". BB_CATEGORIES ." WHERE cat_id = $from_id"); - - renumber_order('forum', $to_id); - $cat_forums = get_cat_forums(); - $fix = fix_orphan_sf(); - $datastore->update('cat_forums'); - CACHE('bb_cache')->rm(); - - $message = $lang['FORUMS_UPDATED'] . '

        '; - $message .= ($fix) ? "$fix

        " : ''; - $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); - bb_die($message); - - break; - - case 'forum_order': - // Change order of forums - $move = intval($_GET['move']); - $forum_id = intval($_GET[POST_FORUM_URL]); - - $forum_info = get_info('forum', $forum_id); - renumber_order('forum', $forum_info['cat_id']); - - $cat_id = $forum_info['cat_id']; - - $move_down_forum_id = FALSE; - $forums = $cat_forums[$cat_id]['f_ord']; - $forum_order = $forum_info['forum_order']; - $prev_forum = (isset($forums[$forum_order - 10])) ? $forums[$forum_order - 10] : FALSE; - $next_forum = (isset($forums[$forum_order + 10])) ? $forums[$forum_order + 10] : FALSE; - - // move selected forum ($forum_id) UP - if ($move < 0 && $prev_forum) - { - if ($forum_info['forum_parent'] && $prev_forum['forum_parent'] != $forum_info['forum_parent']) - { - $show_main_page = true; - break; - } - else if ($move_down_forum_id = get_prev_root_forum_id($forums, $forum_order)) - { - $move_up_forum_id = $forum_id; - $move_down_ord_val = (get_sf_count($forum_id) + 1) * 10; - $move_up_ord_val = ((get_sf_count($move_down_forum_id) + 1) * 10) + $move_down_ord_val; - $move_down_forum_order = $cat_forums[$cat_id]['f'][$move_down_forum_id]['forum_order']; - } - } - // move selected forum ($forum_id) DOWN - else if ($move > 0 && $next_forum) - { - if ($forum_info['forum_parent'] && $next_forum['forum_parent'] != $forum_info['forum_parent']) - { - $show_main_page = true; - break; - } - else if ($move_up_forum_id = get_next_root_forum_id($forums, $forum_order)) - { - $move_down_forum_id = $forum_id; - $move_down_forum_order = $forum_order; - $move_down_ord_val = (get_sf_count($move_up_forum_id) + 1) * 10; - $move_up_ord_val = ((get_sf_count($move_down_forum_id) + 1) * 10) + $move_down_ord_val; - } - } - else - { - $show_main_page = true; - break; - } - - if ($forum_info['forum_parent']) - { - DB()->query(" - UPDATE ". BB_FORUMS ." SET - forum_order = forum_order + $move - WHERE forum_id = $forum_id - "); - } - else if ($move_down_forum_id) - { - DB()->query(" - UPDATE ". BB_FORUMS ." SET - forum_order = forum_order + $move_down_ord_val - WHERE cat_id = $cat_id - AND forum_order >= $move_down_forum_order - "); - DB()->query(" - UPDATE ". BB_FORUMS ." SET - forum_order = forum_order - $move_up_ord_val - WHERE forum_id = $move_up_forum_id - OR forum_parent = $move_up_forum_id - "); - } - - renumber_order('forum', $forum_info['cat_id']); - $datastore->update('cat_forums'); - CACHE('bb_cache')->rm(); - - $show_main_page = true; - break; - - case 'cat_order': - $move = (int) $_GET['move']; - $cat_id = (int) $_GET['c']; - - DB()->query(" - UPDATE ". BB_CATEGORIES ." SET - cat_order = cat_order + $move - WHERE cat_id = $cat_id - "); - - renumber_order('category'); - $datastore->update('cat_forums'); - CACHE('bb_cache')->rm(); - - $show_main_page = true; - break; - - case 'forum_sync': - sync('forum', intval($_GET['f'])); - $datastore->update('cat_forums'); - CACHE('bb_cache')->rm(); - - $show_main_page = true; - break; - - default: - bb_die($lang['NO_MODE']); - - break; - } -} - -if (!$mode || $show_main_page) -{ - $template->assign_vars(array( - 'TPL_FORUMS_LIST' => true, - - 'S_FORUM_ACTION' => 'admin_forums.php', - 'L_FORUM_TITLE' => $lang['FORUM_ADMIN_MAIN'], - )); - - $sql = "SELECT cat_id, cat_title, cat_order FROM " . BB_CATEGORIES . " ORDER BY cat_order"; - if (!$q_categories = DB()->sql_query($sql)) - { - bb_die('Could not query categories list'); - } - - if ($total_categories = DB()->num_rows($q_categories)) - { - $category_rows = DB()->sql_fetchrowset($q_categories); - - $where_cat_sql = $req_cat_id = ''; - - if ($c =& $_REQUEST['c']) - { - if ($c !== 'all') - { - $req_cat_id = (int) $c; - $where_cat_sql = "WHERE cat_id = $req_cat_id"; - } - else - { - $req_cat_id = 'all'; - } - } - else - { - $where_cat_sql = "WHERE cat_id = '-1'"; - } - - $sql = "SELECT * FROM ". BB_FORUMS ." $where_cat_sql ORDER BY cat_id, forum_order"; - if (!$q_forums = DB()->sql_query($sql)) - { - bb_die('Could not query forums information'); - } - - if ($total_forums = DB()->num_rows($q_forums)) - { - $forum_rows = DB()->sql_fetchrowset($q_forums); - } - - // Okay, let's build the index - $gen_cat = array(); - - $bgr_class_1 = 'prow1'; - $bgr_class_2 = 'prow2'; - $bgr_class_over = 'prow3'; - - $template->assign_vars(array( - 'U_ALL_FORUMS' => 'admin_forums.php?c=all', - 'FORUMS_COUNT' => $total_forums, - )); - - for ($i = 0; $i < $total_categories; $i++) - { - $cat_id = $category_rows[$i]['cat_id']; - - $template->assign_block_vars("c", array( - 'S_ADD_FORUM_SUBMIT' => "addforum[$cat_id]", - 'S_ADD_FORUM_NAME' => "forumname[$cat_id]", - - 'CAT_ID' => $cat_id, - 'CAT_DESC' => htmlCHR($category_rows[$i]['cat_title']), - - 'U_CAT_EDIT' => "admin_forums.php?mode=editcat&c=$cat_id", - 'U_CAT_DELETE' => "admin_forums.php?mode=deletecat&c=$cat_id", - 'U_CAT_MOVE_UP' => "admin_forums.php?mode=cat_order&move=-15&c=$cat_id", - 'U_CAT_MOVE_DOWN' => "admin_forums.php?mode=cat_order&move=15&c=$cat_id", - 'U_VIEWCAT' => "admin_forums.php?c=$cat_id", - 'U_CREATE_FORUM' => "admin_forums.php?mode=addforum&c=$cat_id", - )); - - for ($j = 0; $j < $total_forums; $j++) - { - $forum_id = $forum_rows[$j]['forum_id']; - - $bgr_class = (!($j % 2)) ? $bgr_class_2 : $bgr_class_1; - $row_bgr = " class=\"$bgr_class\" onmouseover=\"this.className='$bgr_class_over';\" onmouseout=\"this.className='$bgr_class';\""; - - if ($forum_rows[$j]['cat_id'] == $cat_id) - { - - $template->assign_block_vars("c.f", array( - 'FORUM_NAME' => htmlCHR($forum_rows[$j]['forum_name']), - 'FORUM_DESC' => htmlCHR($forum_rows[$j]['forum_desc']), - 'NUM_TOPICS' => $forum_rows[$j]['forum_topics'], - 'NUM_POSTS' => $forum_rows[$j]['forum_posts'], - 'PRUNE_DAYS' => ($forum_rows[$j]['prune_days']) ? $forum_rows[$j]['prune_days'] : '-', - - 'ORDER' => $forum_rows[$j]['forum_order'], - 'FORUM_ID' => $forum_rows[$j]['forum_id'], - 'ROW_BGR' => $row_bgr, - - 'SHOW_ON_INDEX' => (bool) $forum_rows[$j]['show_on_index'], - 'FORUM_PARENT' => $forum_rows[$j]['forum_parent'], - 'SF_PAD' => ($forum_rows[$j]['forum_parent']) ? ' style="padding-left: 20px;" ' : '', - 'FORUM_NAME_CLASS' => ($forum_rows[$j]['forum_parent']) ? 'genmed' : 'gen', - 'ADD_SUB_HREF' => "admin_forums.php?mode=addforum&forum_parent={$forum_rows[$j]['forum_id']}", - 'U_VIEWFORUM' => BB_ROOT ."viewforum.php?f=$forum_id", - 'U_FORUM_EDIT' => "admin_forums.php?mode=editforum&f=$forum_id", - 'U_FORUM_PERM' => "admin_forumauth.php?f=$forum_id", - 'U_FORUM_DELETE' => "admin_forums.php?mode=deleteforum&f=$forum_id", - 'U_FORUM_MOVE_UP' => "admin_forums.php?mode=forum_order&move=-15&f=$forum_id&c=$req_cat_id", - 'U_FORUM_MOVE_DOWN' => "admin_forums.php?mode=forum_order&move=15&f=$forum_id&c=$req_cat_id", - 'U_FORUM_RESYNC' => "admin_forums.php?mode=forum_sync&f=$forum_id", - )); - - }// if ... forumid == catid - } // for ... forums - } // for ... categories - }// if ... total_categories -} - -print_page('admin_forums.tpl', 'admin'); - -// Functions -function get_info ($mode, $id) -{ - switch($mode) - { - case 'category': - $table = BB_CATEGORIES; - $idfield = 'cat_id'; - $namefield = 'cat_title'; - break; - - case 'forum': - $table = BB_FORUMS; - $idfield = 'forum_id'; - $namefield = 'forum_name'; - break; - - default: - bb_die('Wrong mode for generating select list #1'); - break; - } - $sql = "SELECT count(*) as total FROM $table"; - if( !$result = DB()->sql_query($sql) ) - { - bb_die('Could not get forum / category information #1'); - } - $count = DB()->sql_fetchrow($result); - $count = $count['total']; - - $sql = "SELECT * FROM $table WHERE $idfield = $id"; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not get forum / category information #2'); - } - - if (DB()->num_rows($result) != 1) - { - bb_die('Forum / category does not exist or multiple forums / categories with ID '. $id); - } - - $return = DB()->sql_fetchrow($result); - $return['number'] = $count; - return $return; -} - -function get_list ($mode, $id, $select) -{ - switch($mode) - { - case 'category': - $table = BB_CATEGORIES; - $idfield = 'cat_id'; - $namefield = 'cat_title'; - $order = 'cat_order'; - break; - - case 'forum': - $table = BB_FORUMS; - $idfield = 'forum_id'; - $namefield = 'forum_name'; - $order = 'cat_id, forum_order'; - break; - - default: - bb_die('Wrong mode for generating select list #2'); - break; - } - - $sql = "SELECT * FROM $table"; - if( $select == 0 ) - { - $sql .= " WHERE $idfield <> $id"; - } - $sql .= " ORDER BY $order"; - - if( !$result = DB()->sql_query($sql) ) - { - bb_die('Could not get list of categories / forums #1'); - } - - $catlist = ''; - - while( $row = DB()->sql_fetchrow($result) ) - { - $s = ''; - if ($row[$idfield] == $id) - { - $s = ' selected="selected"'; - } - $catlist .= '\n'; - } - - return($catlist); -} - -function renumber_order ($mode, $cat = 0) -{ - switch($mode) - { - case 'category': - $table = BB_CATEGORIES; - $idfield = 'cat_id'; - $orderfield = 'cat_order'; - $cat = 0; - break; - - case 'forum': - $table = BB_FORUMS; - $idfield = 'forum_id'; - $orderfield = 'forum_order'; - $catfield = 'cat_id'; - break; - - default: - bb_die('Wrong mode for generating select list #3'); - break; - } - - $sql = "SELECT * FROM $table"; - if( $cat != 0) - { - $sql .= " WHERE $catfield = $cat"; - } - $sql .= " ORDER BY $orderfield ASC"; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not get list of categories / forums #2'); - } - - $i = 10; - - while ($row = DB()->sql_fetchrow($result)) - { - $sql = "UPDATE $table SET $orderfield = $i WHERE $idfield = " . $row[$idfield]; - if (!DB()->sql_query($sql)) - { - bb_die('Could not update order fields'); - } - $i += 10; - } - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not get list of categories / forums #3'); - } - -} - -function get_cat_forums ($cat_id = FALSE) -{ - $forums = array(); - $where_sql = ''; - - if ($cat_id = intval($cat_id)) - { - $where_sql = "AND f.cat_id = $cat_id"; - } - - $sql = 'SELECT c.cat_title, f.* - FROM '. BB_FORUMS .' f, '. BB_CATEGORIES ." c - WHERE f.cat_id = c.cat_id - $where_sql - ORDER BY c.cat_order, f.cat_id, f.forum_order"; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not get list of categories / forums #4'); - } - - if ($rowset = DB()->sql_fetchrowset($result)) - { - foreach ($rowset as $rid => $row) - { - $forums[$row['cat_id']]['cat_title'] = $row['cat_title']; - $forums[$row['cat_id']]['f'][$row['forum_id']] = $row; - $forums[$row['cat_id']]['f_ord'][$row['forum_order']] = $row; - } - } - - return $forums; -} - -function get_sf_count ($forum_id) -{ - global $cat_forums; - - $sf_count = 0; - - foreach ($cat_forums as $cid => $c) - { - foreach ($c['f'] as $fid => $f) - { - if ($f['forum_parent'] == $forum_id) - { - $sf_count++; - } - } - } - - return $sf_count; -} - -function get_prev_root_forum_id ($forums, $curr_forum_order) -{ - $i = $curr_forum_order - 10; - - while ($i > 0) - { - if (isset($forums[$i]) && !$forums[$i]['forum_parent']) - { - return $forums[$i]['forum_id']; - } - $i = $i - 10; - } - - return FALSE; -} - -function get_next_root_forum_id ($forums, $curr_forum_order) -{ - $i = $curr_forum_order + 10; - $limit = (count($forums) * 10) + 10; - - while ($i < $limit) - { - if (isset($forums[$i]) && !$forums[$i]['forum_parent']) - { - return $forums[$i]['forum_id']; - } - $i = $i + 10; - } - - return FALSE; -} - -function get_orphan_sf () -{ - global $cat_forums; - - $last_root = 0; - $bad_sf_ary = array(); - - foreach ($cat_forums as $cid => $c) - { - foreach ($c['f'] as $fid => $f) - { - if ($f['forum_parent']) - { - if ($f['forum_parent'] != $last_root) - { - $bad_sf_ary[] = $f['forum_id']; - } - } - else - { - $last_root = $f['forum_id']; - } - } - } - - return implode(',', $bad_sf_ary); -} - -function fix_orphan_sf ($orphan_sf_sql = '', $show_mess = FALSE) -{ - global $lang; - - $done_mess = ''; - - if (!$orphan_sf_sql) - { - $orphan_sf_sql = get_orphan_sf(); - } - - if ($orphan_sf_sql) - { - $sql = "UPDATE ". BB_FORUMS ." SET forum_parent = 0, show_on_index = 1 WHERE forum_id IN($orphan_sf_sql)"; - - if (!DB()->sql_query($sql)) - { - bb_die('Could not change subforums data'); - } - - if ($affectedrows = DB()->affected_rows()) - { - $done_mess = 'Subforums data corrected. '. $affectedrows .' orphan subforum(s) moved to root level.'; - } - - if ($show_mess) - { - $message = $done_mess .'

        '; - $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') .'

        '; - $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); - bb_die($message); - } - } - - return $done_mess; -} - -function sf_get_list ($mode, $exclude = 0, $select = 0) -{ - global $cat_forums, $forum_parent; - - $opt = ''; - - if ($mode == 'forum') - { - foreach ($cat_forums as $cid => $c) - { - $opt .= ''; - - foreach ($c['f'] as $fid => $f) - { - $selected = ($fid == $select) ? HTML_SELECTED : ''; - $disabled = ($fid == $exclude && !$forum_parent) ? HTML_DISABLED : ''; - $style = ($disabled) ? ' style="color: gray" ' : (($fid == $exclude) ? ' style="color: darkred" ' : ''); - $opt .= '\n"; - } - - $opt .= ''; - } - } - - return $opt; -} - -function get_forum_data ($forum_id) -{ - global $cat_forums; - - foreach ($cat_forums as $cid => $c) - { - foreach ($c['f'] as $fid => $f) - { - if ($fid == $forum_id) - { - return $f; - } - } - } - - return FALSE; -} - -function get_max_forum_order ($cat_id) -{ - $row = DB()->fetch_row(" - SELECT MAX(forum_order) AS max_forum_order - FROM ". BB_FORUMS ." - WHERE cat_id = $cat_id - "); - - return intval($row['max_forum_order']); -} - -function check_name_dup ($mode, $name, $die_on_error = true) -{ - $name_sql = DB()->escape($name); - - if ($mode == 'cat') - { - $what_checked = 'category'; - $sql = "SELECT cat_id FROM ". BB_CATEGORIES ." WHERE cat_title = '$name_sql'"; - } - else - { - $what_checked = 'forum'; - $sql = "SELECT forum_id FROM ". BB_FORUMS ." WHERE forum_name = '$name_sql'"; - } - - $name_is_dup = DB()->fetch_row($sql); - - if ($name_is_dup && $die_on_error) - { - bb_die('This '. $what_checked .' name taken, please choose something else'); - } - - return $name_is_dup; -} - -/** - * Change subforums cat_id if parent's cat_id was changed - */ -function change_sf_cat ($parent_id, $new_cat_id, $order_shear) -{ - DB()->query(" - UPDATE ". BB_FORUMS ." SET - cat_id = $new_cat_id, - forum_order = forum_order + $order_shear - WHERE forum_parent = $parent_id - "); + AUTH_ALL, + 'auth_read' => AUTH_ALL, + 'auth_post' => AUTH_REG, + 'auth_reply' => AUTH_REG, + 'auth_edit' => AUTH_REG, + 'auth_delete' => AUTH_REG, + 'auth_sticky' => AUTH_MOD, + 'auth_announce' => AUTH_MOD, + 'auth_vote' => AUTH_REG, + 'auth_pollcreate' => AUTH_REG, + 'auth_attachments' => AUTH_REG, + 'auth_download' => AUTH_REG, +); + +$mode = (@$_REQUEST['mode']) ? (string) $_REQUEST['mode'] : ''; + +$cat_forums = get_cat_forums(); + +if ($orphan_sf_sql = get_orphan_sf()) +{ + fix_orphan_sf($orphan_sf_sql, TRUE); +} +$forum_parent = $cat_id = 0; +$forumname = ''; + +if (isset($_REQUEST['addforum']) || isset($_REQUEST['addcategory'])) +{ + $mode = (isset($_REQUEST['addforum'])) ? "addforum" : "addcat"; + + if ($mode == 'addforum' && isset($_POST['addforum']) && isset($_POST['forumname']) && is_array($_POST['addforum'])) + { + $req_cat_id = array_keys($_POST['addforum']); + $cat_id = $req_cat_id[0]; + $forumname = stripslashes($_POST['forumname'][$cat_id]); + } +} + +$show_main_page = false; + +if ($mode) +{ + switch ($mode) + { + case 'addforum': + case 'editforum': + // + // Show form to create/modify a forum + // + if ($mode == 'editforum') + { + // $newmode determines if we are going to INSERT or UPDATE after posting? + + $l_title = $lang['EDIT_FORUM']; + $newmode = 'modforum'; + $buttonvalue = $lang['UPDATE']; + + $forum_id = intval($_GET[POST_FORUM_URL]); + + $row = get_info('forum', $forum_id); + + $cat_id = $row['cat_id']; + $forumname = $row['forum_name']; + $forumdesc = $row['forum_desc']; + $forumstatus = $row['forum_status']; + $forum_display_sort = $row['forum_display_sort']; + $forum_display_order = $row['forum_display_order']; + $forum_parent = $row['forum_parent']; + $show_on_index = $row['show_on_index']; + $prune_days = $row['prune_days']; + $forum_tpl_id = $row['forum_tpl_id']; + $allow_reg_tracker = $row['allow_reg_tracker']; + $allow_porno_topic = $row['allow_porno_topic']; + $self_moderated = $row['self_moderated']; + } + else + { + $l_title = $lang['CREATE_FORUM']; + $newmode = 'createforum'; + $buttonvalue = $lang['CREATE_FORUM']; + + $forumdesc = ''; + $forumstatus = FORUM_UNLOCKED; + $forum_display_sort = 0; + $forum_display_order = 0; + $forum_id = ''; + $show_on_index = 1; + $prune_days = 0; + $forum_tpl_id = 0; + $allow_reg_tracker = 0; + $allow_porno_topic = 0; + $self_moderated = 0; + } + + if (isset($_REQUEST['forum_parent'])) + { + $forum_parent = intval($_REQUEST['forum_parent']); + + if ($parent = get_forum_data($forum_parent)) + { + $cat_id = $parent['cat_id']; + } + } + else if (isset($_REQUEST['c'])) + { + $cat_id = (int) $_REQUEST['c']; + } + + $catlist = get_list('category', $cat_id, TRUE); + $forumlocked = $forumunlocked = ''; + + $forumstatus == ( FORUM_LOCKED ) ? $forumlocked = 'selected="selected"' : $forumunlocked = 'selected="selected"'; + + $statuslist = '\n'; + $statuslist .= '\n'; + + $forum_display_sort_list = get_forum_display_sort_option($forum_display_sort, 'list', 'sort'); + $forum_display_order_list = get_forum_display_sort_option($forum_display_order, 'list', 'order'); + + $s_hidden_fields = ''; + + $s_parent = '\n'; + $sel_forum = ($forum_parent && !isset($_REQUEST['forum_parent'])) ? $forum_id : $forum_parent; + $s_parent .= sf_get_list('forum', $forum_id, $sel_forum); + + $template->assign_vars(array( + 'TPL_EDIT_FORUM' => true, + + 'S_FORUM_DISPLAY_SORT_LIST' => $forum_display_sort_list, + 'S_FORUM_DISPLAY_ORDER_LIST' => $forum_display_order_list, + 'S_FORUM_ACTION' => 'admin_forums.php', + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_SUBMIT_VALUE' => $buttonvalue, + 'S_CAT_LIST' => $catlist, + 'S_STATUS_LIST' => $statuslist, + + 'SHOW_ON_INDEX' => $show_on_index, + 'S_PARENT_FORUM' => $s_parent, + 'CAT_LIST_CLASS' => ($forum_parent) ? 'hidden' : '', + 'SHOW_ON_INDEX_CLASS' => (!$forum_parent) ? 'hidden' : '', + 'TPL_SELECT' => get_select('forum_tpl', $forum_tpl_id, 'html', $lang['TEMPLATE_DISABLE']), + 'ALLOW_REG_TRACKER' => build_select('allow_reg_tracker', array($lang['DISALLOWED'] => 0, $lang['ALLOWED'] => 1), $allow_reg_tracker), + 'ALLOW_PORNO_TOPIC' => build_select('allow_porno_topic', array($lang['NONE'] => 0, $lang['YES'] => 1), $allow_porno_topic), + 'SELF_MODERATED' => build_select('self_moderated', array($lang['NONE'] => 0, $lang['YES'] => 1), $self_moderated), + + 'L_FORUM_TITLE' => $l_title, + + 'PRUNE_DAYS' => $prune_days, + 'FORUM_NAME' => htmlCHR($forumname), + 'DESCRIPTION' => htmlCHR($forumdesc), + )); + break; + + case 'createforum': + // + // Create a forum in the DB + // + $cat_id = intval($_POST[POST_CAT_URL]); + $forum_name = (string) $_POST['forumname']; + $forum_desc = (string) $_POST['forumdesc']; + $forum_status = intval($_POST['forumstatus']); + + $prune_days = intval($_POST['prune_days']); + + $forum_parent = ($_POST['forum_parent'] != -1) ? intval($_POST['forum_parent']) : 0; + $show_on_index = ($forum_parent) ? intval($_POST['show_on_index']) : 1; + + $forum_display_sort = intval($_POST['forum_display_sort']); + $forum_display_order = intval($_POST['forum_display_order']); + + $forum_tpl_id = (int) $_POST['forum_tpl_select']; + $allow_reg_tracker = (int) $_POST['allow_reg_tracker']; + $allow_porno_topic = (int) $_POST['allow_porno_topic']; + $self_moderated = (int) $_POST['self_moderated']; + + if (!$forum_name) + { + bb_die('Can not create a forum without a name'); + } + + if ($forum_parent) + { + if (!$parent = get_forum_data($forum_parent)) + { + bb_die('Parent forum with id '. $forum_parent .' not found'); + } + + $cat_id = $parent['cat_id']; + $forum_parent = ($parent['forum_parent']) ? $parent['forum_parent'] : $parent['forum_id']; + $forum_order = $parent['forum_order'] + 5; + } + else + { + $max_order = get_max_forum_order($cat_id); + $forum_order = $max_order + 5; + } + + // Default permissions of public forum + $field_sql = $value_sql = ''; + + foreach ($default_forum_auth as $field => $value) + { + $field_sql .= ", $field"; + $value_sql .= ", $value"; + } + + $forum_name_sql = DB()->escape($forum_name); + $forum_desc_sql = DB()->escape($forum_desc); + + $columns = ' forum_name, cat_id, forum_desc, forum_order, forum_status, prune_days, forum_parent, show_on_index, forum_display_sort, forum_display_order, forum_tpl_id, allow_reg_tracker, allow_porno_topic, self_moderated'. $field_sql; + $values = "'$forum_name_sql', $cat_id, '$forum_desc_sql', $forum_order, $forum_status, $prune_days, $forum_parent, $show_on_index, $forum_display_sort, $forum_display_order, $forum_tpl_id, $allow_reg_tracker, $allow_porno_topic, $self_moderated". $value_sql; + + DB()->query("INSERT INTO ". BB_FORUMS ." ($columns) VALUES ($values)"); + + renumber_order('forum', $cat_id); + $datastore->update('cat_forums'); + CACHE('bb_cache')->rm(); + + bb_die($lang['FORUMS_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + + break; + + case 'modforum': + // + // Modify a forum in the DB + // + $cat_id = intval($_POST[POST_CAT_URL]); + $forum_id = intval($_POST[POST_FORUM_URL]); + $forum_name = (string) $_POST['forumname']; + $forum_desc = (string) $_POST['forumdesc']; + $forum_status = intval($_POST['forumstatus']); + $prune_days = intval($_POST['prune_days']); + + $forum_parent = ($_POST['forum_parent'] != -1) ? intval($_POST['forum_parent']) : 0; + $show_on_index = ($forum_parent) ? intval($_POST['show_on_index']) : 1; + + $forum_display_order = intval($_POST['forum_display_order']); + $forum_display_sort = intval($_POST['forum_display_sort']); + $forum_tpl_id = (int) $_POST['forum_tpl_select']; + $allow_reg_tracker = (int) $_POST['allow_reg_tracker']; + $allow_porno_topic = (int) $_POST['allow_porno_topic']; + $self_moderated = (int) $_POST['self_moderated']; + + $forum_data = get_forum_data($forum_id); + $old_cat_id = $forum_data['cat_id']; + $forum_order = $forum_data['forum_order']; + + if (!$forum_name) + { + bb_die('Can not modify a forum without a name'); + } + + if ($forum_parent) + { + if (!$parent = get_forum_data($forum_parent)) + { + bb_die('Parent forum with id '. $forum_parent .' not found'); + } + + $cat_id = $parent['cat_id']; + $forum_parent = ($parent['forum_parent']) ? $parent['forum_parent'] : $parent['forum_id']; + $forum_order = $parent['forum_order'] + 5; + + if ($forum_id == $forum_parent) + { + bb_die('Ambiguous forum ID. Please select other parent forum'); + } + } + else if ($cat_id != $old_cat_id) + { + $max_order = get_max_forum_order($cat_id); + $forum_order = $max_order + 5; + } + else if ($forum_data['forum_parent']) + { + $old_parent = $forum_data['forum_parent']; + $forum_order = $cat_forums[$old_cat_id]['f'][$old_parent]['forum_order'] - 5; + } + + $forum_name_sql = DB()->escape($forum_name); + $forum_desc_sql = DB()->escape($forum_desc); + + DB()->query(" + UPDATE ". BB_FORUMS ." SET + forum_name = '$forum_name_sql', + cat_id = $cat_id, + forum_desc = '$forum_desc_sql', + forum_order = $forum_order, + forum_status = $forum_status, + prune_days = $prune_days, + forum_parent = $forum_parent, + show_on_index = $show_on_index, + forum_tpl_id = $forum_tpl_id, + allow_reg_tracker = $allow_reg_tracker, + allow_porno_topic = $allow_porno_topic, + self_moderated = $self_moderated, + forum_display_order = $forum_display_order, + forum_display_sort = $forum_display_sort + WHERE forum_id = $forum_id + "); + + if ($cat_id != $old_cat_id) + { + change_sf_cat($forum_id, $cat_id, $forum_order); + renumber_order('forum', $cat_id); + } + + renumber_order('forum', $old_cat_id); + + $cat_forums = get_cat_forums(); + $fix = fix_orphan_sf(); + $datastore->update('cat_forums'); + CACHE('bb_cache')->rm(); + + $message = $lang['FORUMS_UPDATED'] . '

        '; + $message .= ($fix) ? "$fix

        " : ''; + $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); + bb_die($message); + + break; + + case 'addcat': + // + // Create a category in the DB + // + if (!$new_cat_title = trim($_POST['categoryname'])) + { + bb_die('Category name is empty'); + } + + check_name_dup('cat', $new_cat_title); + + $order = DB()->fetch_row("SELECT MAX(cat_order) AS max_order FROM ". BB_CATEGORIES); + + $args = DB()->build_array('INSERT', array( + 'cat_title' => (string) $new_cat_title, + 'cat_order' => (int) $order['max_order'] + 10, + )); + + DB()->query("INSERT INTO ". BB_CATEGORIES . $args); + + $datastore->update('cat_forums'); + CACHE('bb_cache')->rm(); + + bb_die($lang['FORUMS_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + + break; + + case 'editcat': + // + // Show form to edit a category + // + $cat_id = (int) $_GET['c']; + $cat_info = get_info('category', $cat_id); + + $hidden_fields = array( + 'mode' => 'modcat', + 'c' => $cat_id, + ); + + $template->assign_vars(array( + 'TPL_EDIT_CATEGORY' => true, + 'CAT_TITLE' => htmlCHR($cat_info['cat_title']), + 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields), + 'S_SUBMIT_VALUE' => $lang['UPDATE'], + 'S_FORUM_ACTION' => "admin_forums.php", + )); + + break; + + case 'modcat': + // + // Modify a category in the DB + // + if (!$new_cat_title = trim($_POST['cat_title'])) + { + bb_die('Category name is empty'); + } + + $cat_id = (int) $_POST['c']; + + $row = get_info('category', $cat_id); + $cur_cat_title = $row['cat_title']; + + if ($cur_cat_title && $cur_cat_title !== $new_cat_title) + { + check_name_dup('cat', $new_cat_title); + + $new_cat_title_sql = DB()->escape($new_cat_title); + + DB()->query(" + UPDATE ". BB_CATEGORIES ." SET + cat_title = '$new_cat_title_sql' + WHERE cat_id = $cat_id + "); + } + + $datastore->update('cat_forums'); + CACHE('bb_cache')->rm(); + + bb_die($lang['FORUMS_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + + break; + + case 'deleteforum': + // + // Show form to delete a forum + // + $forum_id = (int) $_GET['f']; + + $move_to_options = ''; + $move_to_options .= sf_get_list('forum', $forum_id, 0); + + $foruminfo = get_info('forum', $forum_id); + + $hidden_fields = array( + 'mode' => 'movedelforum', + 'from_id' => $forum_id, + ); + + $template->assign_vars(array( + 'TPL_DELETE_FORUM' => true, + + 'WHAT_TO_DELETE' => htmlCHR($foruminfo['forum_name']), + 'DELETE_TITLE' => $lang['FORUM_DELETE'], + 'CAT_FORUM_NAME' => $lang['FORUM_NAME'], + + 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields), + 'S_FORUM_ACTION' => "admin_forums.php", + 'MOVE_TO_OPTIONS' => $move_to_options, + 'S_SUBMIT_VALUE' => $lang['MOVE_AND_DELETE'], + )); + + break; + + case 'movedelforum': + // + // Move or delete a forum in the DB + // + $from_id = (int) $_POST['from_id']; + $to_id = (int) $_POST['to_id']; + + if ($to_id == -1) + { + // Delete everything from forum + topic_delete('prune', $from_id, 0, true); + } + else + { + // Move all posts + $sql = "SELECT * FROM ". BB_FORUMS ." WHERE forum_id IN($from_id, $to_id)"; + $result = DB()->query($sql); + + if (DB()->num_rows($result) != 2) + { + bb_die('Ambiguous forum ID'); + } + + DB()->query("UPDATE ". BB_TOPICS ." SET forum_id = $to_id WHERE forum_id = $from_id"); + DB()->query("UPDATE ". BB_BT_TORRENTS ." SET forum_id = $to_id WHERE forum_id = $from_id"); + + $row = DB()->fetch_row("SELECT MIN(post_id) AS start_id, MAX(post_id) AS finish_id FROM ". BB_POSTS); + $start_id = (int) $row['start_id']; + $finish_id = (int) $row['finish_id']; + $per_cycle = 10000; + while (true) + { + set_time_limit(600); + $end_id = $start_id + $per_cycle - 1; + DB()->query(" + UPDATE ". BB_POSTS ." SET forum_id = $to_id WHERE post_id BETWEEN $start_id AND $end_id AND forum_id = $from_id + "); + if ($end_id > $finish_id) + { + break; + } + $start_id += $per_cycle; + } + + sync('forum', $to_id); + } + + DB()->query("DELETE FROM ". BB_FORUMS ." WHERE forum_id = $from_id"); + DB()->query("DELETE FROM ". BB_AUTH_ACCESS ." WHERE forum_id = $from_id"); + DB()->query("DELETE FROM ". BB_AUTH_ACCESS_SNAP ." WHERE forum_id = $from_id"); + + $cat_forums = get_cat_forums(); + fix_orphan_sf(); + update_user_level('all'); + $datastore->update('cat_forums'); + CACHE('bb_cache')->rm(); + + bb_die($lang['FORUMS_UPDATED'] . '

        ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + + break; + + case 'deletecat': + // Show form to delete a category + $cat_id = (int) $_GET['c']; + $catinfo = get_info('category', $cat_id); + $categories_count = $catinfo['number']; + + if ($categories_count == 1) + { + $row = DB()->fetch_row("SELECT COUNT(*) AS forums_count FROM ". BB_FORUMS); + + if ($row['forums_count'] > 0) + { + bb_die($lang['MUST_DELETE_FORUMS']); + } + else + { + $template->assign_var('NOWHERE_TO_MOVE', $lang['NOWHERE_TO_MOVE']); + } + } + + $hidden_fields = array( + 'mode' => 'movedelcat', + 'from_id' => $cat_id, + ); + + $template->assign_vars(array( + 'TPL_DELETE_FORUM' => true, + + 'WHAT_TO_DELETE' => htmlCHR($catinfo['cat_title']), + 'DELETE_TITLE' => $lang['CATEGORY_DELETE'], + 'CAT_FORUM_NAME' => $lang['CATEGORY'], + + 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields), + 'S_FORUM_ACTION' => "admin_forums.php", + 'MOVE_TO_OPTIONS' => get_list('category', $cat_id, 0), + 'S_SUBMIT_VALUE' => $lang['MOVE_AND_DELETE'], + )); + + break; + + case 'movedelcat': + // Move or delete a category in the DB + $from_id = (int) $_POST['from_id']; + $to_id = (int) $_POST['to_id']; + + if ($from_id == $to_id || !cat_exists($from_id) || !cat_exists($to_id)) + { + bb_die('Bad input'); + } + + $order_shear = get_max_forum_order($to_id) + 10; + + DB()->query(" + UPDATE ". BB_FORUMS ." SET + cat_id = $to_id, + forum_order = forum_order + $order_shear + WHERE cat_id = $from_id + "); + + DB()->query("DELETE FROM ". BB_CATEGORIES ." WHERE cat_id = $from_id"); + + renumber_order('forum', $to_id); + $cat_forums = get_cat_forums(); + $fix = fix_orphan_sf(); + $datastore->update('cat_forums'); + CACHE('bb_cache')->rm(); + + $message = $lang['FORUMS_UPDATED'] . '

        '; + $message .= ($fix) ? "$fix

        " : ''; + $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); + bb_die($message); + + break; + + case 'forum_order': + // Change order of forums + $move = intval($_GET['move']); + $forum_id = intval($_GET[POST_FORUM_URL]); + + $forum_info = get_info('forum', $forum_id); + renumber_order('forum', $forum_info['cat_id']); + + $cat_id = $forum_info['cat_id']; + + $move_down_forum_id = FALSE; + $forums = $cat_forums[$cat_id]['f_ord']; + $forum_order = $forum_info['forum_order']; + $prev_forum = (isset($forums[$forum_order - 10])) ? $forums[$forum_order - 10] : FALSE; + $next_forum = (isset($forums[$forum_order + 10])) ? $forums[$forum_order + 10] : FALSE; + + // move selected forum ($forum_id) UP + if ($move < 0 && $prev_forum) + { + if ($forum_info['forum_parent'] && $prev_forum['forum_parent'] != $forum_info['forum_parent']) + { + $show_main_page = true; + break; + } + else if ($move_down_forum_id = get_prev_root_forum_id($forums, $forum_order)) + { + $move_up_forum_id = $forum_id; + $move_down_ord_val = (get_sf_count($forum_id) + 1) * 10; + $move_up_ord_val = ((get_sf_count($move_down_forum_id) + 1) * 10) + $move_down_ord_val; + $move_down_forum_order = $cat_forums[$cat_id]['f'][$move_down_forum_id]['forum_order']; + } + } + // move selected forum ($forum_id) DOWN + else if ($move > 0 && $next_forum) + { + if ($forum_info['forum_parent'] && $next_forum['forum_parent'] != $forum_info['forum_parent']) + { + $show_main_page = true; + break; + } + else if ($move_up_forum_id = get_next_root_forum_id($forums, $forum_order)) + { + $move_down_forum_id = $forum_id; + $move_down_forum_order = $forum_order; + $move_down_ord_val = (get_sf_count($move_up_forum_id) + 1) * 10; + $move_up_ord_val = ((get_sf_count($move_down_forum_id) + 1) * 10) + $move_down_ord_val; + } + } + else + { + $show_main_page = true; + break; + } + + if ($forum_info['forum_parent']) + { + DB()->query(" + UPDATE ". BB_FORUMS ." SET + forum_order = forum_order + $move + WHERE forum_id = $forum_id + "); + } + else if ($move_down_forum_id) + { + DB()->query(" + UPDATE ". BB_FORUMS ." SET + forum_order = forum_order + $move_down_ord_val + WHERE cat_id = $cat_id + AND forum_order >= $move_down_forum_order + "); + DB()->query(" + UPDATE ". BB_FORUMS ." SET + forum_order = forum_order - $move_up_ord_val + WHERE forum_id = $move_up_forum_id + OR forum_parent = $move_up_forum_id + "); + } + + renumber_order('forum', $forum_info['cat_id']); + $datastore->update('cat_forums'); + CACHE('bb_cache')->rm(); + + $show_main_page = true; + break; + + case 'cat_order': + $move = (int) $_GET['move']; + $cat_id = (int) $_GET['c']; + + DB()->query(" + UPDATE ". BB_CATEGORIES ." SET + cat_order = cat_order + $move + WHERE cat_id = $cat_id + "); + + renumber_order('category'); + $datastore->update('cat_forums'); + CACHE('bb_cache')->rm(); + + $show_main_page = true; + break; + + case 'forum_sync': + sync('forum', intval($_GET['f'])); + $datastore->update('cat_forums'); + CACHE('bb_cache')->rm(); + + $show_main_page = true; + break; + + default: + bb_die($lang['NO_MODE']); + + break; + } +} + +if (!$mode || $show_main_page) +{ + $template->assign_vars(array( + 'TPL_FORUMS_LIST' => true, + + 'S_FORUM_ACTION' => 'admin_forums.php', + 'L_FORUM_TITLE' => $lang['FORUM_ADMIN_MAIN'], + )); + + $sql = "SELECT cat_id, cat_title, cat_order FROM " . BB_CATEGORIES . " ORDER BY cat_order"; + if (!$q_categories = DB()->sql_query($sql)) + { + bb_die('Could not query categories list'); + } + + if ($total_categories = DB()->num_rows($q_categories)) + { + $category_rows = DB()->sql_fetchrowset($q_categories); + + $where_cat_sql = $req_cat_id = ''; + + if ($c =& $_REQUEST['c']) + { + if ($c !== 'all') + { + $req_cat_id = (int) $c; + $where_cat_sql = "WHERE cat_id = $req_cat_id"; + } + else + { + $req_cat_id = 'all'; + } + } + else + { + $where_cat_sql = "WHERE cat_id = '-1'"; + } + + $sql = "SELECT * FROM ". BB_FORUMS ." $where_cat_sql ORDER BY cat_id, forum_order"; + if (!$q_forums = DB()->sql_query($sql)) + { + bb_die('Could not query forums information'); + } + + if ($total_forums = DB()->num_rows($q_forums)) + { + $forum_rows = DB()->sql_fetchrowset($q_forums); + } + + // Okay, let's build the index + $gen_cat = array(); + + $bgr_class_1 = 'prow1'; + $bgr_class_2 = 'prow2'; + $bgr_class_over = 'prow3'; + + $template->assign_vars(array( + 'U_ALL_FORUMS' => 'admin_forums.php?c=all', + 'FORUMS_COUNT' => $total_forums, + )); + + for ($i = 0; $i < $total_categories; $i++) + { + $cat_id = $category_rows[$i]['cat_id']; + + $template->assign_block_vars("c", array( + 'S_ADD_FORUM_SUBMIT' => "addforum[$cat_id]", + 'S_ADD_FORUM_NAME' => "forumname[$cat_id]", + + 'CAT_ID' => $cat_id, + 'CAT_DESC' => htmlCHR($category_rows[$i]['cat_title']), + + 'U_CAT_EDIT' => "admin_forums.php?mode=editcat&c=$cat_id", + 'U_CAT_DELETE' => "admin_forums.php?mode=deletecat&c=$cat_id", + 'U_CAT_MOVE_UP' => "admin_forums.php?mode=cat_order&move=-15&c=$cat_id", + 'U_CAT_MOVE_DOWN' => "admin_forums.php?mode=cat_order&move=15&c=$cat_id", + 'U_VIEWCAT' => "admin_forums.php?c=$cat_id", + 'U_CREATE_FORUM' => "admin_forums.php?mode=addforum&c=$cat_id", + )); + + for ($j = 0; $j < $total_forums; $j++) + { + $forum_id = $forum_rows[$j]['forum_id']; + + $bgr_class = (!($j % 2)) ? $bgr_class_2 : $bgr_class_1; + $row_bgr = " class=\"$bgr_class\" onmouseover=\"this.className='$bgr_class_over';\" onmouseout=\"this.className='$bgr_class';\""; + + if ($forum_rows[$j]['cat_id'] == $cat_id) + { + + $template->assign_block_vars("c.f", array( + 'FORUM_NAME' => htmlCHR($forum_rows[$j]['forum_name']), + 'FORUM_DESC' => htmlCHR($forum_rows[$j]['forum_desc']), + 'NUM_TOPICS' => $forum_rows[$j]['forum_topics'], + 'NUM_POSTS' => $forum_rows[$j]['forum_posts'], + 'PRUNE_DAYS' => ($forum_rows[$j]['prune_days']) ? $forum_rows[$j]['prune_days'] : '-', + + 'ORDER' => $forum_rows[$j]['forum_order'], + 'FORUM_ID' => $forum_rows[$j]['forum_id'], + 'ROW_BGR' => $row_bgr, + + 'SHOW_ON_INDEX' => (bool) $forum_rows[$j]['show_on_index'], + 'FORUM_PARENT' => $forum_rows[$j]['forum_parent'], + 'SF_PAD' => ($forum_rows[$j]['forum_parent']) ? ' style="padding-left: 20px;" ' : '', + 'FORUM_NAME_CLASS' => ($forum_rows[$j]['forum_parent']) ? 'genmed' : 'gen', + 'ADD_SUB_HREF' => "admin_forums.php?mode=addforum&forum_parent={$forum_rows[$j]['forum_id']}", + 'U_VIEWFORUM' => BB_ROOT ."viewforum.php?f=$forum_id", + 'U_FORUM_EDIT' => "admin_forums.php?mode=editforum&f=$forum_id", + 'U_FORUM_PERM' => "admin_forumauth.php?f=$forum_id", + 'U_FORUM_DELETE' => "admin_forums.php?mode=deleteforum&f=$forum_id", + 'U_FORUM_MOVE_UP' => "admin_forums.php?mode=forum_order&move=-15&f=$forum_id&c=$req_cat_id", + 'U_FORUM_MOVE_DOWN' => "admin_forums.php?mode=forum_order&move=15&f=$forum_id&c=$req_cat_id", + 'U_FORUM_RESYNC' => "admin_forums.php?mode=forum_sync&f=$forum_id", + )); + + }// if ... forumid == catid + } // for ... forums + } // for ... categories + }// if ... total_categories +} + +print_page('admin_forums.tpl', 'admin'); + +// Functions +function get_info ($mode, $id) +{ + switch($mode) + { + case 'category': + $table = BB_CATEGORIES; + $idfield = 'cat_id'; + $namefield = 'cat_title'; + break; + + case 'forum': + $table = BB_FORUMS; + $idfield = 'forum_id'; + $namefield = 'forum_name'; + break; + + default: + bb_die('Wrong mode for generating select list #1'); + break; + } + $sql = "SELECT count(*) as total FROM $table"; + if( !$result = DB()->sql_query($sql) ) + { + bb_die('Could not get forum / category information #1'); + } + $count = DB()->sql_fetchrow($result); + $count = $count['total']; + + $sql = "SELECT * FROM $table WHERE $idfield = $id"; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not get forum / category information #2'); + } + + if (DB()->num_rows($result) != 1) + { + bb_die('Forum / category does not exist or multiple forums / categories with ID '. $id); + } + + $return = DB()->sql_fetchrow($result); + $return['number'] = $count; + return $return; +} + +function get_list ($mode, $id, $select) +{ + switch($mode) + { + case 'category': + $table = BB_CATEGORIES; + $idfield = 'cat_id'; + $namefield = 'cat_title'; + $order = 'cat_order'; + break; + + case 'forum': + $table = BB_FORUMS; + $idfield = 'forum_id'; + $namefield = 'forum_name'; + $order = 'cat_id, forum_order'; + break; + + default: + bb_die('Wrong mode for generating select list #2'); + break; + } + + $sql = "SELECT * FROM $table"; + if( $select == 0 ) + { + $sql .= " WHERE $idfield <> $id"; + } + $sql .= " ORDER BY $order"; + + if( !$result = DB()->sql_query($sql) ) + { + bb_die('Could not get list of categories / forums #1'); + } + + $catlist = ''; + + while( $row = DB()->sql_fetchrow($result) ) + { + $s = ''; + if ($row[$idfield] == $id) + { + $s = ' selected="selected"'; + } + $catlist .= '\n'; + } + + return($catlist); +} + +function renumber_order ($mode, $cat = 0) +{ + switch($mode) + { + case 'category': + $table = BB_CATEGORIES; + $idfield = 'cat_id'; + $orderfield = 'cat_order'; + $cat = 0; + break; + + case 'forum': + $table = BB_FORUMS; + $idfield = 'forum_id'; + $orderfield = 'forum_order'; + $catfield = 'cat_id'; + break; + + default: + bb_die('Wrong mode for generating select list #3'); + break; + } + + $sql = "SELECT * FROM $table"; + if( $cat != 0) + { + $sql .= " WHERE $catfield = $cat"; + } + $sql .= " ORDER BY $orderfield ASC"; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not get list of categories / forums #2'); + } + + $i = 10; + + while ($row = DB()->sql_fetchrow($result)) + { + $sql = "UPDATE $table SET $orderfield = $i WHERE $idfield = " . $row[$idfield]; + if (!DB()->sql_query($sql)) + { + bb_die('Could not update order fields'); + } + $i += 10; + } + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not get list of categories / forums #3'); + } + +} + +function get_cat_forums ($cat_id = FALSE) +{ + $forums = array(); + $where_sql = ''; + + if ($cat_id = intval($cat_id)) + { + $where_sql = "AND f.cat_id = $cat_id"; + } + + $sql = 'SELECT c.cat_title, f.* + FROM '. BB_FORUMS .' f, '. BB_CATEGORIES ." c + WHERE f.cat_id = c.cat_id + $where_sql + ORDER BY c.cat_order, f.cat_id, f.forum_order"; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not get list of categories / forums #4'); + } + + if ($rowset = DB()->sql_fetchrowset($result)) + { + foreach ($rowset as $rid => $row) + { + $forums[$row['cat_id']]['cat_title'] = $row['cat_title']; + $forums[$row['cat_id']]['f'][$row['forum_id']] = $row; + $forums[$row['cat_id']]['f_ord'][$row['forum_order']] = $row; + } + } + + return $forums; +} + +function get_sf_count ($forum_id) +{ + global $cat_forums; + + $sf_count = 0; + + foreach ($cat_forums as $cid => $c) + { + foreach ($c['f'] as $fid => $f) + { + if ($f['forum_parent'] == $forum_id) + { + $sf_count++; + } + } + } + + return $sf_count; +} + +function get_prev_root_forum_id ($forums, $curr_forum_order) +{ + $i = $curr_forum_order - 10; + + while ($i > 0) + { + if (isset($forums[$i]) && !$forums[$i]['forum_parent']) + { + return $forums[$i]['forum_id']; + } + $i = $i - 10; + } + + return FALSE; +} + +function get_next_root_forum_id ($forums, $curr_forum_order) +{ + $i = $curr_forum_order + 10; + $limit = (count($forums) * 10) + 10; + + while ($i < $limit) + { + if (isset($forums[$i]) && !$forums[$i]['forum_parent']) + { + return $forums[$i]['forum_id']; + } + $i = $i + 10; + } + + return FALSE; +} + +function get_orphan_sf () +{ + global $cat_forums; + + $last_root = 0; + $bad_sf_ary = array(); + + foreach ($cat_forums as $cid => $c) + { + foreach ($c['f'] as $fid => $f) + { + if ($f['forum_parent']) + { + if ($f['forum_parent'] != $last_root) + { + $bad_sf_ary[] = $f['forum_id']; + } + } + else + { + $last_root = $f['forum_id']; + } + } + } + + return implode(',', $bad_sf_ary); +} + +function fix_orphan_sf ($orphan_sf_sql = '', $show_mess = FALSE) +{ + global $lang; + + $done_mess = ''; + + if (!$orphan_sf_sql) + { + $orphan_sf_sql = get_orphan_sf(); + } + + if ($orphan_sf_sql) + { + $sql = "UPDATE ". BB_FORUMS ." SET forum_parent = 0, show_on_index = 1 WHERE forum_id IN($orphan_sf_sql)"; + + if (!DB()->sql_query($sql)) + { + bb_die('Could not change subforums data'); + } + + if ($affectedrows = DB()->affected_rows()) + { + $done_mess = 'Subforums data corrected. '. $affectedrows .' orphan subforum(s) moved to root level.'; + } + + if ($show_mess) + { + $message = $done_mess .'

        '; + $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') .'

        '; + $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); + bb_die($message); + } + } + + return $done_mess; +} + +function sf_get_list ($mode, $exclude = 0, $select = 0) +{ + global $cat_forums, $forum_parent; + + $opt = ''; + + if ($mode == 'forum') + { + foreach ($cat_forums as $cid => $c) + { + $opt .= ''; + + foreach ($c['f'] as $fid => $f) + { + $selected = ($fid == $select) ? HTML_SELECTED : ''; + $disabled = ($fid == $exclude && !$forum_parent) ? HTML_DISABLED : ''; + $style = ($disabled) ? ' style="color: gray" ' : (($fid == $exclude) ? ' style="color: darkred" ' : ''); + $opt .= '\n"; + } + + $opt .= ''; + } + } + + return $opt; +} + +function get_forum_data ($forum_id) +{ + global $cat_forums; + + foreach ($cat_forums as $cid => $c) + { + foreach ($c['f'] as $fid => $f) + { + if ($fid == $forum_id) + { + return $f; + } + } + } + + return FALSE; +} + +function get_max_forum_order ($cat_id) +{ + $row = DB()->fetch_row(" + SELECT MAX(forum_order) AS max_forum_order + FROM ". BB_FORUMS ." + WHERE cat_id = $cat_id + "); + + return intval($row['max_forum_order']); +} + +function check_name_dup ($mode, $name, $die_on_error = true) +{ + $name_sql = DB()->escape($name); + + if ($mode == 'cat') + { + $what_checked = 'category'; + $sql = "SELECT cat_id FROM ". BB_CATEGORIES ." WHERE cat_title = '$name_sql'"; + } + else + { + $what_checked = 'forum'; + $sql = "SELECT forum_id FROM ". BB_FORUMS ." WHERE forum_name = '$name_sql'"; + } + + $name_is_dup = DB()->fetch_row($sql); + + if ($name_is_dup && $die_on_error) + { + bb_die('This '. $what_checked .' name taken, please choose something else'); + } + + return $name_is_dup; +} + +/** + * Change subforums cat_id if parent's cat_id was changed + */ +function change_sf_cat ($parent_id, $new_cat_id, $order_shear) +{ + DB()->query(" + UPDATE ". BB_FORUMS ." SET + cat_id = $new_cat_id, + forum_order = forum_order + $order_shear + WHERE forum_parent = $parent_id + "); } \ No newline at end of file diff --git a/upload/admin/admin_mass_email.php b/upload/admin/admin_mass_email.php index 0708c05d1..884a738ba 100644 --- a/upload/admin/admin_mass_email.php +++ b/upload/admin/admin_mass_email.php @@ -1,104 +1,104 @@ -fetch_rowset("SELECT ban_userid FROM ". BB_BANLIST ." WHERE ban_userid != 0"); - - foreach ($sql as $row) - { - $user_id_sql[] = ','. $row['ban_userid']; - } - $user_id_sql = join('', $user_id_sql); - - if ($group_id != -1) - { - $user_list = DB()->fetch_rowset(" - SELECT u.username, u.user_email, u.user_lang - FROM ". BB_USERS ." u, ". BB_USER_GROUP ." ug - WHERE ug.group_id = $group_id - AND ug.user_pending = 0 - AND u.user_id = ug.user_id - AND u.user_active = 1 - AND u.user_id NOT IN(". EXCLUDED_USERS_CSV . $user_id_sql .") - "); - } - else - { - $user_list = DB()->fetch_rowset(" - SELECT username, user_email, user_lang - FROM ". BB_USERS ." - WHERE user_active = 1 - AND user_id NOT IN(". EXCLUDED_USERS_CSV . $user_id_sql .") - "); - } - - require(INC_DIR .'emailer.class.php'); - - foreach ($user_list as $i => $row) - { - $emailer = new emailer($bb_cfg['smtp_delivery']); - - $emailer->from($bb_cfg['sitename'] ." <{$bb_cfg['board_email']}>"); - $emailer->email_address($row['username'] ." <{$row['user_email']}>"); - $emailer->use_template('admin_send_email'); - - $emailer->assign_vars(array( - 'SUBJECT' => html_entity_decode($subject), - 'MESSAGE' => html_entity_decode($message), - )); - - $emailer->send(); - $emailer->reset(); - } - } -} - -// -// Generate page -// -$sql = "SELECT group_id, group_name - FROM ". BB_GROUPS ." - WHERE group_single_user = 0 - ORDER BY group_name -"; - -$groups = array('-- '. $lang['ALL_USERS'] .' --' => -1); -foreach (DB()->fetch_rowset($sql) as $row) -{ - $groups[$row['group_name']] = $row['group_id']; -} - -$template->assign_vars(array( - 'MESSAGE' => $message, - 'SUBJECT' => $subject, - - 'ERROR_MESSAGE' => ($errors) ? join('
        ', array_unique($errors)) : '', - - 'S_USER_ACTION' => 'admin_mass_email.php', - 'S_GROUP_SELECT' => build_select(POST_GROUPS_URL, $groups), -)); - +fetch_rowset("SELECT ban_userid FROM ". BB_BANLIST ." WHERE ban_userid != 0"); + + foreach ($sql as $row) + { + $user_id_sql[] = ','. $row['ban_userid']; + } + $user_id_sql = join('', $user_id_sql); + + if ($group_id != -1) + { + $user_list = DB()->fetch_rowset(" + SELECT u.username, u.user_email, u.user_lang + FROM ". BB_USERS ." u, ". BB_USER_GROUP ." ug + WHERE ug.group_id = $group_id + AND ug.user_pending = 0 + AND u.user_id = ug.user_id + AND u.user_active = 1 + AND u.user_id NOT IN(". EXCLUDED_USERS_CSV . $user_id_sql .") + "); + } + else + { + $user_list = DB()->fetch_rowset(" + SELECT username, user_email, user_lang + FROM ". BB_USERS ." + WHERE user_active = 1 + AND user_id NOT IN(". EXCLUDED_USERS_CSV . $user_id_sql .") + "); + } + + require(INC_DIR .'emailer.class.php'); + + foreach ($user_list as $i => $row) + { + $emailer = new emailer($bb_cfg['smtp_delivery']); + + $emailer->from($bb_cfg['sitename'] ." <{$bb_cfg['board_email']}>"); + $emailer->email_address($row['username'] ." <{$row['user_email']}>"); + $emailer->use_template('admin_send_email'); + + $emailer->assign_vars(array( + 'SUBJECT' => html_entity_decode($subject), + 'MESSAGE' => html_entity_decode($message), + )); + + $emailer->send(); + $emailer->reset(); + } + } +} + +// +// Generate page +// +$sql = "SELECT group_id, group_name + FROM ". BB_GROUPS ." + WHERE group_single_user = 0 + ORDER BY group_name +"; + +$groups = array('-- '. $lang['ALL_USERS'] .' --' => -1); +foreach (DB()->fetch_rowset($sql) as $row) +{ + $groups[$row['group_name']] = $row['group_id']; +} + +$template->assign_vars(array( + 'MESSAGE' => $message, + 'SUBJECT' => $subject, + + 'ERROR_MESSAGE' => ($errors) ? join('
        ', array_unique($errors)) : '', + + 'S_USER_ACTION' => 'admin_mass_email.php', + 'S_GROUP_SELECT' => build_select(POST_GROUPS_URL, $groups), +)); + print_page('admin_mass_email.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_ranks.php b/upload/admin/admin_ranks.php index 4c33bdb72..220d1e8f8 100644 --- a/upload/admin/admin_ranks.php +++ b/upload/admin/admin_ranks.php @@ -1,257 +1,257 @@ -sql_query($sql)) - { - bb_die('Could not obtain ranks data #1'); - } - - $rank_info = DB()->sql_fetchrow($result); - $s_hidden_fields .= ''; - } - else - { - $rank_info['rank_special'] = 0; - } - - $s_hidden_fields .= ''; - - $rank_is_special = !empty($rank_info['rank_special']) ? HTML_CHECKED : ''; - $rank_is_not_special = empty($rank_info['rank_special']) ? HTML_CHECKED : ''; - - $template->assign_vars(array( - 'TPL_RANKS_EDIT' => true, - - 'RANK' => !empty($rank_info['rank_title']) ? $rank_info['rank_title'] : '', - 'SPECIAL_RANK' => $rank_is_special, - 'NOT_SPECIAL_RANK' => $rank_is_not_special, - 'MINIMUM' => ($rank_is_special) ? '' : @$rank_info['rank_min'], - 'IMAGE' => !empty($rank_info['rank_image']) ? $rank_info['rank_image'] : 'images/ranks/rank_image.png', - 'STYLE' => !empty($rank_info['rank_style']) ? $rank_info['rank_style'] : '', - 'IMAGE_DISPLAY' => !empty($rank_info['rank_image']) ? '' : '', - - 'S_RANK_ACTION' => "admin_ranks.php", - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - )); - } - elseif ($mode == 'save') - { - // - // Ok, they sent us our info, let's update it. - // - - $rank_id = (isset($_POST['id'])) ? intval($_POST['id']) : 0; - $rank_title = (isset($_POST['title'])) ? trim($_POST['title']) : ''; - $rank_style = (isset($_POST['style'])) ? trim($_POST['style']) : ''; - $special_rank = ($_POST['special_rank'] == 1) ? TRUE : 0; - $min_posts = (isset($_POST['min_posts'])) ? intval($_POST['min_posts']) : -1; - $rank_image = ((isset($_POST['rank_image']))) ? trim($_POST['rank_image']) : ''; - - if ($rank_title == '') - { - bb_die($lang['MUST_SELECT_RANK']); - } - - if ($special_rank == 1) - { - $max_posts = -1; - $min_posts = -1; - } - - // - // The rank image has to be a jpg, gif or png - // - if ($rank_image != '') - { - if (!preg_match('/(\.gif|\.png|\.jpg)$/is', $rank_image)) - { - $rank_image = ''; - } - } - - if ($rank_id) - { - if (!$special_rank) - { - $sql = "UPDATE " . BB_USERS . " SET user_rank = 0 WHERE user_rank = $rank_id"; - if (!$result = DB()->sql_query($sql)) - { - bb_die($lang['NO_UPDATE_RANKS']); - } - } - $sql = "UPDATE " . BB_RANKS . " - SET rank_title = '". DB()->escape($rank_title) ."', - rank_special = $special_rank, - rank_min = $min_posts, - rank_image = '". DB()->escape($rank_image) . "', - rank_style = '". DB()->escape($rank_style) ."' - WHERE rank_id = $rank_id"; - - $message = $lang['RANK_UPDATED']; - } - else - { - $sql = "INSERT INTO " . BB_RANKS . " (rank_title, rank_special, rank_min, rank_image, rank_style) - VALUES ('". DB()->escape($rank_title) ."', $special_rank, $min_posts, '". DB()->escape($rank_image) ."', '". DB()->escape($rank_style) ."')"; - - $message = $lang['RANK_ADDED']; - } - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not update / insert into ranks table'); - } - - $message .= '

        ' . sprintf($lang['CLICK_RETURN_RANKADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); - - $datastore->update('ranks'); - - bb_die($message); - } - elseif ($mode == 'delete') - { - // - // Ok, they want to delete their rank - // - - if (isset($_POST['id']) || isset($_GET['id'])) - { - $rank_id = (isset($_POST['id'])) ? intval($_POST['id']) : intval($_GET['id']); - } - else - { - $rank_id = 0; - } - - if ($rank_id) - { - $sql = "DELETE FROM " . BB_RANKS . " WHERE rank_id = $rank_id"; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not delete rank data'); - } - - $sql = "UPDATE " . BB_USERS . " SET user_rank = 0 WHERE user_rank = $rank_id"; - if (!$result = DB()->sql_query($sql)) - { - bb_die($lang['NO_UPDATE_RANKS']); - } - - $datastore->update('ranks'); - - bb_die($lang['RANK_REMOVED'] . '

        ' . sprintf($lang['CLICK_RETURN_RANKADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - } - else - { - bb_die($lang['MUST_SELECT_RANK']); - } - } - else - { - bb_die('Invalid mode'); - } -} -else -{ - // - // Show the default page - // - $sql = "SELECT * FROM " . BB_RANKS . " ORDER BY rank_min, rank_title"; - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not obtain ranks data #2'); - } - $rank_count = DB()->num_rows($result); - $rank_rows = DB()->sql_fetchrowset($result); - - $template->assign_vars(array( - 'TPL_RANKS_LIST' => true, - 'S_RANKS_ACTION' => "admin_ranks.php", - )); - - for ($i = 0; $i < $rank_count; $i++) - { - $rank = $rank_rows[$i]['rank_title']; - $special_rank = $rank_rows[$i]['rank_special']; - $rank_id = $rank_rows[$i]['rank_id']; - $rank_min = $rank_rows[$i]['rank_min']; - - if ($special_rank == 1) - { - $rank_min = $rank_max = '-'; - } - - $row_class = !($i % 2) ? 'row1' : 'row2'; - - $rank_is_special = ($special_rank) ? $lang['YES'] : $lang['NO']; - - $template->assign_block_vars('ranks', array( - 'ROW_CLASS' => $row_class, - 'RANK' => $rank, - 'STYLE' => $rank_rows[$i]['rank_style'], - 'IMAGE_DISPLAY' => ($rank_rows[$i]['rank_image']) ? '' : '', - 'SPECIAL_RANK' => $rank_is_special, - 'RANK_MIN' => $rank_min, - - 'U_RANK_EDIT' => "admin_ranks.php?mode=edit&id=$rank_id", - 'U_RANK_DELETE' => "admin_ranks.php?mode=delete&id=$rank_id", - )); - } -} - +sql_query($sql)) + { + bb_die('Could not obtain ranks data #1'); + } + + $rank_info = DB()->sql_fetchrow($result); + $s_hidden_fields .= ''; + } + else + { + $rank_info['rank_special'] = 0; + } + + $s_hidden_fields .= ''; + + $rank_is_special = !empty($rank_info['rank_special']) ? HTML_CHECKED : ''; + $rank_is_not_special = empty($rank_info['rank_special']) ? HTML_CHECKED : ''; + + $template->assign_vars(array( + 'TPL_RANKS_EDIT' => true, + + 'RANK' => !empty($rank_info['rank_title']) ? $rank_info['rank_title'] : '', + 'SPECIAL_RANK' => $rank_is_special, + 'NOT_SPECIAL_RANK' => $rank_is_not_special, + 'MINIMUM' => ($rank_is_special) ? '' : @$rank_info['rank_min'], + 'IMAGE' => !empty($rank_info['rank_image']) ? $rank_info['rank_image'] : 'images/ranks/rank_image.png', + 'STYLE' => !empty($rank_info['rank_style']) ? $rank_info['rank_style'] : '', + 'IMAGE_DISPLAY' => !empty($rank_info['rank_image']) ? '' : '', + + 'S_RANK_ACTION' => "admin_ranks.php", + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + )); + } + elseif ($mode == 'save') + { + // + // Ok, they sent us our info, let's update it. + // + + $rank_id = (isset($_POST['id'])) ? intval($_POST['id']) : 0; + $rank_title = (isset($_POST['title'])) ? trim($_POST['title']) : ''; + $rank_style = (isset($_POST['style'])) ? trim($_POST['style']) : ''; + $special_rank = ($_POST['special_rank'] == 1) ? TRUE : 0; + $min_posts = (isset($_POST['min_posts'])) ? intval($_POST['min_posts']) : -1; + $rank_image = ((isset($_POST['rank_image']))) ? trim($_POST['rank_image']) : ''; + + if ($rank_title == '') + { + bb_die($lang['MUST_SELECT_RANK']); + } + + if ($special_rank == 1) + { + $max_posts = -1; + $min_posts = -1; + } + + // + // The rank image has to be a jpg, gif or png + // + if ($rank_image != '') + { + if (!preg_match('/(\.gif|\.png|\.jpg)$/is', $rank_image)) + { + $rank_image = ''; + } + } + + if ($rank_id) + { + if (!$special_rank) + { + $sql = "UPDATE " . BB_USERS . " SET user_rank = 0 WHERE user_rank = $rank_id"; + if (!$result = DB()->sql_query($sql)) + { + bb_die($lang['NO_UPDATE_RANKS']); + } + } + $sql = "UPDATE " . BB_RANKS . " + SET rank_title = '". DB()->escape($rank_title) ."', + rank_special = $special_rank, + rank_min = $min_posts, + rank_image = '". DB()->escape($rank_image) . "', + rank_style = '". DB()->escape($rank_style) ."' + WHERE rank_id = $rank_id"; + + $message = $lang['RANK_UPDATED']; + } + else + { + $sql = "INSERT INTO " . BB_RANKS . " (rank_title, rank_special, rank_min, rank_image, rank_style) + VALUES ('". DB()->escape($rank_title) ."', $special_rank, $min_posts, '". DB()->escape($rank_image) ."', '". DB()->escape($rank_style) ."')"; + + $message = $lang['RANK_ADDED']; + } + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not update / insert into ranks table'); + } + + $message .= '

        ' . sprintf($lang['CLICK_RETURN_RANKADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); + + $datastore->update('ranks'); + + bb_die($message); + } + elseif ($mode == 'delete') + { + // + // Ok, they want to delete their rank + // + + if (isset($_POST['id']) || isset($_GET['id'])) + { + $rank_id = (isset($_POST['id'])) ? intval($_POST['id']) : intval($_GET['id']); + } + else + { + $rank_id = 0; + } + + if ($rank_id) + { + $sql = "DELETE FROM " . BB_RANKS . " WHERE rank_id = $rank_id"; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not delete rank data'); + } + + $sql = "UPDATE " . BB_USERS . " SET user_rank = 0 WHERE user_rank = $rank_id"; + if (!$result = DB()->sql_query($sql)) + { + bb_die($lang['NO_UPDATE_RANKS']); + } + + $datastore->update('ranks'); + + bb_die($lang['RANK_REMOVED'] . '

        ' . sprintf($lang['CLICK_RETURN_RANKADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + } + else + { + bb_die($lang['MUST_SELECT_RANK']); + } + } + else + { + bb_die('Invalid mode'); + } +} +else +{ + // + // Show the default page + // + $sql = "SELECT * FROM " . BB_RANKS . " ORDER BY rank_min, rank_title"; + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not obtain ranks data #2'); + } + $rank_count = DB()->num_rows($result); + $rank_rows = DB()->sql_fetchrowset($result); + + $template->assign_vars(array( + 'TPL_RANKS_LIST' => true, + 'S_RANKS_ACTION' => "admin_ranks.php", + )); + + for ($i = 0; $i < $rank_count; $i++) + { + $rank = $rank_rows[$i]['rank_title']; + $special_rank = $rank_rows[$i]['rank_special']; + $rank_id = $rank_rows[$i]['rank_id']; + $rank_min = $rank_rows[$i]['rank_min']; + + if ($special_rank == 1) + { + $rank_min = $rank_max = '-'; + } + + $row_class = !($i % 2) ? 'row1' : 'row2'; + + $rank_is_special = ($special_rank) ? $lang['YES'] : $lang['NO']; + + $template->assign_block_vars('ranks', array( + 'ROW_CLASS' => $row_class, + 'RANK' => $rank, + 'STYLE' => $rank_rows[$i]['rank_style'], + 'IMAGE_DISPLAY' => ($rank_rows[$i]['rank_image']) ? '' : '', + 'SPECIAL_RANK' => $rank_is_special, + 'RANK_MIN' => $rank_min, + + 'U_RANK_EDIT' => "admin_ranks.php?mode=edit&id=$rank_id", + 'U_RANK_DELETE' => "admin_ranks.php?mode=delete&id=$rank_id", + )); + } +} + print_page('admin_ranks.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_rebuild_search.php b/upload/admin/admin_rebuild_search.php index 0899627e7..8600334d9 100644 --- a/upload/admin/admin_rebuild_search.php +++ b/upload/admin/admin_rebuild_search.php @@ -1,627 +1,627 @@ -query(" - UPDATE ". BB_SEARCH_REBUILD ." SET - rebuild_session_status = ". REBUILD_SEARCH_ABORTED ." - WHERE rebuild_session_id = $last_session_id - "); - } - - bb_die(sprintf($lang['REBUILD_SEARCH_ABORTED'], $last_session_data['end_post_id']) .'

        '. sprintf($lang['CLICK_RETURN_REBUILD_SEARCH'], '', '')); -} - -// from which post to start processing -$start = abs(intval(@$_REQUEST['start'])); - -// get the total number of posts in the db -$total_posts = get_total_posts(); - -// clear the search tables and clear mode (delete or truncate) -$clear_search = isset($_REQUEST['clear_search']) ? (int) $_REQUEST['clear_search'] : 0; - -// get the number of total/session posts already processed -$total_posts_processed = ( $start != 0 ) ? get_total_posts('before', $last_session_data['end_post_id']) : 0; -$session_posts_processed = ( $mode == 'refresh' ) ? get_processed_posts('session') : 0; - -// find how many posts aren't processed -$total_posts_processing = $total_posts - $total_posts_processed; - -// how many posts to process in this session -if ($session_posts_processing = @intval($_REQUEST['session_posts_processing'])) -{ - if ($mode == 'submit') - { - // check if we passed over total_posts just after submitting - if ($session_posts_processing + $total_posts_processed > $total_posts) - { - $session_posts_processing = $total_posts - $total_posts_processed; - } - } - // correct it when posts are deleted during processing - $session_posts_processing = ($session_posts_processing > $total_posts) ? $total_posts : $session_posts_processing; -} -else -{ - // if we have finished, get all the posts, else only the remaining - $session_posts_processing = (!$total_posts_processing) ? $total_posts : $total_posts_processing; -} - -// how many posts to process per cycle -$post_limit = isset($_REQUEST['post_limit']) ? (int) $_REQUEST['post_limit'] : $def_post_limit; - -// correct the post_limit when we pass over it -if ( $session_posts_processed + $post_limit > $session_posts_processing ) -{ - $post_limit = $session_posts_processing - $session_posts_processed; -} - -// how much time to wait per cycle -if (isset($_REQUEST['time_limit'])) -{ - $time_limit = (int) $_REQUEST['time_limit']; -} -else -{ - $time_limit = $def_time_limit; - $time_limit_explain = $lang['TIME_LIMIT_EXPLAIN']; - - // check for safe mode timeout - if ( ini_get('safe_mode') ) - { - // get execution time - $max_execution_time = ini_get('max_execution_time'); - $time_limit_explain .= '
        ' . sprintf($lang['TIME_LIMIT_EXPLAIN_SAFE'], $max_execution_time); - - if ( $time_limit > $max_execution_time ) - { - $time_limit = $max_execution_time; - } - } - - // check for webserver timeout (IE returns null) - if ( isset($_SERVER["HTTP_KEEP_ALIVE"]) ) - { - // get webserver timeout - $webserver_timeout = intval($_SERVER["HTTP_KEEP_ALIVE"]); - $time_limit_explain .= '
        ' . sprintf($lang['TIME_LIMIT_EXPLAIN_WEBSERVER'], $webserver_timeout); - - if ( $time_limit > $webserver_timeout ) - { - $time_limit = $webserver_timeout; - } - } -} - -// how much time to wait between page refreshes -$refresh_rate = isset($_REQUEST['refresh_rate']) ? (int) $_REQUEST['refresh_rate'] : $def_refresh_rate; - -// check if the user gave wrong input -if ($mode == 'submit') -{ - if (($session_posts_processing || $post_limit || $refresh_rate || $time_limit) <= 0) - { - bb_die($lang['WRONG_INPUT'] .'

        '. sprintf($lang['CLICK_RETURN_REBUILD_SEARCH'], '', '')); - } -} - -// Increase maximum execution time in case of a lot of posts, but don't complain about it if it isn't allowed. -@set_time_limit($time_limit + 20); - -// check if we are should start processing -if ($mode == 'submit' || $mode == 'refresh') -{ - // check if we are in the beginning of processing - if ($start == 0) - { - $last_session_data = get_empty_last_session_data(); - clear_search_tables($clear_search); - } - - // get the db sizes - list($search_data_size, $search_index_size, $search_tables_size) = get_db_sizes(); - - // get the post subject/text of each post - $result = DB()->query(" - SELECT - pt.post_id, pt.post_text, - IF(p.post_id = t.topic_first_post_id, t.topic_title, '') AS post_subject - FROM - ". BB_POSTS_TEXT ." pt, - ". BB_POSTS ." p, - ". BB_TOPICS ." t - WHERE p.post_id = pt.post_id - AND t.topic_id = p.topic_id - AND p.poster_id NOT IN(". BOT_UID .") - AND pt.post_id >= $start - ORDER BY pt.post_id ASC - LIMIT $post_limit - "); - - $expire_time = $start_time + $time_limit - 5; - $start_post_id = $end_post_id = $num_rows = 0; - $timer_expired = false; - $words_sql = array(); - - while ($row = DB()->fetch_next($result) AND !$timer_expired) - { - @set_time_limit(600); - $start_post_id = ($num_rows == 0) ? $row['post_id'] : $start_post_id; - $end_post_id = $row['post_id']; - - // Get search words - $s_post_text = str_replace('\n', "\n", $row['post_text']); - $s_post_subject = str_replace('\n', "\n", $row['post_subject']); - $words_sql[] = array( - 'post_id' => (int) $row['post_id'], - 'search_words' => add_search_words($row['post_id'], stripslashes($s_post_text), stripslashes($s_post_subject), true), - ); - - $timer_expired = (TIMENOW > $expire_time); - $num_rows++; - } - - // Store search words - if ($words_sql) - { - DB()->query("REPLACE INTO ". BB_POSTS_SEARCH . DB()->build_array('MULTI_INSERT', $words_sql)); - } - - // find how much time the last cycle took - $last_cycle_time = intval(TIMENOW - $start_time); - - // check if we had any data - if ($num_rows != 0) - { - if ($mode == 'submit') - { - // insert a new session entry - $args = DB()->build_array('INSERT', array( - 'end_post_id' => (int) $end_post_id, - 'end_time' => (int) TIMENOW, - 'last_cycle_time' => (int) $last_cycle_time, - 'session_time' => (int) $last_cycle_time, - 'session_posts' => (int) $num_rows, - 'session_cycles' => (int) 1, - 'start_post_id' => (int) $start_post_id, - 'start_time' => (int) $start_time, - 'search_size' => (int) $search_tables_size, - 'rebuild_session_status' => REBUILD_SEARCH_PROCESSED, - )); - DB()->query("REPLACE INTO ". BB_SEARCH_REBUILD . $args); - } - else // refresh - { - // update the last session entry - DB()->query(" - UPDATE ". BB_SEARCH_REBUILD ." SET - end_post_id = $end_post_id, - end_time = ". TIMENOW .", - last_cycle_time = $last_cycle_time, - session_time = session_time + $last_cycle_time, - session_posts = session_posts + $num_rows, - session_cycles = session_cycles + 1, - rebuild_session_status = ". REBUILD_SEARCH_PROCESSED ." - WHERE rebuild_session_id = $last_session_id - "); - } - } - - $last_session_data = get_rebuild_session_details('last', 'all'); - $template->assign_vars(array('TPL_REBUILD_SEARCH_PROGRESS' => true)); - - $processing_messages = ''; - $processing_messages .= ($timer_expired) ? sprintf($lang['TIMER_EXPIRED'], TIMENOW - $start_time) : ''; - $processing_messages .= ($start == 0 && $clear_search) ? $lang['CLEARED_SEARCH_TABLES'] : ''; - - // check if we have reached the end of our post processing - $session_posts_processed = get_processed_posts('session'); - $total_posts_processed = get_total_posts('before', $last_session_data['end_post_id']); - $total_posts = get_total_posts(); - - if ( $session_posts_processed < $session_posts_processing && $total_posts_processed < $total_posts ) - { - $form_parameters = '&start='.($end_post_id+1); - $form_parameters .= '&session_posts_processing='.$session_posts_processing; - $form_parameters .= '&post_limit='.$post_limit; - $form_parameters .= '&time_limit='.$time_limit; - $form_parameters .= '&refresh_rate='.$refresh_rate; - - $form_action = 'admin_rebuild_search.php'.'?mode=refresh'.$form_parameters; - $next_button = $lang['NEXT']; - $progress_bar_img = $images['progress_bar']; - - $processing_messages .= sprintf($lang['PROCESSING_NEXT_POSTS'], $post_limit); - - meta_refresh($form_action, $refresh_rate); - - // create the meta tag for refresh - $template->assign_vars(array( - 'CANCEL_BUTTON' => true, - )); - } - else // end of processing - { - $form_action = "admin_rebuild_search.php"; - $next_button = $lang['FINISHED']; - $progress_bar_img = $images['progress_bar_full']; - - $processing_messages .= ( $session_posts_processed < $session_posts_processing ) ? sprintf($lang['DELETED_POSTS'], $session_posts_processing - $session_posts_processed) : ''; - $processing_messages .= ( $total_posts_processed == $total_posts ) ? $lang['ALL_POSTS_PROCESSED'] : $lang['ALL_SESSION_POSTS_PROCESSED']; - - // if we have processed all the db posts we need to update the rebuild_status - DB()->query("UPDATE ". BB_SEARCH_REBUILD ." SET - rebuild_session_status = ". REBUILD_SEARCH_COMPLETED ." - WHERE rebuild_session_id = $last_session_id - AND end_post_id = $max_post_id - "); - - // optimize all search tables when finished - $table_ary = array(BB_POSTS_SEARCH); - - foreach ($table_ary as $table) - { - DB()->query("ANALYZE TABLE $table"); - DB()->query("OPTIMIZE TABLE $table"); - } - - $processing_messages .= '
        ' . $lang['ALL_TABLES_OPTIMIZED']; - } - - // calculate the percent - $session_percent = ($session_posts_processed / $session_posts_processing) * 100; - $total_percent = ($total_posts_processed / $total_posts) * 100; - - // get the db sizes - list($search_data_size, $search_index_size, $search_tables_size) = get_db_sizes(); - - // calculate the final (estimated) values - $final_search_tables_size = ''; - - if ($search_tables_size) - { - $start_search_tables_size = $last_session_data['search_size']; - $final_search_tables_size = $start_search_tables_size + round(($search_tables_size - $start_search_tables_size) * (100 / $session_percent)); - } - - // calculate various times - $session_time = $last_session_data['session_time']; - $session_average_cycle_time = round($session_time / $last_session_data['session_cycles']); - $session_estimated_time = round($session_time * (100 / $session_percent)) - $session_time; - - // create the percent boxes - create_percent_box('session', create_percent_color($session_percent), $session_percent); - create_percent_box('total', create_percent_color($total_percent), $total_percent); - - $template->assign_vars(array( - 'L_NEXT' => $next_button, - 'L_TIME_LAST_POSTS_ADMIN' => sprintf($lang['TIME_LAST_POSTS'], $num_rows), - - 'PROCESSING_POSTS' => sprintf($lang['PROCESSED_POST_IDS'], $start_post_id, $end_post_id), - 'PROCESSING_MESSAGES' => $processing_messages, - 'PROGRESS_BAR_IMG' => $progress_bar_img, - - 'SESSION_DETAILS' => sprintf($lang['PROCESS_DETAILS'], $session_posts_processed - $num_rows + 1, $session_posts_processed, $session_posts_processing), - 'SESSION_PERCENT' => sprintf($lang['PERCENT_COMPLETED'], round($session_percent, 2)), - - 'TOTAL_DETAILS' => sprintf($lang['PROCESS_DETAILS'], $total_posts_processed - $num_rows + 1, $total_posts_processed, $total_posts), - 'TOTAL_PERCENT' => sprintf($lang['PERCENT_COMPLETED'], round($total_percent, 2)), - - 'LAST_CYCLE_TIME' => delta_time(TIMENOW), - 'SESSION_TIME' => delta_time($last_session_data['start_time']), - 'SESSION_AVERAGE_CYCLE_TIME'=> delta_time($session_average_cycle_time, 0), - 'SESSION_ESTIMATED_TIME' => delta_time($session_estimated_time, 0), - - 'SEARCH_TABLES_SIZE' => humn_size($search_tables_size), - 'FINAL_SEARCH_TABLES_SIZE' => humn_size($final_search_tables_size), - 'SEARCH_DATA_SIZE' => humn_size($search_data_size), - 'SEARCH_INDEX_SIZE' => humn_size($search_index_size), - - 'START_POST' => $last_session_data['start_post_id'], - 'POST_LIMIT' => $num_rows, - 'TIME_LIMIT' => $time_limit, - 'REFRESH_RATE' => $refresh_rate, - - 'S_REBUILD_SEARCH_ACTION' => $form_action, - )); -} -else // show the input page -{ - // create the page - // used only with the select input - $post_limit_hidden = ( $def_post_limit > $total_posts ) ? $total_posts : $def_post_limit; - - $s_hidden_fields = ''; - $s_hidden_fields .= ''; - - $next_start_post_id = 0; - $last_saved_processing = ''; - $clear_search_disabled = ''; - - if ($last_session_data['rebuild_session_id']) - { - $last_saved_post_id = $last_session_data['end_post_id']; - $next_start_post_id = $last_saved_post_id + 1; - $last_saved_date = bb_date($last_session_data['end_time']); - - // check our last status - if ( $last_session_data['rebuild_session_status'] == REBUILD_SEARCH_PROCESSED ) - { - $last_saved_processing = sprintf($lang['INFO_PROCESSING_STOPPED'], $last_saved_post_id, $total_posts_processed, $last_saved_date); - $clear_search_disabled = 'disabled="disabled"'; - - $template->assign_block_vars("start_select_input", array()); - } - elseif ( $last_session_data['rebuild_session_status'] == REBUILD_SEARCH_ABORTED ) - { - $last_saved_processing = sprintf($lang['INFO_PROCESSING_ABORTED'], $last_saved_post_id, $total_posts_processed, $last_saved_date); - // check if the interrupted cycle has finished - if ( TIMENOW - $last_session_data['end_time'] < $last_session_data['last_cycle_time'] ) - { - $last_saved_processing .= '
        '.$lang['INFO_PROCESSING_ABORTED_SOON']; - } - $clear_search_disabled = 'disabled="disabled"'; - - $template->assign_block_vars("start_select_input", array()); - } - else // when finished - { - if ( $last_session_data['end_post_id'] < $max_post_id ) - { - $last_saved_processing = sprintf($lang['INFO_PROCESSING_FINISHED_NEW'], $last_saved_post_id, $total_posts_processed, $last_saved_date, ($total_posts - $total_posts_processed)); - $clear_search_disabled = 'disabled="disabled"'; - - $template->assign_block_vars("start_select_input", array()); - } - else - { - $last_saved_processing = sprintf($lang['INFO_PROCESSING_FINISHED'], $total_posts, $last_saved_date); - - $template->assign_block_vars("start_text_input", array()); - } - } - - $template->assign_block_vars("last_saved_info", array()); - } - else - { - $template->assign_block_vars("start_text_input", array()); - } - - // create the output of page - $template->assign_vars(array( - 'TPL_REBUILD_SEARCH_MAIN' => true, - - 'L_TIME_LIMIT_EXPLAIN' => $time_limit_explain, - - 'NEXT_START_POST_ID' => $next_start_post_id, - 'CLEAR_SEARCH_DISABLED' => $clear_search_disabled, - 'SESSION_POSTS_PROCESSING' => $session_posts_processing, - 'POST_LIMIT' => $post_limit, - 'REFRESH_RATE' => $refresh_rate, - 'TIME_LIMIT' => $time_limit, - - 'LAST_SAVED_PROCESSING' => $last_saved_processing, - - 'SESSION_ID' => $userdata['session_id'], - - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - 'S_REBUILD_SEARCH_ACTION' => "admin_rebuild_search.php?mode=submit", - )); -} - -print_page('admin_rebuild_search.tpl', 'admin'); - -// -// Functions -// -function get_db_sizes () -{ - $search_data_size = $search_index_size = 0; - $search_table_like = DB()->escape(BB_POSTS_SEARCH); - - $sql = "SHOW TABLE STATUS FROM `". DB()->selected_db ."` LIKE '$search_table_like'"; - - foreach (DB()->fetch_rowset($sql) as $row) - { - $search_data_size += $row['Data_length']; - $search_index_size += $row['Index_length']; - } - - return array($search_data_size, $search_index_size, $search_data_size+$search_index_size); -} - -// get the latest post_id in the forum -function get_latest_post_id () -{ - $row = DB()->fetch_row("SELECT MAX(post_id) as post_id FROM ". BB_POSTS_TEXT); - - return (int) $row['post_id']; -} - -function get_empty_last_session_data () -{ - return array( - 'rebuild_session_id' => 0, - 'start_post_id' => 0, - 'end_post_id' => 0, - 'start_time' => 0, - 'end_time' => 0, - 'last_cycle_time' => 0, - 'session_time' => 0, - 'session_posts' => 0, - 'session_cycles' => 0, - 'search_size' => 0, - 'rebuild_session_status' => REBUILD_SEARCH_COMPLETED, - ); -} - -// get some or all of the rebuild details of a specific session or of the last session -// $id is the id or the 'last' id -// $details is one of the fields or 'all' of them -function get_rebuild_session_details ($id, $details = 'all') -{ - $session_details = get_empty_last_session_data(); - - if ($id != 'last') - { - $sql = "SELECT * FROM ". BB_SEARCH_REBUILD ." WHERE rebuild_session_id = $id"; - } - else - { - $sql = "SELECT * FROM ". BB_SEARCH_REBUILD ." ORDER BY rebuild_session_id DESC LIMIT 1"; - } - - if ($row = DB()->fetch_row($sql)) - { - $session_details = ($details == 'all') ? $row : $row[$details]; - } - - return $session_details; -} - -// get the number of processed posts in the last session or in all sessions -// 'total' to get the sum of posts of all sessions -// 'session' to get the posts of the last session -function get_processed_posts ($mode = 'session') -{ - global $last_session_data; - - if ($mode == 'total') - { - $sql = "SELECT SUM(session_posts) as posts FROM ". BB_SEARCH_REBUILD; - $row = DB()->fetch_row($sql); - } - else - { - $row['posts'] = $last_session_data['session_posts']; - } - - return (int) $row['posts']; -} - -// how many posts are in the db before or after a specific post_id -// after/before require and the post_id -function get_total_posts ($mode = 'after', $post_id = 0) -{ - if ($post_id) - { - $sql = "SELECT COUNT(post_id) as total_posts FROM " . BB_POSTS_TEXT . " - WHERE post_id " . (($mode == 'after') ? '>= ' : '<= ' ) . (int) $post_id; - } - else - { - $sql = "SELECT COUNT(*) as total_posts FROM " . BB_POSTS_TEXT; - } - - $row = DB()->fetch_row($sql); - - return (int) $row['total_posts']; -} - -function clear_search_tables ($mode = '') -{ - DB()->query("DELETE FROM ". BB_SEARCH_REBUILD); - - if ($mode) - { - $table_ary = array(BB_POSTS_SEARCH); - - foreach ($table_ary as $table) - { - $sql = (($mode == 1) ? "DELETE FROM " : "TRUNCATE TABLE ") . $table; - DB()->query($sql); - } - } -} - -// Create the percent color -// We use an array with the color percent limits. -// One color stays constantly at FF when the percent is between its limits -// and we adjust the other 2 accordingly to percent, from 200 to 0. -// We limit the result to 200, in order to avoid white (255). -function create_percent_color($percent) -{ - $percent_ary = array( - 'r' => array(86, 100), - 'g' => array(0, 50), - 'b' => array(51, 85), - ); - - foreach ($percent_ary as $key => $value) - { - if ( $percent <= $value[1] ) - { - $percent_color = create_color($key, round(200-($percent-$value[0])*(200/($value[1]-$value[0])))); - break; - } - } - - return $percent_color; -} - -// create the hex representation of color -function create_color($mode, $code) -{ - return (($mode == 'r') ? 'FF': sprintf("%02X", $code)) . (($mode == 'g') ? 'FF': sprintf("%02X", $code)) . (($mode == 'b') ? 'FF': sprintf("%02X", $code)); -} - -// create the percent bar & box -function create_percent_box($box, $percent_color, $percent_width) -{ - global $template; - - if ($box == 'session') - { - $template->assign_vars(array( - 'SESSION_PERCENT_BOX' => true, - 'SESSION_PERCENT_COLOR' => $percent_color, - 'SESSION_PERCENT_WIDTH' => round($percent_width), - )); - } - else - { - $template->assign_vars(array( - 'TOTAL_PERCENT_BOX' => true, - 'TOTAL_PERCENT_COLOR' => $percent_color, - 'TOTAL_PERCENT_WIDTH' => round($percent_width), - )); - } +query(" + UPDATE ". BB_SEARCH_REBUILD ." SET + rebuild_session_status = ". REBUILD_SEARCH_ABORTED ." + WHERE rebuild_session_id = $last_session_id + "); + } + + bb_die(sprintf($lang['REBUILD_SEARCH_ABORTED'], $last_session_data['end_post_id']) .'

        '. sprintf($lang['CLICK_RETURN_REBUILD_SEARCH'], '', '')); +} + +// from which post to start processing +$start = abs(intval(@$_REQUEST['start'])); + +// get the total number of posts in the db +$total_posts = get_total_posts(); + +// clear the search tables and clear mode (delete or truncate) +$clear_search = isset($_REQUEST['clear_search']) ? (int) $_REQUEST['clear_search'] : 0; + +// get the number of total/session posts already processed +$total_posts_processed = ( $start != 0 ) ? get_total_posts('before', $last_session_data['end_post_id']) : 0; +$session_posts_processed = ( $mode == 'refresh' ) ? get_processed_posts('session') : 0; + +// find how many posts aren't processed +$total_posts_processing = $total_posts - $total_posts_processed; + +// how many posts to process in this session +if ($session_posts_processing = @intval($_REQUEST['session_posts_processing'])) +{ + if ($mode == 'submit') + { + // check if we passed over total_posts just after submitting + if ($session_posts_processing + $total_posts_processed > $total_posts) + { + $session_posts_processing = $total_posts - $total_posts_processed; + } + } + // correct it when posts are deleted during processing + $session_posts_processing = ($session_posts_processing > $total_posts) ? $total_posts : $session_posts_processing; +} +else +{ + // if we have finished, get all the posts, else only the remaining + $session_posts_processing = (!$total_posts_processing) ? $total_posts : $total_posts_processing; +} + +// how many posts to process per cycle +$post_limit = isset($_REQUEST['post_limit']) ? (int) $_REQUEST['post_limit'] : $def_post_limit; + +// correct the post_limit when we pass over it +if ( $session_posts_processed + $post_limit > $session_posts_processing ) +{ + $post_limit = $session_posts_processing - $session_posts_processed; +} + +// how much time to wait per cycle +if (isset($_REQUEST['time_limit'])) +{ + $time_limit = (int) $_REQUEST['time_limit']; +} +else +{ + $time_limit = $def_time_limit; + $time_limit_explain = $lang['TIME_LIMIT_EXPLAIN']; + + // check for safe mode timeout + if ( ini_get('safe_mode') ) + { + // get execution time + $max_execution_time = ini_get('max_execution_time'); + $time_limit_explain .= '
        ' . sprintf($lang['TIME_LIMIT_EXPLAIN_SAFE'], $max_execution_time); + + if ( $time_limit > $max_execution_time ) + { + $time_limit = $max_execution_time; + } + } + + // check for webserver timeout (IE returns null) + if ( isset($_SERVER["HTTP_KEEP_ALIVE"]) ) + { + // get webserver timeout + $webserver_timeout = intval($_SERVER["HTTP_KEEP_ALIVE"]); + $time_limit_explain .= '
        ' . sprintf($lang['TIME_LIMIT_EXPLAIN_WEBSERVER'], $webserver_timeout); + + if ( $time_limit > $webserver_timeout ) + { + $time_limit = $webserver_timeout; + } + } +} + +// how much time to wait between page refreshes +$refresh_rate = isset($_REQUEST['refresh_rate']) ? (int) $_REQUEST['refresh_rate'] : $def_refresh_rate; + +// check if the user gave wrong input +if ($mode == 'submit') +{ + if (($session_posts_processing || $post_limit || $refresh_rate || $time_limit) <= 0) + { + bb_die($lang['WRONG_INPUT'] .'

        '. sprintf($lang['CLICK_RETURN_REBUILD_SEARCH'], '', '')); + } +} + +// Increase maximum execution time in case of a lot of posts, but don't complain about it if it isn't allowed. +@set_time_limit($time_limit + 20); + +// check if we are should start processing +if ($mode == 'submit' || $mode == 'refresh') +{ + // check if we are in the beginning of processing + if ($start == 0) + { + $last_session_data = get_empty_last_session_data(); + clear_search_tables($clear_search); + } + + // get the db sizes + list($search_data_size, $search_index_size, $search_tables_size) = get_db_sizes(); + + // get the post subject/text of each post + $result = DB()->query(" + SELECT + pt.post_id, pt.post_text, + IF(p.post_id = t.topic_first_post_id, t.topic_title, '') AS post_subject + FROM + ". BB_POSTS_TEXT ." pt, + ". BB_POSTS ." p, + ". BB_TOPICS ." t + WHERE p.post_id = pt.post_id + AND t.topic_id = p.topic_id + AND p.poster_id NOT IN(". BOT_UID .") + AND pt.post_id >= $start + ORDER BY pt.post_id ASC + LIMIT $post_limit + "); + + $expire_time = $start_time + $time_limit - 5; + $start_post_id = $end_post_id = $num_rows = 0; + $timer_expired = false; + $words_sql = array(); + + while ($row = DB()->fetch_next($result) AND !$timer_expired) + { + @set_time_limit(600); + $start_post_id = ($num_rows == 0) ? $row['post_id'] : $start_post_id; + $end_post_id = $row['post_id']; + + // Get search words + $s_post_text = str_replace('\n', "\n", $row['post_text']); + $s_post_subject = str_replace('\n', "\n", $row['post_subject']); + $words_sql[] = array( + 'post_id' => (int) $row['post_id'], + 'search_words' => add_search_words($row['post_id'], stripslashes($s_post_text), stripslashes($s_post_subject), true), + ); + + $timer_expired = (TIMENOW > $expire_time); + $num_rows++; + } + + // Store search words + if ($words_sql) + { + DB()->query("REPLACE INTO ". BB_POSTS_SEARCH . DB()->build_array('MULTI_INSERT', $words_sql)); + } + + // find how much time the last cycle took + $last_cycle_time = intval(TIMENOW - $start_time); + + // check if we had any data + if ($num_rows != 0) + { + if ($mode == 'submit') + { + // insert a new session entry + $args = DB()->build_array('INSERT', array( + 'end_post_id' => (int) $end_post_id, + 'end_time' => (int) TIMENOW, + 'last_cycle_time' => (int) $last_cycle_time, + 'session_time' => (int) $last_cycle_time, + 'session_posts' => (int) $num_rows, + 'session_cycles' => (int) 1, + 'start_post_id' => (int) $start_post_id, + 'start_time' => (int) $start_time, + 'search_size' => (int) $search_tables_size, + 'rebuild_session_status' => REBUILD_SEARCH_PROCESSED, + )); + DB()->query("REPLACE INTO ". BB_SEARCH_REBUILD . $args); + } + else // refresh + { + // update the last session entry + DB()->query(" + UPDATE ". BB_SEARCH_REBUILD ." SET + end_post_id = $end_post_id, + end_time = ". TIMENOW .", + last_cycle_time = $last_cycle_time, + session_time = session_time + $last_cycle_time, + session_posts = session_posts + $num_rows, + session_cycles = session_cycles + 1, + rebuild_session_status = ". REBUILD_SEARCH_PROCESSED ." + WHERE rebuild_session_id = $last_session_id + "); + } + } + + $last_session_data = get_rebuild_session_details('last', 'all'); + $template->assign_vars(array('TPL_REBUILD_SEARCH_PROGRESS' => true)); + + $processing_messages = ''; + $processing_messages .= ($timer_expired) ? sprintf($lang['TIMER_EXPIRED'], TIMENOW - $start_time) : ''; + $processing_messages .= ($start == 0 && $clear_search) ? $lang['CLEARED_SEARCH_TABLES'] : ''; + + // check if we have reached the end of our post processing + $session_posts_processed = get_processed_posts('session'); + $total_posts_processed = get_total_posts('before', $last_session_data['end_post_id']); + $total_posts = get_total_posts(); + + if ( $session_posts_processed < $session_posts_processing && $total_posts_processed < $total_posts ) + { + $form_parameters = '&start='.($end_post_id+1); + $form_parameters .= '&session_posts_processing='.$session_posts_processing; + $form_parameters .= '&post_limit='.$post_limit; + $form_parameters .= '&time_limit='.$time_limit; + $form_parameters .= '&refresh_rate='.$refresh_rate; + + $form_action = 'admin_rebuild_search.php'.'?mode=refresh'.$form_parameters; + $next_button = $lang['NEXT']; + $progress_bar_img = $images['progress_bar']; + + $processing_messages .= sprintf($lang['PROCESSING_NEXT_POSTS'], $post_limit); + + meta_refresh($form_action, $refresh_rate); + + // create the meta tag for refresh + $template->assign_vars(array( + 'CANCEL_BUTTON' => true, + )); + } + else // end of processing + { + $form_action = "admin_rebuild_search.php"; + $next_button = $lang['FINISHED']; + $progress_bar_img = $images['progress_bar_full']; + + $processing_messages .= ( $session_posts_processed < $session_posts_processing ) ? sprintf($lang['DELETED_POSTS'], $session_posts_processing - $session_posts_processed) : ''; + $processing_messages .= ( $total_posts_processed == $total_posts ) ? $lang['ALL_POSTS_PROCESSED'] : $lang['ALL_SESSION_POSTS_PROCESSED']; + + // if we have processed all the db posts we need to update the rebuild_status + DB()->query("UPDATE ". BB_SEARCH_REBUILD ." SET + rebuild_session_status = ". REBUILD_SEARCH_COMPLETED ." + WHERE rebuild_session_id = $last_session_id + AND end_post_id = $max_post_id + "); + + // optimize all search tables when finished + $table_ary = array(BB_POSTS_SEARCH); + + foreach ($table_ary as $table) + { + DB()->query("ANALYZE TABLE $table"); + DB()->query("OPTIMIZE TABLE $table"); + } + + $processing_messages .= '
        ' . $lang['ALL_TABLES_OPTIMIZED']; + } + + // calculate the percent + $session_percent = ($session_posts_processed / $session_posts_processing) * 100; + $total_percent = ($total_posts_processed / $total_posts) * 100; + + // get the db sizes + list($search_data_size, $search_index_size, $search_tables_size) = get_db_sizes(); + + // calculate the final (estimated) values + $final_search_tables_size = ''; + + if ($search_tables_size) + { + $start_search_tables_size = $last_session_data['search_size']; + $final_search_tables_size = $start_search_tables_size + round(($search_tables_size - $start_search_tables_size) * (100 / $session_percent)); + } + + // calculate various times + $session_time = $last_session_data['session_time']; + $session_average_cycle_time = round($session_time / $last_session_data['session_cycles']); + $session_estimated_time = round($session_time * (100 / $session_percent)) - $session_time; + + // create the percent boxes + create_percent_box('session', create_percent_color($session_percent), $session_percent); + create_percent_box('total', create_percent_color($total_percent), $total_percent); + + $template->assign_vars(array( + 'L_NEXT' => $next_button, + 'L_TIME_LAST_POSTS_ADMIN' => sprintf($lang['TIME_LAST_POSTS'], $num_rows), + + 'PROCESSING_POSTS' => sprintf($lang['PROCESSED_POST_IDS'], $start_post_id, $end_post_id), + 'PROCESSING_MESSAGES' => $processing_messages, + 'PROGRESS_BAR_IMG' => $progress_bar_img, + + 'SESSION_DETAILS' => sprintf($lang['PROCESS_DETAILS'], $session_posts_processed - $num_rows + 1, $session_posts_processed, $session_posts_processing), + 'SESSION_PERCENT' => sprintf($lang['PERCENT_COMPLETED'], round($session_percent, 2)), + + 'TOTAL_DETAILS' => sprintf($lang['PROCESS_DETAILS'], $total_posts_processed - $num_rows + 1, $total_posts_processed, $total_posts), + 'TOTAL_PERCENT' => sprintf($lang['PERCENT_COMPLETED'], round($total_percent, 2)), + + 'LAST_CYCLE_TIME' => delta_time(TIMENOW), + 'SESSION_TIME' => delta_time($last_session_data['start_time']), + 'SESSION_AVERAGE_CYCLE_TIME'=> delta_time($session_average_cycle_time, 0), + 'SESSION_ESTIMATED_TIME' => delta_time($session_estimated_time, 0), + + 'SEARCH_TABLES_SIZE' => humn_size($search_tables_size), + 'FINAL_SEARCH_TABLES_SIZE' => humn_size($final_search_tables_size), + 'SEARCH_DATA_SIZE' => humn_size($search_data_size), + 'SEARCH_INDEX_SIZE' => humn_size($search_index_size), + + 'START_POST' => $last_session_data['start_post_id'], + 'POST_LIMIT' => $num_rows, + 'TIME_LIMIT' => $time_limit, + 'REFRESH_RATE' => $refresh_rate, + + 'S_REBUILD_SEARCH_ACTION' => $form_action, + )); +} +else // show the input page +{ + // create the page + // used only with the select input + $post_limit_hidden = ( $def_post_limit > $total_posts ) ? $total_posts : $def_post_limit; + + $s_hidden_fields = ''; + $s_hidden_fields .= ''; + + $next_start_post_id = 0; + $last_saved_processing = ''; + $clear_search_disabled = ''; + + if ($last_session_data['rebuild_session_id']) + { + $last_saved_post_id = $last_session_data['end_post_id']; + $next_start_post_id = $last_saved_post_id + 1; + $last_saved_date = bb_date($last_session_data['end_time']); + + // check our last status + if ( $last_session_data['rebuild_session_status'] == REBUILD_SEARCH_PROCESSED ) + { + $last_saved_processing = sprintf($lang['INFO_PROCESSING_STOPPED'], $last_saved_post_id, $total_posts_processed, $last_saved_date); + $clear_search_disabled = 'disabled="disabled"'; + + $template->assign_block_vars("start_select_input", array()); + } + elseif ( $last_session_data['rebuild_session_status'] == REBUILD_SEARCH_ABORTED ) + { + $last_saved_processing = sprintf($lang['INFO_PROCESSING_ABORTED'], $last_saved_post_id, $total_posts_processed, $last_saved_date); + // check if the interrupted cycle has finished + if ( TIMENOW - $last_session_data['end_time'] < $last_session_data['last_cycle_time'] ) + { + $last_saved_processing .= '
        '.$lang['INFO_PROCESSING_ABORTED_SOON']; + } + $clear_search_disabled = 'disabled="disabled"'; + + $template->assign_block_vars("start_select_input", array()); + } + else // when finished + { + if ( $last_session_data['end_post_id'] < $max_post_id ) + { + $last_saved_processing = sprintf($lang['INFO_PROCESSING_FINISHED_NEW'], $last_saved_post_id, $total_posts_processed, $last_saved_date, ($total_posts - $total_posts_processed)); + $clear_search_disabled = 'disabled="disabled"'; + + $template->assign_block_vars("start_select_input", array()); + } + else + { + $last_saved_processing = sprintf($lang['INFO_PROCESSING_FINISHED'], $total_posts, $last_saved_date); + + $template->assign_block_vars("start_text_input", array()); + } + } + + $template->assign_block_vars("last_saved_info", array()); + } + else + { + $template->assign_block_vars("start_text_input", array()); + } + + // create the output of page + $template->assign_vars(array( + 'TPL_REBUILD_SEARCH_MAIN' => true, + + 'L_TIME_LIMIT_EXPLAIN' => $time_limit_explain, + + 'NEXT_START_POST_ID' => $next_start_post_id, + 'CLEAR_SEARCH_DISABLED' => $clear_search_disabled, + 'SESSION_POSTS_PROCESSING' => $session_posts_processing, + 'POST_LIMIT' => $post_limit, + 'REFRESH_RATE' => $refresh_rate, + 'TIME_LIMIT' => $time_limit, + + 'LAST_SAVED_PROCESSING' => $last_saved_processing, + + 'SESSION_ID' => $userdata['session_id'], + + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_REBUILD_SEARCH_ACTION' => "admin_rebuild_search.php?mode=submit", + )); +} + +print_page('admin_rebuild_search.tpl', 'admin'); + +// +// Functions +// +function get_db_sizes () +{ + $search_data_size = $search_index_size = 0; + $search_table_like = DB()->escape(BB_POSTS_SEARCH); + + $sql = "SHOW TABLE STATUS FROM `". DB()->selected_db ."` LIKE '$search_table_like'"; + + foreach (DB()->fetch_rowset($sql) as $row) + { + $search_data_size += $row['Data_length']; + $search_index_size += $row['Index_length']; + } + + return array($search_data_size, $search_index_size, $search_data_size+$search_index_size); +} + +// get the latest post_id in the forum +function get_latest_post_id () +{ + $row = DB()->fetch_row("SELECT MAX(post_id) as post_id FROM ". BB_POSTS_TEXT); + + return (int) $row['post_id']; +} + +function get_empty_last_session_data () +{ + return array( + 'rebuild_session_id' => 0, + 'start_post_id' => 0, + 'end_post_id' => 0, + 'start_time' => 0, + 'end_time' => 0, + 'last_cycle_time' => 0, + 'session_time' => 0, + 'session_posts' => 0, + 'session_cycles' => 0, + 'search_size' => 0, + 'rebuild_session_status' => REBUILD_SEARCH_COMPLETED, + ); +} + +// get some or all of the rebuild details of a specific session or of the last session +// $id is the id or the 'last' id +// $details is one of the fields or 'all' of them +function get_rebuild_session_details ($id, $details = 'all') +{ + $session_details = get_empty_last_session_data(); + + if ($id != 'last') + { + $sql = "SELECT * FROM ". BB_SEARCH_REBUILD ." WHERE rebuild_session_id = $id"; + } + else + { + $sql = "SELECT * FROM ". BB_SEARCH_REBUILD ." ORDER BY rebuild_session_id DESC LIMIT 1"; + } + + if ($row = DB()->fetch_row($sql)) + { + $session_details = ($details == 'all') ? $row : $row[$details]; + } + + return $session_details; +} + +// get the number of processed posts in the last session or in all sessions +// 'total' to get the sum of posts of all sessions +// 'session' to get the posts of the last session +function get_processed_posts ($mode = 'session') +{ + global $last_session_data; + + if ($mode == 'total') + { + $sql = "SELECT SUM(session_posts) as posts FROM ". BB_SEARCH_REBUILD; + $row = DB()->fetch_row($sql); + } + else + { + $row['posts'] = $last_session_data['session_posts']; + } + + return (int) $row['posts']; +} + +// how many posts are in the db before or after a specific post_id +// after/before require and the post_id +function get_total_posts ($mode = 'after', $post_id = 0) +{ + if ($post_id) + { + $sql = "SELECT COUNT(post_id) as total_posts FROM " . BB_POSTS_TEXT . " + WHERE post_id " . (($mode == 'after') ? '>= ' : '<= ' ) . (int) $post_id; + } + else + { + $sql = "SELECT COUNT(*) as total_posts FROM " . BB_POSTS_TEXT; + } + + $row = DB()->fetch_row($sql); + + return (int) $row['total_posts']; +} + +function clear_search_tables ($mode = '') +{ + DB()->query("DELETE FROM ". BB_SEARCH_REBUILD); + + if ($mode) + { + $table_ary = array(BB_POSTS_SEARCH); + + foreach ($table_ary as $table) + { + $sql = (($mode == 1) ? "DELETE FROM " : "TRUNCATE TABLE ") . $table; + DB()->query($sql); + } + } +} + +// Create the percent color +// We use an array with the color percent limits. +// One color stays constantly at FF when the percent is between its limits +// and we adjust the other 2 accordingly to percent, from 200 to 0. +// We limit the result to 200, in order to avoid white (255). +function create_percent_color($percent) +{ + $percent_ary = array( + 'r' => array(86, 100), + 'g' => array(0, 50), + 'b' => array(51, 85), + ); + + foreach ($percent_ary as $key => $value) + { + if ( $percent <= $value[1] ) + { + $percent_color = create_color($key, round(200-($percent-$value[0])*(200/($value[1]-$value[0])))); + break; + } + } + + return $percent_color; +} + +// create the hex representation of color +function create_color($mode, $code) +{ + return (($mode == 'r') ? 'FF': sprintf("%02X", $code)) . (($mode == 'g') ? 'FF': sprintf("%02X", $code)) . (($mode == 'b') ? 'FF': sprintf("%02X", $code)); +} + +// create the percent bar & box +function create_percent_box($box, $percent_color, $percent_width) +{ + global $template; + + if ($box == 'session') + { + $template->assign_vars(array( + 'SESSION_PERCENT_BOX' => true, + 'SESSION_PERCENT_COLOR' => $percent_color, + 'SESSION_PERCENT_WIDTH' => round($percent_width), + )); + } + else + { + $template->assign_vars(array( + 'TOTAL_PERCENT_BOX' => true, + 'TOTAL_PERCENT_COLOR' => $percent_color, + 'TOTAL_PERCENT_WIDTH' => round($percent_width), + )); + } } \ No newline at end of file diff --git a/upload/admin/admin_reports.php b/upload/admin/admin_reports.php index d59e295b9..e18e1c17a 100644 --- a/upload/admin/admin_reports.php +++ b/upload/admin/admin_reports.php @@ -1,560 +1,560 @@ - '

        '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''), - 'config' => '

        '. sprintf($lang['CLICK_RETURN_REPORT_CONFIG'], '', ''), - 'admin' => '

        '. sprintf($lang['CLICK_RETURN_REPORT_ADMIN'], '', '') -); - -$redirect_url = 'admin/admin_reports.php'; - -$template->assign_var('S_REPORT_ACTION', 'admin_reports.php'); - -if (isset($_POST['mode']) || isset($_GET['mode'])) -{ - $mode = (isset($_POST['mode'])) ? $_POST['mode'] : $_GET['mode']; - - // - // allow multiple modes (we need this for sub-modes, e.g. the report reasons) - // - if (is_array($mode)) - { - $modes = $mode; - $mode = $modes[0]; - } - else - { - $modes = array($mode); - } -} -else -{ - $mode = ''; - $modes = array(); -} - -// -// Configuration page -// -if ($mode == 'config') -{ - if (isset($_POST['submit'])) - { - $config_update = (isset($_POST['bb_cfg'])) ? $_POST['bb_cfg'] : array(); - - bb_update_config($config_update); - report_modules_cache_clean(); - - bb_die($lang['REPORT_CONFIG_UPDATED'] . $return_links['config'] . $return_links['index']); - } - else - { - $template->assign_vars(array( - 'S_HIDDEN_FIELDS' => '', - - 'REPORT_SUBJECT_AUTH_ON' => ($bb_cfg['report_subject_auth']) ? ' checked="checked"' : '', - 'REPORT_SUBJECT_AUTH_OFF' => (!$bb_cfg['report_subject_auth']) ? ' checked="checked"' : '', - 'REPORT_MODULES_CACHE_ON' => ($bb_cfg['report_modules_cache']) ? ' checked="checked"' : '', - 'REPORT_MODULES_CACHE_OFF' => (!$bb_cfg['report_modules_cache']) ? ' checked="checked"' : '', - 'REPORT_NOTIFY_CHANGE' => ($bb_cfg['report_notify'] == REPORT_NOTIFY_CHANGE) ? ' checked="checked"' : '', - 'REPORT_NOTIFY_NEW' => ($bb_cfg['report_notify'] == REPORT_NOTIFY_NEW) ? ' checked="checked"' : '', - 'REPORT_NOTIFY_OFF' => (!$bb_cfg['report_notify']) ? ' checked="checked"' : '', - 'REPORT_LIST_ADMIN_ON' => ($bb_cfg['report_list_admin']) ? ' checked="checked"' : '', - 'REPORT_LIST_ADMIN_OFF' => (!$bb_cfg['report_list_admin']) ? ' checked="checked"' : '', - 'REPORT_NEW_WINDOW_ON' => ($bb_cfg['report_new_window']) ? ' checked="checked"' : '', - 'REPORT_NEW_WINDOW_OFF' => (!$bb_cfg['report_new_window']) ? ' checked="checked"' : '', - )); - - print_page('report_config_body.tpl', 'admin'); - } -} -else if (isset($_POST[POST_CAT_URL]) || isset($_GET[POST_CAT_URL])) -{ - $module_id = (isset($_POST[POST_CAT_URL])) ? (int) $_POST[POST_CAT_URL] : (int) $_GET[POST_CAT_URL]; - - if (!$report_module = report_modules('id', $module_id)) - { - bb_die($lang['REPORT_MODULE_NOT_EXISTS'] . $return_links['admin'] . $return_links['index']); - } - - switch ($mode) - { - // - // Edit module - // - case 'edit': - if (isset($_POST['submit'])) - { - $module_notify = (isset($_POST['report_module_notify']) && $_POST['report_module_notify'] == 1) ? 1 : 0; - $module_prune = (isset($_POST['report_module_prune'])) ? (int) $_POST['report_module_prune'] : $report_module->data['report_module_prune']; - - $auth_write = (isset($_POST['auth_write'])) ? (int) $_POST['auth_write'] : $report_module->data['auth_write']; - $auth_view = (isset($_POST['auth_view'])) ? (int) $_POST['auth_view'] : $report_module->data['auth_view']; - $auth_notify = (isset($_POST['auth_notify'])) ? (int) $_POST['auth_notify'] : $report_module->data['auth_notify']; - $auth_delete = (isset($_POST['auth_delete'])) ? (int) $_POST['auth_delete'] : $report_module->data['auth_delete']; - - report_module_edit($module_id, $module_notify, $module_prune, $auth_write, $auth_view, $auth_notify, $auth_delete); - - bb_die($lang['REPORT_MODULE_EDITED'] . $return_links['admin'] . $return_links['index']); - } - else if (isset($_POST['cancel'])) - { - redirect($redirect_url); - } - - $module_info = $report_module->info(); - - $hidden_fields = ''; - - $template->assign_vars(array( - 'S_HIDDEN_FIELDS' => $hidden_fields, - 'MODULE_TITLE' => $module_info['title'], - 'MODULE_EXPLAIN' => $module_info['explain'], - 'MODULE_NOTIFY_ON' => ($report_module->data['report_module_notify']) ? ' checked="checked"' : '', - 'MODULE_NOTIFY_OFF' => (!$report_module->data['report_module_notify']) ? ' checked="checked"' : '', - 'MODULE_PRUNE' => $report_module->data['report_module_prune']) - ); - - // - // Authorisation selects - // - report_auth_select('auth_write', $report_module->data['auth_write'], array(REPORT_AUTH_USER, REPORT_AUTH_MOD, REPORT_AUTH_ADMIN)); - report_auth_select('auth_view', $report_module->data['auth_view']); - report_auth_select('auth_notify', $report_module->data['auth_notify']); - report_auth_select('auth_delete', $report_module->data['auth_delete'], array(REPORT_AUTH_MOD, REPORT_AUTH_CONFIRM, REPORT_AUTH_ADMIN)); - - print_page('report_module_edit_body.tpl', 'admin'); - break; - - // - // Report reasons - // - case 'reasons': - $reason_mode = (isset($modes[1])) ? $modes[1] : ''; - - $temp_url = "admin_reports.php?mode=reasons&" . POST_CAT_URL . "=$module_id"; - $return_links['reasons'] = '

        ' . sprintf($lang['CLICK_RETURN_REPORT_REASONS'], '', ''); - - $redirect_url = 'admin/admin_reports.php?mode=reasons&' . POST_CAT_URL . "=$module_id"; - - if (isset($_POST[POST_REPORT_REASON_URL]) || isset($_GET[POST_REPORT_REASON_URL])) - { - $reason_id = (isset($_POST[POST_REPORT_REASON_URL])) ? (int) $_POST[POST_REPORT_REASON_URL] : (int) $_GET[POST_REPORT_REASON_URL]; - - switch ($reason_mode) - { - // - // Edit reason - // - case 'edit': - $errors = array(); - - if (isset($_POST['submit'])) - { - $reason_desc = (isset($_POST['report_reason_desc'])) ? htmlspecialchars($_POST['report_reason_desc']) : ''; - - // - // Validate reason desc - // - if (empty($reason_desc)) - { - $errors[] = $lang['REASON_DESC_EMPTY']; - } - - if (empty($errors)) - { - $reason_desc = str_replace("\'", "'", $reason_desc); - - report_reason_edit($reason_id, $module_id, $reason_desc); - - bb_die($lang['REPORT_REASON_EDITED'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); - } - } - else if (isset($_POST['cancel'])) - { - redirect($redirect_url); - } - - // - // Show validation errors - // - if (!empty($errors)) - { - $template->assign_block_vars('switch_report_errors', array()); - foreach ($errors as $error) - { - $template->assign_block_vars('switch_report_errors.report_errors', array( - 'MESSAGE' => $error) - ); - } - } - - if (!$report_reason = report_reason_obtain($reason_id)) - { - bb_die($lang['REPORT_REASON_NOT_EXISTS'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); - } - - if (isset($reason_desc)) - { - $report_reason['report_reason_desc'] = stripslashes($reason_desc); - } - - $hidden_fields = ''; - $hidden_fields .= ''; - - $template->assign_vars(array( - 'S_HIDDEN_FIELDS' => $hidden_fields, - 'REASON_DESC' => $report_reason['report_reason_desc']) - ); - - print_page('report_reason_edit_body.tpl', 'admin'); - break; - - // - // Move reason up/down - // - case 'up': - case 'down': - report_reason_move($reason_mode, $reason_id); - - redirect($redirect_url); - break; - - // - // Delete reason - // - case 'delete': - if (isset($_POST['confirm'])) - { - report_reason_delete($reason_id); - - bb_die($lang['REPORT_REASON_DELETED'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); - } - else if (isset($_POST['cancel'])) - { - redirect($redirect_url); - } - - $hidden_fields = ''; - $hidden_fields .= ''; - - print_confirmation(array( - 'CONFIRM_TITLE' => $lang['DELETE_REASON'], - 'QUESTION' => $lang['DELETE_REPORT_REASON_EXPLAIN'], - 'FORM_ACTION' => "admin_reports.php", - 'HIDDEN_FIELDS' => $hidden_fields, - )); - break; - - default: - bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); - break; - } - } - else - { - switch ($reason_mode) - { - // - // Add reason - // - case 'add': - $errors = array(); - - if (isset($_POST['submit'])) - { - $reason_desc = (isset($_POST['report_reason_desc'])) ? htmlspecialchars($_POST['report_reason_desc']) : ''; - - // - // Validate reason desc - // - if (empty($reason_desc)) - { - $errors[] = $lang['REASON_DESC_EMPTY']; - } - - if (empty($errors)) - { - $reason_desc = str_replace("\'", "'", $reason_desc); - - report_reason_insert($module_id, $reason_desc); - - bb_die($lang['REPORT_REASON_ADDED'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); - } - } - else if (isset($_POST['cancel'])) - { - redirect($redirect_url); - } - - // - // Show validation errors - // - if (!empty($errors)) - { - $template->assign_block_vars('switch_report_errors', array()); - foreach ($errors as $error) - { - $template->assign_block_vars('switch_report_errors.report_errors', array( - 'MESSAGE' => $error) - ); - } - } - - $hidden_fields = ''; - $hidden_fields .= ''; - - $template->assign_vars(array( - 'S_HIDDEN_FIELDS' => $hidden_fields, - 'REASON_DESC' => (isset($reason_desc)) ? stripslashes($reason_desc) : '') - ); - - print_page('report_reason_edit_body.tpl', 'admin'); - break; - - case '': - - if ($report_reasons = $report_module->reasons_obtain()) - { - foreach ($report_reasons as $reason_id => $reason_desc) - { - $template->assign_block_vars('report_reasons', array( - 'DESC' => $reason_desc, - - 'U_EDIT' => 'admin_reports.php?mode[]=reasons&' . POST_CAT_URL . "=$module_id&mode[]=edit&" . POST_REPORT_REASON_URL . "=$reason_id", - 'U_MOVE_UP' => 'admin_reports.php?mode[]=reasons&' . POST_CAT_URL . "=$module_id&mode[]=up&" . POST_REPORT_REASON_URL . "=$reason_id", - 'U_MOVE_DOWN' => 'admin_reports.php?mode[]=reasons&' . POST_CAT_URL . "=$module_id&mode[]=down&" . POST_REPORT_REASON_URL . "=$reason_id", - 'U_DELETE' => 'admin_reports.php?mode[]=reasons&' . POST_CAT_URL . "=$module_id&mode[]=delete&" . POST_REPORT_REASON_URL . "=$reason_id") - ); - } - } - else - { - $template->assign_block_vars('switch_no_reasons', array()); - } - - $template->assign_vars(array( - 'U_ADD_REASON' => 'admin_reports.php?mode[]=reasons&' . POST_CAT_URL . "=$module_id&mode[]=add", - 'U_MODULES' => "admin_reports.php", - )); - - print_page('report_module_reasons_body.tpl', 'admin'); - break; - - default: - bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); - break; - } - } - break; - - // - // Move module up/down - // - case 'up': - case 'down': - report_module_move($mode, $module_id); - - redirect($redirect_url); - break; - - // - // Synchronize module - // - case 'sync': - if (!method_exists($report_module, 'sync')) - { - bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['admin'] . $return_links['index']); - } - - $report_module->sync(); - - bb_die($lang['REPORT_MODULE_SYNCED'] . $return_links['admin'] . $return_links['index']); - break; - - // - // Uninstall module - // - case 'uninstall': - if (isset($_POST['confirm'])) - { - report_module_uninstall($module_id); - - bb_die($lang['REPORT_MODULE_UNINSTALLED'] . $return_links['admin'] . $return_links['index']); - } - else if (isset($_POST['cancel'])) - { - redirect($redirect_url); - } - - $hidden_fields = ''; - - print_confirmation(array( - 'CONFIRM_TITLE' => $lang['UNINSTALL_REPORT_MODULE'], - 'QUESTION' => $lang['UNINSTALL_REPORT_MODULE_EXPLAIN'], - 'FORM_ACTION' => 'admin_reports.php', - 'HIDDEN_FIELDS' => $hidden_fields, - )); - break; - - default: - bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['admin'] . $return_links['index']); - break; - } -} -else if (isset($_POST['module']) || isset($_GET['module'])) -{ - $module_name = (isset($_POST['module'])) ? stripslashes($_POST['module']) : stripslashes($_GET['module']); - - if (!$report_module = report_modules_inactive('name', $module_name)) - { - bb_die($lang['REPORT_MODULE_NOT_EXISTS'] . $return_links['admin'] . $return_links['index']); - } - - switch ($mode) - { - // - // Install module - // - case 'install': - if (isset($_POST['submit'])) - { - $module_notify = (isset($_POST['report_module_notify']) && $_POST['report_module_notify'] == 1) ? 1 : 0; - $module_prune = (isset($_POST['report_module_prune'])) ? (int) $_POST['report_module_prune'] : 0; - - $auth_write = (isset($_POST['auth_write'])) ? (int) $_POST['auth_write'] : REPORT_AUTH_USER; - $auth_view = (isset($_POST['auth_view'])) ? (int) $_POST['auth_view'] : REPORT_AUTH_MOD; - $auth_notify = (isset($_POST['auth_notify'])) ? (int) $_POST['auth_notify'] : REPORT_AUTH_MOD; - $auth_delete = (isset($_POST['auth_delete'])) ? (int) $_POST['auth_delete'] : REPORT_AUTH_ADMIN; - - report_module_install($module_notify, $module_prune, $module_name, $auth_write, $auth_view, $auth_notify, $auth_delete, false); - - bb_die($lang['REPORT_MODULE_INSTALLED'] . $return_links['admin'] . $return_links['index']); - } - else if (isset($_POST['cancel'])) - { - redirect($redirect_url); - } - - $module_info = $report_module->info(); - - $hidden_fields = ''; - - $template->assign_vars(array( - 'S_HIDDEN_FIELDS' => $hidden_fields, - - 'MODULE_TITLE' => $module_info['title'], - 'MODULE_EXPLAIN' => $module_info['explain'], - 'MODULE_NOTIFY_ON' => ($bb_cfg['report_notify']) ? ' checked="checked"' : '', - 'MODULE_NOTIFY_OFF' => (!$bb_cfg['report_notify']) ? ' checked="checked"' : '', - 'MODULE_PRUNE' => 0, - )); - - // - // Authorisation selects - // - report_auth_select('auth_write', REPORT_AUTH_USER, array(REPORT_AUTH_USER, REPORT_AUTH_MOD, REPORT_AUTH_ADMIN)); - report_auth_select('auth_view', REPORT_AUTH_MOD); - report_auth_select('auth_notify', REPORT_AUTH_MOD); - report_auth_select('auth_delete', REPORT_AUTH_CONFIRM, array(REPORT_AUTH_MOD, REPORT_AUTH_CONFIRM, REPORT_AUTH_ADMIN)); - - print_page('report_module_edit_body.tpl', 'admin'); - break; - - default: - bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['admin'] . $return_links['index']); - break; - } -} -else -{ - switch ($mode) - { - case '': - $report_modules = report_modules(); - $report_counts = report_counts_obtain(); - $report_reason_counts = report_reason_counts_obtain(); - - // - // Display installed modules - // - $template->assign_block_vars('installed_modules', array()); - foreach (array_keys($report_modules) as $report_module_id) - { - $report_module =& $report_modules[$report_module_id]; - $module_info = $report_module->info(); - - $template->assign_block_vars('installed_modules.modules', array( - 'L_REASONS' => sprintf($lang['REASONS'], $report_reason_counts[$report_module->id]), - - 'MODULE_TITLE' => $module_info['title'], - 'MODULE_EXPLAIN' => $module_info['explain'], - 'REPORT_COUNT' => $report_counts[$report_module->id], - - 'U_EDIT' => 'admin_reports.php?mode=edit&' . POST_CAT_URL . '=' . $report_module->id, - 'U_REASONS' => 'admin_reports.php?mode=reasons&' . POST_CAT_URL . '=' . $report_module->id, - 'U_MOVE_UP' => 'admin_reports.php?mode=up&' . POST_CAT_URL . '=' . $report_module->id, - 'U_MOVE_DOWN' => 'admin_reports.php?mode=down&' . POST_CAT_URL . '=' . $report_module->id, - 'U_SYNC' => 'admin_reports.php?mode=sync&' . POST_CAT_URL . '=' . $report_module->id, - 'U_UNINSTALL' => 'admin_reports.php?mode=uninstall&' . POST_CAT_URL . '=' . $report_module->id) - ); - - // - // Display sync option if available - // - if (method_exists($report_module, 'sync')) - { - $template->assign_block_vars('installed_modules.modules.switch_sync', array()); - } - } - - if (empty($report_modules)) - { - $template->assign_block_vars('installed_modules.switch_no_modules', array()); - } - - $report_modules_inactive = report_modules_inactive(); - - // - // Display inactive modules - // - $template->assign_block_vars('inactive_modules', array()); - foreach (array_keys($report_modules_inactive) as $key) - { - $report_module =& $report_modules_inactive[$key]; - $module_info = $report_module->info(); - - $template->assign_block_vars('inactive_modules.modules', array( - 'MODULE_TITLE' => $module_info['title'], - 'MODULE_EXPLAIN' => $module_info['explain'], - 'REPORT_COUNT' => '-', - - 'U_INSTALL' => 'admin_reports.php?mode=install&module=' . $report_module->data['module_name']) - ); - } - - if (empty($report_modules_inactive)) - { - $template->assign_block_vars('inactive_modules.switch_no_modules', array()); - } - - print_page('report_modules_body.tpl', 'admin'); - break; - - default: - bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['admin'] . $return_links['index']); - break; - } + '

        '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''), + 'config' => '

        '. sprintf($lang['CLICK_RETURN_REPORT_CONFIG'], '', ''), + 'admin' => '

        '. sprintf($lang['CLICK_RETURN_REPORT_ADMIN'], '', '') +); + +$redirect_url = 'admin/admin_reports.php'; + +$template->assign_var('S_REPORT_ACTION', 'admin_reports.php'); + +if (isset($_POST['mode']) || isset($_GET['mode'])) +{ + $mode = (isset($_POST['mode'])) ? $_POST['mode'] : $_GET['mode']; + + // + // allow multiple modes (we need this for sub-modes, e.g. the report reasons) + // + if (is_array($mode)) + { + $modes = $mode; + $mode = $modes[0]; + } + else + { + $modes = array($mode); + } +} +else +{ + $mode = ''; + $modes = array(); +} + +// +// Configuration page +// +if ($mode == 'config') +{ + if (isset($_POST['submit'])) + { + $config_update = (isset($_POST['bb_cfg'])) ? $_POST['bb_cfg'] : array(); + + bb_update_config($config_update); + report_modules_cache_clean(); + + bb_die($lang['REPORT_CONFIG_UPDATED'] . $return_links['config'] . $return_links['index']); + } + else + { + $template->assign_vars(array( + 'S_HIDDEN_FIELDS' => '', + + 'REPORT_SUBJECT_AUTH_ON' => ($bb_cfg['report_subject_auth']) ? ' checked="checked"' : '', + 'REPORT_SUBJECT_AUTH_OFF' => (!$bb_cfg['report_subject_auth']) ? ' checked="checked"' : '', + 'REPORT_MODULES_CACHE_ON' => ($bb_cfg['report_modules_cache']) ? ' checked="checked"' : '', + 'REPORT_MODULES_CACHE_OFF' => (!$bb_cfg['report_modules_cache']) ? ' checked="checked"' : '', + 'REPORT_NOTIFY_CHANGE' => ($bb_cfg['report_notify'] == REPORT_NOTIFY_CHANGE) ? ' checked="checked"' : '', + 'REPORT_NOTIFY_NEW' => ($bb_cfg['report_notify'] == REPORT_NOTIFY_NEW) ? ' checked="checked"' : '', + 'REPORT_NOTIFY_OFF' => (!$bb_cfg['report_notify']) ? ' checked="checked"' : '', + 'REPORT_LIST_ADMIN_ON' => ($bb_cfg['report_list_admin']) ? ' checked="checked"' : '', + 'REPORT_LIST_ADMIN_OFF' => (!$bb_cfg['report_list_admin']) ? ' checked="checked"' : '', + 'REPORT_NEW_WINDOW_ON' => ($bb_cfg['report_new_window']) ? ' checked="checked"' : '', + 'REPORT_NEW_WINDOW_OFF' => (!$bb_cfg['report_new_window']) ? ' checked="checked"' : '', + )); + + print_page('report_config_body.tpl', 'admin'); + } +} +else if (isset($_POST[POST_CAT_URL]) || isset($_GET[POST_CAT_URL])) +{ + $module_id = (isset($_POST[POST_CAT_URL])) ? (int) $_POST[POST_CAT_URL] : (int) $_GET[POST_CAT_URL]; + + if (!$report_module = report_modules('id', $module_id)) + { + bb_die($lang['REPORT_MODULE_NOT_EXISTS'] . $return_links['admin'] . $return_links['index']); + } + + switch ($mode) + { + // + // Edit module + // + case 'edit': + if (isset($_POST['submit'])) + { + $module_notify = (isset($_POST['report_module_notify']) && $_POST['report_module_notify'] == 1) ? 1 : 0; + $module_prune = (isset($_POST['report_module_prune'])) ? (int) $_POST['report_module_prune'] : $report_module->data['report_module_prune']; + + $auth_write = (isset($_POST['auth_write'])) ? (int) $_POST['auth_write'] : $report_module->data['auth_write']; + $auth_view = (isset($_POST['auth_view'])) ? (int) $_POST['auth_view'] : $report_module->data['auth_view']; + $auth_notify = (isset($_POST['auth_notify'])) ? (int) $_POST['auth_notify'] : $report_module->data['auth_notify']; + $auth_delete = (isset($_POST['auth_delete'])) ? (int) $_POST['auth_delete'] : $report_module->data['auth_delete']; + + report_module_edit($module_id, $module_notify, $module_prune, $auth_write, $auth_view, $auth_notify, $auth_delete); + + bb_die($lang['REPORT_MODULE_EDITED'] . $return_links['admin'] . $return_links['index']); + } + else if (isset($_POST['cancel'])) + { + redirect($redirect_url); + } + + $module_info = $report_module->info(); + + $hidden_fields = ''; + + $template->assign_vars(array( + 'S_HIDDEN_FIELDS' => $hidden_fields, + 'MODULE_TITLE' => $module_info['title'], + 'MODULE_EXPLAIN' => $module_info['explain'], + 'MODULE_NOTIFY_ON' => ($report_module->data['report_module_notify']) ? ' checked="checked"' : '', + 'MODULE_NOTIFY_OFF' => (!$report_module->data['report_module_notify']) ? ' checked="checked"' : '', + 'MODULE_PRUNE' => $report_module->data['report_module_prune']) + ); + + // + // Authorisation selects + // + report_auth_select('auth_write', $report_module->data['auth_write'], array(REPORT_AUTH_USER, REPORT_AUTH_MOD, REPORT_AUTH_ADMIN)); + report_auth_select('auth_view', $report_module->data['auth_view']); + report_auth_select('auth_notify', $report_module->data['auth_notify']); + report_auth_select('auth_delete', $report_module->data['auth_delete'], array(REPORT_AUTH_MOD, REPORT_AUTH_CONFIRM, REPORT_AUTH_ADMIN)); + + print_page('report_module_edit_body.tpl', 'admin'); + break; + + // + // Report reasons + // + case 'reasons': + $reason_mode = (isset($modes[1])) ? $modes[1] : ''; + + $temp_url = "admin_reports.php?mode=reasons&" . POST_CAT_URL . "=$module_id"; + $return_links['reasons'] = '

        ' . sprintf($lang['CLICK_RETURN_REPORT_REASONS'], '', ''); + + $redirect_url = 'admin/admin_reports.php?mode=reasons&' . POST_CAT_URL . "=$module_id"; + + if (isset($_POST[POST_REPORT_REASON_URL]) || isset($_GET[POST_REPORT_REASON_URL])) + { + $reason_id = (isset($_POST[POST_REPORT_REASON_URL])) ? (int) $_POST[POST_REPORT_REASON_URL] : (int) $_GET[POST_REPORT_REASON_URL]; + + switch ($reason_mode) + { + // + // Edit reason + // + case 'edit': + $errors = array(); + + if (isset($_POST['submit'])) + { + $reason_desc = (isset($_POST['report_reason_desc'])) ? htmlspecialchars($_POST['report_reason_desc']) : ''; + + // + // Validate reason desc + // + if (empty($reason_desc)) + { + $errors[] = $lang['REASON_DESC_EMPTY']; + } + + if (empty($errors)) + { + $reason_desc = str_replace("\'", "'", $reason_desc); + + report_reason_edit($reason_id, $module_id, $reason_desc); + + bb_die($lang['REPORT_REASON_EDITED'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); + } + } + else if (isset($_POST['cancel'])) + { + redirect($redirect_url); + } + + // + // Show validation errors + // + if (!empty($errors)) + { + $template->assign_block_vars('switch_report_errors', array()); + foreach ($errors as $error) + { + $template->assign_block_vars('switch_report_errors.report_errors', array( + 'MESSAGE' => $error) + ); + } + } + + if (!$report_reason = report_reason_obtain($reason_id)) + { + bb_die($lang['REPORT_REASON_NOT_EXISTS'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); + } + + if (isset($reason_desc)) + { + $report_reason['report_reason_desc'] = stripslashes($reason_desc); + } + + $hidden_fields = ''; + $hidden_fields .= ''; + + $template->assign_vars(array( + 'S_HIDDEN_FIELDS' => $hidden_fields, + 'REASON_DESC' => $report_reason['report_reason_desc']) + ); + + print_page('report_reason_edit_body.tpl', 'admin'); + break; + + // + // Move reason up/down + // + case 'up': + case 'down': + report_reason_move($reason_mode, $reason_id); + + redirect($redirect_url); + break; + + // + // Delete reason + // + case 'delete': + if (isset($_POST['confirm'])) + { + report_reason_delete($reason_id); + + bb_die($lang['REPORT_REASON_DELETED'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); + } + else if (isset($_POST['cancel'])) + { + redirect($redirect_url); + } + + $hidden_fields = ''; + $hidden_fields .= ''; + + print_confirmation(array( + 'CONFIRM_TITLE' => $lang['DELETE_REASON'], + 'QUESTION' => $lang['DELETE_REPORT_REASON_EXPLAIN'], + 'FORM_ACTION' => "admin_reports.php", + 'HIDDEN_FIELDS' => $hidden_fields, + )); + break; + + default: + bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); + break; + } + } + else + { + switch ($reason_mode) + { + // + // Add reason + // + case 'add': + $errors = array(); + + if (isset($_POST['submit'])) + { + $reason_desc = (isset($_POST['report_reason_desc'])) ? htmlspecialchars($_POST['report_reason_desc']) : ''; + + // + // Validate reason desc + // + if (empty($reason_desc)) + { + $errors[] = $lang['REASON_DESC_EMPTY']; + } + + if (empty($errors)) + { + $reason_desc = str_replace("\'", "'", $reason_desc); + + report_reason_insert($module_id, $reason_desc); + + bb_die($lang['REPORT_REASON_ADDED'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); + } + } + else if (isset($_POST['cancel'])) + { + redirect($redirect_url); + } + + // + // Show validation errors + // + if (!empty($errors)) + { + $template->assign_block_vars('switch_report_errors', array()); + foreach ($errors as $error) + { + $template->assign_block_vars('switch_report_errors.report_errors', array( + 'MESSAGE' => $error) + ); + } + } + + $hidden_fields = ''; + $hidden_fields .= ''; + + $template->assign_vars(array( + 'S_HIDDEN_FIELDS' => $hidden_fields, + 'REASON_DESC' => (isset($reason_desc)) ? stripslashes($reason_desc) : '') + ); + + print_page('report_reason_edit_body.tpl', 'admin'); + break; + + case '': + + if ($report_reasons = $report_module->reasons_obtain()) + { + foreach ($report_reasons as $reason_id => $reason_desc) + { + $template->assign_block_vars('report_reasons', array( + 'DESC' => $reason_desc, + + 'U_EDIT' => 'admin_reports.php?mode[]=reasons&' . POST_CAT_URL . "=$module_id&mode[]=edit&" . POST_REPORT_REASON_URL . "=$reason_id", + 'U_MOVE_UP' => 'admin_reports.php?mode[]=reasons&' . POST_CAT_URL . "=$module_id&mode[]=up&" . POST_REPORT_REASON_URL . "=$reason_id", + 'U_MOVE_DOWN' => 'admin_reports.php?mode[]=reasons&' . POST_CAT_URL . "=$module_id&mode[]=down&" . POST_REPORT_REASON_URL . "=$reason_id", + 'U_DELETE' => 'admin_reports.php?mode[]=reasons&' . POST_CAT_URL . "=$module_id&mode[]=delete&" . POST_REPORT_REASON_URL . "=$reason_id") + ); + } + } + else + { + $template->assign_block_vars('switch_no_reasons', array()); + } + + $template->assign_vars(array( + 'U_ADD_REASON' => 'admin_reports.php?mode[]=reasons&' . POST_CAT_URL . "=$module_id&mode[]=add", + 'U_MODULES' => "admin_reports.php", + )); + + print_page('report_module_reasons_body.tpl', 'admin'); + break; + + default: + bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['reasons'] . $return_links['admin'] . $return_links['index']); + break; + } + } + break; + + // + // Move module up/down + // + case 'up': + case 'down': + report_module_move($mode, $module_id); + + redirect($redirect_url); + break; + + // + // Synchronize module + // + case 'sync': + if (!method_exists($report_module, 'sync')) + { + bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['admin'] . $return_links['index']); + } + + $report_module->sync(); + + bb_die($lang['REPORT_MODULE_SYNCED'] . $return_links['admin'] . $return_links['index']); + break; + + // + // Uninstall module + // + case 'uninstall': + if (isset($_POST['confirm'])) + { + report_module_uninstall($module_id); + + bb_die($lang['REPORT_MODULE_UNINSTALLED'] . $return_links['admin'] . $return_links['index']); + } + else if (isset($_POST['cancel'])) + { + redirect($redirect_url); + } + + $hidden_fields = ''; + + print_confirmation(array( + 'CONFIRM_TITLE' => $lang['UNINSTALL_REPORT_MODULE'], + 'QUESTION' => $lang['UNINSTALL_REPORT_MODULE_EXPLAIN'], + 'FORM_ACTION' => 'admin_reports.php', + 'HIDDEN_FIELDS' => $hidden_fields, + )); + break; + + default: + bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['admin'] . $return_links['index']); + break; + } +} +else if (isset($_POST['module']) || isset($_GET['module'])) +{ + $module_name = (isset($_POST['module'])) ? stripslashes($_POST['module']) : stripslashes($_GET['module']); + + if (!$report_module = report_modules_inactive('name', $module_name)) + { + bb_die($lang['REPORT_MODULE_NOT_EXISTS'] . $return_links['admin'] . $return_links['index']); + } + + switch ($mode) + { + // + // Install module + // + case 'install': + if (isset($_POST['submit'])) + { + $module_notify = (isset($_POST['report_module_notify']) && $_POST['report_module_notify'] == 1) ? 1 : 0; + $module_prune = (isset($_POST['report_module_prune'])) ? (int) $_POST['report_module_prune'] : 0; + + $auth_write = (isset($_POST['auth_write'])) ? (int) $_POST['auth_write'] : REPORT_AUTH_USER; + $auth_view = (isset($_POST['auth_view'])) ? (int) $_POST['auth_view'] : REPORT_AUTH_MOD; + $auth_notify = (isset($_POST['auth_notify'])) ? (int) $_POST['auth_notify'] : REPORT_AUTH_MOD; + $auth_delete = (isset($_POST['auth_delete'])) ? (int) $_POST['auth_delete'] : REPORT_AUTH_ADMIN; + + report_module_install($module_notify, $module_prune, $module_name, $auth_write, $auth_view, $auth_notify, $auth_delete, false); + + bb_die($lang['REPORT_MODULE_INSTALLED'] . $return_links['admin'] . $return_links['index']); + } + else if (isset($_POST['cancel'])) + { + redirect($redirect_url); + } + + $module_info = $report_module->info(); + + $hidden_fields = ''; + + $template->assign_vars(array( + 'S_HIDDEN_FIELDS' => $hidden_fields, + + 'MODULE_TITLE' => $module_info['title'], + 'MODULE_EXPLAIN' => $module_info['explain'], + 'MODULE_NOTIFY_ON' => ($bb_cfg['report_notify']) ? ' checked="checked"' : '', + 'MODULE_NOTIFY_OFF' => (!$bb_cfg['report_notify']) ? ' checked="checked"' : '', + 'MODULE_PRUNE' => 0, + )); + + // + // Authorisation selects + // + report_auth_select('auth_write', REPORT_AUTH_USER, array(REPORT_AUTH_USER, REPORT_AUTH_MOD, REPORT_AUTH_ADMIN)); + report_auth_select('auth_view', REPORT_AUTH_MOD); + report_auth_select('auth_notify', REPORT_AUTH_MOD); + report_auth_select('auth_delete', REPORT_AUTH_CONFIRM, array(REPORT_AUTH_MOD, REPORT_AUTH_CONFIRM, REPORT_AUTH_ADMIN)); + + print_page('report_module_edit_body.tpl', 'admin'); + break; + + default: + bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['admin'] . $return_links['index']); + break; + } +} +else +{ + switch ($mode) + { + case '': + $report_modules = report_modules(); + $report_counts = report_counts_obtain(); + $report_reason_counts = report_reason_counts_obtain(); + + // + // Display installed modules + // + $template->assign_block_vars('installed_modules', array()); + foreach (array_keys($report_modules) as $report_module_id) + { + $report_module =& $report_modules[$report_module_id]; + $module_info = $report_module->info(); + + $template->assign_block_vars('installed_modules.modules', array( + 'L_REASONS' => sprintf($lang['REASONS'], $report_reason_counts[$report_module->id]), + + 'MODULE_TITLE' => $module_info['title'], + 'MODULE_EXPLAIN' => $module_info['explain'], + 'REPORT_COUNT' => $report_counts[$report_module->id], + + 'U_EDIT' => 'admin_reports.php?mode=edit&' . POST_CAT_URL . '=' . $report_module->id, + 'U_REASONS' => 'admin_reports.php?mode=reasons&' . POST_CAT_URL . '=' . $report_module->id, + 'U_MOVE_UP' => 'admin_reports.php?mode=up&' . POST_CAT_URL . '=' . $report_module->id, + 'U_MOVE_DOWN' => 'admin_reports.php?mode=down&' . POST_CAT_URL . '=' . $report_module->id, + 'U_SYNC' => 'admin_reports.php?mode=sync&' . POST_CAT_URL . '=' . $report_module->id, + 'U_UNINSTALL' => 'admin_reports.php?mode=uninstall&' . POST_CAT_URL . '=' . $report_module->id) + ); + + // + // Display sync option if available + // + if (method_exists($report_module, 'sync')) + { + $template->assign_block_vars('installed_modules.modules.switch_sync', array()); + } + } + + if (empty($report_modules)) + { + $template->assign_block_vars('installed_modules.switch_no_modules', array()); + } + + $report_modules_inactive = report_modules_inactive(); + + // + // Display inactive modules + // + $template->assign_block_vars('inactive_modules', array()); + foreach (array_keys($report_modules_inactive) as $key) + { + $report_module =& $report_modules_inactive[$key]; + $module_info = $report_module->info(); + + $template->assign_block_vars('inactive_modules.modules', array( + 'MODULE_TITLE' => $module_info['title'], + 'MODULE_EXPLAIN' => $module_info['explain'], + 'REPORT_COUNT' => '-', + + 'U_INSTALL' => 'admin_reports.php?mode=install&module=' . $report_module->data['module_name']) + ); + } + + if (empty($report_modules_inactive)) + { + $template->assign_block_vars('inactive_modules.switch_no_modules', array()); + } + + print_page('report_modules_body.tpl', 'admin'); + break; + + default: + bb_die($lang['REPORT_NOT_SUPPORTED'] . $return_links['admin'] . $return_links['index']); + break; + } } \ No newline at end of file diff --git a/upload/admin/admin_smilies.php b/upload/admin/admin_smilies.php index 01cbf65fb..9427a59c0 100644 --- a/upload/admin/admin_smilies.php +++ b/upload/admin/admin_smilies.php @@ -1,373 +1,373 @@ -sql_query($sql)) - { - bb_die('Could not delete current smilies'); - } - $datastore->update('smile_replacements'); - } - else - { - $sql = "SELECT code FROM ". BB_SMILIES; - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not get current smilies'); - } - - $cur_smilies = DB()->sql_fetchrowset($result); - - for ($i = 0; $i < count($cur_smilies); $i++) - { - $k = $cur_smilies[$i]['code']; - $smiles[$k] = 1; - } - } - - $fcontents = @file(BB_ROOT . $bb_cfg['smilies_path'] . '/'. $smile_pak); - - if (empty($fcontents)) - { - bb_die('Could not read smiley pak file'); - } - - for ($i = 0; $i < count($fcontents); $i++) - { - $smile_data = explode($delimeter, trim(addslashes($fcontents[$i]))); - - for ($j = 2; $j < count($smile_data); $j++) - { - // Replace > and < with the proper html_entities for matching - $smile_data[$j] = str_replace('<', '<', $smile_data[$j]); - $smile_data[$j] = str_replace('>', '>', $smile_data[$j]); - $k = $smile_data[$j]; - - if (isset($smiles[$k])) - { - if( !empty($replace_existing) ) - { - $sql = "UPDATE " . BB_SMILIES . " - SET smile_url = '" . DB()->escape($smile_data[0]) . "', emoticon = '" . DB()->escape($smile_data[1]) . "' - WHERE code = '" . DB()->escape($smile_data[$j]) . "'"; - } - else - { - $sql = ''; - } - } - else - { - $sql = "INSERT INTO " . BB_SMILIES . " (code, smile_url, emoticon) - VALUES('" . DB()->escape($smile_data[$j]) . "', '" . DB()->escape($smile_data[0]) . "', '" . DB()->escape($smile_data[1]) . "')"; - } - - if ($sql != '') - { - $result = DB()->sql_query($sql); - if (!$result) - { - bb_die('Could not update smilies #1'); - } - $datastore->update('smile_replacements'); - } - } - } - - bb_die($lang['SMILEY_IMPORT_SUCCESS'] . '

        ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - } - else - { - // Display the script to get the smile_pak cfg file - $smile_paks_select = ''; - - $hidden_vars = ''; - - $template->assign_vars(array( - 'TPL_SMILE_IMPORT' => true, - - 'S_SMILEY_ACTION' => 'admin_smilies.php', - 'S_SMILE_SELECT' => $smile_paks_select, - 'S_HIDDEN_FIELDS' => $hidden_vars, - )); - } -} -else if (isset($_POST['export_pack']) || isset($_GET['export_pack'])) -{ - $export_pack = (string) request_var('export_pack', ''); - - if ($export_pack == 'send') - { - $sql = "SELECT * FROM " . BB_SMILIES; - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not get smiley list'); - } - - $resultset = DB()->sql_fetchrowset($result); - - $smile_pak = ''; - for ($i = 0; $i < count($resultset); $i++) - { - $smile_pak .= $resultset[$i]['smile_url'] . $delimeter; - $smile_pak .= $resultset[$i]['emoticon'] . $delimeter; - $smile_pak .= $resultset[$i]['code'] . "\n"; - } - - header("Content-Type: text/x-delimtext; name=\"smiles.pak\""); - header("Content-disposition: attachment; filename=smiles.pak"); - - echo $smile_pak; - - exit; - } - - bb_die(sprintf($lang['EXPORT_SMILES'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); -} -else if (isset($_POST['add']) || isset($_GET['add'])) -{ - $filename_list = ''; - for ($i = 0; $i < count($smiley_images); $i++) - { - $filename_list .= ''; - } - - $s_hidden_fields = ''; - - $template->assign_vars(array( - 'TPL_SMILE_EDIT' => true, - 'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] . '/' . $smiley_images[0], - 'S_SMILEY_ACTION' => "admin_smilies.php", - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - 'S_FILENAME_OPTIONS' => $filename_list, - 'S_SMILEY_BASEDIR' => BB_ROOT . $bb_cfg['smilies_path'] - )); -} -else if ( $mode != '' ) -{ - switch( $mode ) - { - case 'delete': - $smiley_id = ( !empty($_POST['id']) ) ? $_POST['id'] : $_GET['id']; - $smiley_id = intval($smiley_id); - - $sql = "DELETE FROM " . BB_SMILIES . " WHERE smilies_id = " . $smiley_id; - $result = DB()->sql_query($sql); - if (!$result) - { - bb_die('Could not delete smiley'); - } - $datastore->update('smile_replacements'); - - bb_die($lang['SMILEY_DEL_SUCCESS'] . '

        ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - break; - - case 'edit': - $smiley_id = ( !empty($_POST['id']) ) ? $_POST['id'] : $_GET['id']; - $smiley_id = intval($smiley_id); - - $sql = "SELECT * FROM " . BB_SMILIES . " WHERE smilies_id = " . $smiley_id; - $result = DB()->sql_query($sql); - if (!$result) - { - bb_die('Could not obtain emoticon information'); - } - $smile_data = DB()->sql_fetchrow($result); - - $filename_list = ''; - for ($i = 0; $i < count($smiley_images); $i++) - { - if ($smiley_images[$i] == $smile_data['smile_url']) - { - $smiley_selected = 'selected="selected"'; - $smiley_edit_img = $smiley_images[$i]; - } - else - { - $smiley_selected = ''; - } - $filename_list .= ''; - } - - $s_hidden_fields = ''; - - $template->assign_vars(array( - 'TPL_SMILE_EDIT' => true, - 'SMILEY_CODE' => $smile_data['code'], - 'SMILEY_EMOTICON' => $smile_data['emoticon'], - 'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] . '/' . $smiley_edit_img, - 'S_SMILEY_ACTION' => "admin_smilies.php", - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - 'S_FILENAME_OPTIONS' => $filename_list, - 'S_SMILEY_BASEDIR' => BB_ROOT . $bb_cfg['smilies_path'], - )); - - break; - - case 'save': - $smile_code = ( isset($_POST['smile_code']) ) ? trim($_POST['smile_code']) : trim($_GET['smile_code']); - $smile_url = ( isset($_POST['smile_url']) ) ? trim($_POST['smile_url']) : trim($_GET['smile_url']); - $smile_url = bb_ltrim(basename($smile_url), "'"); - $smile_emotion = ( isset($_POST['smile_emotion']) ) ? trim($_POST['smile_emotion']) : trim($_GET['smile_emotion']); - $smile_id = ( isset($_POST['smile_id']) ) ? intval($_POST['smile_id']) : intval($_GET['smile_id']); - - // If no code was entered complain - if ($smile_code == '' || $smile_url == '') - { - bb_die($lang['FIELDS_EMPTY']); - } - - // Convert < and > to proper htmlentities for parsing - $smile_code = str_replace('<', '<', $smile_code); - $smile_code = str_replace('>', '>', $smile_code); - - // Proceed with updating the smiley table - $sql = "UPDATE " . BB_SMILIES . " - SET code = '" . DB()->escape($smile_code) . "', smile_url = '" . DB()->escape($smile_url) . "', emoticon = '" . DB()->escape($smile_emotion) . "' - WHERE smilies_id = $smile_id"; - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not update smilies #2'); - } - $datastore->update('smile_replacements'); - - bb_die($lang['SMILEY_EDIT_SUCCESS'] . '

        ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - break; - - case 'savenew': - $smile_code = ( isset($_POST['smile_code']) ) ? $_POST['smile_code'] : $_GET['smile_code']; - $smile_url = ( isset($_POST['smile_url']) ) ? $_POST['smile_url'] : $_GET['smile_url']; - $smile_url = bb_ltrim(basename($smile_url), "'"); - $smile_emotion = ( isset($_POST['smile_emotion']) ) ? $_POST['smile_emotion'] : $_GET['smile_emotion']; - $smile_code = trim($smile_code); - $smile_url = trim($smile_url); - $smile_emotion = trim($smile_emotion); - - // If no code was entered complain - if ($smile_code == '' || $smile_url == '') - { - bb_die($lang['FIELDS_EMPTY']); - } - - // Convert < and > to proper htmlentities for parsing - $smile_code = str_replace('<', '<', $smile_code); - $smile_code = str_replace('>', '>', $smile_code); - - // Save the data to the smiley table - $sql = "INSERT INTO " . BB_SMILIES . " (code, smile_url, emoticon) - VALUES ('" . DB()->escape($smile_code) . "', '" . DB()->escape($smile_url) . "', '" . DB()->escape($smile_emotion) . "')"; - $result = DB()->sql_query($sql); - if (!$result) - { - bb_die('Could not insert new smiley'); - } - $datastore->update('smile_replacements'); - - bb_die($lang['SMILEY_ADD_SUCCESS'] . '

        ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - break; - } -} -else -{ - $sql = "SELECT * FROM " . BB_SMILIES; - $result = DB()->sql_query($sql); - if (!$result) - { - bb_die('Could not obtain smileys from database'); - } - - $smilies = DB()->sql_fetchrowset($result); - - $template->assign_vars(array( - 'TPL_SMILE_MAIN' => true, - 'S_HIDDEN_FIELDS' => @$s_hidden_fields, - 'S_SMILEY_ACTION' => 'admin_smilies.php', - )); - - // Loop throuh the rows of smilies setting block vars for the template - for ($i = 0; $i < count($smilies); $i++) - { - // Replace htmlentites for < and > with actual character - $smilies[$i]['code'] = str_replace('<', '<', $smilies[$i]['code']); - $smilies[$i]['code'] = str_replace('>', '>', $smilies[$i]['code']); - - $row_class = !($i % 2) ? 'row1' : 'row2'; - - $template->assign_block_vars('smiles', array( - 'ROW_CLASS' => $row_class, - - 'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] .'/'. $smilies[$i]['smile_url'], - 'CODE' => $smilies[$i]['code'], - 'EMOT' => $smilies[$i]['emoticon'], - - 'U_SMILEY_EDIT' => "admin_smilies.php?mode=edit&id=". $smilies[$i]['smilies_id'], - 'U_SMILEY_DELETE' => "admin_smilies.php?mode=delete&id=". $smilies[$i]['smilies_id'], - )); - } -} - +sql_query($sql)) + { + bb_die('Could not delete current smilies'); + } + $datastore->update('smile_replacements'); + } + else + { + $sql = "SELECT code FROM ". BB_SMILIES; + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not get current smilies'); + } + + $cur_smilies = DB()->sql_fetchrowset($result); + + for ($i = 0; $i < count($cur_smilies); $i++) + { + $k = $cur_smilies[$i]['code']; + $smiles[$k] = 1; + } + } + + $fcontents = @file(BB_ROOT . $bb_cfg['smilies_path'] . '/'. $smile_pak); + + if (empty($fcontents)) + { + bb_die('Could not read smiley pak file'); + } + + for ($i = 0; $i < count($fcontents); $i++) + { + $smile_data = explode($delimeter, trim(addslashes($fcontents[$i]))); + + for ($j = 2; $j < count($smile_data); $j++) + { + // Replace > and < with the proper html_entities for matching + $smile_data[$j] = str_replace('<', '<', $smile_data[$j]); + $smile_data[$j] = str_replace('>', '>', $smile_data[$j]); + $k = $smile_data[$j]; + + if (isset($smiles[$k])) + { + if( !empty($replace_existing) ) + { + $sql = "UPDATE " . BB_SMILIES . " + SET smile_url = '" . DB()->escape($smile_data[0]) . "', emoticon = '" . DB()->escape($smile_data[1]) . "' + WHERE code = '" . DB()->escape($smile_data[$j]) . "'"; + } + else + { + $sql = ''; + } + } + else + { + $sql = "INSERT INTO " . BB_SMILIES . " (code, smile_url, emoticon) + VALUES('" . DB()->escape($smile_data[$j]) . "', '" . DB()->escape($smile_data[0]) . "', '" . DB()->escape($smile_data[1]) . "')"; + } + + if ($sql != '') + { + $result = DB()->sql_query($sql); + if (!$result) + { + bb_die('Could not update smilies #1'); + } + $datastore->update('smile_replacements'); + } + } + } + + bb_die($lang['SMILEY_IMPORT_SUCCESS'] . '

        ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + } + else + { + // Display the script to get the smile_pak cfg file + $smile_paks_select = ''; + + $hidden_vars = ''; + + $template->assign_vars(array( + 'TPL_SMILE_IMPORT' => true, + + 'S_SMILEY_ACTION' => 'admin_smilies.php', + 'S_SMILE_SELECT' => $smile_paks_select, + 'S_HIDDEN_FIELDS' => $hidden_vars, + )); + } +} +else if (isset($_POST['export_pack']) || isset($_GET['export_pack'])) +{ + $export_pack = (string) request_var('export_pack', ''); + + if ($export_pack == 'send') + { + $sql = "SELECT * FROM " . BB_SMILIES; + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not get smiley list'); + } + + $resultset = DB()->sql_fetchrowset($result); + + $smile_pak = ''; + for ($i = 0; $i < count($resultset); $i++) + { + $smile_pak .= $resultset[$i]['smile_url'] . $delimeter; + $smile_pak .= $resultset[$i]['emoticon'] . $delimeter; + $smile_pak .= $resultset[$i]['code'] . "\n"; + } + + header("Content-Type: text/x-delimtext; name=\"smiles.pak\""); + header("Content-disposition: attachment; filename=smiles.pak"); + + echo $smile_pak; + + exit; + } + + bb_die(sprintf($lang['EXPORT_SMILES'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); +} +else if (isset($_POST['add']) || isset($_GET['add'])) +{ + $filename_list = ''; + for ($i = 0; $i < count($smiley_images); $i++) + { + $filename_list .= ''; + } + + $s_hidden_fields = ''; + + $template->assign_vars(array( + 'TPL_SMILE_EDIT' => true, + 'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] . '/' . $smiley_images[0], + 'S_SMILEY_ACTION' => "admin_smilies.php", + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_FILENAME_OPTIONS' => $filename_list, + 'S_SMILEY_BASEDIR' => BB_ROOT . $bb_cfg['smilies_path'] + )); +} +else if ( $mode != '' ) +{ + switch( $mode ) + { + case 'delete': + $smiley_id = ( !empty($_POST['id']) ) ? $_POST['id'] : $_GET['id']; + $smiley_id = intval($smiley_id); + + $sql = "DELETE FROM " . BB_SMILIES . " WHERE smilies_id = " . $smiley_id; + $result = DB()->sql_query($sql); + if (!$result) + { + bb_die('Could not delete smiley'); + } + $datastore->update('smile_replacements'); + + bb_die($lang['SMILEY_DEL_SUCCESS'] . '

        ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + break; + + case 'edit': + $smiley_id = ( !empty($_POST['id']) ) ? $_POST['id'] : $_GET['id']; + $smiley_id = intval($smiley_id); + + $sql = "SELECT * FROM " . BB_SMILIES . " WHERE smilies_id = " . $smiley_id; + $result = DB()->sql_query($sql); + if (!$result) + { + bb_die('Could not obtain emoticon information'); + } + $smile_data = DB()->sql_fetchrow($result); + + $filename_list = ''; + for ($i = 0; $i < count($smiley_images); $i++) + { + if ($smiley_images[$i] == $smile_data['smile_url']) + { + $smiley_selected = 'selected="selected"'; + $smiley_edit_img = $smiley_images[$i]; + } + else + { + $smiley_selected = ''; + } + $filename_list .= ''; + } + + $s_hidden_fields = ''; + + $template->assign_vars(array( + 'TPL_SMILE_EDIT' => true, + 'SMILEY_CODE' => $smile_data['code'], + 'SMILEY_EMOTICON' => $smile_data['emoticon'], + 'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] . '/' . $smiley_edit_img, + 'S_SMILEY_ACTION' => "admin_smilies.php", + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_FILENAME_OPTIONS' => $filename_list, + 'S_SMILEY_BASEDIR' => BB_ROOT . $bb_cfg['smilies_path'], + )); + + break; + + case 'save': + $smile_code = ( isset($_POST['smile_code']) ) ? trim($_POST['smile_code']) : trim($_GET['smile_code']); + $smile_url = ( isset($_POST['smile_url']) ) ? trim($_POST['smile_url']) : trim($_GET['smile_url']); + $smile_url = bb_ltrim(basename($smile_url), "'"); + $smile_emotion = ( isset($_POST['smile_emotion']) ) ? trim($_POST['smile_emotion']) : trim($_GET['smile_emotion']); + $smile_id = ( isset($_POST['smile_id']) ) ? intval($_POST['smile_id']) : intval($_GET['smile_id']); + + // If no code was entered complain + if ($smile_code == '' || $smile_url == '') + { + bb_die($lang['FIELDS_EMPTY']); + } + + // Convert < and > to proper htmlentities for parsing + $smile_code = str_replace('<', '<', $smile_code); + $smile_code = str_replace('>', '>', $smile_code); + + // Proceed with updating the smiley table + $sql = "UPDATE " . BB_SMILIES . " + SET code = '" . DB()->escape($smile_code) . "', smile_url = '" . DB()->escape($smile_url) . "', emoticon = '" . DB()->escape($smile_emotion) . "' + WHERE smilies_id = $smile_id"; + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not update smilies #2'); + } + $datastore->update('smile_replacements'); + + bb_die($lang['SMILEY_EDIT_SUCCESS'] . '

        ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + break; + + case 'savenew': + $smile_code = ( isset($_POST['smile_code']) ) ? $_POST['smile_code'] : $_GET['smile_code']; + $smile_url = ( isset($_POST['smile_url']) ) ? $_POST['smile_url'] : $_GET['smile_url']; + $smile_url = bb_ltrim(basename($smile_url), "'"); + $smile_emotion = ( isset($_POST['smile_emotion']) ) ? $_POST['smile_emotion'] : $_GET['smile_emotion']; + $smile_code = trim($smile_code); + $smile_url = trim($smile_url); + $smile_emotion = trim($smile_emotion); + + // If no code was entered complain + if ($smile_code == '' || $smile_url == '') + { + bb_die($lang['FIELDS_EMPTY']); + } + + // Convert < and > to proper htmlentities for parsing + $smile_code = str_replace('<', '<', $smile_code); + $smile_code = str_replace('>', '>', $smile_code); + + // Save the data to the smiley table + $sql = "INSERT INTO " . BB_SMILIES . " (code, smile_url, emoticon) + VALUES ('" . DB()->escape($smile_code) . "', '" . DB()->escape($smile_url) . "', '" . DB()->escape($smile_emotion) . "')"; + $result = DB()->sql_query($sql); + if (!$result) + { + bb_die('Could not insert new smiley'); + } + $datastore->update('smile_replacements'); + + bb_die($lang['SMILEY_ADD_SUCCESS'] . '

        ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + break; + } +} +else +{ + $sql = "SELECT * FROM " . BB_SMILIES; + $result = DB()->sql_query($sql); + if (!$result) + { + bb_die('Could not obtain smileys from database'); + } + + $smilies = DB()->sql_fetchrowset($result); + + $template->assign_vars(array( + 'TPL_SMILE_MAIN' => true, + 'S_HIDDEN_FIELDS' => @$s_hidden_fields, + 'S_SMILEY_ACTION' => 'admin_smilies.php', + )); + + // Loop throuh the rows of smilies setting block vars for the template + for ($i = 0; $i < count($smilies); $i++) + { + // Replace htmlentites for < and > with actual character + $smilies[$i]['code'] = str_replace('<', '<', $smilies[$i]['code']); + $smilies[$i]['code'] = str_replace('>', '>', $smilies[$i]['code']); + + $row_class = !($i % 2) ? 'row1' : 'row2'; + + $template->assign_block_vars('smiles', array( + 'ROW_CLASS' => $row_class, + + 'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] .'/'. $smilies[$i]['smile_url'], + 'CODE' => $smilies[$i]['code'], + 'EMOT' => $smilies[$i]['emoticon'], + + 'U_SMILEY_EDIT' => "admin_smilies.php?mode=edit&id=". $smilies[$i]['smilies_id'], + 'U_SMILEY_DELETE' => "admin_smilies.php?mode=delete&id=". $smilies[$i]['smilies_id'], + )); + } +} + print_page('admin_smilies.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_ug_auth.php b/upload/admin/admin_ug_auth.php index e7786cab1..ea01ecfb7 100644 --- a/upload/admin/admin_ug_auth.php +++ b/upload/admin/admin_ug_auth.php @@ -1,476 +1,476 @@ -fetch_row($sql)) - { - $group_id = $row['group_id']; - } - else - { - $group_id = create_user_group($user_id); - } - - if (!$group_id || !$user_id || is_null($this_user_level)) - { - trigger_error('data missing', E_USER_ERROR); - } - - // Make user an admin (if already user) - if (@$_POST['userlevel'] === 'admin') - { - if ($userdata['user_id'] == $user_id || $user_id == GUEST_UID || $user_id == BOT_UID) - { - bb_die("Could not update admin status"); - } - - DB()->query("UPDATE ". BB_USERS ." SET user_level = ". ADMIN ." WHERE user_id = $user_id LIMIT 1"); - - // Delete any entries in auth_access, they are not required if user is becoming an admin - delete_permissions($group_id, $user_id); - - $message = $lang['AUTH_UPDATED'] .'

        '; - $message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '', '') .'

        '; - $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); - - bb_die($message); - } - // Make admin a user (if already admin) - else if (@$_POST['userlevel'] === 'user') - { - // ignore if you're trying to change yourself from an admin to user! - if ($userdata['user_id'] == $user_id) - { - bb_die("Could not update admin status

        Could not change yourself from an admin to user"); - } - // Update users level, reset to USER - DB()->query("UPDATE ". BB_USERS ." SET user_level = ". USER ." WHERE user_id = $user_id LIMIT 1"); - - delete_permissions($group_id, $user_id); - - $message = $lang['AUTH_UPDATED'] .'

        '; - $message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '', '') .'

        '; - $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); - - bb_die($message); - } - - // - // Submit new USER permissions - // - $auth = array(); - - if (is_array(@$_POST['auth'])) - { - array_deep($_POST['auth'], 'intval'); - - foreach ($_POST['auth'] as $f_id => $bf_ary) - { - if (array_sum($bf_ary)) - { - $auth[$f_id] = bit2dec(array_keys($bf_ary, 1)); - } - } - } - - delete_permissions($group_id, null, $cat_id); - store_permissions($group_id, $auth); - - update_user_level($user_id); - - $l_auth_return = ($mode == 'user') ? $lang['CLICK_RETURN_USERAUTH'] : $lang['CLICK_RETURN_GROUPAUTH']; - $message = $lang['AUTH_UPDATED'] .'

        '; - $message .= sprintf($l_auth_return, '', '') .'

        '; - $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); - - bb_die($message); -} -// -// Submit new GROUP permissions -// -else if ($submit && $mode == 'group' && is_array(@$_POST['auth'])) -{ - if (!$group_data = get_group_data($group_id)) - { - bb_die($lang['GROUP_NOT_EXIST']); - } - - $auth = array(); - array_deep($_POST['auth'], 'intval'); - - foreach ($_POST['auth'] as $f_id => $bf_ary) - { - if (array_sum($bf_ary)) - { - $auth[$f_id] = bit2dec(array_keys($bf_ary, 1)); - } - } - - delete_permissions($group_id, null, $cat_id); - store_permissions($group_id, $auth); - - update_user_level('all'); - - $l_auth_return = $lang['CLICK_RETURN_GROUPAUTH']; - $message = $lang['AUTH_UPDATED'] .'

        '; - $message .= sprintf($l_auth_return, '', '') .'

        '; - $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); - - bb_die($message); -} - -// -// Front end (changing permissions) -// -if ($mode == 'user' && (!empty($_POST['username']) || $user_id)) -{ - $page_cfg['quirks_mode'] = true; - - if (!empty($_POST['username'])) - { - $this_userdata = get_userdata($_POST['username'], true); - $user_id = $this_userdata['user_id']; - } - else - { - $this_userdata = get_userdata($user_id); - } - if (!$this_userdata) - { - bb_die($lang['NO_SUCH_USER']); - } - - if (!$forums = $datastore->get('cat_forums')) - { - $datastore->update('cat_forums'); - $forums = $datastore->get('cat_forums'); - } - $base_url = basename(__FILE__) ."?mode=user&u=$user_id"; - - $ug_data = $this_userdata; - $ug_data['session_logged_in'] = 1; - - $u_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data, array(), UG_PERM_USER_ONLY); - $g_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data, array(), UG_PERM_GROUP_ONLY); - - foreach ($forums['c'] as $c_id => $c_data) - { - $template->assign_block_vars('c', array( - 'CAT_ID' => $c_id, - 'CAT_TITLE' => $forums['cat_title_html'][$c_id], - 'CAT_HREF' => "$base_url&c=$c_id", - )); - - if (!$c =& $_REQUEST['c'] OR !in_array($c, array('all', $c_id)) OR empty($c_data['forums'])) - { - continue; - } - - foreach ($c_data['forums'] as $f_id) - { - $f_data = $forums['f'][$f_id]; - $auth_mod = ($u_access[$f_id]['auth_mod'] || $g_access[$f_id]['auth_mod']); - $disabled = $g_access[$f_id]['auth_mod']; - - $template->assign_block_vars('c.f', array( - 'DISABLED' => $disabled, - 'FORUM_ID' => $f_id, - 'FORUM_NAME' => str_short($forums['forum_name_html'][$f_id], $max_forum_name_length), - 'SF_SPACER' => ($f_data['forum_parent']) ? HTML_SF_SPACER : '', - 'IS_MODERATOR' => (bool) $auth_mod, - 'MOD_STATUS' => ($auth_mod) ? $lang['MODERATOR'] : $lang['NONE'], - 'MOD_CLASS' => ($auth_mod) ? (($disabled) ? 'yesDisabled' : 'yesMOD') : 'noMOD', - 'AUTH_MOD_VAL' => ($auth_mod) ? 1 : 0, - )); - - foreach ($forum_auth_fields as $auth_type) - { - $bf_num = $bf['forum_perm'][$auth_type]; - $f_perm = $f_data[$auth_type]; - $auth_via_acl = ($u_access[$f_id][$auth_type] || $g_access[$f_id][$auth_type]); - - if ($f_perm == AUTH_ACL) - { - $disabled = ($auth_mod || $g_access[$f_id][$auth_type]); - $perm_sign = ($auth_via_acl || $auth_mod) ? $yes_sign : $no_sign; - $acl_class = ($auth_via_acl || $auth_mod) ? 'yes' : 'no'; - } - else - { - $disabled = true; - $perm_sign = ($auth_via_acl) ? $yes_sign : $no_sign; - $acl_class = ($auth_via_acl) ? 'yes' : 'no'; - } - - $template->assign_block_vars('c.f.acl', array( - 'DISABLED' => $disabled, - 'PERM_SIGN' => $perm_sign, - 'ACL_CLASS' => $acl_class, - 'FORUM_ID' => $f_id, - 'ACL_TYPE_BF' => $bf_num, - 'ACL_VAL' => ($auth_via_acl) ? 1 : 0, - )); - } - } - } - - $template->assign_vars(array( - 'AUTH_MOD_BF' => AUTH_MOD, - )); - - $s_column_span = 2; - - foreach ($forum_auth_fields as $auth_type) - { - $template->assign_block_vars('acltype', array( - 'ACL_TYPE_NAME' => preg_replace("#(.{5})#u", "\\1
        ", $lang[strtoupper($auth_type)]), - 'ACL_TYPE_BF' => $bf['forum_perm'][$auth_type], - )); - $s_column_span++; - } - - unset($forums, $u_access, $g_access); - $datastore->rm('cat_forums'); - - $s_hidden_fields = ' - - - '; - - $s_user_type = ($this_userdata['user_level'] == ADMIN) ? ' - - ' : ' - - '; - - $template->assign_block_vars('switch_user_auth', array()); - - $template->assign_vars(array( - 'TPL_AUTH_UG_MAIN' => true, - - 'USER_OR_GROUPNAME' => $this_userdata['username'], - 'USER_LEVEL' => $lang['USER_LEVEL'] .' : '. $s_user_type, - 'USER_GROUP_MEMBERSHIPS' => $lang['GROUP_MEMBERSHIPS'], - )); - - $template->assign_vars(array( - 'T_USER_OR_GROUPNAME' => $lang['USERNAME'], - 'T_AUTH_TITLE' => $lang['AUTH_CONTROL_USER'], - 'T_AUTH_EXPLAIN' => $lang['USER_AUTH_EXPLAIN'], - - 'S_COLUMN_SPAN' => $s_column_span, - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - )); -} -else if ($mode == 'group' && $group_id) -{ - $page_cfg['quirks_mode'] = true; - - if (!$group_data = get_group_data($group_id)) - { - bb_die($lang['GROUP_NOT_EXIST']); - } - - if (!$forums = $datastore->get('cat_forums')) - { - $datastore->update('cat_forums'); - $forums = $datastore->get('cat_forums'); - } - $base_url = basename(__FILE__) ."?mode=group&g=$group_id"; - - $ug_data = array('group_id' => $group_id); - $u_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data); - - foreach ($forums['c'] as $c_id => $c_data) - { - $template->assign_block_vars('c', array( - 'CAT_ID' => $c_id, - 'CAT_TITLE' => $forums['cat_title_html'][$c_id], - 'CAT_HREF' => "$base_url&c=$c_id", - )); - - if (!$c =& $_REQUEST['c'] OR !in_array($c, array('all', $c_id)) OR empty($c_data['forums'])) - { - continue; - } - - foreach ($c_data['forums'] as $f_id) - { - $f_data = $forums['f'][$f_id]; - $auth_mod = $u_access[$f_id]['auth_mod']; - - $template->assign_block_vars('c.f', array( - 'DISABLED' => false, - 'FORUM_ID' => $f_id, - 'FORUM_NAME' => str_short($forums['forum_name_html'][$f_id], $max_forum_name_length), - 'SF_SPACER' => ($f_data['forum_parent']) ? HTML_SF_SPACER : '', - 'IS_MODERATOR' => (bool) $auth_mod, - 'MOD_STATUS' => ($auth_mod) ? $lang['MODERATOR'] : $lang['NO'], - 'MOD_CLASS' => ($auth_mod) ? 'yesMOD' : 'noMOD', - 'AUTH_MOD_VAL' => ($auth_mod) ? 1 : 0, - )); - - foreach ($forum_auth_fields as $auth_type) - { - $bf_num = $bf['forum_perm'][$auth_type]; - $f_perm = $f_data[$auth_type]; - $auth_via_acl = $u_access[$f_id][$auth_type]; - - if ($f_perm == AUTH_ACL) - { - $disabled = $auth_mod; - $perm_sign = ($auth_via_acl || $auth_mod) ? $yes_sign : $no_sign; - $acl_class = ($auth_via_acl || $auth_mod) ? 'yes' : 'no'; - } - else - { - $disabled = true; - $perm_sign = ($auth_via_acl) ? $yes_sign : $no_sign; - $acl_class = ($auth_via_acl) ? 'yes' : 'no'; - } - - $template->assign_block_vars('c.f.acl', array( - 'DISABLED' => $disabled, - 'PERM_SIGN' => $perm_sign, - 'ACL_CLASS' => $acl_class, - 'FORUM_ID' => $f_id, - 'ACL_TYPE_BF' => $bf_num, - 'ACL_VAL' => ($auth_via_acl) ? 1 : 0, - )); - } - } - } - - $template->assign_vars(array( - 'AUTH_MOD_BF' => AUTH_MOD, - )); - - $s_column_span = 2; - - foreach ($forum_auth_fields as $auth_type) - { - $template->assign_block_vars('acltype', array( - 'ACL_TYPE_NAME' => preg_replace("#(.{5})#u", "\\1
        ", $lang[strtoupper($auth_type)]), - 'ACL_TYPE_BF' => $bf['forum_perm'][$auth_type], - )); - $s_column_span++; - } - - unset($forums, $ug_data, $u_access); - $datastore->rm('cat_forums'); - - $s_hidden_fields = ' - - - '; - - $template->assign_vars(array( - 'TPL_AUTH_UG_MAIN' => true, - - 'T_USER_OR_GROUPNAME' => $lang['GROUP_NAME'], - 'USER_LEVEL' => false, - 'T_AUTH_TITLE' => $lang['AUTH_CONTROL_GROUP'], - 'T_AUTH_EXPLAIN' => $lang['GROUP_AUTH_EXPLAIN'], - 'USER_OR_GROUPNAME' => htmlCHR($group_data['group_name']), - 'S_COLUMN_SPAN' => $s_column_span, - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - )); -} -else -{ - // Select a user/group - if ($mode == 'user') - { - $template->assign_vars(array( - 'TPL_SELECT_USER' => true, - 'U_SEARCH_USER' => BB_ROOT ."search.php?mode=searchuser", - )); - } - else - { - $template->assign_vars(array( - 'TPL_SELECT_GROUP' => true, - 'S_GROUP_SELECT' => get_select('groups'), - )); - } - - $s_hidden_fields = ''; - - $template->assign_vars(array( - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - )); -} - -$template->assign_vars(array( - 'YES_SIGN' => $yes_sign, - 'NO_SIGN' => $no_sign, - 'T_MOD_YES' => $lang['MODERATOR'], - 'T_MOD_NO' => $lang['NO'], - 'S_AUTH_ACTION' => "admin_ug_auth.php", - 'SELECTED_CAT' => !empty($_REQUEST['c']) ? $_REQUEST['c'] : '', - 'U_ALL_FORUMS' => !empty($base_url) ? "$base_url&c=all" : '', -)); - +fetch_row($sql)) + { + $group_id = $row['group_id']; + } + else + { + $group_id = create_user_group($user_id); + } + + if (!$group_id || !$user_id || is_null($this_user_level)) + { + trigger_error('data missing', E_USER_ERROR); + } + + // Make user an admin (if already user) + if (@$_POST['userlevel'] === 'admin') + { + if ($userdata['user_id'] == $user_id || $user_id == GUEST_UID || $user_id == BOT_UID) + { + bb_die("Could not update admin status"); + } + + DB()->query("UPDATE ". BB_USERS ." SET user_level = ". ADMIN ." WHERE user_id = $user_id LIMIT 1"); + + // Delete any entries in auth_access, they are not required if user is becoming an admin + delete_permissions($group_id, $user_id); + + $message = $lang['AUTH_UPDATED'] .'

        '; + $message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '', '') .'

        '; + $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); + + bb_die($message); + } + // Make admin a user (if already admin) + else if (@$_POST['userlevel'] === 'user') + { + // ignore if you're trying to change yourself from an admin to user! + if ($userdata['user_id'] == $user_id) + { + bb_die("Could not update admin status

        Could not change yourself from an admin to user"); + } + // Update users level, reset to USER + DB()->query("UPDATE ". BB_USERS ." SET user_level = ". USER ." WHERE user_id = $user_id LIMIT 1"); + + delete_permissions($group_id, $user_id); + + $message = $lang['AUTH_UPDATED'] .'

        '; + $message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '', '') .'

        '; + $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); + + bb_die($message); + } + + // + // Submit new USER permissions + // + $auth = array(); + + if (is_array(@$_POST['auth'])) + { + array_deep($_POST['auth'], 'intval'); + + foreach ($_POST['auth'] as $f_id => $bf_ary) + { + if (array_sum($bf_ary)) + { + $auth[$f_id] = bit2dec(array_keys($bf_ary, 1)); + } + } + } + + delete_permissions($group_id, null, $cat_id); + store_permissions($group_id, $auth); + + update_user_level($user_id); + + $l_auth_return = ($mode == 'user') ? $lang['CLICK_RETURN_USERAUTH'] : $lang['CLICK_RETURN_GROUPAUTH']; + $message = $lang['AUTH_UPDATED'] .'

        '; + $message .= sprintf($l_auth_return, '', '') .'

        '; + $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); + + bb_die($message); +} +// +// Submit new GROUP permissions +// +else if ($submit && $mode == 'group' && is_array(@$_POST['auth'])) +{ + if (!$group_data = get_group_data($group_id)) + { + bb_die($lang['GROUP_NOT_EXIST']); + } + + $auth = array(); + array_deep($_POST['auth'], 'intval'); + + foreach ($_POST['auth'] as $f_id => $bf_ary) + { + if (array_sum($bf_ary)) + { + $auth[$f_id] = bit2dec(array_keys($bf_ary, 1)); + } + } + + delete_permissions($group_id, null, $cat_id); + store_permissions($group_id, $auth); + + update_user_level('all'); + + $l_auth_return = $lang['CLICK_RETURN_GROUPAUTH']; + $message = $lang['AUTH_UPDATED'] .'

        '; + $message .= sprintf($l_auth_return, '', '') .'

        '; + $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); + + bb_die($message); +} + +// +// Front end (changing permissions) +// +if ($mode == 'user' && (!empty($_POST['username']) || $user_id)) +{ + $page_cfg['quirks_mode'] = true; + + if (!empty($_POST['username'])) + { + $this_userdata = get_userdata($_POST['username'], true); + $user_id = $this_userdata['user_id']; + } + else + { + $this_userdata = get_userdata($user_id); + } + if (!$this_userdata) + { + bb_die($lang['NO_SUCH_USER']); + } + + if (!$forums = $datastore->get('cat_forums')) + { + $datastore->update('cat_forums'); + $forums = $datastore->get('cat_forums'); + } + $base_url = basename(__FILE__) ."?mode=user&u=$user_id"; + + $ug_data = $this_userdata; + $ug_data['session_logged_in'] = 1; + + $u_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data, array(), UG_PERM_USER_ONLY); + $g_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data, array(), UG_PERM_GROUP_ONLY); + + foreach ($forums['c'] as $c_id => $c_data) + { + $template->assign_block_vars('c', array( + 'CAT_ID' => $c_id, + 'CAT_TITLE' => $forums['cat_title_html'][$c_id], + 'CAT_HREF' => "$base_url&c=$c_id", + )); + + if (!$c =& $_REQUEST['c'] OR !in_array($c, array('all', $c_id)) OR empty($c_data['forums'])) + { + continue; + } + + foreach ($c_data['forums'] as $f_id) + { + $f_data = $forums['f'][$f_id]; + $auth_mod = ($u_access[$f_id]['auth_mod'] || $g_access[$f_id]['auth_mod']); + $disabled = $g_access[$f_id]['auth_mod']; + + $template->assign_block_vars('c.f', array( + 'DISABLED' => $disabled, + 'FORUM_ID' => $f_id, + 'FORUM_NAME' => str_short($forums['forum_name_html'][$f_id], $max_forum_name_length), + 'SF_SPACER' => ($f_data['forum_parent']) ? HTML_SF_SPACER : '', + 'IS_MODERATOR' => (bool) $auth_mod, + 'MOD_STATUS' => ($auth_mod) ? $lang['MODERATOR'] : $lang['NONE'], + 'MOD_CLASS' => ($auth_mod) ? (($disabled) ? 'yesDisabled' : 'yesMOD') : 'noMOD', + 'AUTH_MOD_VAL' => ($auth_mod) ? 1 : 0, + )); + + foreach ($forum_auth_fields as $auth_type) + { + $bf_num = $bf['forum_perm'][$auth_type]; + $f_perm = $f_data[$auth_type]; + $auth_via_acl = ($u_access[$f_id][$auth_type] || $g_access[$f_id][$auth_type]); + + if ($f_perm == AUTH_ACL) + { + $disabled = ($auth_mod || $g_access[$f_id][$auth_type]); + $perm_sign = ($auth_via_acl || $auth_mod) ? $yes_sign : $no_sign; + $acl_class = ($auth_via_acl || $auth_mod) ? 'yes' : 'no'; + } + else + { + $disabled = true; + $perm_sign = ($auth_via_acl) ? $yes_sign : $no_sign; + $acl_class = ($auth_via_acl) ? 'yes' : 'no'; + } + + $template->assign_block_vars('c.f.acl', array( + 'DISABLED' => $disabled, + 'PERM_SIGN' => $perm_sign, + 'ACL_CLASS' => $acl_class, + 'FORUM_ID' => $f_id, + 'ACL_TYPE_BF' => $bf_num, + 'ACL_VAL' => ($auth_via_acl) ? 1 : 0, + )); + } + } + } + + $template->assign_vars(array( + 'AUTH_MOD_BF' => AUTH_MOD, + )); + + $s_column_span = 2; + + foreach ($forum_auth_fields as $auth_type) + { + $template->assign_block_vars('acltype', array( + 'ACL_TYPE_NAME' => preg_replace("#(.{5})#u", "\\1
        ", $lang[strtoupper($auth_type)]), + 'ACL_TYPE_BF' => $bf['forum_perm'][$auth_type], + )); + $s_column_span++; + } + + unset($forums, $u_access, $g_access); + $datastore->rm('cat_forums'); + + $s_hidden_fields = ' + + + '; + + $s_user_type = ($this_userdata['user_level'] == ADMIN) ? ' + + ' : ' + + '; + + $template->assign_block_vars('switch_user_auth', array()); + + $template->assign_vars(array( + 'TPL_AUTH_UG_MAIN' => true, + + 'USER_OR_GROUPNAME' => $this_userdata['username'], + 'USER_LEVEL' => $lang['USER_LEVEL'] .' : '. $s_user_type, + 'USER_GROUP_MEMBERSHIPS' => $lang['GROUP_MEMBERSHIPS'], + )); + + $template->assign_vars(array( + 'T_USER_OR_GROUPNAME' => $lang['USERNAME'], + 'T_AUTH_TITLE' => $lang['AUTH_CONTROL_USER'], + 'T_AUTH_EXPLAIN' => $lang['USER_AUTH_EXPLAIN'], + + 'S_COLUMN_SPAN' => $s_column_span, + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + )); +} +else if ($mode == 'group' && $group_id) +{ + $page_cfg['quirks_mode'] = true; + + if (!$group_data = get_group_data($group_id)) + { + bb_die($lang['GROUP_NOT_EXIST']); + } + + if (!$forums = $datastore->get('cat_forums')) + { + $datastore->update('cat_forums'); + $forums = $datastore->get('cat_forums'); + } + $base_url = basename(__FILE__) ."?mode=group&g=$group_id"; + + $ug_data = array('group_id' => $group_id); + $u_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data); + + foreach ($forums['c'] as $c_id => $c_data) + { + $template->assign_block_vars('c', array( + 'CAT_ID' => $c_id, + 'CAT_TITLE' => $forums['cat_title_html'][$c_id], + 'CAT_HREF' => "$base_url&c=$c_id", + )); + + if (!$c =& $_REQUEST['c'] OR !in_array($c, array('all', $c_id)) OR empty($c_data['forums'])) + { + continue; + } + + foreach ($c_data['forums'] as $f_id) + { + $f_data = $forums['f'][$f_id]; + $auth_mod = $u_access[$f_id]['auth_mod']; + + $template->assign_block_vars('c.f', array( + 'DISABLED' => false, + 'FORUM_ID' => $f_id, + 'FORUM_NAME' => str_short($forums['forum_name_html'][$f_id], $max_forum_name_length), + 'SF_SPACER' => ($f_data['forum_parent']) ? HTML_SF_SPACER : '', + 'IS_MODERATOR' => (bool) $auth_mod, + 'MOD_STATUS' => ($auth_mod) ? $lang['MODERATOR'] : $lang['NO'], + 'MOD_CLASS' => ($auth_mod) ? 'yesMOD' : 'noMOD', + 'AUTH_MOD_VAL' => ($auth_mod) ? 1 : 0, + )); + + foreach ($forum_auth_fields as $auth_type) + { + $bf_num = $bf['forum_perm'][$auth_type]; + $f_perm = $f_data[$auth_type]; + $auth_via_acl = $u_access[$f_id][$auth_type]; + + if ($f_perm == AUTH_ACL) + { + $disabled = $auth_mod; + $perm_sign = ($auth_via_acl || $auth_mod) ? $yes_sign : $no_sign; + $acl_class = ($auth_via_acl || $auth_mod) ? 'yes' : 'no'; + } + else + { + $disabled = true; + $perm_sign = ($auth_via_acl) ? $yes_sign : $no_sign; + $acl_class = ($auth_via_acl) ? 'yes' : 'no'; + } + + $template->assign_block_vars('c.f.acl', array( + 'DISABLED' => $disabled, + 'PERM_SIGN' => $perm_sign, + 'ACL_CLASS' => $acl_class, + 'FORUM_ID' => $f_id, + 'ACL_TYPE_BF' => $bf_num, + 'ACL_VAL' => ($auth_via_acl) ? 1 : 0, + )); + } + } + } + + $template->assign_vars(array( + 'AUTH_MOD_BF' => AUTH_MOD, + )); + + $s_column_span = 2; + + foreach ($forum_auth_fields as $auth_type) + { + $template->assign_block_vars('acltype', array( + 'ACL_TYPE_NAME' => preg_replace("#(.{5})#u", "\\1
        ", $lang[strtoupper($auth_type)]), + 'ACL_TYPE_BF' => $bf['forum_perm'][$auth_type], + )); + $s_column_span++; + } + + unset($forums, $ug_data, $u_access); + $datastore->rm('cat_forums'); + + $s_hidden_fields = ' + + + '; + + $template->assign_vars(array( + 'TPL_AUTH_UG_MAIN' => true, + + 'T_USER_OR_GROUPNAME' => $lang['GROUP_NAME'], + 'USER_LEVEL' => false, + 'T_AUTH_TITLE' => $lang['AUTH_CONTROL_GROUP'], + 'T_AUTH_EXPLAIN' => $lang['GROUP_AUTH_EXPLAIN'], + 'USER_OR_GROUPNAME' => htmlCHR($group_data['group_name']), + 'S_COLUMN_SPAN' => $s_column_span, + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + )); +} +else +{ + // Select a user/group + if ($mode == 'user') + { + $template->assign_vars(array( + 'TPL_SELECT_USER' => true, + 'U_SEARCH_USER' => BB_ROOT ."search.php?mode=searchuser", + )); + } + else + { + $template->assign_vars(array( + 'TPL_SELECT_GROUP' => true, + 'S_GROUP_SELECT' => get_select('groups'), + )); + } + + $s_hidden_fields = ''; + + $template->assign_vars(array( + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + )); +} + +$template->assign_vars(array( + 'YES_SIGN' => $yes_sign, + 'NO_SIGN' => $no_sign, + 'T_MOD_YES' => $lang['MODERATOR'], + 'T_MOD_NO' => $lang['NO'], + 'S_AUTH_ACTION' => "admin_ug_auth.php", + 'SELECTED_CAT' => !empty($_REQUEST['c']) ? $_REQUEST['c'] : '', + 'U_ALL_FORUMS' => !empty($base_url) ? "$base_url&c=all" : '', +)); + print_page('admin_ug_auth.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_user_ban.php b/upload/admin/admin_user_ban.php index 795fdffd0..a069c9d53 100644 --- a/upload/admin/admin_user_ban.php +++ b/upload/admin/admin_user_ban.php @@ -1,364 +1,364 @@ -sql_query($sql))) - { - bb_die('Could not obtain banlist information'); - } - - $current_banlist = DB()->sql_fetchrowset($result); - DB()->sql_freeresult($result); - - $kill_session_sql = ''; - for ($i = 0; $i < count($user_list); $i++) - { - $in_banlist = false; - for ($j = 0; $j < count($current_banlist); $j++) - { - if ($user_list[$i] == $current_banlist[$j]['ban_userid']) - { - $in_banlist = true; - } - } - - if (!$in_banlist) - { - $kill_session_sql .= ( ( $kill_session_sql != '' ) ? ' OR ' : '' ) . "session_user_id = " . $user_list[$i]; - - $sql = "INSERT INTO " . BB_BANLIST . " (ban_userid) VALUES (" . $user_list[$i] . ")"; - if (!DB()->sql_query($sql)) - { - bb_die('Could not insert ban_userid info into database'); - } - } - } - - for ($i = 0; $i < count($ip_list); $i++) - { - $in_banlist = false; - for ($j = 0; $j < count($current_banlist); $j++) - { - if ($ip_list[$i] == $current_banlist[$j]['ban_ip']) - { - $in_banlist = true; - } - } - - if (!$in_banlist) - { - if (preg_match('/(ff\.)|(\.ff)/is', chunk_split($ip_list[$i], 2, '.'))) - { - $kill_ip_sql = "session_ip LIKE '" . str_replace('.', '', preg_replace('/(ff\.)|(\.ff)/is', '%', chunk_split($ip_list[$i], 2, "."))) . "'"; - } - else - { - $kill_ip_sql = "session_ip = '" . $ip_list[$i] . "'"; - } - - $kill_session_sql .= ( ( $kill_session_sql != '' ) ? ' OR ' : '' ) . $kill_ip_sql; - - $sql = "INSERT INTO " . BB_BANLIST . " (ban_ip) VALUES ('" . $ip_list[$i] . "')"; - if ( !DB()->sql_query($sql) ) - { - bb_die('Could not insert ban_ip info into database'); - } - } - } - - // Now we'll delete all entries from the session table - if ($kill_session_sql != '') - { - $sql = "DELETE FROM " . BB_SESSIONS . " WHERE $kill_session_sql"; - if (!DB()->sql_query($sql)) - { - bb_die('Could not delete banned sessions from database'); - } - } - - for ($i = 0; $i < count($email_list); $i++) - { - $in_banlist = false; - for ($j = 0; $j < count($current_banlist); $j++) - { - if ($email_list[$i] == $current_banlist[$j]['ban_email']) - { - $in_banlist = true; - } - } - - if (!$in_banlist) - { - $sql = "INSERT INTO " . BB_BANLIST . " (ban_email) VALUES ('" . DB()->escape($email_list[$i]) . "')"; - if (!DB()->sql_query($sql)) - { - bb_die('Could not insert ban_email info into database'); - } - } - } - - $where_sql = ''; - - if (isset($_POST['unban_user'])) - { - $user_list = $_POST['unban_user']; - - for ($i = 0; $i < count($user_list); $i++) - { - if ($user_list[$i] != -1) - { - $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . intval($user_list[$i]); - } - } - } - - if (isset($_POST['unban_ip'])) - { - $ip_list = $_POST['unban_ip']; - - for ($i = 0; $i < count($ip_list); $i++) - { - if ($ip_list[$i] != -1) - { - $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . DB()->escape($ip_list[$i]); - } - } - } - - if (isset($_POST['unban_email'])) - { - $email_list = $_POST['unban_email']; - - for ($i = 0; $i < count($email_list); $i++) - { - if ($email_list[$i] != -1) - { - $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . DB()->escape($email_list[$i]); - } - } - } - - if ($where_sql != '') - { - $sql = "DELETE FROM " . BB_BANLIST . " WHERE ban_id IN ($where_sql)"; - if (!DB()->sql_query($sql)) - { - bb_die('Could not delete ban info from database'); - } - } - - bb_die($lang['BAN_UPDATE_SUCESSFUL'] . '

        ' . sprintf($lang['CLICK_RETURN_BANADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); -} -else -{ - $template->assign_vars(array( - 'S_BANLIST_ACTION' => 'admin_user_ban.php', - )); - - $userban_count = 0; - $ipban_count = 0; - $emailban_count = 0; - - $sql = "SELECT b.ban_id, u.user_id, u.username - FROM " . BB_BANLIST . " b, " . BB_USERS . " u - WHERE u.user_id = b.ban_userid - AND b.ban_userid <> 0 - AND u.user_id <> " . GUEST_UID . " - ORDER BY u.username ASC"; - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not select current user_id ban list'); - } - - $user_list = DB()->sql_fetchrowset($result); - DB()->sql_freeresult($result); - - $select_userlist = ''; - for ($i = 0; $i < count($user_list); $i++) - { - $select_userlist .= ''; - $userban_count++; - } - - if ($select_userlist == '') - { - $select_userlist = ''; - } - - $select_userlist = ''; - - $sql = "SELECT ban_id, ban_ip, ban_email FROM ". BB_BANLIST ." ORDER BY ban_ip"; - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not select current ip ban list'); - } - - $banlist = DB()->sql_fetchrowset($result); - DB()->sql_freeresult($result); - - $select_iplist = ''; - $select_emaillist = ''; - - for ($i = 0; $i < count($banlist); $i++) - { - $ban_id = $banlist[$i]['ban_id']; - - if (!empty($banlist[$i]['ban_ip'])) - { - $ban_ip = str_replace('255', '*', decode_ip($banlist[$i]['ban_ip'])); - $select_iplist .= ''; - $ipban_count++; - } - else if (!empty($banlist[$i]['ban_email'])) - { - $ban_email = $banlist[$i]['ban_email']; - $select_emaillist .= ''; - $emailban_count++; - } - } - - if ($select_iplist == '') - { - $select_iplist = ''; - } - - if ($select_emaillist == '') - { - $select_emaillist = ''; - } - - $select_iplist = ''; - $select_emaillist = ''; - - $template->assign_vars(array( - 'U_SEARCH_USER' => './../search.php?mode=searchuser', - 'S_UNBAN_USERLIST_SELECT' => $select_userlist, - 'S_UNBAN_IPLIST_SELECT' => $select_iplist, - 'S_UNBAN_EMAILLIST_SELECT' => $select_emaillist, - 'S_BAN_ACTION' => 'admin_user_ban.php', - )); -} - +sql_query($sql))) + { + bb_die('Could not obtain banlist information'); + } + + $current_banlist = DB()->sql_fetchrowset($result); + DB()->sql_freeresult($result); + + $kill_session_sql = ''; + for ($i = 0; $i < count($user_list); $i++) + { + $in_banlist = false; + for ($j = 0; $j < count($current_banlist); $j++) + { + if ($user_list[$i] == $current_banlist[$j]['ban_userid']) + { + $in_banlist = true; + } + } + + if (!$in_banlist) + { + $kill_session_sql .= ( ( $kill_session_sql != '' ) ? ' OR ' : '' ) . "session_user_id = " . $user_list[$i]; + + $sql = "INSERT INTO " . BB_BANLIST . " (ban_userid) VALUES (" . $user_list[$i] . ")"; + if (!DB()->sql_query($sql)) + { + bb_die('Could not insert ban_userid info into database'); + } + } + } + + for ($i = 0; $i < count($ip_list); $i++) + { + $in_banlist = false; + for ($j = 0; $j < count($current_banlist); $j++) + { + if ($ip_list[$i] == $current_banlist[$j]['ban_ip']) + { + $in_banlist = true; + } + } + + if (!$in_banlist) + { + if (preg_match('/(ff\.)|(\.ff)/is', chunk_split($ip_list[$i], 2, '.'))) + { + $kill_ip_sql = "session_ip LIKE '" . str_replace('.', '', preg_replace('/(ff\.)|(\.ff)/is', '%', chunk_split($ip_list[$i], 2, "."))) . "'"; + } + else + { + $kill_ip_sql = "session_ip = '" . $ip_list[$i] . "'"; + } + + $kill_session_sql .= ( ( $kill_session_sql != '' ) ? ' OR ' : '' ) . $kill_ip_sql; + + $sql = "INSERT INTO " . BB_BANLIST . " (ban_ip) VALUES ('" . $ip_list[$i] . "')"; + if ( !DB()->sql_query($sql) ) + { + bb_die('Could not insert ban_ip info into database'); + } + } + } + + // Now we'll delete all entries from the session table + if ($kill_session_sql != '') + { + $sql = "DELETE FROM " . BB_SESSIONS . " WHERE $kill_session_sql"; + if (!DB()->sql_query($sql)) + { + bb_die('Could not delete banned sessions from database'); + } + } + + for ($i = 0; $i < count($email_list); $i++) + { + $in_banlist = false; + for ($j = 0; $j < count($current_banlist); $j++) + { + if ($email_list[$i] == $current_banlist[$j]['ban_email']) + { + $in_banlist = true; + } + } + + if (!$in_banlist) + { + $sql = "INSERT INTO " . BB_BANLIST . " (ban_email) VALUES ('" . DB()->escape($email_list[$i]) . "')"; + if (!DB()->sql_query($sql)) + { + bb_die('Could not insert ban_email info into database'); + } + } + } + + $where_sql = ''; + + if (isset($_POST['unban_user'])) + { + $user_list = $_POST['unban_user']; + + for ($i = 0; $i < count($user_list); $i++) + { + if ($user_list[$i] != -1) + { + $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . intval($user_list[$i]); + } + } + } + + if (isset($_POST['unban_ip'])) + { + $ip_list = $_POST['unban_ip']; + + for ($i = 0; $i < count($ip_list); $i++) + { + if ($ip_list[$i] != -1) + { + $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . DB()->escape($ip_list[$i]); + } + } + } + + if (isset($_POST['unban_email'])) + { + $email_list = $_POST['unban_email']; + + for ($i = 0; $i < count($email_list); $i++) + { + if ($email_list[$i] != -1) + { + $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . DB()->escape($email_list[$i]); + } + } + } + + if ($where_sql != '') + { + $sql = "DELETE FROM " . BB_BANLIST . " WHERE ban_id IN ($where_sql)"; + if (!DB()->sql_query($sql)) + { + bb_die('Could not delete ban info from database'); + } + } + + bb_die($lang['BAN_UPDATE_SUCESSFUL'] . '

        ' . sprintf($lang['CLICK_RETURN_BANADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); +} +else +{ + $template->assign_vars(array( + 'S_BANLIST_ACTION' => 'admin_user_ban.php', + )); + + $userban_count = 0; + $ipban_count = 0; + $emailban_count = 0; + + $sql = "SELECT b.ban_id, u.user_id, u.username + FROM " . BB_BANLIST . " b, " . BB_USERS . " u + WHERE u.user_id = b.ban_userid + AND b.ban_userid <> 0 + AND u.user_id <> " . GUEST_UID . " + ORDER BY u.username ASC"; + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not select current user_id ban list'); + } + + $user_list = DB()->sql_fetchrowset($result); + DB()->sql_freeresult($result); + + $select_userlist = ''; + for ($i = 0; $i < count($user_list); $i++) + { + $select_userlist .= ''; + $userban_count++; + } + + if ($select_userlist == '') + { + $select_userlist = ''; + } + + $select_userlist = ''; + + $sql = "SELECT ban_id, ban_ip, ban_email FROM ". BB_BANLIST ." ORDER BY ban_ip"; + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not select current ip ban list'); + } + + $banlist = DB()->sql_fetchrowset($result); + DB()->sql_freeresult($result); + + $select_iplist = ''; + $select_emaillist = ''; + + for ($i = 0; $i < count($banlist); $i++) + { + $ban_id = $banlist[$i]['ban_id']; + + if (!empty($banlist[$i]['ban_ip'])) + { + $ban_ip = str_replace('255', '*', decode_ip($banlist[$i]['ban_ip'])); + $select_iplist .= ''; + $ipban_count++; + } + else if (!empty($banlist[$i]['ban_email'])) + { + $ban_email = $banlist[$i]['ban_email']; + $select_emaillist .= ''; + $emailban_count++; + } + } + + if ($select_iplist == '') + { + $select_iplist = ''; + } + + if ($select_emaillist == '') + { + $select_emaillist = ''; + } + + $select_iplist = ''; + $select_emaillist = ''; + + $template->assign_vars(array( + 'U_SEARCH_USER' => './../search.php?mode=searchuser', + 'S_UNBAN_USERLIST_SELECT' => $select_userlist, + 'S_UNBAN_IPLIST_SELECT' => $select_iplist, + 'S_UNBAN_EMAILLIST_SELECT' => $select_emaillist, + 'S_BAN_ACTION' => 'admin_user_ban.php', + )); +} + print_page('admin_user_ban.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_user_search.php b/upload/admin/admin_user_search.php index 4fea05511..b4113f27d 100644 --- a/upload/admin/admin_user_search.php +++ b/upload/admin/admin_user_search.php @@ -1,1054 +1,1054 @@ -sql_query($sql)) - { - bb_die('Could not select group data #1'); - } - - $group_list = ''; - - if (DB()->num_rows($result) != 0) - { - $template->assign_block_vars('groups_exist', array()); - - while ($row = DB()->sql_fetchrow($result)) - { - $group_list .= ''; - } - } - - $sql = "SELECT * FROM " . BB_RANKS . " WHERE rank_special = 1 ORDER BY rank_title"; - if (!($result = DB()->sql_query($sql))) - { - bb_die('Could not obtain ranks data'); - } - $rank_select_box = ''; - if (DB()->num_rows($result) != 0) - { - $template->assign_block_vars('ranks_exist', array()); - while( $row = DB()->sql_fetchrow($result) ) - { - $rank = $row['rank_title']; - $rank_id = $row['rank_id']; - $rank_select_box .= ''; - } - } - - $language_list = language_select('', 'language_type'); - $timezone_list = tz_select('', 'timezone_type'); - - $sql = "SELECT f.forum_id, f.forum_name, f.forum_parent, c.cat_id, c.cat_title - FROM ( ". BB_FORUMS ." AS f INNER JOIN ". BB_CATEGORIES ." AS c ON c.cat_id = f.cat_id ) - ORDER BY c.cat_order, f.forum_order ASC"; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not select forum data'); - } - - $forums = array(); - - if (DB()->num_rows($result) != 0) - { - $template->assign_block_vars('forums_exist', array()); - - $last_cat_id = -1; - $forums_list = ''; - - while ($row = DB()->sql_fetchrow($result)) - { - if ($row['cat_id'] != $last_cat_id) - { - $forums_list .= ''; - $last_cat_id = $row['cat_id']; - } - - $forums_list .= ''; - } - } - - $lastvisited = array(1, 7, 14, 30, 60, 120, 365, 500, 730, 1000); - $lastvisited_list = ''; - - foreach ($lastvisited as $days) - { - $lastvisited_list .= ''; - } - - $template->assign_vars(array( - 'TPL_ADMIN_USER_SEARCH_MAIN' => true, - - 'YEAR' => date("Y"), - 'MONTH' => date("m"), - 'DAY' => date("d"), - 'GROUP_LIST' => $group_list, - 'RANK_SELECT_BOX' => $rank_select_box, - 'LANGUAGE_LIST' => $language_list, - 'TIMEZONE_LIST' => $timezone_list, - 'FORUMS_LIST' => $forums_list, - 'LASTVISITED_LIST' => $lastvisited_list, - - 'S_SEARCH_ACTION' => 'admin_user_search.php', - )); -} -else -{ - $mode = ''; - - // validate mode - if (isset($_REQUEST['search_username'])) - { - $mode = 'search_username'; - } - elseif (isset($_REQUEST['search_email'])) - { - $mode = 'search_email'; - } - elseif (isset($_REQUEST['search_ip'])) - { - $mode = 'search_ip'; - } - elseif (isset($_REQUEST['search_joindate'])) - { - $mode = 'search_joindate'; - } - elseif (isset($_REQUEST['search_group'])) - { - $mode = 'search_group'; - } - elseif (isset($_REQUEST['search_rank'])) - { - $mode = 'search_rank'; - } - elseif (isset($_REQUEST['search_postcount'])) - { - $mode = 'search_postcount'; - } - elseif (isset($_REQUEST['search_userfield'])) - { - $mode = 'search_userfield'; - } - elseif (isset($_REQUEST['search_lastvisited'])) - { - $mode = 'search_lastvisited'; - } - elseif (isset($_REQUEST['search_language'])) - { - $mode = 'search_language'; - } - elseif (isset($_REQUEST['search_timezone'])) - { - $mode = 'search_timezone'; - } - elseif (isset($_REQUEST['search_moderators'])) - { - $mode = 'search_moderators'; - } - elseif (isset($_REQUEST['search_misc'])) - { - $mode = 'search_misc'; - } - - // validate fields (that they exist) - switch ($mode) - { - case 'search_username': - $username = $_REQUEST['username']; - if (!$username) bb_die($lang['SEARCH_INVALID_USERNAME']); - break; - - case 'search_email': - $email = $_REQUEST['email']; - if (!$email) bb_die($lang['SEARCH_INVALID_EMAIL']); - break; - - case 'search_ip': - $ip_address = $_REQUEST['ip_address']; - if (!$ip_address) bb_die($lang['SEARCH_INVALID_IP']); - break; - - case 'search_joindate': - $date_type = $_REQUEST['date_type']; - $date_day = $_REQUEST['date_day']; - $date_month = $_REQUEST['date_month']; - $date_year = $_REQUEST['date_year']; - if (!($date_type || $date_day || $date_month || $date_year)) bb_die($lang['SEARCH_INVALID_DATE']); - break; - - case 'search_group': - $group_id = $_REQUEST['group_id']; - if (!$group_id) bb_die($lang['SEARCH_INVALID_GROUP']); - break; - - case 'search_rank': - $rank_id = $_REQUEST['rank_id']; - if (!$rank_id) bb_die($lang['SEARCH_INVALID_RANK']); - break; - - case 'search_postcount': - $postcount_type = $_REQUEST['postcount_type']; - $postcount_value = $_REQUEST['postcount_value']; - if (!$postcount_type || (!$postcount_value && $postcount_value != 0)) bb_die($lang['SEARCH_INVALID_POSTCOUNT']); - break; - - case 'search_userfield': - $userfield_type = $_REQUEST['userfield_type']; - $userfield_value = $_REQUEST['userfield_value']; - if (!$userfield_type || !$userfield_value) bb_die($lang['SEARCH_INVALID_USERFIELD']); - break; - - case 'search_lastvisited': - $lastvisited_days = $_REQUEST['lastvisited_days']; - $lastvisited_type = $_REQUEST['lastvisited_type']; - if (!$lastvisited_days || !$lastvisited_type) bb_die($lang['SEARCH_INVALID_LASTVISITED']); - break; - - case 'search_language': - $language_type = $_REQUEST['language_type']; - if (!$language_type) bb_die($lang['SEARCH_INVALID_LANGUAGE']); - break; - - case 'search_timezone': - $timezone_type = $_REQUEST['timezone_type']; - if (!$timezone_type && $timezone_type != 0) bb_die($lang['SEARCH_INVALID_TIMEZONE']); - break; - - case 'search_moderators': - $moderators_forum = $_REQUEST['moderators_forum']; - if (!$moderators_forum) bb_die($lang['SEARCH_INVALID_MODERATORS']); - break; - - case 'search_misc': - $misc = $_REQUEST['misc']; - if (!$misc) bb_die($lang['SEARCH_INVALID']); - break; - - default: - bb_die('Invalid mode'); - } - - $base_url = 'admin_user_search.php?dosearch=true'; - - $select_sql = "SELECT u.user_id, u.username, u.user_rank, u.user_email, u.user_posts, u.user_regdate, u.user_level, u.user_active, u.user_lastvisit FROM ". BB_USERS ." AS u"; - - $lower_b = 'LOWER('; - $lower_e = ')'; - - // validate data & prepare sql - switch($mode) - { - case 'search_username': - $base_url .= '&search_username=true&username='.rawurlencode(stripslashes($username)); - - $text = sprintf($lang['SEARCH_FOR_USERNAME'], strip_tags(htmlspecialchars(stripslashes($username)))); - - $username = preg_replace('/\*/', '%', trim(strip_tags(strtolower($username)))); - - if (strstr($username, '%')) - { - $op = 'LIKE'; - } - else - { - $op = '='; - } - - if ($username == '') bb_die($lang['SEARCH_INVALID_USERNAME']); - - $total_sql .= "SELECT COUNT(user_id) AS total FROM ".BB_USERS." WHERE {$lower_b}username{$lower_e} $op '".DB()->escape($username)."' AND user_id <> ".GUEST_UID; - $select_sql .= " WHERE {$lower_b}u.username{$lower_e} $op '".DB()->escape($username)."' AND u.user_id <> ".GUEST_UID; - break; - - case 'search_email': - $base_url .= '&search_email=true&email='.rawurlencode(stripslashes($email)); - - $text = sprintf($lang['SEARCH_FOR_EMAIL'], strip_tags(htmlspecialchars(stripslashes($email)))); - - $email = preg_replace('/\*/', '%', trim(strip_tags(strtolower($email)))); - - if (strstr($email, '%')) - { - $op = 'LIKE'; - } - else - { - $op = '='; - } - - if ($email == '') bb_die($lang['SEARCH_INVALID_EMAIL']); - - $total_sql .= "SELECT COUNT(user_id) AS total FROM ".BB_USERS." WHERE {$lower_b}user_email{$lower_e} $op '".DB()->escape($email)."' AND user_id <> ".GUEST_UID; - $select_sql .= " WHERE {$lower_b}u.user_email{$lower_e} $op '".DB()->escape($email)."' AND u.user_id <> ".GUEST_UID; - break; - - case 'search_ip': - $base_url .= '&search_ip=true&ip_address='.rawurlencode(stripslashes($ip_address)); - - $ip_address = trim($ip_address); - - $text = sprintf($lang['SEARCH_FOR_IP'], strip_tags(htmlspecialchars(stripslashes($ip_address)))); - - unset($users); - $users = array(); - - // Let's see if they entered a full valid IPv4 address - if (preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}$/', $ip_address)) - { - $ip = encode_ip($ip_address); - $users[] = $ip; - } - elseif (preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){0,2}\.\*/', $ip_address)) - { - $ip_split = explode('.', $ip_address); - switch (count($ip_split)) - { - case 4: - $users[] = encode_ip($ip_split[0].".".$ip_split[1].".".$ip_split[2].".255"); - break; - case 3: - $users[] = encode_ip($ip_split[0].".".$ip_split[1].".255.255"); - break; - case 2: - $users[] = encode_ip($ip_split[0].".255.255.255"); - break; - } - } - elseif (preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}(\s)*-(\s)*([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}$/', $ip_address)) - { - $range = preg_split('/[-\s]+/', $ip_address); - $start_range = explode('.', $range[0]); - $end_range = explode('.', $range[1]); - if (($start_range[0].$start_range[1].$start_range[2] != $end_range[0].$end_range[1].$end_range[2]) || ($start_range[3] > $end_range[3])) bb_die($lang['SEARCH_INVALID_IP']); - for ($i = $start_range[3]; $i <= $end_range[3]; $i++) - { - $users[] = encode_ip($start_range[0].".".$start_range[1 ].".".$start_range[2].".".$i); - } - } - else - { - bb_die($lang['SEARCH_INVALID_IP']); - } - - $ip_in_sql = $ip_like_sql = $ip_like_sql_flylast = $ip_like_sql_flyreg = ''; - - foreach ($users as $address) - { - if (preg_match('/(ff){1,3}$/i', $address)) - { - if (preg_match('/[0-9a-f]{2}ffffff/i', $address)) - { - $ip_start = substr($address, 0, 2); - } - elseif (preg_match('/[0-9a-f]{4}ffff/i', $address)) - { - $ip_start = substr($address, 0, 4); - } - elseif (preg_match('/[0-9a-f]{6}ff/i', $address)) - { - $ip_start = substr($address, 0, 6); - } - $ip_like_sql_flylast = $ip_like_sql . ( $ip_like_sql != '' ) ? " OR user_last_ip LIKE '".$ip_start."%'" : "user_last_ip LIKE '".$ip_start."%'"; - $ip_like_sql_flyreg = $ip_like_sql . ( $ip_like_sql != '' ) ? " OR user_reg_ip LIKE '".$ip_start."%'" : "user_reg_ip LIKE '".$ip_start."%'"; - $ip_like_sql .= ( $ip_like_sql != '' ) ? " OR poster_ip LIKE '".$ip_start."%'" : "poster_ip LIKE '".$ip_start."%'"; - } - else - { - $ip_in_sql .= ( $ip_in_sql == '' ) ? "'$address'" : ", '$address'"; - } - } - - $where_sql = ''; - $where_sql .= ( $ip_in_sql != '' ) ? "poster_ip IN ($ip_in_sql)": ""; - $where_sql .= ( $ip_like_sql != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql" : "$ip_like_sql": ""; - - if (!$where_sql) bb_die('invalid request'); - - // start search - $no_result_search = false; - $ip_users_sql = ''; - $sql = "SELECT poster_id FROM ".BB_POSTS." WHERE poster_id <> ".GUEST_UID." AND ($where_sql) GROUP BY poster_id"; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not count users #1'); - } - - if (DB()->num_rows($result) == 0) - { - $no_result_search = true; - } - else - { - $total_pages['total'] = DB()->num_rows($result); - $total_sql = NULL; - $ip_users_sql = ''; - while($row = DB()->sql_fetchrow($result)) - { - $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['poster_id'] : ', '.$row['poster_id']; - } - } - $where_sql = ''; - $where_sql .= ( $ip_in_sql != '' ) ? "user_last_ip IN ($ip_in_sql)": ""; - $where_sql .= ( $ip_like_sql_flylast != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql_flylast" : "$ip_like_sql_flylast": ""; - $sql = "SELECT user_id FROM ".BB_USERS." WHERE user_id <> ".GUEST_UID." AND ($where_sql) GROUP BY user_id"; - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not count users #2'); - } - if (DB()->num_rows($result) != 0) - { - if ($no_result_search == true) $no_result_search = false; - $total_pages['total'] = DB()->num_rows($result); - $total_sql = NULL; - while ($row = DB()->sql_fetchrow($result)) - { - $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['user_id'] : ', '.$row['user_id']; - } - } - $where_sql = ''; - $where_sql .= ( $ip_in_sql != '' ) ? "user_reg_ip IN ($ip_in_sql)": ""; - $where_sql .= ( $ip_like_sql_flyreg != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql_flyreg" : "$ip_like_sql_flyreg": ""; - $sql = "SELECT user_id FROM ".BB_USERS." WHERE user_id <> ".GUEST_UID." AND ($where_sql) GROUP BY user_id"; - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not count users #3'); - } - if (DB()->num_rows($result) != 0) - { - if ($no_result_search == true) $no_result_search = false; - $total_pages['total'] = DB()->num_rows($result); - $total_sql = NULL; - while ($row = DB()->sql_fetchrow($result)) - { - $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['user_id'] : ', '.$row['user_id']; - } - } - if ($no_result_search == true) - { - bb_die($lang['SEARCH_NO_RESULTS']); - } - - $select_sql .= " WHERE u.user_id IN ($ip_users_sql)"; - break; - - case 'search_joindate': - $base_url .= '&search_joindate=true&date_type='. rawurlencode($date_type) .'&date_day='. rawurlencode($date_day) .'&date_month='. rawurlencode($date_month) .'&date_year='. rawurlencode(stripslashes($date_year)); - - $date_type = trim(strtolower($date_type)); - - if ($date_type != 'before' && $date_type != 'after') - { - bb_die($lang['SEARCH_INVALID_DATE']); - } - - $date_day = intval($date_day); - - if (!preg_match('/^([1-9]|[0-2][0-9]|3[0-1])$/', $date_day)) - { - bb_die($lang['SEARCH_INVALID_DAY']); - } - - $date_month = intval($date_month); - - if (!preg_match('/^(0?[1-9]|1[0-2])$/', $date_month)) - { - bb_die($lang['SEARCH_INVALID_MONTH']); - } - - $date_year = intval($date_year); - - if (!preg_match('/^(20[0-9]{2}|19[0-9]{2})$/', $date_year)) - { - bb_die($lang['SEARCH_INVALID_YEAR']); - } - - $text = sprintf($lang['SEARCH_FOR_DATE'], strip_tags(htmlspecialchars(stripslashes($date_type))), $date_year, $date_month, $date_day); - - $time = mktime(0,0,0,$date_month, $date_day, $date_year); - - if ($date_type == 'before') - { - $arg = '<'; - } - else - { - $arg = '>'; - } - - $total_sql .= "SELECT COUNT(user_id) AS total FROM ".BB_USERS." WHERE user_regdate $arg $time AND user_id <> ".GUEST_UID; - $select_sql .= " WHERE u.user_regdate $arg $time AND u.user_id <> ".GUEST_UID; - break; - - case 'search_group': - $group_id = intval($group_id); - - $base_url .= '&search_group=true&group_id='. rawurlencode($group_id); - - if (!$group_id) - { - bb_die($lang['SEARCH_INVALID_GROUP']); - } - - $sql = "SELECT group_name FROM ".BB_GROUPS." WHERE group_id = $group_id AND group_single_user = 0"; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not select group data #2'); - } - - if (DB()->num_rows($result)==0) - { - bb_die($lang['SEARCH_INVALID_GROUP']); - } - - $group_name = DB()->sql_fetchrow($result); - - $text = sprintf($lang['SEARCH_FOR_GROUP'], strip_tags(htmlspecialchars($group_name['group_name']))); - - $total_sql .= "SELECT COUNT(u.user_id) AS total - FROM ".BB_USERS." AS u, ".BB_USER_GROUP." AS ug - WHERE u.user_id = ug.user_id - AND ug.group_id = $group_id - AND u.user_id <> ".GUEST_UID; - - $select_sql .= ", ".BB_USER_GROUP." AS ug - WHERE u.user_id = ug.user_id - AND ug.group_id = $group_id - AND u.user_id <> ".GUEST_UID; - break; - - case 'search_rank': - $rank_id = intval($rank_id); - - $base_url .= '&search_rank=true&rank_id='. rawurlencode($rank_id); - - if (!$rank_id) - { - bb_die($lang['SEARCH_INVALID_RANK']); - } - - $sql = "SELECT rank_title FROM ".BB_RANKS." WHERE rank_id = $rank_id AND rank_special = 1"; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not select rank data'); - } - - if (DB()->num_rows($result)==0) - { - bb_die($lang['SEARCH_INVALID_RANK']); - } - - $rank_title = DB()->sql_fetchrow($result); - - $text = sprintf($lang['SEARCH_FOR_RANK'], strip_tags(htmlspecialchars($rank_title['rank_title']))); - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_rank = $rank_id - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_rank = $rank_id - AND u.user_id <> ".GUEST_UID; - break; - - case 'search_postcount': - $postcount_type = trim(strtolower($postcount_type)); - $postcount_value = trim(strtolower($postcount_value)); - - $base_url .= '&search_postcount=true&postcount_type='. rawurlencode($postcount_type) .'&postcount_value='. rawurlencode(stripslashes($postcount_value)); - - switch($postcount_type) - { - case 'greater': - $postcount_value = intval($postcount_value); - - $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_GREATER'], $postcount_value); - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_posts > $postcount_value - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_posts > $postcount_value - AND u.user_id <> ".GUEST_UID; - break; - case 'lesser': - $postcount_value = intval($postcount_value); - - $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_LESSER'], $postcount_value); - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_posts < $postcount_value - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_posts < $postcount_value - AND u.user_id <> ".GUEST_UID; - break; - case 'equals': - // looking for a - - if (strstr($postcount_value, '-')) - { - $range = preg_split('/[-\s]+/', $postcount_value); - - $range_begin = intval($range[0]); - $range_end = intval($range[1]); - - if ($range_begin > $range_end) - { - bb_die($lang['SEARCH_INVALID_POSTCOUNT']); - } - - $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_RANGE'], $range_begin, $range_end); - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_posts >= $range_begin - AND user_posts <= $range_end - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_posts >= $range_begin - AND u.user_posts <= $range_end - AND u.user_id <> ".GUEST_UID; - } - else - { - $postcount_value = intval($postcount_value); - - $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_EQUALS'], $postcount_value); - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_posts = $postcount_value - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_posts = $postcount_value - AND u.user_id <> ".GUEST_UID; - } - break; - default: - bb_die($lang['SEARCH_INVALID']); - } - break; - - case 'search_userfield': - $base_url .= '&search_userfield=true&userfield_type='. rawurlencode($userfield_type) .'&userfield_value='. rawurlencode(stripslashes($userfield_value)); - - $text = strip_tags(htmlspecialchars(stripslashes($userfield_value))); - - $userfield_value = preg_replace('/\*/', '%', trim(strip_tags(strtolower($userfield_value)))); - - if (strstr($userfield_value, '%')) - { - $op = 'LIKE'; - } - else - { - $op = '='; - } - - if ($userfield_value == '') bb_die($lang['SEARCH_INVALID_USERFIELD']); - - $userfield_type = trim(strtolower($userfield_type)); - - switch ($userfield_type) - { - case 'icq': - $text = sprintf($lang['SEARCH_FOR_USERFIELD_ICQ'],$text); - $field = 'user_icq'; - break; - case 'skype': - $text = sprintf($lang['SEARCH_FOR_USERFIELD_SKYPE'],$text); - $field = 'user_skype'; - break; - case 'twitter': - $text = sprintf($lang['SEARCH_FOR_USERFIELD_TWITTER'],$text); - $field = 'user_twitter'; - break; - case 'website': - $text = sprintf($lang['SEARCH_FOR_USERFIELD_WEBSITE'],$text); - $field = 'user_website'; - break; - case 'location': - $text = sprintf($lang['SEARCH_FOR_USERFIELD_LOCATION'],$text); - $field = 'user_from'; - break; - case 'interests': - $text = sprintf($lang['SEARCH_FOR_USERFIELD_INTERESTS'],$text); - $field = 'user_interests'; - break; - case 'occupation': - $text = sprintf($lang['SEARCH_FOR_USERFIELD_OCCUPATION'],$text); - $field = 'user_occ'; - break; - default: - bb_die( $lang['SEARCH_INVALID']); - } - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE {$lower_b}$field{$lower_e} $op '".DB()->escape($userfield_value)."' - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE {$lower_b}u.$field{$lower_e} $op '".DB()->escape($userfield_value)."' - AND u.user_id <> ".GUEST_UID; - break; - - case 'search_lastvisited': - $lastvisited_type = trim(strtolower($lastvisited_type)); - $lastvisited_days = intval($lastvisited_days); - - $base_url .= '&search_lastvisited=true&lastvisited_type='. rawurlencode(stripslashes($lastvisited_type)) .'&lastvisited_days='. rawurlencode($lastvisited_days); - - $lastvisited_seconds = ( TIMENOW - ( ( ( $lastvisited_days * 24 ) * 60 ) * 60 ) ); - - switch($lastvisited_type) - { - case 'in': - $text = sprintf($lang['SEARCH_FOR_LASTVISITED_INTHELAST'], $lastvisited_days, ( ( $lastvisited_days > 1 ) ? $lang['DAYS'] : $lang['DAY'] ) ); - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_lastvisit >= $lastvisited_seconds - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_lastvisit >= $lastvisited_seconds - AND u.user_id <> ".GUEST_UID; - break; - case 'after': - $text = sprintf($lang['SEARCH_FOR_LASTVISITED_AFTERTHELAST'], $lastvisited_days, ( ( $lastvisited_days > 1 ) ? $lang['DAYS'] : $lang['DAY'] )); - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_lastvisit < $lastvisited_seconds - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_lastvisit < $lastvisited_seconds - AND u.user_id <> ".GUEST_UID; - - break; - default: - bb_die($lang['SEARCH_INVALID_LASTVISITED']); - } - break; - - case 'search_language': - $base_url .= '&search_language=true&language_type='. rawurlencode(stripslashes($language_type)); - - $language_type = trim(strtolower(stripslashes($language_type))); - - if ($language_type == '') - { - bb_die($lang['SEARCH_INVALID_LANGUAGE']); - } - - $text = sprintf($lang['SEARCH_FOR_LANGUAGE'], strip_tags(htmlspecialchars($language_type))); - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_lang = '".DB()->escape($language_type)."' - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_lang = '".DB()->escape($language_type)."' - AND u.user_id <> ".GUEST_UID; - break; - - case 'search_timezone': - $base_url .= '&search_timezone=true&timezone_type='. rawurlencode(stripslashes($timezone_type)); - $text = sprintf($lang['SEARCH_FOR_TIMEZONE'], strip_tags(htmlspecialchars(stripslashes($timezone_type)))); - - $timezone_type = intval($timezone_type); - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_timezone = $timezone_type - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_timezone = $timezone_type - AND u.user_id <> ".GUEST_UID; - break; - - case 'search_moderators': - $base_url .= '&search_moderators=true&moderators_forum='. rawurlencode(stripslashes($moderators_forum)); - $moderators_forum = intval($moderators_forum); - - $sql = "SELECT forum_name FROM ".BB_FORUMS." WHERE forum_id = ".$moderators_forum; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not select forum data'); - } - - if (DB()->num_rows($result)==0) - { - bb_die($lang['SEARCH_INVALID_MODERATORS']); - } - - $forum_name = DB()->sql_fetchrow($result); - - $text = sprintf($lang['SEARCH_FOR_MODERATORS'], htmlCHR($forum_name['forum_name'])); - - $total_sql .= "SELECT COUNT(DISTINCT u.user_id) AS total - FROM ".BB_USERS." AS u, ".BB_GROUPS." AS g, ".BB_USER_GROUP." AS ug, ".BB_AUTH_ACCESS." AS aa - WHERE u.user_id = ug.user_id - AND ug.group_id = g.group_id - AND g.group_id = aa.group_id - AND aa.forum_id = ". $moderators_forum ." - AND aa.forum_perm & ". BF_AUTH_MOD ." - AND u.user_id <> ".GUEST_UID; - - $select_sql .= ", ".BB_GROUPS." AS g, ".BB_USER_GROUP." AS ug, ".BB_AUTH_ACCESS." AS aa - WHERE u.user_id = ug.user_id - AND ug.group_id = g.group_id - AND g.group_id = aa.group_id - AND aa.forum_id = ". $moderators_forum ." - AND aa.forum_perm & ". BF_AUTH_MOD ." - AND u.user_id <> ".GUEST_UID." - GROUP BY u.user_id, u.username, u.user_email, u.user_posts, u.user_regdate, u.user_level, u.user_active, u.user_lastvisit"; - break; - - case 'search_misc': - default: - $misc = trim(strtolower($misc)); - - $base_url .= '&search_misc=true&misc='. rawurlencode(stripslashes($misc)); - - switch ($misc) - { - case 'admins': - $text = $lang['SEARCH_FOR_ADMINS']; - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_level = ".ADMIN." - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_level = ".ADMIN." - AND u.user_id <> ".GUEST_UID; - break; - case 'mods': - $text = $lang['SEARCH_FOR_MODS']; - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_level = ".MOD." - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_level = ".MOD." - AND u.user_id <> ".GUEST_UID; - break; - case 'banned': - $text = $lang['SEARCH_FOR_BANNED']; - - $total_sql .= "SELECT COUNT(u.user_id) AS total - FROM ".BB_USERS." AS u, ".BB_BANLIST." AS b - WHERE u.user_id = b.ban_userid - AND u.user_id <> ".GUEST_UID; - - $select_sql .= ", ".BB_BANLIST." AS b - WHERE u.user_id = b.ban_userid - AND u.user_id <> ".GUEST_UID; - - break; - case 'disabled': - $text = $lang['SEARCH_FOR_DISABLED']; - - $total_sql .= "SELECT COUNT(user_id) AS total - FROM ".BB_USERS." - WHERE user_active = 0 - AND user_id <> ".GUEST_UID; - - $select_sql .= " WHERE u.user_active = 0 - AND u.user_id <> ".GUEST_UID; - - break; - default: - bb_die($lang['SEARCH_INVALID']); - } - } - - $select_sql .= " ORDER BY "; - - switch (strtolower(@$_GET['sort'])) - { - case 'regdate': - $sort = 'regdate'; - $select_sql .= 'u.user_regdate'; - break; - - case 'posts': - $sort = 'posts'; - $select_sql .= 'u.user_posts'; - break; - - case 'user_email': - $sort = 'user_email'; - $select_sql .= 'u.user_email'; - break; - - case 'lastvisit': - $sort = 'lastvisit'; - $select_sql .= 'u.user_lastvisit'; - break; - - case 'username': - default: - $sort = 'username'; - $select_sql .= 'u.username'; - } - - switch (@$_GET['order']) - { - case 'DESC': - $order = 'DESC'; - $o_order = 'ASC'; - break; - - default: - $o_order = 'DESC'; - $order = 'ASC'; - } - - $select_sql .= " $order"; - - $page = ( isset($_GET['page']) ) ? intval($_GET['page']) : intval(trim(@$_POST['page'])); - - if ($page < 1) - { - $page = 1; - } - - if ($page == 1) - { - $offset = 0; - } - else - { - $offset = ( ($page - 1) * $bb_cfg['topics_per_page']); - } - - $limit = "LIMIT $offset, ".$bb_cfg['topics_per_page']; - - $select_sql .= " $limit"; - - if (!is_null($total_sql)) - { - if (!$result = DB()->sql_query($total_sql)) - { - bb_die('Could not count users'); - } - - $total_pages = DB()->sql_fetchrow($result); - - if ($total_pages['total'] == 0) - { - bb_die($lang['SEARCH_NO_RESULTS']); - } - } - $num_pages = ceil( ( $total_pages['total'] / $bb_cfg['topics_per_page'] ) ); - - $pagination = ''; - - if ($page > 1) - { - $pagination .= ''. $lang['PREVIOUS'] .''; - } - if ($page < $num_pages) - { - $pagination .= ( $pagination == '' ) ? ''.$lang['NEXT'].'' : ' | '.$lang['NEXT'].''; - } - if ($num_pages > 2) - { - $pagination .= '   '; - } - $template->assign_vars(array( - 'TPL_ADMIN_USER_SEARCH_RESULTS' => true, - - 'PAGE_NUMBER' => sprintf($lang['PAGE_OF'], $page, $num_pages), - 'PAGINATION' => $pagination, - 'NEW_SEARCH' => sprintf($lang['SEARCH_USERS_NEW'],$text, $total_pages['total'], 'admin_user_search.php'), - - 'U_USERNAME' => ($sort == 'username') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=username&order=$order", - 'U_EMAIL' => ($sort == 'user_email') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=user_email&order=$order", - 'U_POSTS' => ($sort == 'posts') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=posts&order=$order", - 'U_JOINDATE' => ($sort == 'regdate') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=regdate&order=$order", - 'U_LASTVISIT' => ($sort == 'lastvisit') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=lastvisit&order=$order", - - 'S_POST_ACTION' => "$base_url&sort=$sort&order=$order" - )); - - if (!$result = DB()->sql_query($select_sql)) - { - bb_die('Could not select user data'); - } - - $rowset = DB()->sql_fetchrowset($result); - - $users_sql = ''; - - foreach ($rowset as $array) - { - $users_sql .= ( $users_sql == '' ) ? $array['user_id'] : ', '.$array['user_id']; - } - - $sql = "SELECT ban_userid AS user_id FROM ". BB_BANLIST ." WHERE ban_userid IN ($users_sql)"; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not select banned data'); - } - - unset($banned); - - $banned = array(); - - while ($row = DB()->sql_fetchrow($result)) - { - $banned[$row['user_id']] = true; - } - - for ($i = 0; $i < count($rowset); $i++) - { - $row_class = !($i % 2) ? 'row1' : 'row2'; - - $template->assign_block_vars('userrow', array( - 'ROW_CLASS' => $row_class, - 'USER' => profile_url($rowset[$i]), - 'EMAIL' => $rowset[$i]['user_email'], - 'JOINDATE' => bb_date($rowset[$i]['user_regdate']), - 'LASTVISIT' => bb_date($rowset[$i]['user_lastvisit']), - 'POSTS' => $rowset[$i]['user_posts'], - 'BAN' => ( ( !isset($banned[$rowset[$i]['user_id']]) ) ? $lang['NOT_BANNED'] : $lang['BANNED'] ), - 'ABLED' => ( ( $rowset[$i]['user_active'] ) ? $lang['ENABLED'] : $lang['DISABLED'] ), - - 'U_VIEWPOSTS' => "../search.php?search_author=1&uid={$rowset[$i]['user_id']}", - 'U_MANAGE' => '../profile.php?mode=editprofile&'. POST_USERS_URL .'='.$rowset[$i]['user_id'].'&admin=1', - 'U_PERMISSIONS' => 'admin_ug_auth.php?mode=user&'. POST_USERS_URL .'='. $rowset[$i]['user_id'], - )); - } -} - +sql_query($sql)) + { + bb_die('Could not select group data #1'); + } + + $group_list = ''; + + if (DB()->num_rows($result) != 0) + { + $template->assign_block_vars('groups_exist', array()); + + while ($row = DB()->sql_fetchrow($result)) + { + $group_list .= ''; + } + } + + $sql = "SELECT * FROM " . BB_RANKS . " WHERE rank_special = 1 ORDER BY rank_title"; + if (!($result = DB()->sql_query($sql))) + { + bb_die('Could not obtain ranks data'); + } + $rank_select_box = ''; + if (DB()->num_rows($result) != 0) + { + $template->assign_block_vars('ranks_exist', array()); + while( $row = DB()->sql_fetchrow($result) ) + { + $rank = $row['rank_title']; + $rank_id = $row['rank_id']; + $rank_select_box .= ''; + } + } + + $language_list = language_select('', 'language_type'); + $timezone_list = tz_select('', 'timezone_type'); + + $sql = "SELECT f.forum_id, f.forum_name, f.forum_parent, c.cat_id, c.cat_title + FROM ( ". BB_FORUMS ." AS f INNER JOIN ". BB_CATEGORIES ." AS c ON c.cat_id = f.cat_id ) + ORDER BY c.cat_order, f.forum_order ASC"; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not select forum data'); + } + + $forums = array(); + + if (DB()->num_rows($result) != 0) + { + $template->assign_block_vars('forums_exist', array()); + + $last_cat_id = -1; + $forums_list = ''; + + while ($row = DB()->sql_fetchrow($result)) + { + if ($row['cat_id'] != $last_cat_id) + { + $forums_list .= ''; + $last_cat_id = $row['cat_id']; + } + + $forums_list .= ''; + } + } + + $lastvisited = array(1, 7, 14, 30, 60, 120, 365, 500, 730, 1000); + $lastvisited_list = ''; + + foreach ($lastvisited as $days) + { + $lastvisited_list .= ''; + } + + $template->assign_vars(array( + 'TPL_ADMIN_USER_SEARCH_MAIN' => true, + + 'YEAR' => date("Y"), + 'MONTH' => date("m"), + 'DAY' => date("d"), + 'GROUP_LIST' => $group_list, + 'RANK_SELECT_BOX' => $rank_select_box, + 'LANGUAGE_LIST' => $language_list, + 'TIMEZONE_LIST' => $timezone_list, + 'FORUMS_LIST' => $forums_list, + 'LASTVISITED_LIST' => $lastvisited_list, + + 'S_SEARCH_ACTION' => 'admin_user_search.php', + )); +} +else +{ + $mode = ''; + + // validate mode + if (isset($_REQUEST['search_username'])) + { + $mode = 'search_username'; + } + elseif (isset($_REQUEST['search_email'])) + { + $mode = 'search_email'; + } + elseif (isset($_REQUEST['search_ip'])) + { + $mode = 'search_ip'; + } + elseif (isset($_REQUEST['search_joindate'])) + { + $mode = 'search_joindate'; + } + elseif (isset($_REQUEST['search_group'])) + { + $mode = 'search_group'; + } + elseif (isset($_REQUEST['search_rank'])) + { + $mode = 'search_rank'; + } + elseif (isset($_REQUEST['search_postcount'])) + { + $mode = 'search_postcount'; + } + elseif (isset($_REQUEST['search_userfield'])) + { + $mode = 'search_userfield'; + } + elseif (isset($_REQUEST['search_lastvisited'])) + { + $mode = 'search_lastvisited'; + } + elseif (isset($_REQUEST['search_language'])) + { + $mode = 'search_language'; + } + elseif (isset($_REQUEST['search_timezone'])) + { + $mode = 'search_timezone'; + } + elseif (isset($_REQUEST['search_moderators'])) + { + $mode = 'search_moderators'; + } + elseif (isset($_REQUEST['search_misc'])) + { + $mode = 'search_misc'; + } + + // validate fields (that they exist) + switch ($mode) + { + case 'search_username': + $username = $_REQUEST['username']; + if (!$username) bb_die($lang['SEARCH_INVALID_USERNAME']); + break; + + case 'search_email': + $email = $_REQUEST['email']; + if (!$email) bb_die($lang['SEARCH_INVALID_EMAIL']); + break; + + case 'search_ip': + $ip_address = $_REQUEST['ip_address']; + if (!$ip_address) bb_die($lang['SEARCH_INVALID_IP']); + break; + + case 'search_joindate': + $date_type = $_REQUEST['date_type']; + $date_day = $_REQUEST['date_day']; + $date_month = $_REQUEST['date_month']; + $date_year = $_REQUEST['date_year']; + if (!($date_type || $date_day || $date_month || $date_year)) bb_die($lang['SEARCH_INVALID_DATE']); + break; + + case 'search_group': + $group_id = $_REQUEST['group_id']; + if (!$group_id) bb_die($lang['SEARCH_INVALID_GROUP']); + break; + + case 'search_rank': + $rank_id = $_REQUEST['rank_id']; + if (!$rank_id) bb_die($lang['SEARCH_INVALID_RANK']); + break; + + case 'search_postcount': + $postcount_type = $_REQUEST['postcount_type']; + $postcount_value = $_REQUEST['postcount_value']; + if (!$postcount_type || (!$postcount_value && $postcount_value != 0)) bb_die($lang['SEARCH_INVALID_POSTCOUNT']); + break; + + case 'search_userfield': + $userfield_type = $_REQUEST['userfield_type']; + $userfield_value = $_REQUEST['userfield_value']; + if (!$userfield_type || !$userfield_value) bb_die($lang['SEARCH_INVALID_USERFIELD']); + break; + + case 'search_lastvisited': + $lastvisited_days = $_REQUEST['lastvisited_days']; + $lastvisited_type = $_REQUEST['lastvisited_type']; + if (!$lastvisited_days || !$lastvisited_type) bb_die($lang['SEARCH_INVALID_LASTVISITED']); + break; + + case 'search_language': + $language_type = $_REQUEST['language_type']; + if (!$language_type) bb_die($lang['SEARCH_INVALID_LANGUAGE']); + break; + + case 'search_timezone': + $timezone_type = $_REQUEST['timezone_type']; + if (!$timezone_type && $timezone_type != 0) bb_die($lang['SEARCH_INVALID_TIMEZONE']); + break; + + case 'search_moderators': + $moderators_forum = $_REQUEST['moderators_forum']; + if (!$moderators_forum) bb_die($lang['SEARCH_INVALID_MODERATORS']); + break; + + case 'search_misc': + $misc = $_REQUEST['misc']; + if (!$misc) bb_die($lang['SEARCH_INVALID']); + break; + + default: + bb_die('Invalid mode'); + } + + $base_url = 'admin_user_search.php?dosearch=true'; + + $select_sql = "SELECT u.user_id, u.username, u.user_rank, u.user_email, u.user_posts, u.user_regdate, u.user_level, u.user_active, u.user_lastvisit FROM ". BB_USERS ." AS u"; + + $lower_b = 'LOWER('; + $lower_e = ')'; + + // validate data & prepare sql + switch($mode) + { + case 'search_username': + $base_url .= '&search_username=true&username='.rawurlencode(stripslashes($username)); + + $text = sprintf($lang['SEARCH_FOR_USERNAME'], strip_tags(htmlspecialchars(stripslashes($username)))); + + $username = preg_replace('/\*/', '%', trim(strip_tags(strtolower($username)))); + + if (strstr($username, '%')) + { + $op = 'LIKE'; + } + else + { + $op = '='; + } + + if ($username == '') bb_die($lang['SEARCH_INVALID_USERNAME']); + + $total_sql .= "SELECT COUNT(user_id) AS total FROM ".BB_USERS." WHERE {$lower_b}username{$lower_e} $op '".DB()->escape($username)."' AND user_id <> ".GUEST_UID; + $select_sql .= " WHERE {$lower_b}u.username{$lower_e} $op '".DB()->escape($username)."' AND u.user_id <> ".GUEST_UID; + break; + + case 'search_email': + $base_url .= '&search_email=true&email='.rawurlencode(stripslashes($email)); + + $text = sprintf($lang['SEARCH_FOR_EMAIL'], strip_tags(htmlspecialchars(stripslashes($email)))); + + $email = preg_replace('/\*/', '%', trim(strip_tags(strtolower($email)))); + + if (strstr($email, '%')) + { + $op = 'LIKE'; + } + else + { + $op = '='; + } + + if ($email == '') bb_die($lang['SEARCH_INVALID_EMAIL']); + + $total_sql .= "SELECT COUNT(user_id) AS total FROM ".BB_USERS." WHERE {$lower_b}user_email{$lower_e} $op '".DB()->escape($email)."' AND user_id <> ".GUEST_UID; + $select_sql .= " WHERE {$lower_b}u.user_email{$lower_e} $op '".DB()->escape($email)."' AND u.user_id <> ".GUEST_UID; + break; + + case 'search_ip': + $base_url .= '&search_ip=true&ip_address='.rawurlencode(stripslashes($ip_address)); + + $ip_address = trim($ip_address); + + $text = sprintf($lang['SEARCH_FOR_IP'], strip_tags(htmlspecialchars(stripslashes($ip_address)))); + + unset($users); + $users = array(); + + // Let's see if they entered a full valid IPv4 address + if (preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}$/', $ip_address)) + { + $ip = encode_ip($ip_address); + $users[] = $ip; + } + elseif (preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){0,2}\.\*/', $ip_address)) + { + $ip_split = explode('.', $ip_address); + switch (count($ip_split)) + { + case 4: + $users[] = encode_ip($ip_split[0].".".$ip_split[1].".".$ip_split[2].".255"); + break; + case 3: + $users[] = encode_ip($ip_split[0].".".$ip_split[1].".255.255"); + break; + case 2: + $users[] = encode_ip($ip_split[0].".255.255.255"); + break; + } + } + elseif (preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}(\s)*-(\s)*([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}$/', $ip_address)) + { + $range = preg_split('/[-\s]+/', $ip_address); + $start_range = explode('.', $range[0]); + $end_range = explode('.', $range[1]); + if (($start_range[0].$start_range[1].$start_range[2] != $end_range[0].$end_range[1].$end_range[2]) || ($start_range[3] > $end_range[3])) bb_die($lang['SEARCH_INVALID_IP']); + for ($i = $start_range[3]; $i <= $end_range[3]; $i++) + { + $users[] = encode_ip($start_range[0].".".$start_range[1 ].".".$start_range[2].".".$i); + } + } + else + { + bb_die($lang['SEARCH_INVALID_IP']); + } + + $ip_in_sql = $ip_like_sql = $ip_like_sql_flylast = $ip_like_sql_flyreg = ''; + + foreach ($users as $address) + { + if (preg_match('/(ff){1,3}$/i', $address)) + { + if (preg_match('/[0-9a-f]{2}ffffff/i', $address)) + { + $ip_start = substr($address, 0, 2); + } + elseif (preg_match('/[0-9a-f]{4}ffff/i', $address)) + { + $ip_start = substr($address, 0, 4); + } + elseif (preg_match('/[0-9a-f]{6}ff/i', $address)) + { + $ip_start = substr($address, 0, 6); + } + $ip_like_sql_flylast = $ip_like_sql . ( $ip_like_sql != '' ) ? " OR user_last_ip LIKE '".$ip_start."%'" : "user_last_ip LIKE '".$ip_start."%'"; + $ip_like_sql_flyreg = $ip_like_sql . ( $ip_like_sql != '' ) ? " OR user_reg_ip LIKE '".$ip_start."%'" : "user_reg_ip LIKE '".$ip_start."%'"; + $ip_like_sql .= ( $ip_like_sql != '' ) ? " OR poster_ip LIKE '".$ip_start."%'" : "poster_ip LIKE '".$ip_start."%'"; + } + else + { + $ip_in_sql .= ( $ip_in_sql == '' ) ? "'$address'" : ", '$address'"; + } + } + + $where_sql = ''; + $where_sql .= ( $ip_in_sql != '' ) ? "poster_ip IN ($ip_in_sql)": ""; + $where_sql .= ( $ip_like_sql != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql" : "$ip_like_sql": ""; + + if (!$where_sql) bb_die('invalid request'); + + // start search + $no_result_search = false; + $ip_users_sql = ''; + $sql = "SELECT poster_id FROM ".BB_POSTS." WHERE poster_id <> ".GUEST_UID." AND ($where_sql) GROUP BY poster_id"; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not count users #1'); + } + + if (DB()->num_rows($result) == 0) + { + $no_result_search = true; + } + else + { + $total_pages['total'] = DB()->num_rows($result); + $total_sql = NULL; + $ip_users_sql = ''; + while($row = DB()->sql_fetchrow($result)) + { + $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['poster_id'] : ', '.$row['poster_id']; + } + } + $where_sql = ''; + $where_sql .= ( $ip_in_sql != '' ) ? "user_last_ip IN ($ip_in_sql)": ""; + $where_sql .= ( $ip_like_sql_flylast != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql_flylast" : "$ip_like_sql_flylast": ""; + $sql = "SELECT user_id FROM ".BB_USERS." WHERE user_id <> ".GUEST_UID." AND ($where_sql) GROUP BY user_id"; + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not count users #2'); + } + if (DB()->num_rows($result) != 0) + { + if ($no_result_search == true) $no_result_search = false; + $total_pages['total'] = DB()->num_rows($result); + $total_sql = NULL; + while ($row = DB()->sql_fetchrow($result)) + { + $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['user_id'] : ', '.$row['user_id']; + } + } + $where_sql = ''; + $where_sql .= ( $ip_in_sql != '' ) ? "user_reg_ip IN ($ip_in_sql)": ""; + $where_sql .= ( $ip_like_sql_flyreg != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql_flyreg" : "$ip_like_sql_flyreg": ""; + $sql = "SELECT user_id FROM ".BB_USERS." WHERE user_id <> ".GUEST_UID." AND ($where_sql) GROUP BY user_id"; + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not count users #3'); + } + if (DB()->num_rows($result) != 0) + { + if ($no_result_search == true) $no_result_search = false; + $total_pages['total'] = DB()->num_rows($result); + $total_sql = NULL; + while ($row = DB()->sql_fetchrow($result)) + { + $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['user_id'] : ', '.$row['user_id']; + } + } + if ($no_result_search == true) + { + bb_die($lang['SEARCH_NO_RESULTS']); + } + + $select_sql .= " WHERE u.user_id IN ($ip_users_sql)"; + break; + + case 'search_joindate': + $base_url .= '&search_joindate=true&date_type='. rawurlencode($date_type) .'&date_day='. rawurlencode($date_day) .'&date_month='. rawurlencode($date_month) .'&date_year='. rawurlencode(stripslashes($date_year)); + + $date_type = trim(strtolower($date_type)); + + if ($date_type != 'before' && $date_type != 'after') + { + bb_die($lang['SEARCH_INVALID_DATE']); + } + + $date_day = intval($date_day); + + if (!preg_match('/^([1-9]|[0-2][0-9]|3[0-1])$/', $date_day)) + { + bb_die($lang['SEARCH_INVALID_DAY']); + } + + $date_month = intval($date_month); + + if (!preg_match('/^(0?[1-9]|1[0-2])$/', $date_month)) + { + bb_die($lang['SEARCH_INVALID_MONTH']); + } + + $date_year = intval($date_year); + + if (!preg_match('/^(20[0-9]{2}|19[0-9]{2})$/', $date_year)) + { + bb_die($lang['SEARCH_INVALID_YEAR']); + } + + $text = sprintf($lang['SEARCH_FOR_DATE'], strip_tags(htmlspecialchars(stripslashes($date_type))), $date_year, $date_month, $date_day); + + $time = mktime(0,0,0,$date_month, $date_day, $date_year); + + if ($date_type == 'before') + { + $arg = '<'; + } + else + { + $arg = '>'; + } + + $total_sql .= "SELECT COUNT(user_id) AS total FROM ".BB_USERS." WHERE user_regdate $arg $time AND user_id <> ".GUEST_UID; + $select_sql .= " WHERE u.user_regdate $arg $time AND u.user_id <> ".GUEST_UID; + break; + + case 'search_group': + $group_id = intval($group_id); + + $base_url .= '&search_group=true&group_id='. rawurlencode($group_id); + + if (!$group_id) + { + bb_die($lang['SEARCH_INVALID_GROUP']); + } + + $sql = "SELECT group_name FROM ".BB_GROUPS." WHERE group_id = $group_id AND group_single_user = 0"; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not select group data #2'); + } + + if (DB()->num_rows($result)==0) + { + bb_die($lang['SEARCH_INVALID_GROUP']); + } + + $group_name = DB()->sql_fetchrow($result); + + $text = sprintf($lang['SEARCH_FOR_GROUP'], strip_tags(htmlspecialchars($group_name['group_name']))); + + $total_sql .= "SELECT COUNT(u.user_id) AS total + FROM ".BB_USERS." AS u, ".BB_USER_GROUP." AS ug + WHERE u.user_id = ug.user_id + AND ug.group_id = $group_id + AND u.user_id <> ".GUEST_UID; + + $select_sql .= ", ".BB_USER_GROUP." AS ug + WHERE u.user_id = ug.user_id + AND ug.group_id = $group_id + AND u.user_id <> ".GUEST_UID; + break; + + case 'search_rank': + $rank_id = intval($rank_id); + + $base_url .= '&search_rank=true&rank_id='. rawurlencode($rank_id); + + if (!$rank_id) + { + bb_die($lang['SEARCH_INVALID_RANK']); + } + + $sql = "SELECT rank_title FROM ".BB_RANKS." WHERE rank_id = $rank_id AND rank_special = 1"; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not select rank data'); + } + + if (DB()->num_rows($result)==0) + { + bb_die($lang['SEARCH_INVALID_RANK']); + } + + $rank_title = DB()->sql_fetchrow($result); + + $text = sprintf($lang['SEARCH_FOR_RANK'], strip_tags(htmlspecialchars($rank_title['rank_title']))); + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_rank = $rank_id + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_rank = $rank_id + AND u.user_id <> ".GUEST_UID; + break; + + case 'search_postcount': + $postcount_type = trim(strtolower($postcount_type)); + $postcount_value = trim(strtolower($postcount_value)); + + $base_url .= '&search_postcount=true&postcount_type='. rawurlencode($postcount_type) .'&postcount_value='. rawurlencode(stripslashes($postcount_value)); + + switch($postcount_type) + { + case 'greater': + $postcount_value = intval($postcount_value); + + $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_GREATER'], $postcount_value); + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_posts > $postcount_value + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_posts > $postcount_value + AND u.user_id <> ".GUEST_UID; + break; + case 'lesser': + $postcount_value = intval($postcount_value); + + $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_LESSER'], $postcount_value); + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_posts < $postcount_value + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_posts < $postcount_value + AND u.user_id <> ".GUEST_UID; + break; + case 'equals': + // looking for a - + if (strstr($postcount_value, '-')) + { + $range = preg_split('/[-\s]+/', $postcount_value); + + $range_begin = intval($range[0]); + $range_end = intval($range[1]); + + if ($range_begin > $range_end) + { + bb_die($lang['SEARCH_INVALID_POSTCOUNT']); + } + + $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_RANGE'], $range_begin, $range_end); + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_posts >= $range_begin + AND user_posts <= $range_end + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_posts >= $range_begin + AND u.user_posts <= $range_end + AND u.user_id <> ".GUEST_UID; + } + else + { + $postcount_value = intval($postcount_value); + + $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_EQUALS'], $postcount_value); + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_posts = $postcount_value + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_posts = $postcount_value + AND u.user_id <> ".GUEST_UID; + } + break; + default: + bb_die($lang['SEARCH_INVALID']); + } + break; + + case 'search_userfield': + $base_url .= '&search_userfield=true&userfield_type='. rawurlencode($userfield_type) .'&userfield_value='. rawurlencode(stripslashes($userfield_value)); + + $text = strip_tags(htmlspecialchars(stripslashes($userfield_value))); + + $userfield_value = preg_replace('/\*/', '%', trim(strip_tags(strtolower($userfield_value)))); + + if (strstr($userfield_value, '%')) + { + $op = 'LIKE'; + } + else + { + $op = '='; + } + + if ($userfield_value == '') bb_die($lang['SEARCH_INVALID_USERFIELD']); + + $userfield_type = trim(strtolower($userfield_type)); + + switch ($userfield_type) + { + case 'icq': + $text = sprintf($lang['SEARCH_FOR_USERFIELD_ICQ'],$text); + $field = 'user_icq'; + break; + case 'skype': + $text = sprintf($lang['SEARCH_FOR_USERFIELD_SKYPE'],$text); + $field = 'user_skype'; + break; + case 'twitter': + $text = sprintf($lang['SEARCH_FOR_USERFIELD_TWITTER'],$text); + $field = 'user_twitter'; + break; + case 'website': + $text = sprintf($lang['SEARCH_FOR_USERFIELD_WEBSITE'],$text); + $field = 'user_website'; + break; + case 'location': + $text = sprintf($lang['SEARCH_FOR_USERFIELD_LOCATION'],$text); + $field = 'user_from'; + break; + case 'interests': + $text = sprintf($lang['SEARCH_FOR_USERFIELD_INTERESTS'],$text); + $field = 'user_interests'; + break; + case 'occupation': + $text = sprintf($lang['SEARCH_FOR_USERFIELD_OCCUPATION'],$text); + $field = 'user_occ'; + break; + default: + bb_die( $lang['SEARCH_INVALID']); + } + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE {$lower_b}$field{$lower_e} $op '".DB()->escape($userfield_value)."' + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE {$lower_b}u.$field{$lower_e} $op '".DB()->escape($userfield_value)."' + AND u.user_id <> ".GUEST_UID; + break; + + case 'search_lastvisited': + $lastvisited_type = trim(strtolower($lastvisited_type)); + $lastvisited_days = intval($lastvisited_days); + + $base_url .= '&search_lastvisited=true&lastvisited_type='. rawurlencode(stripslashes($lastvisited_type)) .'&lastvisited_days='. rawurlencode($lastvisited_days); + + $lastvisited_seconds = ( TIMENOW - ( ( ( $lastvisited_days * 24 ) * 60 ) * 60 ) ); + + switch($lastvisited_type) + { + case 'in': + $text = sprintf($lang['SEARCH_FOR_LASTVISITED_INTHELAST'], $lastvisited_days, ( ( $lastvisited_days > 1 ) ? $lang['DAYS'] : $lang['DAY'] ) ); + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_lastvisit >= $lastvisited_seconds + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_lastvisit >= $lastvisited_seconds + AND u.user_id <> ".GUEST_UID; + break; + case 'after': + $text = sprintf($lang['SEARCH_FOR_LASTVISITED_AFTERTHELAST'], $lastvisited_days, ( ( $lastvisited_days > 1 ) ? $lang['DAYS'] : $lang['DAY'] )); + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_lastvisit < $lastvisited_seconds + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_lastvisit < $lastvisited_seconds + AND u.user_id <> ".GUEST_UID; + + break; + default: + bb_die($lang['SEARCH_INVALID_LASTVISITED']); + } + break; + + case 'search_language': + $base_url .= '&search_language=true&language_type='. rawurlencode(stripslashes($language_type)); + + $language_type = trim(strtolower(stripslashes($language_type))); + + if ($language_type == '') + { + bb_die($lang['SEARCH_INVALID_LANGUAGE']); + } + + $text = sprintf($lang['SEARCH_FOR_LANGUAGE'], strip_tags(htmlspecialchars($language_type))); + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_lang = '".DB()->escape($language_type)."' + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_lang = '".DB()->escape($language_type)."' + AND u.user_id <> ".GUEST_UID; + break; + + case 'search_timezone': + $base_url .= '&search_timezone=true&timezone_type='. rawurlencode(stripslashes($timezone_type)); + $text = sprintf($lang['SEARCH_FOR_TIMEZONE'], strip_tags(htmlspecialchars(stripslashes($timezone_type)))); + + $timezone_type = intval($timezone_type); + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_timezone = $timezone_type + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_timezone = $timezone_type + AND u.user_id <> ".GUEST_UID; + break; + + case 'search_moderators': + $base_url .= '&search_moderators=true&moderators_forum='. rawurlencode(stripslashes($moderators_forum)); + $moderators_forum = intval($moderators_forum); + + $sql = "SELECT forum_name FROM ".BB_FORUMS." WHERE forum_id = ".$moderators_forum; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not select forum data'); + } + + if (DB()->num_rows($result)==0) + { + bb_die($lang['SEARCH_INVALID_MODERATORS']); + } + + $forum_name = DB()->sql_fetchrow($result); + + $text = sprintf($lang['SEARCH_FOR_MODERATORS'], htmlCHR($forum_name['forum_name'])); + + $total_sql .= "SELECT COUNT(DISTINCT u.user_id) AS total + FROM ".BB_USERS." AS u, ".BB_GROUPS." AS g, ".BB_USER_GROUP." AS ug, ".BB_AUTH_ACCESS." AS aa + WHERE u.user_id = ug.user_id + AND ug.group_id = g.group_id + AND g.group_id = aa.group_id + AND aa.forum_id = ". $moderators_forum ." + AND aa.forum_perm & ". BF_AUTH_MOD ." + AND u.user_id <> ".GUEST_UID; + + $select_sql .= ", ".BB_GROUPS." AS g, ".BB_USER_GROUP." AS ug, ".BB_AUTH_ACCESS." AS aa + WHERE u.user_id = ug.user_id + AND ug.group_id = g.group_id + AND g.group_id = aa.group_id + AND aa.forum_id = ". $moderators_forum ." + AND aa.forum_perm & ". BF_AUTH_MOD ." + AND u.user_id <> ".GUEST_UID." + GROUP BY u.user_id, u.username, u.user_email, u.user_posts, u.user_regdate, u.user_level, u.user_active, u.user_lastvisit"; + break; + + case 'search_misc': + default: + $misc = trim(strtolower($misc)); + + $base_url .= '&search_misc=true&misc='. rawurlencode(stripslashes($misc)); + + switch ($misc) + { + case 'admins': + $text = $lang['SEARCH_FOR_ADMINS']; + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_level = ".ADMIN." + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_level = ".ADMIN." + AND u.user_id <> ".GUEST_UID; + break; + case 'mods': + $text = $lang['SEARCH_FOR_MODS']; + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_level = ".MOD." + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_level = ".MOD." + AND u.user_id <> ".GUEST_UID; + break; + case 'banned': + $text = $lang['SEARCH_FOR_BANNED']; + + $total_sql .= "SELECT COUNT(u.user_id) AS total + FROM ".BB_USERS." AS u, ".BB_BANLIST." AS b + WHERE u.user_id = b.ban_userid + AND u.user_id <> ".GUEST_UID; + + $select_sql .= ", ".BB_BANLIST." AS b + WHERE u.user_id = b.ban_userid + AND u.user_id <> ".GUEST_UID; + + break; + case 'disabled': + $text = $lang['SEARCH_FOR_DISABLED']; + + $total_sql .= "SELECT COUNT(user_id) AS total + FROM ".BB_USERS." + WHERE user_active = 0 + AND user_id <> ".GUEST_UID; + + $select_sql .= " WHERE u.user_active = 0 + AND u.user_id <> ".GUEST_UID; + + break; + default: + bb_die($lang['SEARCH_INVALID']); + } + } + + $select_sql .= " ORDER BY "; + + switch (strtolower(@$_GET['sort'])) + { + case 'regdate': + $sort = 'regdate'; + $select_sql .= 'u.user_regdate'; + break; + + case 'posts': + $sort = 'posts'; + $select_sql .= 'u.user_posts'; + break; + + case 'user_email': + $sort = 'user_email'; + $select_sql .= 'u.user_email'; + break; + + case 'lastvisit': + $sort = 'lastvisit'; + $select_sql .= 'u.user_lastvisit'; + break; + + case 'username': + default: + $sort = 'username'; + $select_sql .= 'u.username'; + } + + switch (@$_GET['order']) + { + case 'DESC': + $order = 'DESC'; + $o_order = 'ASC'; + break; + + default: + $o_order = 'DESC'; + $order = 'ASC'; + } + + $select_sql .= " $order"; + + $page = ( isset($_GET['page']) ) ? intval($_GET['page']) : intval(trim(@$_POST['page'])); + + if ($page < 1) + { + $page = 1; + } + + if ($page == 1) + { + $offset = 0; + } + else + { + $offset = ( ($page - 1) * $bb_cfg['topics_per_page']); + } + + $limit = "LIMIT $offset, ".$bb_cfg['topics_per_page']; + + $select_sql .= " $limit"; + + if (!is_null($total_sql)) + { + if (!$result = DB()->sql_query($total_sql)) + { + bb_die('Could not count users'); + } + + $total_pages = DB()->sql_fetchrow($result); + + if ($total_pages['total'] == 0) + { + bb_die($lang['SEARCH_NO_RESULTS']); + } + } + $num_pages = ceil( ( $total_pages['total'] / $bb_cfg['topics_per_page'] ) ); + + $pagination = ''; + + if ($page > 1) + { + $pagination .= ''. $lang['PREVIOUS'] .''; + } + if ($page < $num_pages) + { + $pagination .= ( $pagination == '' ) ? ''.$lang['NEXT'].'' : ' | '.$lang['NEXT'].''; + } + if ($num_pages > 2) + { + $pagination .= '   '; + } + $template->assign_vars(array( + 'TPL_ADMIN_USER_SEARCH_RESULTS' => true, + + 'PAGE_NUMBER' => sprintf($lang['PAGE_OF'], $page, $num_pages), + 'PAGINATION' => $pagination, + 'NEW_SEARCH' => sprintf($lang['SEARCH_USERS_NEW'],$text, $total_pages['total'], 'admin_user_search.php'), + + 'U_USERNAME' => ($sort == 'username') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=username&order=$order", + 'U_EMAIL' => ($sort == 'user_email') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=user_email&order=$order", + 'U_POSTS' => ($sort == 'posts') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=posts&order=$order", + 'U_JOINDATE' => ($sort == 'regdate') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=regdate&order=$order", + 'U_LASTVISIT' => ($sort == 'lastvisit') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=lastvisit&order=$order", + + 'S_POST_ACTION' => "$base_url&sort=$sort&order=$order" + )); + + if (!$result = DB()->sql_query($select_sql)) + { + bb_die('Could not select user data'); + } + + $rowset = DB()->sql_fetchrowset($result); + + $users_sql = ''; + + foreach ($rowset as $array) + { + $users_sql .= ( $users_sql == '' ) ? $array['user_id'] : ', '.$array['user_id']; + } + + $sql = "SELECT ban_userid AS user_id FROM ". BB_BANLIST ." WHERE ban_userid IN ($users_sql)"; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not select banned data'); + } + + unset($banned); + + $banned = array(); + + while ($row = DB()->sql_fetchrow($result)) + { + $banned[$row['user_id']] = true; + } + + for ($i = 0; $i < count($rowset); $i++) + { + $row_class = !($i % 2) ? 'row1' : 'row2'; + + $template->assign_block_vars('userrow', array( + 'ROW_CLASS' => $row_class, + 'USER' => profile_url($rowset[$i]), + 'EMAIL' => $rowset[$i]['user_email'], + 'JOINDATE' => bb_date($rowset[$i]['user_regdate']), + 'LASTVISIT' => bb_date($rowset[$i]['user_lastvisit']), + 'POSTS' => $rowset[$i]['user_posts'], + 'BAN' => ( ( !isset($banned[$rowset[$i]['user_id']]) ) ? $lang['NOT_BANNED'] : $lang['BANNED'] ), + 'ABLED' => ( ( $rowset[$i]['user_active'] ) ? $lang['ENABLED'] : $lang['DISABLED'] ), + + 'U_VIEWPOSTS' => "../search.php?search_author=1&uid={$rowset[$i]['user_id']}", + 'U_MANAGE' => '../profile.php?mode=editprofile&'. POST_USERS_URL .'='.$rowset[$i]['user_id'].'&admin=1', + 'U_PERMISSIONS' => 'admin_ug_auth.php?mode=user&'. POST_USERS_URL .'='. $rowset[$i]['user_id'], + )); + } +} + print_page('admin_user_search.tpl', 'admin'); \ No newline at end of file diff --git a/upload/admin/admin_words.php b/upload/admin/admin_words.php index 407542292..11bef0b02 100644 --- a/upload/admin/admin_words.php +++ b/upload/admin/admin_words.php @@ -1,159 +1,159 @@ -
        ($bb_cfg[\'use_word_censor\'] in config.php)'); -} - -$mode = request_var('mode', ''); -$mode = htmlspecialchars($mode); - -if (isset($_POST['add'])) -{ - $mode = 'add'; -} -else if (isset($_POST['save'])) -{ - $mode = 'save'; -} - -if ($mode != '') -{ - if ($mode == 'edit' || $mode == 'add') - { - $word_id = intval(request_var('id', 0)); - - $s_hidden_fields = $word = $replacement = ''; - - if ($mode == 'edit') - { - if ($word_id) - { - $sql = "SELECT * FROM " . BB_WORDS . " WHERE word_id = $word_id"; - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not query words table #1'); - } - - $word_info = DB()->sql_fetchrow($result); - $s_hidden_fields .= ''; - $word = $word_info['word']; - $replacement = $word_info['replacement']; - } - else - { - bb_die($lang['NO_WORD_SELECTED']); - } - } - - $template->assign_vars(array( - 'TPL_ADMIN_WORDS_EDIT' => true, - 'WORD' => $word, - 'REPLACEMENT' => $replacement, - 'S_WORDS_ACTION' => 'admin_words.php', - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - )); - } - else if ($mode == 'save') - { - $word_id = intval(request_var('id', 0)); - $word = trim(request_var('word', '')); - $replacement = trim(request_var('replacement', '')); - - if ($word == '' || $replacement == '') - { - bb_die($lang['MUST_ENTER_WORD']); - } - - if ($word_id) - { - $sql = "UPDATE " . BB_WORDS . " - SET word = '" . DB()->escape($word) . "', replacement = '" . DB()->escape($replacement) . "' - WHERE word_id = $word_id"; - $message = $lang['WORD_UPDATED']; - } - else - { - $sql = "INSERT INTO " . BB_WORDS . " (word, replacement) - VALUES ('" . DB()->escape($word) . "', '" . DB()->escape($replacement) . "')"; - $message = $lang['WORD_ADDED']; - } - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not insert data into words table'); - } - - CACHE('bb_cache')->rm('censored'); - $message .= '

        ' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); - - bb_die($message); - } - else if ($mode == 'delete') - { - $word_id = intval(request_var('id', 0)); - - if ($word_id) - { - $sql = "DELETE FROM " . BB_WORDS . " WHERE word_id = $word_id"; - - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not remove data from words table'); - } - - CACHE('bb_cache')->rm('censored'); - - bb_die($lang['WORD_REMOVED'] . '

        ' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); - } - else - { - bb_die($lang['NO_WORD_SELECTED']); - } - } -} -else -{ - $sql = "SELECT * FROM " . BB_WORDS . " ORDER BY word"; - if (!$result = DB()->sql_query($sql)) - { - bb_die('Could not query words table #2'); - } - - $word_rows = DB()->sql_fetchrowset($result); - $word_count = count($word_rows); - - $template->assign_vars(array( - 'TPL_ADMIN_WORDS_LIST' => true, - 'S_WORDS_ACTION' => 'admin_words.php', - 'S_HIDDEN_FIELDS' => '', - )); - - for ($i = 0; $i < $word_count; $i++) - { - $word = $word_rows[$i]['word']; - $replacement = $word_rows[$i]['replacement']; - $word_id = $word_rows[$i]['word_id']; - - $row_class = !($i % 2) ? 'row1' : 'row2'; - - $template->assign_block_vars('words', array( - 'ROW_CLASS' => $row_class, - 'WORD' => $word, - 'REPLACEMENT' => $replacement, - 'U_WORD_EDIT' => "admin_words.php?mode=edit&id=$word_id", - 'U_WORD_DELETE' => "admin_words.php?mode=delete&id=$word_id", - )); - } -} - +
        ($bb_cfg[\'use_word_censor\'] in config.php)'); +} + +$mode = request_var('mode', ''); +$mode = htmlspecialchars($mode); + +if (isset($_POST['add'])) +{ + $mode = 'add'; +} +else if (isset($_POST['save'])) +{ + $mode = 'save'; +} + +if ($mode != '') +{ + if ($mode == 'edit' || $mode == 'add') + { + $word_id = intval(request_var('id', 0)); + + $s_hidden_fields = $word = $replacement = ''; + + if ($mode == 'edit') + { + if ($word_id) + { + $sql = "SELECT * FROM " . BB_WORDS . " WHERE word_id = $word_id"; + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not query words table #1'); + } + + $word_info = DB()->sql_fetchrow($result); + $s_hidden_fields .= ''; + $word = $word_info['word']; + $replacement = $word_info['replacement']; + } + else + { + bb_die($lang['NO_WORD_SELECTED']); + } + } + + $template->assign_vars(array( + 'TPL_ADMIN_WORDS_EDIT' => true, + 'WORD' => $word, + 'REPLACEMENT' => $replacement, + 'S_WORDS_ACTION' => 'admin_words.php', + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + )); + } + else if ($mode == 'save') + { + $word_id = intval(request_var('id', 0)); + $word = trim(request_var('word', '')); + $replacement = trim(request_var('replacement', '')); + + if ($word == '' || $replacement == '') + { + bb_die($lang['MUST_ENTER_WORD']); + } + + if ($word_id) + { + $sql = "UPDATE " . BB_WORDS . " + SET word = '" . DB()->escape($word) . "', replacement = '" . DB()->escape($replacement) . "' + WHERE word_id = $word_id"; + $message = $lang['WORD_UPDATED']; + } + else + { + $sql = "INSERT INTO " . BB_WORDS . " (word, replacement) + VALUES ('" . DB()->escape($word) . "', '" . DB()->escape($replacement) . "')"; + $message = $lang['WORD_ADDED']; + } + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not insert data into words table'); + } + + CACHE('bb_cache')->rm('censored'); + $message .= '

        ' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''); + + bb_die($message); + } + else if ($mode == 'delete') + { + $word_id = intval(request_var('id', 0)); + + if ($word_id) + { + $sql = "DELETE FROM " . BB_WORDS . " WHERE word_id = $word_id"; + + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not remove data from words table'); + } + + CACHE('bb_cache')->rm('censored'); + + bb_die($lang['WORD_REMOVED'] . '

        ' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '', '') . '

        ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); + } + else + { + bb_die($lang['NO_WORD_SELECTED']); + } + } +} +else +{ + $sql = "SELECT * FROM " . BB_WORDS . " ORDER BY word"; + if (!$result = DB()->sql_query($sql)) + { + bb_die('Could not query words table #2'); + } + + $word_rows = DB()->sql_fetchrowset($result); + $word_count = count($word_rows); + + $template->assign_vars(array( + 'TPL_ADMIN_WORDS_LIST' => true, + 'S_WORDS_ACTION' => 'admin_words.php', + 'S_HIDDEN_FIELDS' => '', + )); + + for ($i = 0; $i < $word_count; $i++) + { + $word = $word_rows[$i]['word']; + $replacement = $word_rows[$i]['replacement']; + $word_id = $word_rows[$i]['word_id']; + + $row_class = !($i % 2) ? 'row1' : 'row2'; + + $template->assign_block_vars('words', array( + 'ROW_CLASS' => $row_class, + 'WORD' => $word, + 'REPLACEMENT' => $replacement, + 'U_WORD_EDIT' => "admin_words.php?mode=edit&id=$word_id", + 'U_WORD_DELETE' => "admin_words.php?mode=delete&id=$word_id", + )); + } +} + print_page('admin_words.tpl', 'admin'); \ No newline at end of file diff --git a/upload/ajax/avatar.php b/upload/ajax/avatar.php index d4ee11933..eac82fc83 100644 --- a/upload/ajax/avatar.php +++ b/upload/ajax/avatar.php @@ -1,35 +1,35 @@ -request['mode']; -$user_id = (int) $this->request['user_id']; - -if (!$user_id OR !$u_data = get_userdata($user_id)) -{ - $this->ajax_die('invalid user_id'); -} - -if (!IS_ADMIN && $user_id != $user->id) -{ - $this->ajax_die('Не админ'); -} - -switch ($mode) -{ - case 'delete': - delete_avatar($user_id, $u_data['avatar_ext_id']); - $new_ext_id = 0; - $response = ''. $user_id .''; - break; - default: - $this->ajax_die('invalid mode'); -} - -DB()->query("UPDATE ". BB_USERS ." SET avatar_ext_id = $new_ext_id WHERE user_id = $user_id LIMIT 1"); - -cache_rm_user_sessions($user_id); - +request['mode']; +$user_id = (int) $this->request['user_id']; + +if (!$user_id OR !$u_data = get_userdata($user_id)) +{ + $this->ajax_die('invalid user_id'); +} + +if (!IS_ADMIN && $user_id != $user->id) +{ + $this->ajax_die('Не админ'); +} + +switch ($mode) +{ + case 'delete': + delete_avatar($user_id, $u_data['avatar_ext_id']); + $new_ext_id = 0; + $response = ''. $user_id .''; + break; + default: + $this->ajax_die('invalid mode'); +} + +DB()->query("UPDATE ". BB_USERS ." SET avatar_ext_id = $new_ext_id WHERE user_id = $user_id LIMIT 1"); + +cache_rm_user_sessions($user_id); + $this->response['avatar_html'] = $response; \ No newline at end of file diff --git a/upload/ajax/change_tor_status.php b/upload/ajax/change_tor_status.php index eb0acca15..fe7698c1c 100644 --- a/upload/ajax/change_tor_status.php +++ b/upload/ajax/change_tor_status.php @@ -1,106 +1,106 @@ -request['attach_id'])) $this->ajax_die($lang['EMPTY_ATTACH_ID']); - -$attach_id = (int) $this->request['attach_id']; -$mode = (string) $this->request['mode']; - -if ($bb_cfg['tor_comment']) -{ - $comment = (string) $this->request['comment']; -} - -$tor = DB()->fetch_row(" - SELECT - tor.poster_id, tor.forum_id, tor.topic_id, tor.tor_status, tor.checked_time, tor.checked_user_id, f.cat_id, t.topic_title - FROM ". BB_BT_TORRENTS ." tor - INNER JOIN ". BB_FORUMS ." f ON(f.forum_id = tor.forum_id) - INNER JOIN ". BB_TOPICS ." t ON(t.topic_id = tor.topic_id) - WHERE tor.attach_id = $attach_id - LIMIT 1 -"); - -if (!$tor) $this->ajax_die($lang['TORRENT_FAILED']); - -switch ($mode) -{ - case 'status': - $new_status = (int) $this->request['status']; - - // Валидность статуса - if (!isset($lang['TOR_STATUS_NAME'][$new_status])) $this->ajax_die($lang['TOR_STATUS_FAILED']); - if (!isset($this->request['status'])) $this->ajax_die($lang['TOR_DONT_CHANGE']); - if (!IS_AM) $this->ajax_die($lang['NOT_MODERATOR']); - - // Тот же статус - if ($tor['tor_status'] == $new_status) - { - $this->ajax_die($lang['TOR_STATUS_DUB']); - } - - // Запрет на изменение/присвоение CH-статуса модератором - if ($new_status == TOR_CLOSED_CPHOLD && !IS_ADMIN) - { - $this->ajax_die($lang['TOR_DONT_CHANGE']); - } - - // Права на изменение статуса - if ($tor['tor_status'] == TOR_CLOSED_CPHOLD) - { - if (!IS_ADMIN) $this->verify_mod_rights($tor['forum_id']); - DB()->query("UPDATE ". BB_TOPICS ." SET topic_status = ". TOPIC_UNLOCKED ." WHERE topic_id = {$tor['topic_id']} LIMIT 1"); - } - else - { - $this->verify_mod_rights($tor['forum_id']); - } - - // Подтверждение изменения статуса, выставленного другим модератором - if ($tor['tor_status'] != TOR_NOT_APPROVED && $tor['checked_user_id'] != $userdata['user_id'] && $tor['checked_time'] + 2*3600 > TIMENOW) - { - if (empty($this->request['confirmed'])) - { - $msg = $lang['TOR_STATUS_OF'] ." {$lang['TOR_STATUS_NAME'][$tor['tor_status']]}\n\n"; - $msg .= ($username = get_username($tor['checked_user_id'])) ? $lang['TOR_STATUS_CHANGED'] . html_entity_decode($username) .", ". delta_time($tor['checked_time']) . $lang['TOR_BACK'] ."\n\n" : ""; - $msg .= $lang['PROCEED'] .'?'; - $this->prompt_for_confirm($msg); - } - } - - change_tor_status($attach_id, $new_status); - - $this->response['status'] = $bb_cfg['tor_icons'][$new_status] .' '. $lang['TOR_STATUS_NAME'][$new_status]. ' · '. profile_url($userdata) .' · '. delta_time(TIMENOW) . $lang['TOR_BACK']. ''; - - if ($bb_cfg['tor_comment'] && (($comment && $comment != $lang['COMMENT']) || in_array($new_status, $bb_cfg['tor_reply']))) - { - if ($tor['poster_id'] > 0) - { - $subject = sprintf($lang['TOR_MOD_TITLE'], $tor['topic_title']); - $message = sprintf($lang['TOR_MOD_MSG'], get_username($tor['poster_id']), make_url(TOPIC_URL . $tor['topic_id']), $bb_cfg['tor_icons'][$new_status] .' '.$lang['TOR_STATUS_NAME'][$new_status]); - - if ($comment && $comment != $lang['COMMENT']) $message .= "\n\n[b]". $lang['COMMENT'] .'[/b]: '. $comment; - - send_pm($tor['poster_id'], $subject, $message, $userdata['user_id']); - cache_rm_user_sessions($tor['poster_id']); - } - } - break; - - case 'status_reply': - if (!$bb_cfg['tor_comment']) $this->ajax_die($lang['MODULE_OFF']); - - $subject = sprintf($lang['TOR_AUTH_TITLE'], $tor['topic_title']); - $message = sprintf($lang['TOR_AUTH_MSG'], get_username($tor['checked_user_id']), make_url(TOPIC_URL . $tor['topic_id']), $tor['topic_title']); - - if ($comment && $comment != $lang['COMMENT']) $message .= "\n\n[b]". $lang['COMMENT'] .'[/b]: '. $comment; - - send_pm($tor['checked_user_id'], $subject, $message, $userdata['user_id']); - cache_rm_user_sessions($tor['checked_user_id']); - break; -} - +request['attach_id'])) $this->ajax_die($lang['EMPTY_ATTACH_ID']); + +$attach_id = (int) $this->request['attach_id']; +$mode = (string) $this->request['mode']; + +if ($bb_cfg['tor_comment']) +{ + $comment = (string) $this->request['comment']; +} + +$tor = DB()->fetch_row(" + SELECT + tor.poster_id, tor.forum_id, tor.topic_id, tor.tor_status, tor.checked_time, tor.checked_user_id, f.cat_id, t.topic_title + FROM ". BB_BT_TORRENTS ." tor + INNER JOIN ". BB_FORUMS ." f ON(f.forum_id = tor.forum_id) + INNER JOIN ". BB_TOPICS ." t ON(t.topic_id = tor.topic_id) + WHERE tor.attach_id = $attach_id + LIMIT 1 +"); + +if (!$tor) $this->ajax_die($lang['TORRENT_FAILED']); + +switch ($mode) +{ + case 'status': + $new_status = (int) $this->request['status']; + + // Валидность статуса + if (!isset($lang['TOR_STATUS_NAME'][$new_status])) $this->ajax_die($lang['TOR_STATUS_FAILED']); + if (!isset($this->request['status'])) $this->ajax_die($lang['TOR_DONT_CHANGE']); + if (!IS_AM) $this->ajax_die($lang['NOT_MODERATOR']); + + // Тот же статус + if ($tor['tor_status'] == $new_status) + { + $this->ajax_die($lang['TOR_STATUS_DUB']); + } + + // Запрет на изменение/присвоение CH-статуса модератором + if ($new_status == TOR_CLOSED_CPHOLD && !IS_ADMIN) + { + $this->ajax_die($lang['TOR_DONT_CHANGE']); + } + + // Права на изменение статуса + if ($tor['tor_status'] == TOR_CLOSED_CPHOLD) + { + if (!IS_ADMIN) $this->verify_mod_rights($tor['forum_id']); + DB()->query("UPDATE ". BB_TOPICS ." SET topic_status = ". TOPIC_UNLOCKED ." WHERE topic_id = {$tor['topic_id']} LIMIT 1"); + } + else + { + $this->verify_mod_rights($tor['forum_id']); + } + + // Подтверждение изменения статуса, выставленного другим модератором + if ($tor['tor_status'] != TOR_NOT_APPROVED && $tor['checked_user_id'] != $userdata['user_id'] && $tor['checked_time'] + 2*3600 > TIMENOW) + { + if (empty($this->request['confirmed'])) + { + $msg = $lang['TOR_STATUS_OF'] ." {$lang['TOR_STATUS_NAME'][$tor['tor_status']]}\n\n"; + $msg .= ($username = get_username($tor['checked_user_id'])) ? $lang['TOR_STATUS_CHANGED'] . html_entity_decode($username) .", ". delta_time($tor['checked_time']) . $lang['TOR_BACK'] ."\n\n" : ""; + $msg .= $lang['PROCEED'] .'?'; + $this->prompt_for_confirm($msg); + } + } + + change_tor_status($attach_id, $new_status); + + $this->response['status'] = $bb_cfg['tor_icons'][$new_status] .' '. $lang['TOR_STATUS_NAME'][$new_status]. ' · '. profile_url($userdata) .' · '. delta_time(TIMENOW) . $lang['TOR_BACK']. ''; + + if ($bb_cfg['tor_comment'] && (($comment && $comment != $lang['COMMENT']) || in_array($new_status, $bb_cfg['tor_reply']))) + { + if ($tor['poster_id'] > 0) + { + $subject = sprintf($lang['TOR_MOD_TITLE'], $tor['topic_title']); + $message = sprintf($lang['TOR_MOD_MSG'], get_username($tor['poster_id']), make_url(TOPIC_URL . $tor['topic_id']), $bb_cfg['tor_icons'][$new_status] .' '.$lang['TOR_STATUS_NAME'][$new_status]); + + if ($comment && $comment != $lang['COMMENT']) $message .= "\n\n[b]". $lang['COMMENT'] .'[/b]: '. $comment; + + send_pm($tor['poster_id'], $subject, $message, $userdata['user_id']); + cache_rm_user_sessions($tor['poster_id']); + } + } + break; + + case 'status_reply': + if (!$bb_cfg['tor_comment']) $this->ajax_die($lang['MODULE_OFF']); + + $subject = sprintf($lang['TOR_AUTH_TITLE'], $tor['topic_title']); + $message = sprintf($lang['TOR_AUTH_MSG'], get_username($tor['checked_user_id']), make_url(TOPIC_URL . $tor['topic_id']), $tor['topic_title']); + + if ($comment && $comment != $lang['COMMENT']) $message .= "\n\n[b]". $lang['COMMENT'] .'[/b]: '. $comment; + + send_pm($tor['checked_user_id'], $subject, $message, $userdata['user_id']); + cache_rm_user_sessions($tor['checked_user_id']); + break; +} + $this->response['attach_id'] = $attach_id; \ No newline at end of file diff --git a/upload/ajax/change_torrent.php b/upload/ajax/change_torrent.php index e9277796d..6d1445a66 100644 --- a/upload/ajax/change_torrent.php +++ b/upload/ajax/change_torrent.php @@ -1,104 +1,104 @@ -request['attach_id'])) -{ - $this->ajax_die($lang['EMPTY_ATTACH_ID']); -} -if (!isset($this->request['type'])) -{ - $this->ajax_die('type'); -} -$attach_id = (int) $this->request['attach_id']; -$type = (string) $this->request['type']; - -$torrent = DB()->fetch_row(" - SELECT - a.post_id, d.physical_filename, d.extension, d.tracker_status, - t.topic_first_post_id, - p.poster_id, p.topic_id, p.forum_id, - f.allow_reg_tracker - FROM - ". BB_ATTACHMENTS ." a, - ". BB_ATTACHMENTS_DESC ." d, - ". BB_POSTS ." p, - ". BB_TOPICS ." t, - ". BB_FORUMS ." f - WHERE - a.attach_id = $attach_id - AND d.attach_id = $attach_id - AND p.post_id = a.post_id - AND t.topic_id = p.topic_id - AND f.forum_id = p.forum_id - LIMIT 1 - "); - -if (!$torrent) $this->ajax_die($lang['INVALID_ATTACH_ID']); - -if ($torrent['poster_id'] == $userdata['user_id'] && !IS_AM) -{ - if ($type == 'del_torrent' || $type == 'reg' || $type == 'unreg') - { - true; - } - else - { - $this->ajax_die($lang['ONLY_FOR_MOD']); - } -} -elseif (!IS_AM) -{ - $this->ajax_die($lang['ONLY_FOR_MOD']); -} - -$title = $url = ''; -switch ($type) -{ - case 'set_gold'; - case 'set_silver'; - case 'unset_silver_gold'; - if ($type == 'set_silver') - { - $tor_type = TOR_TYPE_SILVER; - } - elseif ($type == 'set_gold') - { - $tor_type = TOR_TYPE_GOLD; - } - else - { - $tor_type = 0; - } - change_tor_type($attach_id, $tor_type); - $title = $lang['CHANGE_TOR_TYPE']; - $url = make_url(TOPIC_URL . $torrent['topic_id']); - break; - - case 'reg'; - tracker_register($attach_id); - $url = (TOPIC_URL . $torrent['topic_id']); - break; - - case 'unreg'; - tracker_unregister($attach_id); - $url = (TOPIC_URL . $torrent['topic_id']); - break; - - case 'del_torrent'; - if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['DEL_TORRENT']); - delete_torrent($attach_id); - $url = make_url(TOPIC_URL . $torrent['topic_id']); - break; - - case 'del_torrent_move_topic'; - if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['DEL_MOVE_TORRENT']); - delete_torrent($attach_id); - $url = make_url("modcp.php?t={$torrent['topic_id']}&mode=move&sid={$userdata['session_id']}"); - break; -} - -$this->response['url'] = $url; +request['attach_id'])) +{ + $this->ajax_die($lang['EMPTY_ATTACH_ID']); +} +if (!isset($this->request['type'])) +{ + $this->ajax_die('type'); +} +$attach_id = (int) $this->request['attach_id']; +$type = (string) $this->request['type']; + +$torrent = DB()->fetch_row(" + SELECT + a.post_id, d.physical_filename, d.extension, d.tracker_status, + t.topic_first_post_id, + p.poster_id, p.topic_id, p.forum_id, + f.allow_reg_tracker + FROM + ". BB_ATTACHMENTS ." a, + ". BB_ATTACHMENTS_DESC ." d, + ". BB_POSTS ." p, + ". BB_TOPICS ." t, + ". BB_FORUMS ." f + WHERE + a.attach_id = $attach_id + AND d.attach_id = $attach_id + AND p.post_id = a.post_id + AND t.topic_id = p.topic_id + AND f.forum_id = p.forum_id + LIMIT 1 + "); + +if (!$torrent) $this->ajax_die($lang['INVALID_ATTACH_ID']); + +if ($torrent['poster_id'] == $userdata['user_id'] && !IS_AM) +{ + if ($type == 'del_torrent' || $type == 'reg' || $type == 'unreg') + { + true; + } + else + { + $this->ajax_die($lang['ONLY_FOR_MOD']); + } +} +elseif (!IS_AM) +{ + $this->ajax_die($lang['ONLY_FOR_MOD']); +} + +$title = $url = ''; +switch ($type) +{ + case 'set_gold'; + case 'set_silver'; + case 'unset_silver_gold'; + if ($type == 'set_silver') + { + $tor_type = TOR_TYPE_SILVER; + } + elseif ($type == 'set_gold') + { + $tor_type = TOR_TYPE_GOLD; + } + else + { + $tor_type = 0; + } + change_tor_type($attach_id, $tor_type); + $title = $lang['CHANGE_TOR_TYPE']; + $url = make_url(TOPIC_URL . $torrent['topic_id']); + break; + + case 'reg'; + tracker_register($attach_id); + $url = (TOPIC_URL . $torrent['topic_id']); + break; + + case 'unreg'; + tracker_unregister($attach_id); + $url = (TOPIC_URL . $torrent['topic_id']); + break; + + case 'del_torrent'; + if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['DEL_TORRENT']); + delete_torrent($attach_id); + $url = make_url(TOPIC_URL . $torrent['topic_id']); + break; + + case 'del_torrent_move_topic'; + if (empty($this->request['confirmed'])) $this->prompt_for_confirm($lang['DEL_MOVE_TORRENT']); + delete_torrent($attach_id); + $url = make_url("modcp.php?t={$torrent['topic_id']}&mode=move&sid={$userdata['session_id']}"); + break; +} + +$this->response['url'] = $url; $this->response['title'] = $title; \ No newline at end of file diff --git a/upload/ajax/change_user_opt.php b/upload/ajax/change_user_opt.php index 79474075e..5cf33d2ef 100644 --- a/upload/ajax/change_user_opt.php +++ b/upload/ajax/change_user_opt.php @@ -1,33 +1,33 @@ -request['user_id']; -$new_opt = bb_json_decode($this->request['user_opt']); - -if (!$user_id OR !$u_data = get_userdata($user_id)) -{ - $this->ajax_die('invalid user_id'); -} - -if (!is_array($new_opt)) -{ - $this->ajax_die('invalid new_opt'); -} - -foreach ($bf['user_opt'] as $opt_name => $opt_bit) -{ - if (isset($new_opt[$opt_name])) - { - setbit($u_data['user_opt'], $opt_bit, !empty($new_opt[$opt_name])); - } -} - -DB()->query("UPDATE ". BB_USERS ." SET user_opt = {$u_data['user_opt']} WHERE user_id = $user_id LIMIT 1"); - -// Удаляем данные из кеша -cache_rm_user_sessions ($user_id); - +request['user_id']; +$new_opt = bb_json_decode($this->request['user_opt']); + +if (!$user_id OR !$u_data = get_userdata($user_id)) +{ + $this->ajax_die('invalid user_id'); +} + +if (!is_array($new_opt)) +{ + $this->ajax_die('invalid new_opt'); +} + +foreach ($bf['user_opt'] as $opt_name => $opt_bit) +{ + if (isset($new_opt[$opt_name])) + { + setbit($u_data['user_opt'], $opt_bit, !empty($new_opt[$opt_name])); + } +} + +DB()->query("UPDATE ". BB_USERS ." SET user_opt = {$u_data['user_opt']} WHERE user_id = $user_id LIMIT 1"); + +// Удаляем данные из кеша +cache_rm_user_sessions ($user_id); + $this->response['resp_html'] = $lang['SAVED']; \ No newline at end of file diff --git a/upload/ajax/change_user_rank.php b/upload/ajax/change_user_rank.php index 98554480e..a6d283aa0 100644 --- a/upload/ajax/change_user_rank.php +++ b/upload/ajax/change_user_rank.php @@ -1,27 +1,27 @@ -get('ranks'); -$rank_id = intval($this->request['rank_id']); - -if (!$user_id = intval($this->request['user_id']) OR !$profiledata = get_userdata($user_id)) -{ - $this->ajax_die("invalid user_id: $user_id"); -} - -if ($rank_id != 0 && !isset($ranks[$rank_id])) -{ - $this->ajax_die("invalid rank_id: $rank_id"); -} - -DB()->query("UPDATE ". BB_USERS ." SET user_rank = $rank_id WHERE user_id = $user_id LIMIT 1"); - -cache_rm_user_sessions($user_id); - -$user_rank = ($rank_id) ? ''. $ranks[$rank_id]['rank_title'] .'' : ''; - -$this->response['html'] = ($rank_id) ? $lang['AWARDED_RANK'] . " $user_rank " : $lang['SHOT_RANK']; -$this->response['rank_name'] = ($rank_id) ? $user_rank : $lang['USER']; +get('ranks'); +$rank_id = intval($this->request['rank_id']); + +if (!$user_id = intval($this->request['user_id']) OR !$profiledata = get_userdata($user_id)) +{ + $this->ajax_die("invalid user_id: $user_id"); +} + +if ($rank_id != 0 && !isset($ranks[$rank_id])) +{ + $this->ajax_die("invalid rank_id: $rank_id"); +} + +DB()->query("UPDATE ". BB_USERS ." SET user_rank = $rank_id WHERE user_id = $user_id LIMIT 1"); + +cache_rm_user_sessions($user_id); + +$user_rank = ($rank_id) ? ''. $ranks[$rank_id]['rank_title'] .'' : ''; + +$this->response['html'] = ($rank_id) ? $lang['AWARDED_RANK'] . " $user_rank " : $lang['SHOT_RANK']; +$this->response['rank_name'] = ($rank_id) ? $user_rank : $lang['USER']; diff --git a/upload/ajax/edit_user_profile.php b/upload/ajax/edit_user_profile.php index 458a0ff6d..04e11f890 100644 --- a/upload/ajax/edit_user_profile.php +++ b/upload/ajax/edit_user_profile.php @@ -1,168 +1,168 @@ -request['user_id']) OR !$profiledata = get_userdata($user_id)) -{ - $this->ajax_die($lang['NO_USER_ID_SPECIFIED']); -} -if (!$field = (string) $this->request['field']) -{ - $this->ajax_die('invalid profile field'); -} - -$table = BB_USERS; -$value = $this->request['value'] = (string) (isset($this->request['value'])) ? $this->request['value'] : 0; - -switch ($field) -{ - case 'username': - require_once(INC_DIR .'functions_validate.php'); - $value = clean_username($value); - if ($err = validate_username($value)) - { - $this->ajax_die(strip_tags($err)); - } - $this->response['new_value'] = $this->request['value']; - break; - - case 'user_email': - require_once(INC_DIR .'functions_validate.php'); - $value = htmlCHR($value); - if ($err = validate_email($value)) - { - $this->ajax_die($err); - } - $this->response['new_value'] = $this->request['value']; - break; - - case 'user_website': - if ($value == '' || preg_match('#^https?://[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]+$#iu', $value)) - { - $this->response['new_value'] = htmlCHR($value); - } - else $this->ajax_die($lang['WEBSITE_ERROR']); - break; - - case 'user_gender': - if (!$bb_cfg['gender']) $this->ajax_die($lang['MODULE_OFF']); - if (!isset($lang['GENDER_SELECT'][$value])) - { - $this->ajax_die($lang['ERROR']); - } - else $this->response['new_value'] = $lang['GENDER_SELECT'][$value]; - break; - - case 'user_birthday': - if (!$bb_cfg['birthday_enabled']) $this->ajax_die($lang['MODULE_OFF']); - $birthday_date = date_parse($value); - - if (!empty($birthday_date['year'])) - { - if (strtotime($value) >= TIMENOW) - { - $this->ajax_die($lang['WRONG_BIRTHDAY_FORMAT']); - } - elseif (bb_date(TIMENOW, 'Y', 'false') - $birthday_date['year'] > $bb_cfg['birthday_max_age']) - { - $this->ajax_die(sprintf($lang['BIRTHDAY_TO_HIGH'], $bb_cfg['birthday_max_age'])); - } - elseif (bb_date(TIMENOW, 'Y', 'false') - $birthday_date['year'] < $bb_cfg['birthday_min_age']) - { - $this->ajax_die(sprintf($lang['BIRTHDAY_TO_LOW'], $bb_cfg['birthday_min_age'])); - } - } - - $this->response['new_value'] = $this->request['value']; - break; - - case 'user_icq': - if ($value && !preg_match('#^\d{6,15}$#', $value)) - { - $this->ajax_die($lang['ICQ_ERROR']); - } - $this->response['new_value'] = $this->request['value']; - break; - - case 'user_skype': - if ($value && !preg_match("#^[a-zA-Z0-9_.\-@,]{6,32}$#", $value)) - { - $this->ajax_die($lang['SKYPE_ERROR']); - } - $this->response['new_value'] = $this->request['value']; - break; - - case 'user_twitter': - if ($value && !preg_match("#^[a-zA-Z0-9_]{1,15}$#", $value)) - { - $this->ajax_die($lang['TWITTER_ERROR']); - } - $this->response['new_value'] = $this->request['value']; - break; - - case 'user_from': - case 'user_occ': - case 'user_interests': - $value = htmlCHR($value); - $this->response['new_value'] = $value; - break; - - case 'user_regdate': - case 'user_lastvisit': - $tz = TIMENOW + (3600 * $bb_cfg['board_timezone']); - if (($value = strtotime($value, $tz)) < $bb_cfg['board_startdate'] OR $value > TIMENOW) - { - $this->ajax_die($lang['INVALID_DATE'] . $this->request['value']); - } - $this->response['new_value'] = bb_date($value, 'Y-m-d H:i', false); - break; - - case 'u_up_total': - case 'u_down_total': - case 'u_up_release': - case 'u_up_bonus': - if (!IS_ADMIN) $this->ajax_die($lang['NOT_ADMIN']); - - $table = BB_BT_USERS; - $value = (float) str_replace(',', '.', $this->request['value']); - - foreach (array('KB'=>1,'MB'=>2,'GB'=>3,'TB'=>4) as $s => $m) - { - if (strpos($this->request['value'], $s) !== false) - { - $value *= pow(1024, $m); - break; - } - } - $value = sprintf('%.0f', $value); - $this->response['new_value'] = humn_size($value, null, null, ' '); - - if (!$btu = get_bt_userdata($user_id)) - { - require(INC_DIR .'functions_torrent.php'); - generate_passkey($user_id, true); - $btu = get_bt_userdata($user_id); - } - $btu[$field] = $value; - $this->response['update_ids']['u_ratio'] = (string) get_bt_ratio($btu); - break; - - case 'user_points': - $value = htmlCHR($value); - $value = (float) str_replace(',', '.', $this->request['value']); - $value = sprintf('%.2f', $value); - $this->response['new_value'] = $value; - break; - - default: - $this->ajax_die("invalid profile field: $field"); -} - -$value_sql = DB()->escape($value, true); -DB()->query("UPDATE $table SET $field = $value_sql WHERE user_id = $user_id LIMIT 1"); - -cache_rm_user_sessions ($user_id); - +request['user_id']) OR !$profiledata = get_userdata($user_id)) +{ + $this->ajax_die($lang['NO_USER_ID_SPECIFIED']); +} +if (!$field = (string) $this->request['field']) +{ + $this->ajax_die('invalid profile field'); +} + +$table = BB_USERS; +$value = $this->request['value'] = (string) (isset($this->request['value'])) ? $this->request['value'] : 0; + +switch ($field) +{ + case 'username': + require_once(INC_DIR .'functions_validate.php'); + $value = clean_username($value); + if ($err = validate_username($value)) + { + $this->ajax_die(strip_tags($err)); + } + $this->response['new_value'] = $this->request['value']; + break; + + case 'user_email': + require_once(INC_DIR .'functions_validate.php'); + $value = htmlCHR($value); + if ($err = validate_email($value)) + { + $this->ajax_die($err); + } + $this->response['new_value'] = $this->request['value']; + break; + + case 'user_website': + if ($value == '' || preg_match('#^https?://[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]+$#iu', $value)) + { + $this->response['new_value'] = htmlCHR($value); + } + else $this->ajax_die($lang['WEBSITE_ERROR']); + break; + + case 'user_gender': + if (!$bb_cfg['gender']) $this->ajax_die($lang['MODULE_OFF']); + if (!isset($lang['GENDER_SELECT'][$value])) + { + $this->ajax_die($lang['ERROR']); + } + else $this->response['new_value'] = $lang['GENDER_SELECT'][$value]; + break; + + case 'user_birthday': + if (!$bb_cfg['birthday_enabled']) $this->ajax_die($lang['MODULE_OFF']); + $birthday_date = date_parse($value); + + if (!empty($birthday_date['year'])) + { + if (strtotime($value) >= TIMENOW) + { + $this->ajax_die($lang['WRONG_BIRTHDAY_FORMAT']); + } + elseif (bb_date(TIMENOW, 'Y', 'false') - $birthday_date['year'] > $bb_cfg['birthday_max_age']) + { + $this->ajax_die(sprintf($lang['BIRTHDAY_TO_HIGH'], $bb_cfg['birthday_max_age'])); + } + elseif (bb_date(TIMENOW, 'Y', 'false') - $birthday_date['year'] < $bb_cfg['birthday_min_age']) + { + $this->ajax_die(sprintf($lang['BIRTHDAY_TO_LOW'], $bb_cfg['birthday_min_age'])); + } + } + + $this->response['new_value'] = $this->request['value']; + break; + + case 'user_icq': + if ($value && !preg_match('#^\d{6,15}$#', $value)) + { + $this->ajax_die($lang['ICQ_ERROR']); + } + $this->response['new_value'] = $this->request['value']; + break; + + case 'user_skype': + if ($value && !preg_match("#^[a-zA-Z0-9_.\-@,]{6,32}$#", $value)) + { + $this->ajax_die($lang['SKYPE_ERROR']); + } + $this->response['new_value'] = $this->request['value']; + break; + + case 'user_twitter': + if ($value && !preg_match("#^[a-zA-Z0-9_]{1,15}$#", $value)) + { + $this->ajax_die($lang['TWITTER_ERROR']); + } + $this->response['new_value'] = $this->request['value']; + break; + + case 'user_from': + case 'user_occ': + case 'user_interests': + $value = htmlCHR($value); + $this->response['new_value'] = $value; + break; + + case 'user_regdate': + case 'user_lastvisit': + $tz = TIMENOW + (3600 * $bb_cfg['board_timezone']); + if (($value = strtotime($value, $tz)) < $bb_cfg['board_startdate'] OR $value > TIMENOW) + { + $this->ajax_die($lang['INVALID_DATE'] . $this->request['value']); + } + $this->response['new_value'] = bb_date($value, 'Y-m-d H:i', false); + break; + + case 'u_up_total': + case 'u_down_total': + case 'u_up_release': + case 'u_up_bonus': + if (!IS_ADMIN) $this->ajax_die($lang['NOT_ADMIN']); + + $table = BB_BT_USERS; + $value = (float) str_replace(',', '.', $this->request['value']); + + foreach (array('KB'=>1,'MB'=>2,'GB'=>3,'TB'=>4) as $s => $m) + { + if (strpos($this->request['value'], $s) !== false) + { + $value *= pow(1024, $m); + break; + } + } + $value = sprintf('%.0f', $value); + $this->response['new_value'] = humn_size($value, null, null, ' '); + + if (!$btu = get_bt_userdata($user_id)) + { + require(INC_DIR .'functions_torrent.php'); + generate_passkey($user_id, true); + $btu = get_bt_userdata($user_id); + } + $btu[$field] = $value; + $this->response['update_ids']['u_ratio'] = (string) get_bt_ratio($btu); + break; + + case 'user_points': + $value = htmlCHR($value); + $value = (float) str_replace(',', '.', $this->request['value']); + $value = sprintf('%.2f', $value); + $this->response['new_value'] = $value; + break; + + default: + $this->ajax_die("invalid profile field: $field"); +} + +$value_sql = DB()->escape($value, true); +DB()->query("UPDATE $table SET $field = $value_sql WHERE user_id = $user_id LIMIT 1"); + +cache_rm_user_sessions ($user_id); + $this->response['edit_id'] = $this->request['edit_id']; \ No newline at end of file diff --git a/upload/ajax/gen_passkey.php b/upload/ajax/gen_passkey.php index 9802181e4..a3d94bb08 100644 --- a/upload/ajax/gen_passkey.php +++ b/upload/ajax/gen_passkey.php @@ -1,25 +1,25 @@ -request['user_id']; - -if ($req_uid == $userdata['user_id'] || IS_ADMIN) -{ - if (empty($this->request['confirmed'])) - { - $this->prompt_for_confirm($lang['BT_GEN_PASSKEY_NEW']); - } - - if (!$passkey = generate_passkey($req_uid, IS_ADMIN)) - { - $this->ajax_die('Could not insert passkey'); - } - - tracker_rm_user($req_uid); - - $this->response['passkey'] = $passkey; -} +request['user_id']; + +if ($req_uid == $userdata['user_id'] || IS_ADMIN) +{ + if (empty($this->request['confirmed'])) + { + $this->prompt_for_confirm($lang['BT_GEN_PASSKEY_NEW']); + } + + if (!$passkey = generate_passkey($req_uid, IS_ADMIN)) + { + $this->ajax_die('Could not insert passkey'); + } + + tracker_rm_user($req_uid); + + $this->response['passkey'] = $passkey; +} else $this->ajax_die($lang['NOT_AUTHORISED']); \ No newline at end of file diff --git a/upload/ajax/group_membership.php b/upload/ajax/group_membership.php index ad9c0459d..76ac136ae 100644 --- a/upload/ajax/group_membership.php +++ b/upload/ajax/group_membership.php @@ -1,69 +1,69 @@ -request['user_id']) OR !$profiledata = get_userdata($user_id)) -{ - $this->ajax_die("invalid user_id: $user_id"); -} - -if (!$mode = (string) $this->request['mode']) -{ - $this->ajax_die('invalid mode (empty)'); -} - -switch ($mode) -{ - case 'get_group_list': - $sql = " - SELECT ug.user_pending, g.group_id, g.group_type, g.group_name, g.group_moderator, self.user_id AS can_view - FROM ". BB_USER_GROUP ." ug - INNER JOIN ". BB_GROUPS ." g ON(g.group_id = ug.group_id AND g.group_single_user = 0) - LEFT JOIN ". BB_USER_GROUP ." self ON(self.group_id = g.group_id AND self.user_id = {$user->id} AND self.user_pending = 0) - WHERE ug.user_id = $user_id - ORDER BY g.group_name - "; - $html = array(); - foreach (DB()->fetch_rowset($sql) as $row) - { - $class = ($row['user_pending']) ? 'med' : 'med bold'; - $class .= ($row['group_moderator'] == $user_id) ? ' colorMod' : ''; - $href = "groupcp.php?g={$row['group_id']}"; - - if (IS_ADMIN) - { - $href .= "&u=$user_id"; - $link = ''. htmlCHR($row['group_name']) .''; - $html[] = $link; - } - else - { - // скрытая группа и сам юзер не является ее членом - if ($row['group_type'] == GROUP_HIDDEN && !$row['can_view']) - { - continue; - } - if ($row['group_moderator'] == $user->id) - { - $class .= ' selfMod'; - $href .= "&u=$user_id"; // сам юзер модератор этой группы - } - $link = ''. htmlCHR($row['group_name']) .''; - $html[] = $link; - } - } - if ($html) - { - $this->response['group_list_html'] = '
        • '. join('
        • ', $html) .'
        '; - } - else - { - $this->response['group_list_html'] = $lang['GROUP_LIST_HIDDEN']; - } - break; - - default: - $this->ajax_die("invalid mode: $mode"); +request['user_id']) OR !$profiledata = get_userdata($user_id)) +{ + $this->ajax_die("invalid user_id: $user_id"); +} + +if (!$mode = (string) $this->request['mode']) +{ + $this->ajax_die('invalid mode (empty)'); +} + +switch ($mode) +{ + case 'get_group_list': + $sql = " + SELECT ug.user_pending, g.group_id, g.group_type, g.group_name, g.group_moderator, self.user_id AS can_view + FROM ". BB_USER_GROUP ." ug + INNER JOIN ". BB_GROUPS ." g ON(g.group_id = ug.group_id AND g.group_single_user = 0) + LEFT JOIN ". BB_USER_GROUP ." self ON(self.group_id = g.group_id AND self.user_id = {$user->id} AND self.user_pending = 0) + WHERE ug.user_id = $user_id + ORDER BY g.group_name + "; + $html = array(); + foreach (DB()->fetch_rowset($sql) as $row) + { + $class = ($row['user_pending']) ? 'med' : 'med bold'; + $class .= ($row['group_moderator'] == $user_id) ? ' colorMod' : ''; + $href = "groupcp.php?g={$row['group_id']}"; + + if (IS_ADMIN) + { + $href .= "&u=$user_id"; + $link = ''. htmlCHR($row['group_name']) .''; + $html[] = $link; + } + else + { + // скрытая группа и сам юзер не является ее членом + if ($row['group_type'] == GROUP_HIDDEN && !$row['can_view']) + { + continue; + } + if ($row['group_moderator'] == $user->id) + { + $class .= ' selfMod'; + $href .= "&u=$user_id"; // сам юзер модератор этой группы + } + $link = ''. htmlCHR($row['group_name']) .''; + $html[] = $link; + } + } + if ($html) + { + $this->response['group_list_html'] = '
        • '. join('
        • ', $html) .'
        '; + } + else + { + $this->response['group_list_html'] = $lang['GROUP_LIST_HIDDEN']; + } + break; + + default: + $this->ajax_die("invalid mode: $mode"); } \ No newline at end of file diff --git a/upload/ajax/index_data.php b/upload/ajax/index_data.php index 5b355026e..834514a15 100644 --- a/upload/ajax/index_data.php +++ b/upload/ajax/index_data.php @@ -1,132 +1,132 @@ -request['mode']; -$html = ''; - -switch($mode) -{ - case 'birthday_week': - $stats = $datastore->get('stats'); - $datastore->enqueue(array( - 'stats', - )); - - if ($stats['birthday_week_list']) - { - foreach($stats['birthday_week_list'] as $week) - { - $html[] = profile_url($week) .' ('. birthday_age($week['user_birthday']) .')'; - } - $html = sprintf($lang['BIRTHDAY_WEEK'], $bb_cfg['birthday_check_day'], join(', ', $html)); - } - else $html = sprintf($lang['NOBIRTHDAY_WEEK'], $bb_cfg['birthday_check_day']); - break; - - case 'birthday_today': - $stats = $datastore->get('stats'); - $datastore->enqueue(array( - 'stats', - )); - - if ($stats['birthday_today_list']) - { - foreach($stats['birthday_today_list'] as $today) - { - $html[] = profile_url($today) .' ('. birthday_age($today['user_birthday']) .')'; - } - $html = $lang['BIRTHDAY_TODAY'] . join(', ', $html); - } - else $html = $lang['NOBIRTHDAY_TODAY']; - break; - - case 'get_forum_mods': - $forum_id = (int) $this->request['forum_id']; - - $datastore->enqueue(array( - 'moderators', - )); - - $moderators = array(); - $mod = $datastore->get('moderators'); - - if (isset($mod['mod_users'][$forum_id])) - { - foreach ($mod['mod_users'][$forum_id] as $user_id) - { - $moderators[] = ''. $mod['name_users'][$user_id] .''; - } - } - - if (isset($mod['mod_groups'][$forum_id])) - { - foreach ($mod['mod_groups'][$forum_id] as $group_id) - { - $moderators[] = ''. $mod['name_groups'][$group_id] .''; - } - } - - $html = ': '; - $html .= ($moderators) ? join(', ', $moderators) : $lang['NONE']; - unset($moderators, $mod); - $datastore->rm('moderators'); - break; - - case 'change_tz': - $tz = (int) $this->request['tz']; - if ($tz < -12) $tz = -12; - if ($tz > 13) $tz = 13; - if ($tz != $bb_cfg['board_timezone']) - { - // Set current user timezone - DB()->query("UPDATE ". BB_USERS ." SET user_timezone = $tz WHERE user_id = ". $userdata['user_id'] ." LIMIT 1"); - $bb_cfg['board_timezone'] = $tz; - cache_rm_user_sessions ($userdata['user_id']); - } - break; - - case 'get_traf_stats': - $user_id = (int) $this->request['user_id']; - $btu = get_bt_userdata($user_id); - $profiledata = get_userdata($user_id); - - $speed_up = ($btu['speed_up']) ? humn_size($btu['speed_up']).'/s' : '0 KB/s'; - $speed_down = ($btu['speed_down']) ? humn_size($btu['speed_down']).'/s' : '0 KB/s'; - $user_ratio = ($btu['u_down_total'] > MIN_DL_FOR_RATIO) ? ''. get_bt_ratio($btu) .'' : $lang['IT_WILL_BE_DOWN'] .' '. humn_size(MIN_DL_FOR_RATIO) .''; - - $html = ' -
        '. $lang['DOWNLOADED'] .''. $lang['UPLOADED'] .''. $lang['RELEASED'] .''. $lang['BONUS'] .''. $lang['SEED_BONUS'] .'
        '. $lang['TOTAL_TRAF'] .''. humn_size($btu['u_down_total']) .'' .humn_size($btu['u_up_total']) .''. humn_size($btu['u_up_release']) .''. humn_size($btu['u_up_bonus']) .''. $profiledata['user_points'] .'
        '. $lang['MAX_SPEED'] .''. $lang['DL_DL_SPEED'] .': '. $speed_down .''. $lang['DL_UL_SPEED'] .': '. $speed_up .'
        '. $lang['USER_RATIO'] .':'. $user_ratio .'
        '. $lang['DOWNLOADED'] .''. $lang['UPLOADED'] .''. $lang['RELEASED'] .''. $lang['BONUS'] .''. $lang['SEED_BONUS'] .'
        '. $lang['TOTAL_TRAF'] .''. humn_size($btu['u_down_total']) .'' .humn_size($btu['u_up_total']) .''. humn_size($btu['u_up_release']) .''. humn_size($btu['u_up_bonus']) .''. $profiledata['user_points'] .'
        '. $lang['MAX_SPEED'] .''. $lang['DL_DL_SPEED'] .': '. $speed_down .''. $lang['DL_UL_SPEED'] .': '. $speed_up .'
        '. $lang['USER_RATIO'] .':'. $user_ratio .'
        - - - - - - - - - - -
        '. $lang['REG_IP'] .''. $reg_ip .'
        '. $link_reg_ip .'
        '. $lang['LAST_IP'] .''. $last_ip .'
        '. $link_last_ip .'

        - '; - break; +request['mode']; + +switch ($mode) +{ + case 'tor_status': + $topics = (string) $this->request['topic_ids']; + $status = (int) $this->request['status']; + + // Валидность статуса + if (!isset($lang['TOR_STATUS_NAME'][$status])) + { + $this->ajax_die($lang['STATUS_DOES_EXIST'] . $new_status); + } + + $topic_ids = DB()->fetch_rowset("SELECT attach_id FROM ". BB_BT_TORRENTS ." WHERE topic_id IN($topics)", 'attach_id'); + + foreach($topic_ids as $attach_id) + { + change_tor_status($attach_id, $status); + } + $this->response['status'] = $bb_cfg['tor_icons'][$status]; + $this->response['topics'] = explode(',', $topics); + break; + + case 'edit_topic_title': + $topic_id = (int) $this->request['topic_id']; + $topic_title = (string) $this->request['topic_title']; + $new_title = clean_title($topic_title); + + if (!$topic_id) $this->ajax_die($lang['INVALID_TOPIC_ID']); + if ($new_title == '') $this->ajax_die($lang['DONT_MESSAGE_TITLE']); + + if (!$t_data = DB()->fetch_row("SELECT forum_id FROM ". BB_TOPICS ." WHERE topic_id = $topic_id LIMIT 1")) + { + $this->ajax_die($lang['INVALID_TOPIC_ID_DB']); + } + $this->verify_mod_rights($t_data['forum_id']); + + $topic_title_sql = DB()->escape($new_title); + + DB()->query("UPDATE ". BB_TOPICS ." SET topic_title = '$topic_title_sql' WHERE topic_id = $topic_id LIMIT 1"); + + // Обновление кеша новостей на главной + $news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id'])); + if (isset($news_forums[$t_data['forum_id']]) && $bb_cfg['show_latest_news']) + { + $datastore->enqueue('latest_news'); + $datastore->update('latest_news'); + } + + $net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id'])); + if (isset($net_forums[$t_data['forum_id']]) && $bb_cfg['show_network_news']) + { + $datastore->enqueue('network_news'); + $datastore->update('network_news'); + } + + $this->response['topic_id'] = $topic_id; + $this->response['topic_title'] = $new_title; + break; + + case 'profile_ip': + $user_id = (int) $this->request['user_id']; + $profiledata = get_userdata($user_id); + + if (!$user_id) $this->ajax_die($lang['NO_USER_ID_SPECIFIED']); + + $reg_ip = DB()->fetch_rowset("SELECT username, user_id, user_rank FROM ". BB_USERS ." + WHERE user_reg_ip = '{$profiledata['user_reg_ip']}' + AND user_reg_ip != '' + AND user_id != {$profiledata['user_id']} + ORDER BY username ASC"); + + $last_ip = DB()->fetch_rowset("SELECT username, user_id, user_rank FROM " .BB_USERS ." + WHERE user_last_ip = '{$profiledata['user_last_ip']}' + AND user_last_ip != '' + AND user_id != {$profiledata['user_id']}"); + + $link_reg_ip = $link_last_ip = ''; + + if (!empty($reg_ip)) + { + $link_reg_ip .= $lang['OTHER_IP'] .' '; + foreach ($reg_ip as $row) + { + $link_reg_ip .= profile_url($row) .' '; + } + } + + if (!empty($last_ip)) + { + $link_last_ip .= $lang['OTHER_IP'] .' '; + foreach ($last_ip as $row) + { + $link_last_ip .= profile_url($row) .' '; + } + } + + if ($profiledata['user_level'] == ADMIN && !IS_ADMIN) $reg_ip = $last_ip = $lang['HIDDEN']; + elseif ($profiledata['user_level'] == MOD && IS_MOD) $reg_ip = $last_ip = $lang['HIDDEN']; + else + { + $user_reg_ip = decode_ip($profiledata['user_reg_ip']); + $user_last_ip = decode_ip($profiledata['user_last_ip']); + $reg_ip = ''. $user_reg_ip .''; + $last_ip = ''. $user_last_ip .''; + } + + $this->response['ip_list_html'] = ' +
        + + + + + + + + + + +
        '. $lang['REG_IP'] .''. $reg_ip .'
        '. $link_reg_ip .'
        '. $lang['LAST_IP'] .''. $last_ip .'
        '. $link_last_ip .'

        + '; + break; } \ No newline at end of file diff --git a/upload/ajax/post_mod_comment.php b/upload/ajax/post_mod_comment.php index 0d97d6ba8..3cc5e0f5a 100644 --- a/upload/ajax/post_mod_comment.php +++ b/upload/ajax/post_mod_comment.php @@ -1,60 +1,60 @@ -request['post_id']; -$mc_type = (int) $this->request['mc_type']; -$mc_text = (string) $this->request['mc_text']; -if (!$mc_text = prepare_message($mc_text)) $this->ajax_die($lang['EMPTY_MESSAGE']); - -$post = DB()->fetch_row(" - SELECT - p.post_id, p.poster_id - FROM ". BB_POSTS ." p - WHERE p.post_id = $post_id -"); -if (!$post) $this->ajax_die('not post'); - -$data = array( - 'mc_comment' => ($mc_type) ? $mc_text : '', - 'mc_type' => $mc_type, - 'mc_user_id' => ($mc_type) ? $userdata['user_id'] : 0, -); -$sql_args = DB()->build_array('UPDATE', $data); -DB()->query("UPDATE ". BB_POSTS ." SET $sql_args WHERE post_id = $post_id"); - -if ($mc_type && $post['poster_id'] != $userdata['user_id']) -{ - $subject = sprintf($lang['MC_COMMENT_PM_SUBJECT'], $lang['MC_COMMENT'][$mc_type]['type']); - $message = sprintf($lang['MC_COMMENT_PM_MSG'], get_username($post['poster_id']), make_url(POST_URL ."$post_id#$post_id"), $lang['MC_COMMENT'][$mc_type]['type'], $mc_text); - - send_pm($post['poster_id'], $subject, $message); - cache_rm_user_sessions($post['poster_id']); -} - -switch($mc_type) -{ - case 1: // Комментарий - $mc_class = 'success'; - break; - case 2: // Информация - $mc_class = 'info'; - break; - case 3: // Предупреждение - $mc_class = 'warning'; - break; - case 4: // Нарушение - $mc_class = 'danger'; - break; - default: - $mc_class = ''; - break; -} - -$this->response['mc_type'] = $mc_type; -$this->response['post_id'] = $post_id; -$this->response['mc_title'] = sprintf($lang['MC_COMMENT'][$mc_type]['title'], profile_url($userdata)); -$this->response['mc_text'] = bbcode2html($mc_text); +request['post_id']; +$mc_type = (int) $this->request['mc_type']; +$mc_text = (string) $this->request['mc_text']; +if (!$mc_text = prepare_message($mc_text)) $this->ajax_die($lang['EMPTY_MESSAGE']); + +$post = DB()->fetch_row(" + SELECT + p.post_id, p.poster_id + FROM ". BB_POSTS ." p + WHERE p.post_id = $post_id +"); +if (!$post) $this->ajax_die('not post'); + +$data = array( + 'mc_comment' => ($mc_type) ? $mc_text : '', + 'mc_type' => $mc_type, + 'mc_user_id' => ($mc_type) ? $userdata['user_id'] : 0, +); +$sql_args = DB()->build_array('UPDATE', $data); +DB()->query("UPDATE ". BB_POSTS ." SET $sql_args WHERE post_id = $post_id"); + +if ($mc_type && $post['poster_id'] != $userdata['user_id']) +{ + $subject = sprintf($lang['MC_COMMENT_PM_SUBJECT'], $lang['MC_COMMENT'][$mc_type]['type']); + $message = sprintf($lang['MC_COMMENT_PM_MSG'], get_username($post['poster_id']), make_url(POST_URL ."$post_id#$post_id"), $lang['MC_COMMENT'][$mc_type]['type'], $mc_text); + + send_pm($post['poster_id'], $subject, $message); + cache_rm_user_sessions($post['poster_id']); +} + +switch($mc_type) +{ + case 1: // Комментарий + $mc_class = 'success'; + break; + case 2: // Информация + $mc_class = 'info'; + break; + case 3: // Предупреждение + $mc_class = 'warning'; + break; + case 4: // Нарушение + $mc_class = 'danger'; + break; + default: + $mc_class = ''; + break; +} + +$this->response['mc_type'] = $mc_type; +$this->response['post_id'] = $post_id; +$this->response['mc_title'] = sprintf($lang['MC_COMMENT'][$mc_type]['title'], profile_url($userdata)); +$this->response['mc_text'] = bbcode2html($mc_text); $this->response['mc_class'] = $mc_class; \ No newline at end of file diff --git a/upload/ajax/topic_tpl.php b/upload/ajax/topic_tpl.php index 8e2ad698a..fdc366349 100644 --- a/upload/ajax/topic_tpl.php +++ b/upload/ajax/topic_tpl.php @@ -1,172 +1,172 @@ -ajax_die('not auth'); - -array_deep($this->request, 'trim'); - -$mode = (string) $this->request['mode']; -$sql_error = false; - -// установка / начальная валидация значений -switch ($mode) -{ - case 'load': - case 'save': - if (!$tpl_id = (int) $this->request['tpl_id']) - { - $this->ajax_die('Выбранный шаблон не найден, создайте новый (empty tpl_id)'); - } - if (!$tpl_data = DB()->fetch_row("SELECT * FROM ". BB_TOPIC_TPL ." WHERE tpl_id = $tpl_id LIMIT 1")) - { - $this->ajax_die("Шаблон [id: $tpl_id] не найден в БД"); - } - break; -} -switch ($mode) -{ - case 'save': - case 'new': - if (!$tpl_name = htmlCHR(str_compact($this->request['tpl_name']))) - { - $this->ajax_die('не заполнено название шаблона'); - } - $tpl_name = substr($tpl_name, 0, 60); - - if (!$tpl_src_form = htmlCHR($this->request['tpl_src_form'])) - { - $this->ajax_die('не заполнен скрипт формы шаблона'); - } - if (!$tpl_src_title = htmlCHR($this->request['tpl_src_title'])) - { - $this->ajax_die('не заполнен формат названия темы'); - } - $tpl_src_title = str_compact($tpl_src_title); - - if (!$tpl_src_msg = htmlCHR($this->request['tpl_src_msg'])) - { - $this->ajax_die('не заполнен формат создания сообщения'); - } - - $tpl_comment = htmlCHR($this->request['tpl_comment']); - - preg_match('#\d+#', (string) $this->request['tpl_rules'], $m); - $tpl_rules_post_id = isset($m[0]) ? (int) $m[0] : 0; - - $sql_args = array( - 'tpl_name' => (string) $tpl_name, - 'tpl_src_form' => (string) $tpl_src_form, - 'tpl_src_title' => (string) $tpl_src_title, - 'tpl_src_msg' => (string) $tpl_src_msg, - 'tpl_comment' => (string) $tpl_comment, - 'tpl_rules_post_id' => (int) $tpl_rules_post_id, - 'tpl_last_edit_tm' => (int) TIMENOW, - 'tpl_last_edit_by' => (int) $userdata['user_id'], - ); - break; -} -// выполнение -switch ($mode) -{ - // загрузка шаблона - case 'load': - $this->response['val']['tpl-name-save'] = $tpl_data['tpl_name']; - $this->response['val']['tpl-src-form'] = $tpl_data['tpl_src_form']; - $this->response['val']['tpl-src-title'] = $tpl_data['tpl_src_title']; - $this->response['val']['tpl-src-msg'] = $tpl_data['tpl_src_msg']; - $this->response['val']['tpl-comment-save'] = $tpl_data['tpl_comment']; - $this->response['val']['tpl-rules-save'] = $tpl_data['tpl_rules_post_id']; - array_deep($this->response['val'], 'html_ent_decode'); - - $this->response['val']['tpl-id-save'] = $tpl_id; - $this->response['val']['tpl-last-edit-tst'] = $tpl_data['tpl_last_edit_tm']; - $this->response['html']['tpl-name-old-save'] = $tpl_data['tpl_name']; - $this->response['html']['tpl-last-edit-time'] = bb_date($tpl_data['tpl_last_edit_tm'], 'd-M-y H:i'); - $this->response['html']['tpl-last-edit-by'] = get_username(intval($tpl_data['tpl_last_edit_by'])); - - $this->response['tpl_rules_href'] = POST_URL . $tpl_data['tpl_rules_post_id'] .'#'. $tpl_data['tpl_rules_post_id']; - break; - - // включение / отключение шаблона в форуме - case 'assign': - if (!$tpl_id = (int) $this->request['tpl_id']) - { - $this->ajax_die('Выбранный шаблон не найден, создайте новый (empty tpl_id)'); - } - if (!$forum_id = (int) $this->request['forum_id']) - { - $this->ajax_die('empty forum_id'); - } - if (!forum_exists($forum_id)) - { - $this->ajax_die("нет такого форума [id: $forum_id]"); - } - // отключение - if ($tpl_id == -1) - { - $new_tpl_id = 0; - $this->response['msg'] = 'Шаблоны в этом форуме отключены'; - } - // включение - else - { - if (!$tpl_name = DB()->fetch_row("SELECT tpl_name FROM ". BB_TOPIC_TPL ." WHERE tpl_id = $tpl_id LIMIT 1", 'tpl_name')) - { - $this->ajax_die("Шаблон [id: $tpl_id] не найден в БД"); - } - $new_tpl_id = $tpl_id; - $this->response['msg'] = "Включен шаблон $tpl_name"; - } - DB()->query("UPDATE ". BB_FORUMS ." SET forum_tpl_id = $new_tpl_id WHERE forum_id = $forum_id LIMIT 1"); - break; - - // сохранение изменений - case 'save': - if ($tpl_data['tpl_last_edit_tm'] > $this->request['tpl_l_ed_tst'] && $tpl_data['tpl_last_edit_by'] != $userdata['user_id']) - { - $last_edit_by_username = get_username(intval($tpl_data['tpl_last_edit_by'])); - $msg = "Изменения не были сохранены!\n\n"; - $msg .= 'Шаблон был отредактирован: '. html_entity_decode($last_edit_by_username) .', '. delta_time($tpl_data['tpl_last_edit_tm']) ." назад\n\n"; - $this->ajax_die($msg); - } - $sql = "UPDATE ". BB_TOPIC_TPL ." SET ". DB()->build_array('UPDATE', $sql_args) ." WHERE tpl_id = $tpl_id LIMIT 1"; - if (!@DB()->query($sql)) - { - $sql_error = DB()->sql_error(); - } - $this->response['tpl_id'] = $tpl_id; - $this->response['tpl_name'] = $tpl_name; - $this->response['html']['tpl-last-edit-time'] = bb_date(TIMENOW, 'd-M-y H:i'); - $this->response['html']['tpl-last-edit-by'] = $userdata['username']; - break; - - // создание нового шаблона - case 'new': - $sql = "INSERT INTO ". BB_TOPIC_TPL . DB()->build_array('INSERT', $sql_args); - if (!@DB()->query($sql)) - { - $sql_error = DB()->sql_error(); - } - break; - - // ошибочный $mode - default: - $this->ajax_die("invalid mode: $mode"); -} - -// возможный дубль названия шаблона -if ($sql_error) -{ - if ($sql_error['code'] == 1062) // Duplicate entry - { - $this->ajax_die('Шаблон с таким названием уже существует, выберите другое название'); - } - $this->ajax_die("db error {$sql_error['code']}: {$sql_error['message']}"); -} - -// выход -$this->response['mode'] = $mode; +ajax_die('not auth'); + +array_deep($this->request, 'trim'); + +$mode = (string) $this->request['mode']; +$sql_error = false; + +// установка / начальная валидация значений +switch ($mode) +{ + case 'load': + case 'save': + if (!$tpl_id = (int) $this->request['tpl_id']) + { + $this->ajax_die('Выбранный шаблон не найден, создайте новый (empty tpl_id)'); + } + if (!$tpl_data = DB()->fetch_row("SELECT * FROM ". BB_TOPIC_TPL ." WHERE tpl_id = $tpl_id LIMIT 1")) + { + $this->ajax_die("Шаблон [id: $tpl_id] не найден в БД"); + } + break; +} +switch ($mode) +{ + case 'save': + case 'new': + if (!$tpl_name = htmlCHR(str_compact($this->request['tpl_name']))) + { + $this->ajax_die('не заполнено название шаблона'); + } + $tpl_name = substr($tpl_name, 0, 60); + + if (!$tpl_src_form = htmlCHR($this->request['tpl_src_form'])) + { + $this->ajax_die('не заполнен скрипт формы шаблона'); + } + if (!$tpl_src_title = htmlCHR($this->request['tpl_src_title'])) + { + $this->ajax_die('не заполнен формат названия темы'); + } + $tpl_src_title = str_compact($tpl_src_title); + + if (!$tpl_src_msg = htmlCHR($this->request['tpl_src_msg'])) + { + $this->ajax_die('не заполнен формат создания сообщения'); + } + + $tpl_comment = htmlCHR($this->request['tpl_comment']); + + preg_match('#\d+#', (string) $this->request['tpl_rules'], $m); + $tpl_rules_post_id = isset($m[0]) ? (int) $m[0] : 0; + + $sql_args = array( + 'tpl_name' => (string) $tpl_name, + 'tpl_src_form' => (string) $tpl_src_form, + 'tpl_src_title' => (string) $tpl_src_title, + 'tpl_src_msg' => (string) $tpl_src_msg, + 'tpl_comment' => (string) $tpl_comment, + 'tpl_rules_post_id' => (int) $tpl_rules_post_id, + 'tpl_last_edit_tm' => (int) TIMENOW, + 'tpl_last_edit_by' => (int) $userdata['user_id'], + ); + break; +} +// выполнение +switch ($mode) +{ + // загрузка шаблона + case 'load': + $this->response['val']['tpl-name-save'] = $tpl_data['tpl_name']; + $this->response['val']['tpl-src-form'] = $tpl_data['tpl_src_form']; + $this->response['val']['tpl-src-title'] = $tpl_data['tpl_src_title']; + $this->response['val']['tpl-src-msg'] = $tpl_data['tpl_src_msg']; + $this->response['val']['tpl-comment-save'] = $tpl_data['tpl_comment']; + $this->response['val']['tpl-rules-save'] = $tpl_data['tpl_rules_post_id']; + array_deep($this->response['val'], 'html_ent_decode'); + + $this->response['val']['tpl-id-save'] = $tpl_id; + $this->response['val']['tpl-last-edit-tst'] = $tpl_data['tpl_last_edit_tm']; + $this->response['html']['tpl-name-old-save'] = $tpl_data['tpl_name']; + $this->response['html']['tpl-last-edit-time'] = bb_date($tpl_data['tpl_last_edit_tm'], 'd-M-y H:i'); + $this->response['html']['tpl-last-edit-by'] = get_username(intval($tpl_data['tpl_last_edit_by'])); + + $this->response['tpl_rules_href'] = POST_URL . $tpl_data['tpl_rules_post_id'] .'#'. $tpl_data['tpl_rules_post_id']; + break; + + // включение / отключение шаблона в форуме + case 'assign': + if (!$tpl_id = (int) $this->request['tpl_id']) + { + $this->ajax_die('Выбранный шаблон не найден, создайте новый (empty tpl_id)'); + } + if (!$forum_id = (int) $this->request['forum_id']) + { + $this->ajax_die('empty forum_id'); + } + if (!forum_exists($forum_id)) + { + $this->ajax_die("нет такого форума [id: $forum_id]"); + } + // отключение + if ($tpl_id == -1) + { + $new_tpl_id = 0; + $this->response['msg'] = 'Шаблоны в этом форуме отключены'; + } + // включение + else + { + if (!$tpl_name = DB()->fetch_row("SELECT tpl_name FROM ". BB_TOPIC_TPL ." WHERE tpl_id = $tpl_id LIMIT 1", 'tpl_name')) + { + $this->ajax_die("Шаблон [id: $tpl_id] не найден в БД"); + } + $new_tpl_id = $tpl_id; + $this->response['msg'] = "Включен шаблон $tpl_name"; + } + DB()->query("UPDATE ". BB_FORUMS ." SET forum_tpl_id = $new_tpl_id WHERE forum_id = $forum_id LIMIT 1"); + break; + + // сохранение изменений + case 'save': + if ($tpl_data['tpl_last_edit_tm'] > $this->request['tpl_l_ed_tst'] && $tpl_data['tpl_last_edit_by'] != $userdata['user_id']) + { + $last_edit_by_username = get_username(intval($tpl_data['tpl_last_edit_by'])); + $msg = "Изменения не были сохранены!\n\n"; + $msg .= 'Шаблон был отредактирован: '. html_entity_decode($last_edit_by_username) .', '. delta_time($tpl_data['tpl_last_edit_tm']) ." назад\n\n"; + $this->ajax_die($msg); + } + $sql = "UPDATE ". BB_TOPIC_TPL ." SET ". DB()->build_array('UPDATE', $sql_args) ." WHERE tpl_id = $tpl_id LIMIT 1"; + if (!@DB()->query($sql)) + { + $sql_error = DB()->sql_error(); + } + $this->response['tpl_id'] = $tpl_id; + $this->response['tpl_name'] = $tpl_name; + $this->response['html']['tpl-last-edit-time'] = bb_date(TIMENOW, 'd-M-y H:i'); + $this->response['html']['tpl-last-edit-by'] = $userdata['username']; + break; + + // создание нового шаблона + case 'new': + $sql = "INSERT INTO ". BB_TOPIC_TPL . DB()->build_array('INSERT', $sql_args); + if (!@DB()->query($sql)) + { + $sql_error = DB()->sql_error(); + } + break; + + // ошибочный $mode + default: + $this->ajax_die("invalid mode: $mode"); +} + +// возможный дубль названия шаблона +if ($sql_error) +{ + if ($sql_error['code'] == 1062) // Duplicate entry + { + $this->ajax_die('Шаблон с таким названием уже существует, выберите другое название'); + } + $this->ajax_die("db error {$sql_error['code']}: {$sql_error['message']}"); +} + +// выход +$this->response['mode'] = $mode; $this->response['timestamp'] = TIMENOW; \ No newline at end of file diff --git a/upload/ajax/user_register.php b/upload/ajax/user_register.php index b11d7eb5c..3639d128a 100644 --- a/upload/ajax/user_register.php +++ b/upload/ajax/user_register.php @@ -1,76 +1,76 @@ -request['mode']; - -$html = ''; -switch($mode) -{ - case 'check_name': - $username = clean_username($this->request['username']); - - if (empty($username)) - { - $html = ' '. $lang['CHOOSE_A_NAME'] .''; - } - elseif($err = validate_username($username)) - { - $html = ' '. $err .''; - } - break; - - case 'check_email': - $email = (string) $this->request['email']; - - if (empty($email)) - { - $html = ' '. $lang['CHOOSE_E_MAIL'] .''; - } - elseif($err = validate_email($email)) - { - $html = ' '. $err .''; - } - break; - - case 'check_pass': - $pass = (string) $this->request['pass']; - $pass_confirm = (string) $this->request['pass_confirm']; - if (empty($pass) || empty($pass_confirm)) - { - $html = ' '. $lang['CHOOSE_PASS'] .''; - } - else - { - if ($pass != $pass_confirm) - { - $html = ' '. $lang['CHOOSE_PASS_ERR'] .''; - } - else - { - if (mb_strlen($pass, 'UTF-8') > 20) - { - $html = ' '. sprintf($lang['CHOOSE_PASS_ERR_MAX'], 20) .''; - } - elseif (mb_strlen($pass, 'UTF-8') < 5) - { - $html = ' '. sprintf($lang['CHOOSE_PASS_ERR_MIN'], 5) .''; - } - else - { - $text = (IS_GUEST) ? $lang['CHOOSE_PASS_REG_OK'] : $lang['CHOOSE_PASS_OK']; - $html = ' '. $text .''; - } - } - } - break; - - case 'refresh_captcha'; - $html = CAPTCHA()->get_html(); - break; -} - -$this->response['html'] = $html; +request['mode']; + +$html = ''; +switch($mode) +{ + case 'check_name': + $username = clean_username($this->request['username']); + + if (empty($username)) + { + $html = ' '. $lang['CHOOSE_A_NAME'] .''; + } + elseif($err = validate_username($username)) + { + $html = ' '. $err .''; + } + break; + + case 'check_email': + $email = (string) $this->request['email']; + + if (empty($email)) + { + $html = ' '. $lang['CHOOSE_E_MAIL'] .''; + } + elseif($err = validate_email($email)) + { + $html = ' '. $err .''; + } + break; + + case 'check_pass': + $pass = (string) $this->request['pass']; + $pass_confirm = (string) $this->request['pass_confirm']; + if (empty($pass) || empty($pass_confirm)) + { + $html = ' '. $lang['CHOOSE_PASS'] .''; + } + else + { + if ($pass != $pass_confirm) + { + $html = ' '. $lang['CHOOSE_PASS_ERR'] .''; + } + else + { + if (mb_strlen($pass, 'UTF-8') > 20) + { + $html = ' '. sprintf($lang['CHOOSE_PASS_ERR_MAX'], 20) .''; + } + elseif (mb_strlen($pass, 'UTF-8') < 5) + { + $html = ' '. sprintf($lang['CHOOSE_PASS_ERR_MIN'], 5) .''; + } + else + { + $text = (IS_GUEST) ? $lang['CHOOSE_PASS_REG_OK'] : $lang['CHOOSE_PASS_OK']; + $html = ' '. $text .''; + } + } + } + break; + + case 'refresh_captcha'; + $html = CAPTCHA()->get_html(); + break; +} + +$this->response['html'] = $html; $this->response['mode'] = $mode; \ No newline at end of file diff --git a/upload/ajax/view_post.php b/upload/ajax/view_post.php index c8317b012..2f0415b7a 100644 --- a/upload/ajax/view_post.php +++ b/upload/ajax/view_post.php @@ -1,53 +1,53 @@ -request['post_id']; -$topic_id = (int) @$this->request['topic_id']; - -if (!$post_id) -{ - $post_id = DB()->fetch_row("SELECT topic_first_post_id FROM ". BB_TOPICS ." WHERE topic_id = $topic_id", 'topic_first_post_id'); -} - -$sql = " - SELECT - p.*, - h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text, - f.auth_read - FROM ". BB_POSTS ." p - INNER JOIN ". BB_POSTS_TEXT ." pt ON(pt.post_id = p.post_id) - LEFT JOIN ". BB_POSTS_HTML ." h ON(h.post_id = pt.post_id) - INNER JOIN ". BB_FORUMS ." f ON(f.forum_id = p.forum_id) - WHERE - p.post_id = $post_id - LIMIT 1 -"; - -if (!$post_data = DB()->fetch_row($sql)) -{ - $this->ajax_die($lang['TOPIC_POST_NOT_EXIST']); -} - -// Auth check -if ($post_data['auth_read'] == AUTH_REG) -{ - if (IS_GUEST) - { - $this->ajax_die($lang['NEED_TO_LOGIN_FIRST']); - } -} -elseif ($post_data['auth_read'] != AUTH_ALL) -{ - $is_auth = auth(AUTH_READ, $post_data['forum_id'], $user->data, $post_data); - if (!$is_auth['auth_read']) - { - $this->ajax_die($lang['TOPIC_POST_NOT_EXIST']); - } -} - -$this->response['post_id'] = $post_id; -$this->response['topic_id'] = $topic_id; +request['post_id']; +$topic_id = (int) @$this->request['topic_id']; + +if (!$post_id) +{ + $post_id = DB()->fetch_row("SELECT topic_first_post_id FROM ". BB_TOPICS ." WHERE topic_id = $topic_id", 'topic_first_post_id'); +} + +$sql = " + SELECT + p.*, + h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text, + f.auth_read + FROM ". BB_POSTS ." p + INNER JOIN ". BB_POSTS_TEXT ." pt ON(pt.post_id = p.post_id) + LEFT JOIN ". BB_POSTS_HTML ." h ON(h.post_id = pt.post_id) + INNER JOIN ". BB_FORUMS ." f ON(f.forum_id = p.forum_id) + WHERE + p.post_id = $post_id + LIMIT 1 +"; + +if (!$post_data = DB()->fetch_row($sql)) +{ + $this->ajax_die($lang['TOPIC_POST_NOT_EXIST']); +} + +// Auth check +if ($post_data['auth_read'] == AUTH_REG) +{ + if (IS_GUEST) + { + $this->ajax_die($lang['NEED_TO_LOGIN_FIRST']); + } +} +elseif ($post_data['auth_read'] != AUTH_ALL) +{ + $is_auth = auth(AUTH_READ, $post_data['forum_id'], $user->data, $post_data); + if (!$is_auth['auth_read']) + { + $this->ajax_die($lang['TOPIC_POST_NOT_EXIST']); + } +} + +$this->response['post_id'] = $post_id; +$this->response['topic_id'] = $topic_id; $this->response['post_html'] = get_parsed_post($post_data); \ No newline at end of file diff --git a/upload/ajax/view_torrent.php b/upload/ajax/view_torrent.php index 7e0cc5e3f..e339acc90 100644 --- a/upload/ajax/view_torrent.php +++ b/upload/ajax/view_torrent.php @@ -1,172 +1,172 @@ -request['attach_id'])) -{ - $this->ajax_die($lang['EMPTY_ATTACH_ID']); -} -$attach_id = (int) $this->request['attach_id']; - -$torrent = DB()->fetch_row("SELECT at.attach_id, at.physical_filename FROM ". BB_ATTACHMENTS_DESC ." at WHERE at.attach_id = $attach_id LIMIT 1"); -if (!$torrent) $this->ajax_die($lang['EMPTY_ATTACH_ID']); -$filename = get_attachments_dir() .'/'. $torrent['physical_filename']; - -if (($file_contents = @file_get_contents($filename)) === false) -{ - if (IS_AM) - { - $this->ajax_die($lang['ERROR_NO_ATTACHMENT'] ."\n\n". htmlCHR($filename)); - } - else - { - $this->ajax_die($lang['ERROR_NO_ATTACHMENT']); - } -} - -// Построение списка -$tor_filelist = build_tor_filelist($file_contents); - -function build_tor_filelist ($file_contents) -{ - global $lang; - - if (!$tor = bdecode($file_contents)) - { - return $lang['TORFILE_INVALID']; - } - - $torrent = new torrent($tor); - - return $torrent->get_filelist(); -} - -class torrent -{ - var $tor_decoded = array(); - var $files_ary = array('/' => ''); - var $multiple = null; - var $root_dir = ''; - var $files_html = ''; - - function torrent ($decoded_file_contents) - { - $this->tor_decoded = $decoded_file_contents; - } - - function get_filelist () - { - $this->build_filelist_array(); - - if ($this->multiple) - { - if ($this->files_ary['/'] !== '') - { - $this->files_ary = array_merge($this->files_ary, $this->files_ary['/']); - unset($this->files_ary['/']); - } - $filelist = $this->build_filelist_html(); - return "
        {$this->root_dir}
        $filelist"; - } - else - { - return join('', $this->files_ary['/']); - } - } - - function build_filelist_array () - { - global $lang; - - $info = $this->tor_decoded['info']; - - if (isset($info['name.utf-8'])) - { - $info['name'] =& $info['name.utf-8']; - } - - if (isset($info['files']) && is_array($info['files'])) - { - $this->root_dir = isset($info['name']) ? '../'. clean_tor_dirname($info['name']) : '...'; - $this->multiple = true; - - foreach ($info['files'] as $f) - { - if (isset($f['path.utf-8'])) - { - $f['path'] =& $f['path.utf-8']; - } - if (!isset($f['path']) || !is_array($f['path'])) - { - continue; - } - array_deep($f['path'], 'clean_tor_dirname'); - - $length = isset($f['length']) ? (float) $f['length'] : 0; - $subdir_count = count($f['path']) - 1; - - if ($subdir_count > 0) - { - $name = array_pop($f['path']); - $cur_files_ary =& $this->files_ary; - - for ($i=0,$j=1; $i < $subdir_count; $i++,$j++) - { - $subdir = $f['path'][$i]; - - if (!isset($cur_files_ary[$subdir])) - { - $cur_files_ary[$subdir] = array(); - } - $cur_files_ary =& $cur_files_ary[$subdir]; - - if ($j == $subdir_count) - { - if (is_string($cur_files_ary)) - { - bb_die($lang['ERROR_BUILD']); - } - $cur_files_ary[] = $this->build_file_item($name, $length); - } - } - @natsort($cur_files_ary); - } - else - { - $name = $f['path'][0]; - $this->files_ary['/'][] = $this->build_file_item($name, $length); - natsort($this->files_ary['/']); - } - } - } - else - { - $this->multiple = false; - $name = isset($info['name']) ? clean_tor_dirname($info['name']) : ''; - $length = isset($info['length']) ? (int) $info['length'] : 0; - - $this->files_ary['/'][] = $this->build_file_item($name, $length); - natsort($this->files_ary['/']); - } - } - - function build_file_item ($name, $length) - { - return "$name $length"; - } - - function build_filelist_html () - { - global $html; - return $html->array2html($this->files_ary); - } -} - -function clean_tor_dirname ($dirname) -{ - return str_replace(array('[', ']', '<', '>', "'"), array('[', ']', '<', '>', '''), $dirname); -} - +request['attach_id'])) +{ + $this->ajax_die($lang['EMPTY_ATTACH_ID']); +} +$attach_id = (int) $this->request['attach_id']; + +$torrent = DB()->fetch_row("SELECT at.attach_id, at.physical_filename FROM ". BB_ATTACHMENTS_DESC ." at WHERE at.attach_id = $attach_id LIMIT 1"); +if (!$torrent) $this->ajax_die($lang['EMPTY_ATTACH_ID']); +$filename = get_attachments_dir() .'/'. $torrent['physical_filename']; + +if (($file_contents = @file_get_contents($filename)) === false) +{ + if (IS_AM) + { + $this->ajax_die($lang['ERROR_NO_ATTACHMENT'] ."\n\n". htmlCHR($filename)); + } + else + { + $this->ajax_die($lang['ERROR_NO_ATTACHMENT']); + } +} + +// Построение списка +$tor_filelist = build_tor_filelist($file_contents); + +function build_tor_filelist ($file_contents) +{ + global $lang; + + if (!$tor = bdecode($file_contents)) + { + return $lang['TORFILE_INVALID']; + } + + $torrent = new torrent($tor); + + return $torrent->get_filelist(); +} + +class torrent +{ + var $tor_decoded = array(); + var $files_ary = array('/' => ''); + var $multiple = null; + var $root_dir = ''; + var $files_html = ''; + + function torrent ($decoded_file_contents) + { + $this->tor_decoded = $decoded_file_contents; + } + + function get_filelist () + { + $this->build_filelist_array(); + + if ($this->multiple) + { + if ($this->files_ary['/'] !== '') + { + $this->files_ary = array_merge($this->files_ary, $this->files_ary['/']); + unset($this->files_ary['/']); + } + $filelist = $this->build_filelist_html(); + return "
        {$this->root_dir}
        $filelist"; + } + else + { + return join('', $this->files_ary['/']); + } + } + + function build_filelist_array () + { + global $lang; + + $info = $this->tor_decoded['info']; + + if (isset($info['name.utf-8'])) + { + $info['name'] =& $info['name.utf-8']; + } + + if (isset($info['files']) && is_array($info['files'])) + { + $this->root_dir = isset($info['name']) ? '../'. clean_tor_dirname($info['name']) : '...'; + $this->multiple = true; + + foreach ($info['files'] as $f) + { + if (isset($f['path.utf-8'])) + { + $f['path'] =& $f['path.utf-8']; + } + if (!isset($f['path']) || !is_array($f['path'])) + { + continue; + } + array_deep($f['path'], 'clean_tor_dirname'); + + $length = isset($f['length']) ? (float) $f['length'] : 0; + $subdir_count = count($f['path']) - 1; + + if ($subdir_count > 0) + { + $name = array_pop($f['path']); + $cur_files_ary =& $this->files_ary; + + for ($i=0,$j=1; $i < $subdir_count; $i++,$j++) + { + $subdir = $f['path'][$i]; + + if (!isset($cur_files_ary[$subdir])) + { + $cur_files_ary[$subdir] = array(); + } + $cur_files_ary =& $cur_files_ary[$subdir]; + + if ($j == $subdir_count) + { + if (is_string($cur_files_ary)) + { + bb_die($lang['ERROR_BUILD']); + } + $cur_files_ary[] = $this->build_file_item($name, $length); + } + } + @natsort($cur_files_ary); + } + else + { + $name = $f['path'][0]; + $this->files_ary['/'][] = $this->build_file_item($name, $length); + natsort($this->files_ary['/']); + } + } + } + else + { + $this->multiple = false; + $name = isset($info['name']) ? clean_tor_dirname($info['name']) : ''; + $length = isset($info['length']) ? (int) $info['length'] : 0; + + $this->files_ary['/'][] = $this->build_file_item($name, $length); + natsort($this->files_ary['/']); + } + } + + function build_file_item ($name, $length) + { + return "$name $length"; + } + + function build_filelist_html () + { + global $html; + return $html->array2html($this->files_ary); + } +} + +function clean_tor_dirname ($dirname) +{ + return str_replace(array('[', ']', '<', '>', "'"), array('[', ']', '<', '>', '''), $dirname); +} + $this->response['html'] = $tor_filelist; \ No newline at end of file diff --git a/upload/attach_mod/includes/functions_includes.php b/upload/attach_mod/includes/functions_includes.php index 122314be6..a5784ed56 100644 --- a/upload/attach_mod/includes/functions_includes.php +++ b/upload/attach_mod/includes/functions_includes.php @@ -1,204 +1,204 @@ -'; - $s_auth_can .= (($is_auth['auth_download']) ? $lang['RULES_DOWNLOAD_CAN'] : $lang['RULES_DOWNLOAD_CANNOT'] ) . '
        '; -} - -/** -* Called from admin_users.php and admin_groups.php in order to process Quota Settings (admin/admin_users.php:admin/admin_groups.php) -*/ -function attachment_quota_settings($admin_mode, $submit = false, $mode) -{ - global $template, $lang, $attach_config; - - if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':')) - { - $upload_dir = $attach_config['upload_dir']; - } - else - { - $upload_dir = BB_ROOT . $attach_config['upload_dir']; - } - - include(BB_ROOT .'attach_mod/includes/functions_selects.php'); - if (!function_exists("process_quota_settings")) - include(BB_ROOT . 'attach_mod/includes/functions_admin.php'); - - $user_id = 0; - - if ($admin_mode == 'user') - { - // We overwrite submit here... to be sure - $submit = (isset($_POST['submit'])) ? true : false; - - if (!$submit && $mode != 'save') - { - $user_id = get_var(POST_USERS_URL, 0); - $u_name = get_var('username', ''); - - if (!$user_id && !$u_name) - { - bb_die($lang['NO_USER_ID_SPECIFIED'] ); - } - - if ($user_id) - { - $this_userdata['user_id'] = $user_id; - } - else - { - // Get userdata is handling the sanitizing of username - $this_userdata = get_userdata($_POST['username'], true); - } - - $user_id = (int) $this_userdata['user_id']; - } - else - { - $user_id = get_var('id', 0); - - if (!$user_id) - { - bb_die($lang['NO_USER_ID_SPECIFIED'] ); - } - } - } - - if ($admin_mode == 'user' && !$submit && $mode != 'save') - { - // Show the contents - $sql = 'SELECT quota_limit_id, quota_type FROM ' . BB_QUOTA . ' WHERE user_id = ' . (int) $user_id; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Unable to get quota settings #1'); - } - - $pm_quota = $upload_quota = 0; - - if ($row = DB()->sql_fetchrow($result)) - { - do - { - if ($row['quota_type'] == QUOTA_UPLOAD_LIMIT) - { - $upload_quota = $row['quota_limit_id']; - } - else if ($row['quota_type'] == QUOTA_PM_LIMIT) - { - $pm_quota = $row['quota_limit_id']; - } - } - while ($row = DB()->sql_fetchrow($result)); - } - else - { - // Set Default Quota Limit - $upload_quota = $attach_config['default_upload_quota']; - $pm_quota = $attach_config['default_pm_quota']; - - } - DB()->sql_freeresult($result); - - $template->assign_vars(array( - 'S_SELECT_UPLOAD_QUOTA' => quota_limit_select('user_upload_quota', $upload_quota), - 'S_SELECT_PM_QUOTA' => quota_limit_select('user_pm_quota', $pm_quota), - )); - } - - if ($admin_mode == 'user' && $submit && @$_POST['delete_user']) - { - process_quota_settings($admin_mode, $user_id, QUOTA_UPLOAD_LIMIT, 0); - process_quota_settings($admin_mode, $user_id, QUOTA_PM_LIMIT, 0); - } - else if ($admin_mode == 'user' && $submit && $mode == 'save') - { - // Get the contents - $upload_quota = get_var('user_upload_quota', 0); - $pm_quota = get_var('user_pm_quota', 0); - - process_quota_settings($admin_mode, $user_id, QUOTA_UPLOAD_LIMIT, $upload_quota); - process_quota_settings($admin_mode, $user_id, QUOTA_PM_LIMIT, $pm_quota); - } - - if ($admin_mode == 'group' && $mode == 'newgroup') - { - return; - } - - if ($admin_mode == 'group' && !$submit && isset($_POST['edit'])) - { - // Get group id again - $group_id = get_var(POST_GROUPS_URL, 0); - - // Show the contents - $sql = 'SELECT quota_limit_id, quota_type FROM ' . BB_QUOTA . ' WHERE group_id = ' . (int) $group_id; - - if (!($result = DB()->sql_query($sql))) - { - bb_die('Unable to get quota settings #2'); - } - - $pm_quota = $upload_quota = 0; - - if ($row = DB()->sql_fetchrow($result)) - { - do - { - if ($row['quota_type'] == QUOTA_UPLOAD_LIMIT) - { - $upload_quota = $row['quota_limit_id']; - } - else if ($row['quota_type'] == QUOTA_PM_LIMIT) - { - $pm_quota = $row['quota_limit_id']; - } - } - while ($row = DB()->sql_fetchrow($result)); - } - else - { - // Set Default Quota Limit - $upload_quota = $attach_config['default_upload_quota']; - $pm_quota = $attach_config['default_pm_quota']; - } - DB()->sql_freeresult($result); - - $template->assign_vars(array( - 'S_SELECT_UPLOAD_QUOTA' => quota_limit_select('group_upload_quota', $upload_quota), - 'S_SELECT_PM_QUOTA' => quota_limit_select('group_pm_quota', $pm_quota), - )); - } - - if ($admin_mode == 'group' && $submit && isset($_POST['group_delete'])) - { - $group_id = get_var(POST_GROUPS_URL, 0); - - process_quota_settings($admin_mode, $group_id, QUOTA_UPLOAD_LIMIT, 0); - process_quota_settings($admin_mode, $group_id, QUOTA_PM_LIMIT, 0); - } - else if ($admin_mode == 'group' && $submit) - { - $group_id = get_var(POST_GROUPS_URL, 0); - - // Get the contents - $upload_quota = get_var('group_upload_quota', 0); - $pm_quota = get_var('group_pm_quota', 0); - - process_quota_settings($admin_mode, $group_id, QUOTA_UPLOAD_LIMIT, $upload_quota); - process_quota_settings($admin_mode, $group_id, QUOTA_PM_LIMIT, $pm_quota); - } +'; + $s_auth_can .= (($is_auth['auth_download']) ? $lang['RULES_DOWNLOAD_CAN'] : $lang['RULES_DOWNLOAD_CANNOT'] ) . '
        '; +} + +/** +* Called from admin_users.php and admin_groups.php in order to process Quota Settings (admin/admin_users.php:admin/admin_groups.php) +*/ +function attachment_quota_settings($admin_mode, $submit = false, $mode) +{ + global $template, $lang, $attach_config; + + if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':')) + { + $upload_dir = $attach_config['upload_dir']; + } + else + { + $upload_dir = BB_ROOT . $attach_config['upload_dir']; + } + + include(BB_ROOT .'attach_mod/includes/functions_selects.php'); + if (!function_exists("process_quota_settings")) + include(BB_ROOT . 'attach_mod/includes/functions_admin.php'); + + $user_id = 0; + + if ($admin_mode == 'user') + { + // We overwrite submit here... to be sure + $submit = (isset($_POST['submit'])) ? true : false; + + if (!$submit && $mode != 'save') + { + $user_id = get_var(POST_USERS_URL, 0); + $u_name = get_var('username', ''); + + if (!$user_id && !$u_name) + { + bb_die($lang['NO_USER_ID_SPECIFIED'] ); + } + + if ($user_id) + { + $this_userdata['user_id'] = $user_id; + } + else + { + // Get userdata is handling the sanitizing of username + $this_userdata = get_userdata($_POST['username'], true); + } + + $user_id = (int) $this_userdata['user_id']; + } + else + { + $user_id = get_var('id', 0); + + if (!$user_id) + { + bb_die($lang['NO_USER_ID_SPECIFIED'] ); + } + } + } + + if ($admin_mode == 'user' && !$submit && $mode != 'save') + { + // Show the contents + $sql = 'SELECT quota_limit_id, quota_type FROM ' . BB_QUOTA . ' WHERE user_id = ' . (int) $user_id; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Unable to get quota settings #1'); + } + + $pm_quota = $upload_quota = 0; + + if ($row = DB()->sql_fetchrow($result)) + { + do + { + if ($row['quota_type'] == QUOTA_UPLOAD_LIMIT) + { + $upload_quota = $row['quota_limit_id']; + } + else if ($row['quota_type'] == QUOTA_PM_LIMIT) + { + $pm_quota = $row['quota_limit_id']; + } + } + while ($row = DB()->sql_fetchrow($result)); + } + else + { + // Set Default Quota Limit + $upload_quota = $attach_config['default_upload_quota']; + $pm_quota = $attach_config['default_pm_quota']; + + } + DB()->sql_freeresult($result); + + $template->assign_vars(array( + 'S_SELECT_UPLOAD_QUOTA' => quota_limit_select('user_upload_quota', $upload_quota), + 'S_SELECT_PM_QUOTA' => quota_limit_select('user_pm_quota', $pm_quota), + )); + } + + if ($admin_mode == 'user' && $submit && @$_POST['delete_user']) + { + process_quota_settings($admin_mode, $user_id, QUOTA_UPLOAD_LIMIT, 0); + process_quota_settings($admin_mode, $user_id, QUOTA_PM_LIMIT, 0); + } + else if ($admin_mode == 'user' && $submit && $mode == 'save') + { + // Get the contents + $upload_quota = get_var('user_upload_quota', 0); + $pm_quota = get_var('user_pm_quota', 0); + + process_quota_settings($admin_mode, $user_id, QUOTA_UPLOAD_LIMIT, $upload_quota); + process_quota_settings($admin_mode, $user_id, QUOTA_PM_LIMIT, $pm_quota); + } + + if ($admin_mode == 'group' && $mode == 'newgroup') + { + return; + } + + if ($admin_mode == 'group' && !$submit && isset($_POST['edit'])) + { + // Get group id again + $group_id = get_var(POST_GROUPS_URL, 0); + + // Show the contents + $sql = 'SELECT quota_limit_id, quota_type FROM ' . BB_QUOTA . ' WHERE group_id = ' . (int) $group_id; + + if (!($result = DB()->sql_query($sql))) + { + bb_die('Unable to get quota settings #2'); + } + + $pm_quota = $upload_quota = 0; + + if ($row = DB()->sql_fetchrow($result)) + { + do + { + if ($row['quota_type'] == QUOTA_UPLOAD_LIMIT) + { + $upload_quota = $row['quota_limit_id']; + } + else if ($row['quota_type'] == QUOTA_PM_LIMIT) + { + $pm_quota = $row['quota_limit_id']; + } + } + while ($row = DB()->sql_fetchrow($result)); + } + else + { + // Set Default Quota Limit + $upload_quota = $attach_config['default_upload_quota']; + $pm_quota = $attach_config['default_pm_quota']; + } + DB()->sql_freeresult($result); + + $template->assign_vars(array( + 'S_SELECT_UPLOAD_QUOTA' => quota_limit_select('group_upload_quota', $upload_quota), + 'S_SELECT_PM_QUOTA' => quota_limit_select('group_pm_quota', $pm_quota), + )); + } + + if ($admin_mode == 'group' && $submit && isset($_POST['group_delete'])) + { + $group_id = get_var(POST_GROUPS_URL, 0); + + process_quota_settings($admin_mode, $group_id, QUOTA_UPLOAD_LIMIT, 0); + process_quota_settings($admin_mode, $group_id, QUOTA_PM_LIMIT, 0); + } + else if ($admin_mode == 'group' && $submit) + { + $group_id = get_var(POST_GROUPS_URL, 0); + + // Get the contents + $upload_quota = get_var('group_upload_quota', 0); + $pm_quota = get_var('group_pm_quota', 0); + + process_quota_settings($admin_mode, $group_id, QUOTA_UPLOAD_LIMIT, $upload_quota); + process_quota_settings($admin_mode, $group_id, QUOTA_PM_LIMIT, $pm_quota); + } } \ No newline at end of file diff --git a/upload/bt/includes/.htaccess b/upload/bt/includes/.htaccess index 47e399d8f..baa56e5a3 100644 --- a/upload/bt/includes/.htaccess +++ b/upload/bt/includes/.htaccess @@ -1,2 +1,2 @@ -order allow,deny +order allow,deny deny from all \ No newline at end of file diff --git a/upload/callseed.php b/upload/callseed.php index 9ec856a17..0db99f1cd 100644 --- a/upload/callseed.php +++ b/upload/callseed.php @@ -1,94 +1,94 @@ -session_start(array('req_login' => true)); - -$topic_id = (int) request_var('t', 0); -$t_data = topic_info($topic_id); -$forum_id = $t_data['forum_id']; - -set_die_append_msg($forum_id, $topic_id); - -if ($t_data['seeders'] > 2) -{ - bb_die(sprintf($lang['CALLSEED_HAVE_SEED'], $t_data['seeders'])); -} -elseif ($t_data['call_seed_time'] > (TIMENOW - 86400)) -{ - $time_left = delta_time($t_data['call_seed_time'] + 86400, TIMENOW, 'days'); - bb_die(sprintf($lang['CALLSEED_MSG_SPAM'], $time_left)); -} - -$ban_user_id = array(); - -$sql = DB()->fetch_rowset("SELECT ban_userid FROM ". BB_BANLIST ." WHERE ban_userid != 0"); - -foreach ($sql as $row) -{ - $ban_user_id[] = ','. $row['ban_userid']; -} -$ban_user_id = join('', $ban_user_id); - -$user_list = DB()->fetch_rowset(" - SELECT DISTINCT dl.user_id, u.user_opt, tr.user_id as active_dl - FROM ". BB_BT_DLSTATUS ." dl - LEFT JOIN ". BB_USERS ." u ON(u.user_id = dl.user_id) - LEFT JOIN ". BB_BT_TRACKER ." tr ON(tr.user_id = dl.user_id) - WHERE dl.topic_id = $topic_id - AND dl.user_status IN (". DL_STATUS_COMPLETE.", ". DL_STATUS_DOWN.") - AND dl.user_id NOT IN ({$userdata['user_id']}, ". EXCLUDED_USERS_CSV . $ban_user_id .") - AND u.user_active = 1 - GROUP BY dl.user_id -"); - -$subject = sprintf($lang['CALLSEED_SUBJECT'], $t_data['topic_title']); -$message = sprintf($lang['CALLSEED_TEXT'], make_url(TOPIC_URL . $topic_id), $t_data['topic_title'], make_url(DOWNLOAD_URL . $t_data['attach_id'])); - -if ($user_list) -{ - foreach ($user_list as $row) - { - if (!empty($row['active_dl'])) continue; - - if (bf($row['user_opt'], 'user_opt', 'user_callseed')) - { - send_pm($row['user_id'], $subject, $message, BOT_UID); - } - } -} -else -{ - send_pm($t_data['poster_id'], $subject, $message, BOT_UID); -} - -DB()->query("UPDATE ". BB_BT_TORRENTS ." SET call_seed_time = ". TIMENOW ." WHERE topic_id = $topic_id LIMIT 1"); - -meta_refresh(TOPIC_URL . $topic_id); -bb_die($lang['CALLSEED_MSG_OK']); - -function topic_info ($topic_id) -{ - global $lang; - - $sql = " - SELECT - tor.poster_id, tor.forum_id, tor.attach_id, tor.call_seed_time, - t.topic_title, sn.seeders - FROM ". BB_BT_TORRENTS ." tor - LEFT JOIN ". BB_TOPICS ." t USING(topic_id) - LEFT JOIN ". BB_BT_TRACKER_SNAP ." sn USING(topic_id) - WHERE tor.topic_id = $topic_id - "; - - if (!$torrent = DB()->fetch_row($sql)) - { - bb_die($lang['TOPIC_POST_NOT_EXIST']); - } - - return $torrent; -} +session_start(array('req_login' => true)); + +$topic_id = (int) request_var('t', 0); +$t_data = topic_info($topic_id); +$forum_id = $t_data['forum_id']; + +set_die_append_msg($forum_id, $topic_id); + +if ($t_data['seeders'] > 2) +{ + bb_die(sprintf($lang['CALLSEED_HAVE_SEED'], $t_data['seeders'])); +} +elseif ($t_data['call_seed_time'] > (TIMENOW - 86400)) +{ + $time_left = delta_time($t_data['call_seed_time'] + 86400, TIMENOW, 'days'); + bb_die(sprintf($lang['CALLSEED_MSG_SPAM'], $time_left)); +} + +$ban_user_id = array(); + +$sql = DB()->fetch_rowset("SELECT ban_userid FROM ". BB_BANLIST ." WHERE ban_userid != 0"); + +foreach ($sql as $row) +{ + $ban_user_id[] = ','. $row['ban_userid']; +} +$ban_user_id = join('', $ban_user_id); + +$user_list = DB()->fetch_rowset(" + SELECT DISTINCT dl.user_id, u.user_opt, tr.user_id as active_dl + FROM ". BB_BT_DLSTATUS ." dl + LEFT JOIN ". BB_USERS ." u ON(u.user_id = dl.user_id) + LEFT JOIN ". BB_BT_TRACKER ." tr ON(tr.user_id = dl.user_id) + WHERE dl.topic_id = $topic_id + AND dl.user_status IN (". DL_STATUS_COMPLETE.", ". DL_STATUS_DOWN.") + AND dl.user_id NOT IN ({$userdata['user_id']}, ". EXCLUDED_USERS_CSV . $ban_user_id .") + AND u.user_active = 1 + GROUP BY dl.user_id +"); + +$subject = sprintf($lang['CALLSEED_SUBJECT'], $t_data['topic_title']); +$message = sprintf($lang['CALLSEED_TEXT'], make_url(TOPIC_URL . $topic_id), $t_data['topic_title'], make_url(DOWNLOAD_URL . $t_data['attach_id'])); + +if ($user_list) +{ + foreach ($user_list as $row) + { + if (!empty($row['active_dl'])) continue; + + if (bf($row['user_opt'], 'user_opt', 'user_callseed')) + { + send_pm($row['user_id'], $subject, $message, BOT_UID); + } + } +} +else +{ + send_pm($t_data['poster_id'], $subject, $message, BOT_UID); +} + +DB()->query("UPDATE ". BB_BT_TORRENTS ." SET call_seed_time = ". TIMENOW ." WHERE topic_id = $topic_id LIMIT 1"); + +meta_refresh(TOPIC_URL . $topic_id); +bb_die($lang['CALLSEED_MSG_OK']); + +function topic_info ($topic_id) +{ + global $lang; + + $sql = " + SELECT + tor.poster_id, tor.forum_id, tor.attach_id, tor.call_seed_time, + t.topic_title, sn.seeders + FROM ". BB_BT_TORRENTS ." tor + LEFT JOIN ". BB_TOPICS ." t USING(topic_id) + LEFT JOIN ". BB_BT_TRACKER_SNAP ." sn USING(topic_id) + WHERE tor.topic_id = $topic_id + "; + + if (!$torrent = DB()->fetch_row($sql)) + { + bb_die($lang['TOPIC_POST_NOT_EXIST']); + } + + return $torrent; +} diff --git a/upload/cron.php b/upload/cron.php index bbb76f4cd..d500aeb14 100644 --- a/upload/cron.php +++ b/upload/cron.php @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/upload/files/.htaccess b/upload/files/.htaccess index 34ed2a11e..6c4686a91 100644 --- a/upload/files/.htaccess +++ b/upload/files/.htaccess @@ -1,3 +1,3 @@ -php_flag engine off -RemoveHandler .php .php5 .php4 .php3 .phtml .pl .asp +php_flag engine off +RemoveHandler .php .php5 .php4 .php3 .phtml .pl .asp AddType text/plain .php .php .htm .html .phtml .pl .asp \ No newline at end of file diff --git a/upload/files/thumbs/.htaccess b/upload/files/thumbs/.htaccess index 34ed2a11e..6c4686a91 100644 --- a/upload/files/thumbs/.htaccess +++ b/upload/files/thumbs/.htaccess @@ -1,3 +1,3 @@ -php_flag engine off -RemoveHandler .php .php5 .php4 .php3 .phtml .pl .asp +php_flag engine off +RemoveHandler .php .php5 .php4 .php3 .phtml .pl .asp AddType text/plain .php .php .htm .html .phtml .pl .asp \ No newline at end of file diff --git a/upload/groupcp.php b/upload/groupcp.php index f108668c6..af56db610 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -1,630 +1,630 @@ -'. $lang['SEND_PM_TXTB'] .'' : '' . $lang['SEND_PRIVATE_MESSAGE'] . ''; - $avatar = get_avatar($row['user_id'], $row['avatar_ext_id'], !bf($row['user_opt'], 'user_opt', 'dis_avatar'), true, 50, 50); - - if (bf($row['user_opt'], 'user_opt', 'user_viewemail') || $group_mod) - { - $email_uri = ($bb_cfg['board_email_form']) ? ("profile.php?mode=email&". POST_USERS_URL ."=".$row['user_id']) : 'mailto:'. $row['user_email']; - $email = ''. $row['user_email'] .''; - } - else $email = ''; - - if ($row['user_website']) - { - $www = ($bb_cfg['text_buttons']) ? ''. $lang['VISIT_WEBSITE_TXTB'] .'' : '' . $lang['VISIT_WEBSITE'] . ''; - } - else $www = ''; - - return; -} - -$user->session_start(array('req_login' => true)); - -set_die_append_msg(); - -$group_id = isset($_REQUEST[POST_GROUPS_URL]) ? intval($_REQUEST[POST_GROUPS_URL]) : null; -$start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; -$per_page = $bb_cfg['groupcp_members_per_page']; - -$group_info = array(); -$is_moderator = false; - -if ($group_id) -{ - if (!$group_info = get_group_data($group_id)) - { - bb_die($lang['GROUP_NOT_EXIST']); - } - if (!$group_info['group_id'] || !$group_info['group_moderator'] || !$group_info['moderator_name']) - { - bb_die("Invalid group data [group_id: $group_id]"); - } - $is_moderator = ($userdata['user_id'] == $group_info['group_moderator'] || IS_ADMIN); -} - -if (!$group_id) -{ - // Show the main screen where the user can select a group. - $groups = array(); - $pending = 10; - $member = 20; - - $sql = " - SELECT - g.group_name, g.group_description, g.group_id, g.group_type, g.release_group, - IF(ug.user_id IS NOT NULL, IF(ug.user_pending = 1, $pending, $member), 0) AS membership, - g.group_moderator, u.username AS moderator_name, - IF(g.group_moderator = ug.user_id, 1, 0) AS is_group_mod, - COUNT(ug2.user_id) AS members, SUM(ug2.user_pending) AS candidates - FROM - ". BB_GROUPS ." g - LEFT JOIN - ". BB_USER_GROUP ." ug ON - ug.group_id = g.group_id - AND ug.user_id = ". $userdata['user_id'] ." - LEFT JOIN - ". BB_USER_GROUP ." ug2 ON - ug2.group_id = g.group_id - LEFT JOIN - ". BB_USERS ." u ON g.group_moderator = u.user_id - WHERE - g.group_single_user = 0 - GROUP BY g.group_id - ORDER BY - is_group_mod DESC, - membership DESC, - g.group_type ASC, - g.group_name ASC - "; - - foreach (DB()->fetch_rowset($sql) as $row) - { - if ($row['is_group_mod']) - { - $type = 'MOD'; - } - else if ($row['membership'] == $member) - { - $type = 'MEMBER'; - } - else if ($row['membership'] == $pending) - { - $type = 'PENDING'; - } - else if ($row['group_type'] == GROUP_OPEN) - { - $type = 'OPEN'; - } - else if ($row['group_type'] == GROUP_CLOSED) - { - $type = 'CLOSED'; - } - else if ($row['group_type'] == GROUP_HIDDEN && IS_ADMIN) - { - $type = 'HIDDEN'; - } - else - { - continue; - } - - $data = array('id' => $row['group_id'], 'm' => ($row['members'] - $row['candidates']), 'c' => $row['candidates'], 'rg' => $row['release_group']); - - $groups[$type][$row['group_name']] = $data; - } - - function build_group($params) - { - global $lang; - - $options = ''; - - foreach ($params as $name => $data) - { - $text = htmlCHR(str_short(rtrim($name), HTML_SELECT_MAX_LENGTH)); - - $members = ($data['m']) ? $lang['MEMBERS_IN_GROUP'] .': '. $data['m'] : $lang['NO_GROUP_MEMBERS']; - $candidates = ($data['c']) ? $lang['PENDING_MEMBERS'] .': '. $data['c'] : $lang['NO_PENDING_GROUP_MEMBERS']; - - $options .= '
      • '. $text .'
      • '; - $options .= ($data['rg']) ? '
        • '. $lang['RELEASE_GROUP'] .'
        • ' : ''; - $options .= '
        • '. $members .'
        • '; - if (IS_AM) - { - $options .= '
        • '. $candidates .'
        • '; - } - $options .= '
        '; - - } - return $options; - } - - if ($groups) - { - $s_hidden_fields = ''; - - foreach ($groups as $type => $grp) - { - $template->assign_block_vars('groups', array( - 'MEMBERSHIP' => $lang["GROUP_MEMBER_{$type}"], - 'GROUP_SELECT' => build_group($grp), - )); - } - - $template->assign_vars(array( - 'SELECT_GROUP' => true, - 'PAGE_TITLE' => $lang['GROUP_CONTROL_PANEL'], - 'S_USERGROUP_ACTION' => 'groupcp.php', - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - )); - } - else - { - if(IS_ADMIN) - { - redirect('admin/admin_groups.php'); - } - else bb_die($lang['NO_GROUPS_EXIST']); - } -} -else if (@$_POST['joingroup']) -{ - if ($group_info['group_type'] != GROUP_OPEN) - { - bb_die($lang['THIS_CLOSED_GROUP']); - } - - $sql = "SELECT g.group_id, g.group_name, ug.user_id, u.user_email, u.username, u.user_lang - FROM ". BB_GROUPS ." g - LEFT JOIN ". BB_USERS ." u ON(u.user_id = g.group_moderator) - LEFT JOIN ". BB_USER_GROUP ." ug ON(ug.group_id = g.group_id AND ug.user_id = {$userdata['user_id']}) - WHERE g.group_id = $group_id - AND group_single_user = 0 - AND g.group_type = ". GROUP_OPEN ." - LIMIT 1"; - - $row = $moderator = DB()->fetch_row($sql); - - if (!$row['group_id']) - { - bb_die($lang['NO_GROUPS_EXIST']); - } - if ($row['user_id']) - { - bb_die($lang['ALREADY_MEMBER_GROUP']); - } - - add_user_into_group($group_id, $userdata['user_id'], 1, TIMENOW); - - if ($bb_cfg['groupcp_send_email']) - { - require(INC_DIR .'emailer.class.php'); - $emailer = new emailer($bb_cfg['smtp_delivery']); - - $emailer->from($bb_cfg['sitename'] ." <{$bb_cfg['board_email']}>"); - $emailer->email_address($moderator['username'] ." <{$moderator['user_email']}>"); - - $emailer->use_template('group_request', $moderator['user_lang']); - - $emailer->assign_vars(array( - 'USER' => $userdata['username'], - 'SITENAME' => $bb_cfg['sitename'], - 'GROUP_MODERATOR' => $moderator['username'], - 'U_GROUPCP' => make_url(GROUP_URL . $group_id), - )); - - $emailer->send(); - $emailer->reset(); - } - - $message = $lang['GROUP_JOINED'] .'

        '; - $message .= sprintf($lang['CLICK_RETURN_GROUP'], '', '') .'

        '; - $message .= sprintf($lang['CLICK_RETURN_INDEX'], '', ''); - - bb_die($message); -} -else if (!empty($_POST['unsub']) || !empty($_POST['unsubpending'])) -{ - delete_user_group($group_id, $userdata['user_id']); - - $message = $lang['UNSUB_SUCCESS'] .'

        '; - $message .= sprintf($lang['CLICK_RETURN_GROUP'], '', '') .'

        '; - $message .= sprintf($lang['CLICK_RETURN_INDEX'], '', ''); - - bb_die($message); -} -else -{ - // Handle Additions, removals, approvals and denials - $group_moderator = $group_info['group_moderator']; - - if (!empty($_POST['add']) || !empty($_POST['remove']) || !empty($_POST['approve']) || !empty($_POST['deny'])) - { - if (!$is_moderator) - { - bb_die($lang['NOT_GROUP_MODERATOR']); - } - - if (!empty($_POST['add'])) - { - if (!$row = get_userdata(@$_POST['username'], true)) - { - bb_die($lang['COULD_NOT_ADD_USER']); - } - - add_user_into_group($group_id, $row['user_id']); - - if ($bb_cfg['groupcp_send_email']) - { - require(INC_DIR .'emailer.class.php'); - $emailer = new emailer($bb_cfg['smtp_delivery']); - - $emailer->from($bb_cfg['sitename'] ." <{$bb_cfg['board_email']}>"); - $emailer->email_address($row['username'] ." <{$row['user_email']}>"); - - $emailer->use_template('group_added', $row['user_lang']); - - $emailer->assign_vars(array( - 'SITENAME' => $bb_cfg['sitename'], - 'GROUP_NAME' => $group_info['group_name'], - 'U_GROUPCP' => make_url(GROUP_URL . $group_id), - )); - - $emailer->send(); - $emailer->reset(); - } - } - else - { - if (((!empty($_POST['approve']) || !empty($_POST['deny'])) && !empty($_POST['pending_members'])) || (!empty($_POST['remove']) && !empty($_POST['members']))) - { - $members = (!empty($_POST['approve']) || !empty($_POST['deny'])) ? $_POST['pending_members'] : $_POST['members']; - - $sql_in = array(); - foreach ($members as $members_id) - { - $sql_in[] = (int) $members_id; - } - if (!$sql_in = join(',', $sql_in)) - { - bb_die($lang['NONE_SELECTED']); - } - - if (!empty($_POST['approve'])) - { - DB()->query(" - UPDATE ". BB_USER_GROUP ." SET - user_pending = 0 - WHERE user_id IN($sql_in) - AND group_id = $group_id - "); - - update_user_level($sql_in); - } - else if (!empty($_POST['deny']) || !empty($_POST['remove'])) - { - DB()->query(" - DELETE FROM ". BB_USER_GROUP ." - WHERE user_id IN($sql_in) - AND group_id = $group_id - "); - - if (!empty($_POST['remove'])) - { - update_user_level($sql_in); - } - } - // Email users when they are approved - if (!empty($_POST['approve']) && $bb_cfg['groupcp_send_email']) - { - $sql_select = "SELECT username, user_email, user_lang - FROM ". BB_USERS ." - WHERE user_id IN($sql_in)"; - - if (!$result = DB()->sql_query($sql_select)) - { - bb_die('Could not get user email information'); - } - - require(INC_DIR .'emailer.class.php'); - $emailer = new emailer($bb_cfg['smtp_delivery']); - - $emailer->from($bb_cfg['sitename'] ." <{$bb_cfg['board_email']}>"); - - foreach (DB()->fetch_rowset($sql_select) as $row) - { - $emailer->use_template('group_approved', $row['user_lang']); - $emailer->email_address($row['username'] ." <{$row['user_email']}>"); - } - - $emailer->assign_vars(array( - 'SITENAME' => $bb_cfg['sitename'], - 'GROUP_NAME' => $group_info['group_name'], - 'U_GROUPCP' => make_url(GROUP_URL . $group_id), - )); - - $emailer->send(); - $emailer->reset(); - } - } - } - } - // END approve or deny - - // Get moderator details for this group - $group_moderator = DB()->fetch_row(" - SELECT * - FROM ". BB_USERS ." - WHERE user_id = ". $group_info['group_moderator'] ." - "); - - // Members - $count_members = DB()->fetch_rowset(" - SELECT u.username, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time - FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u - WHERE ug.group_id = $group_id - AND ug.user_pending = 0 - AND ug.user_id <> ". $group_moderator['user_id'] ." - AND u.user_id = ug.user_id - ORDER BY u.username - "); - $count_members = count($count_members); - - // Get user information for this group - $modgroup_pending_count = 0; - - // Members - $group_members = DB()->fetch_rowset(" - SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time - FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u - WHERE ug.group_id = $group_id - AND ug.user_pending = 0 - AND ug.user_id <> ". $group_moderator['user_id'] ." - AND u.user_id = ug.user_id - ORDER BY u.username - LIMIT $start, $per_page - "); - $members_count = count($group_members); - - generate_pagination(GROUP_URL . $group_id, $count_members, $per_page, $start); - - // Pending - if ($is_moderator) - { - $modgroup_pending_list = DB()->fetch_rowset(" - SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email - FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u - WHERE ug.group_id = $group_id - AND ug.user_pending = 1 - AND u.user_id = ug.user_id - ORDER BY u.username - LIMIT 200 - "); - $modgroup_pending_count = count($modgroup_pending_list); - } - - // Current user membership - $is_group_member = $is_group_pending_member = false; - - $sql = "SELECT user_pending - FROM ". BB_USER_GROUP ." - WHERE group_id = $group_id - AND user_id = ". $userdata['user_id'] ." - LIMIT 1"; - - if ($row = DB()->fetch_row($sql)) - { - if ($row['user_pending'] == 0) - { - $is_group_member = true; - } - else - { - $is_group_pending_member = true; - } - } - - if ($userdata['user_id'] == $group_moderator['user_id']) - { - $group_details = $lang['ARE_GROUP_MODERATOR']; - $s_hidden_fields = ''; - } - else if ($is_group_member || $is_group_pending_member) - { - $template->assign_vars(array( - 'SHOW_UNSUBSCRIBE_CONTROLS' => true, - 'CONTROL_NAME' => ($is_group_member) ? 'unsub' : 'unsubpending', - )); - $group_details = ($is_group_pending_member) ? $lang['PENDING_THIS_GROUP'] : $lang['MEMBER_THIS_GROUP']; - $s_hidden_fields = ''; - } - else if (IS_GUEST) - { - $group_details = $lang['LOGIN_TO_JOIN']; - $s_hidden_fields = ''; - } - else - { - if ($group_info['group_type'] == GROUP_OPEN) - { - $template->assign_var('SHOW_SUBSCRIBE_CONTROLS'); - - $group_details = $lang['THIS_OPEN_GROUP']; - $s_hidden_fields = ''; - } - else if ($group_info['group_type'] == GROUP_CLOSED) - { - $group_details = $lang['THIS_CLOSED_GROUP']; - $s_hidden_fields = ''; - } - else if ($group_info['group_type'] == GROUP_HIDDEN) - { - $group_details = $lang['THIS_HIDDEN_GROUP']; - $s_hidden_fields = ''; - } - } - - // Add the moderator - $username = $group_moderator['username']; - $user_id = $group_moderator['user_id']; - - generate_user_info($group_moderator, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); - - $group_type = ''; - if ($group_info['group_type'] == GROUP_OPEN) - { - $group_type = $lang['GROUP_OPEN']; - } - elseif ($group_info['group_type'] == GROUP_CLOSED) - { - $group_type = $lang['GROUP_CLOSED']; - } - elseif ($group_info['group_type'] == GROUP_HIDDEN) - { - $group_type = $lang['GROUP_HIDDEN']; - } - - $i = 0; - $template->assign_vars(array( - 'ROW_NUMBER' => $i + ($start + 1), - 'GROUP_INFO' => true, - 'PAGE_TITLE' => $lang['GROUP_CONTROL_PANEL'], - 'GROUP_NAME' => htmlCHR($group_info['group_name']), - 'GROUP_DESCRIPTION' => bbcode2html($group_info['group_description']), - 'GROUP_DETAILS' => $group_details, - 'MOD_USER' => profile_url($group_moderator), - 'MOD_AVATAR' => $avatar, - 'MOD_FROM' => $from, - 'MOD_JOINED' => $joined, - 'MOD_POSTS' => $posts, - 'MOD_PM' => $pm, - 'MOD_EMAIL' => $email, - 'MOD_WWW' => $www, - 'MOD_TIME' => (!empty($group_info['group_time'])) ? bb_date($group_info['group_time']) : $lang['NONE'], - 'U_SEARCH_USER' => "search.php?mode=searchuser", - - 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", - 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, - 'GROUP_TYPE' => $group_type, - - 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, - 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED, - 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN, - 'S_GROUP_OPEN_CHECKED' => ($group_info['group_type'] == GROUP_OPEN) ? ' checked="checked"' : '', - 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? ' checked="checked"' : '', - 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN) ? ' checked="checked"' : '', - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - 'S_MODE_SELECT' => $select_sort_mode, - 'S_ORDER_SELECT' => $select_sort_order, - 'S_GROUPCP_ACTION' => "groupcp.php?" . POST_GROUPS_URL . "=$group_id", - )); - - // Dump out the remaining users - foreach ($group_members as $i => $member) - { - $user_id = $member['user_id']; - - generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); - - if ($group_info['group_type'] != GROUP_HIDDEN || $is_group_member || $is_moderator) - { - $row_class = !($i % 2) ? 'row1' : 'row2'; - - $template->assign_block_vars('member', array( - 'ROW_NUMBER' => $i + ( $start + 1 ), - 'ROW_CLASS' => $row_class, - 'USER' => profile_url($member), - 'AVATAR_IMG' => $avatar, - 'FROM' => $from, - 'JOINED' => $joined, - 'POSTS' => $posts, - 'USER_ID' => $user_id, - 'PM' => $pm, - 'EMAIL' => $email, - 'WWW' => $www, - 'TIME' => $user_time, - )); - - if ($is_moderator) - { - $template->assign_block_vars('member.switch_mod_option', array()); - } - } - } - - // No group members - if (!$members_count) - { - $template->assign_block_vars('switch_no_members', array()); - } - - // No group members - if ($group_info['group_type'] == GROUP_HIDDEN && !$is_group_member && !$is_moderator) - { - $template->assign_block_vars('switch_hidden_group', array()); - } - - // - // We've displayed the members who belong to the group, now we - // do that pending memebers... - // - if ($is_moderator && $modgroup_pending_list) - { - foreach ($modgroup_pending_list as $i => $member) - { - $user_id = $member['user_id']; - - generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); - - $row_class = !($i % 2) ? 'row1' : 'row2'; - - $user_select = ''; - - $template->assign_block_vars('pending', array( - 'ROW_CLASS' => $row_class, - 'AVATAR_IMG'=> $avatar, - 'USER' => profile_url($member), - 'FROM' => $from, - 'JOINED' => $joined, - 'POSTS' => $posts, - 'USER_ID' => $user_id, - 'PM' => $pm, - 'EMAIL' => $email, - )); - } - - $template->assign_vars(array( - 'PENDING_USERS' => true, - )); - } - - if ($is_moderator) - { - $template->assign_block_vars('switch_mod_option', array()); - $template->assign_block_vars('switch_add_member', array()); - } -} - +'. $lang['SEND_PM_TXTB'] .'' : '' . $lang['SEND_PRIVATE_MESSAGE'] . ''; + $avatar = get_avatar($row['user_id'], $row['avatar_ext_id'], !bf($row['user_opt'], 'user_opt', 'dis_avatar'), true, 50, 50); + + if (bf($row['user_opt'], 'user_opt', 'user_viewemail') || $group_mod) + { + $email_uri = ($bb_cfg['board_email_form']) ? ("profile.php?mode=email&". POST_USERS_URL ."=".$row['user_id']) : 'mailto:'. $row['user_email']; + $email = ''. $row['user_email'] .''; + } + else $email = ''; + + if ($row['user_website']) + { + $www = ($bb_cfg['text_buttons']) ? ''. $lang['VISIT_WEBSITE_TXTB'] .'' : '' . $lang['VISIT_WEBSITE'] . ''; + } + else $www = ''; + + return; +} + +$user->session_start(array('req_login' => true)); + +set_die_append_msg(); + +$group_id = isset($_REQUEST[POST_GROUPS_URL]) ? intval($_REQUEST[POST_GROUPS_URL]) : null; +$start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; +$per_page = $bb_cfg['groupcp_members_per_page']; + +$group_info = array(); +$is_moderator = false; + +if ($group_id) +{ + if (!$group_info = get_group_data($group_id)) + { + bb_die($lang['GROUP_NOT_EXIST']); + } + if (!$group_info['group_id'] || !$group_info['group_moderator'] || !$group_info['moderator_name']) + { + bb_die("Invalid group data [group_id: $group_id]"); + } + $is_moderator = ($userdata['user_id'] == $group_info['group_moderator'] || IS_ADMIN); +} + +if (!$group_id) +{ + // Show the main screen where the user can select a group. + $groups = array(); + $pending = 10; + $member = 20; + + $sql = " + SELECT + g.group_name, g.group_description, g.group_id, g.group_type, g.release_group, + IF(ug.user_id IS NOT NULL, IF(ug.user_pending = 1, $pending, $member), 0) AS membership, + g.group_moderator, u.username AS moderator_name, + IF(g.group_moderator = ug.user_id, 1, 0) AS is_group_mod, + COUNT(ug2.user_id) AS members, SUM(ug2.user_pending) AS candidates + FROM + ". BB_GROUPS ." g + LEFT JOIN + ". BB_USER_GROUP ." ug ON + ug.group_id = g.group_id + AND ug.user_id = ". $userdata['user_id'] ." + LEFT JOIN + ". BB_USER_GROUP ." ug2 ON + ug2.group_id = g.group_id + LEFT JOIN + ". BB_USERS ." u ON g.group_moderator = u.user_id + WHERE + g.group_single_user = 0 + GROUP BY g.group_id + ORDER BY + is_group_mod DESC, + membership DESC, + g.group_type ASC, + g.group_name ASC + "; + + foreach (DB()->fetch_rowset($sql) as $row) + { + if ($row['is_group_mod']) + { + $type = 'MOD'; + } + else if ($row['membership'] == $member) + { + $type = 'MEMBER'; + } + else if ($row['membership'] == $pending) + { + $type = 'PENDING'; + } + else if ($row['group_type'] == GROUP_OPEN) + { + $type = 'OPEN'; + } + else if ($row['group_type'] == GROUP_CLOSED) + { + $type = 'CLOSED'; + } + else if ($row['group_type'] == GROUP_HIDDEN && IS_ADMIN) + { + $type = 'HIDDEN'; + } + else + { + continue; + } + + $data = array('id' => $row['group_id'], 'm' => ($row['members'] - $row['candidates']), 'c' => $row['candidates'], 'rg' => $row['release_group']); + + $groups[$type][$row['group_name']] = $data; + } + + function build_group($params) + { + global $lang; + + $options = ''; + + foreach ($params as $name => $data) + { + $text = htmlCHR(str_short(rtrim($name), HTML_SELECT_MAX_LENGTH)); + + $members = ($data['m']) ? $lang['MEMBERS_IN_GROUP'] .': '. $data['m'] : $lang['NO_GROUP_MEMBERS']; + $candidates = ($data['c']) ? $lang['PENDING_MEMBERS'] .': '. $data['c'] : $lang['NO_PENDING_GROUP_MEMBERS']; + + $options .= '
      • '. $text .'
      • '; + $options .= ($data['rg']) ? '
        • '. $lang['RELEASE_GROUP'] .'
        • ' : ''; + $options .= '
        • '. $members .'
        • '; + if (IS_AM) + { + $options .= '
        • '. $candidates .'
        • '; + } + $options .= '
        '; + + } + return $options; + } + + if ($groups) + { + $s_hidden_fields = ''; + + foreach ($groups as $type => $grp) + { + $template->assign_block_vars('groups', array( + 'MEMBERSHIP' => $lang["GROUP_MEMBER_{$type}"], + 'GROUP_SELECT' => build_group($grp), + )); + } + + $template->assign_vars(array( + 'SELECT_GROUP' => true, + 'PAGE_TITLE' => $lang['GROUP_CONTROL_PANEL'], + 'S_USERGROUP_ACTION' => 'groupcp.php', + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + )); + } + else + { + if(IS_ADMIN) + { + redirect('admin/admin_groups.php'); + } + else bb_die($lang['NO_GROUPS_EXIST']); + } +} +else if (@$_POST['joingroup']) +{ + if ($group_info['group_type'] != GROUP_OPEN) + { + bb_die($lang['THIS_CLOSED_GROUP']); + } + + $sql = "SELECT g.group_id, g.group_name, ug.user_id, u.user_email, u.username, u.user_lang + FROM ". BB_GROUPS ." g + LEFT JOIN ". BB_USERS ." u ON(u.user_id = g.group_moderator) + LEFT JOIN ". BB_USER_GROUP ." ug ON(ug.group_id = g.group_id AND ug.user_id = {$userdata['user_id']}) + WHERE g.group_id = $group_id + AND group_single_user = 0 + AND g.group_type = ". GROUP_OPEN ." + LIMIT 1"; + + $row = $moderator = DB()->fetch_row($sql); + + if (!$row['group_id']) + { + bb_die($lang['NO_GROUPS_EXIST']); + } + if ($row['user_id']) + { + bb_die($lang['ALREADY_MEMBER_GROUP']); + } + + add_user_into_group($group_id, $userdata['user_id'], 1, TIMENOW); + + if ($bb_cfg['groupcp_send_email']) + { + require(INC_DIR .'emailer.class.php'); + $emailer = new emailer($bb_cfg['smtp_delivery']); + + $emailer->from($bb_cfg['sitename'] ." <{$bb_cfg['board_email']}>"); + $emailer->email_address($moderator['username'] ." <{$moderator['user_email']}>"); + + $emailer->use_template('group_request', $moderator['user_lang']); + + $emailer->assign_vars(array( + 'USER' => $userdata['username'], + 'SITENAME' => $bb_cfg['sitename'], + 'GROUP_MODERATOR' => $moderator['username'], + 'U_GROUPCP' => make_url(GROUP_URL . $group_id), + )); + + $emailer->send(); + $emailer->reset(); + } + + $message = $lang['GROUP_JOINED'] .'

        '; + $message .= sprintf($lang['CLICK_RETURN_GROUP'], '', '') .'

        '; + $message .= sprintf($lang['CLICK_RETURN_INDEX'], '', ''); + + bb_die($message); +} +else if (!empty($_POST['unsub']) || !empty($_POST['unsubpending'])) +{ + delete_user_group($group_id, $userdata['user_id']); + + $message = $lang['UNSUB_SUCCESS'] .'

        '; + $message .= sprintf($lang['CLICK_RETURN_GROUP'], '', '') .'

        '; + $message .= sprintf($lang['CLICK_RETURN_INDEX'], '', ''); + + bb_die($message); +} +else +{ + // Handle Additions, removals, approvals and denials + $group_moderator = $group_info['group_moderator']; + + if (!empty($_POST['add']) || !empty($_POST['remove']) || !empty($_POST['approve']) || !empty($_POST['deny'])) + { + if (!$is_moderator) + { + bb_die($lang['NOT_GROUP_MODERATOR']); + } + + if (!empty($_POST['add'])) + { + if (!$row = get_userdata(@$_POST['username'], true)) + { + bb_die($lang['COULD_NOT_ADD_USER']); + } + + add_user_into_group($group_id, $row['user_id']); + + if ($bb_cfg['groupcp_send_email']) + { + require(INC_DIR .'emailer.class.php'); + $emailer = new emailer($bb_cfg['smtp_delivery']); + + $emailer->from($bb_cfg['sitename'] ." <{$bb_cfg['board_email']}>"); + $emailer->email_address($row['username'] ." <{$row['user_email']}>"); + + $emailer->use_template('group_added', $row['user_lang']); + + $emailer->assign_vars(array( + 'SITENAME' => $bb_cfg['sitename'], + 'GROUP_NAME' => $group_info['group_name'], + 'U_GROUPCP' => make_url(GROUP_URL . $group_id), + )); + + $emailer->send(); + $emailer->reset(); + } + } + else + { + if (((!empty($_POST['approve']) || !empty($_POST['deny'])) && !empty($_POST['pending_members'])) || (!empty($_POST['remove']) && !empty($_POST['members']))) + { + $members = (!empty($_POST['approve']) || !empty($_POST['deny'])) ? $_POST['pending_members'] : $_POST['members']; + + $sql_in = array(); + foreach ($members as $members_id) + { + $sql_in[] = (int) $members_id; + } + if (!$sql_in = join(',', $sql_in)) + { + bb_die($lang['NONE_SELECTED']); + } + + if (!empty($_POST['approve'])) + { + DB()->query(" + UPDATE ". BB_USER_GROUP ." SET + user_pending = 0 + WHERE user_id IN($sql_in) + AND group_id = $group_id + "); + + update_user_level($sql_in); + } + else if (!empty($_POST['deny']) || !empty($_POST['remove'])) + { + DB()->query(" + DELETE FROM ". BB_USER_GROUP ." + WHERE user_id IN($sql_in) + AND group_id = $group_id + "); + + if (!empty($_POST['remove'])) + { + update_user_level($sql_in); + } + } + // Email users when they are approved + if (!empty($_POST['approve']) && $bb_cfg['groupcp_send_email']) + { + $sql_select = "SELECT username, user_email, user_lang + FROM ". BB_USERS ." + WHERE user_id IN($sql_in)"; + + if (!$result = DB()->sql_query($sql_select)) + { + bb_die('Could not get user email information'); + } + + require(INC_DIR .'emailer.class.php'); + $emailer = new emailer($bb_cfg['smtp_delivery']); + + $emailer->from($bb_cfg['sitename'] ." <{$bb_cfg['board_email']}>"); + + foreach (DB()->fetch_rowset($sql_select) as $row) + { + $emailer->use_template('group_approved', $row['user_lang']); + $emailer->email_address($row['username'] ." <{$row['user_email']}>"); + } + + $emailer->assign_vars(array( + 'SITENAME' => $bb_cfg['sitename'], + 'GROUP_NAME' => $group_info['group_name'], + 'U_GROUPCP' => make_url(GROUP_URL . $group_id), + )); + + $emailer->send(); + $emailer->reset(); + } + } + } + } + // END approve or deny + + // Get moderator details for this group + $group_moderator = DB()->fetch_row(" + SELECT * + FROM ". BB_USERS ." + WHERE user_id = ". $group_info['group_moderator'] ." + "); + + // Members + $count_members = DB()->fetch_rowset(" + SELECT u.username, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time + FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u + WHERE ug.group_id = $group_id + AND ug.user_pending = 0 + AND ug.user_id <> ". $group_moderator['user_id'] ." + AND u.user_id = ug.user_id + ORDER BY u.username + "); + $count_members = count($count_members); + + // Get user information for this group + $modgroup_pending_count = 0; + + // Members + $group_members = DB()->fetch_rowset(" + SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time + FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u + WHERE ug.group_id = $group_id + AND ug.user_pending = 0 + AND ug.user_id <> ". $group_moderator['user_id'] ." + AND u.user_id = ug.user_id + ORDER BY u.username + LIMIT $start, $per_page + "); + $members_count = count($group_members); + + generate_pagination(GROUP_URL . $group_id, $count_members, $per_page, $start); + + // Pending + if ($is_moderator) + { + $modgroup_pending_list = DB()->fetch_rowset(" + SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email + FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u + WHERE ug.group_id = $group_id + AND ug.user_pending = 1 + AND u.user_id = ug.user_id + ORDER BY u.username + LIMIT 200 + "); + $modgroup_pending_count = count($modgroup_pending_list); + } + + // Current user membership + $is_group_member = $is_group_pending_member = false; + + $sql = "SELECT user_pending + FROM ". BB_USER_GROUP ." + WHERE group_id = $group_id + AND user_id = ". $userdata['user_id'] ." + LIMIT 1"; + + if ($row = DB()->fetch_row($sql)) + { + if ($row['user_pending'] == 0) + { + $is_group_member = true; + } + else + { + $is_group_pending_member = true; + } + } + + if ($userdata['user_id'] == $group_moderator['user_id']) + { + $group_details = $lang['ARE_GROUP_MODERATOR']; + $s_hidden_fields = ''; + } + else if ($is_group_member || $is_group_pending_member) + { + $template->assign_vars(array( + 'SHOW_UNSUBSCRIBE_CONTROLS' => true, + 'CONTROL_NAME' => ($is_group_member) ? 'unsub' : 'unsubpending', + )); + $group_details = ($is_group_pending_member) ? $lang['PENDING_THIS_GROUP'] : $lang['MEMBER_THIS_GROUP']; + $s_hidden_fields = ''; + } + else if (IS_GUEST) + { + $group_details = $lang['LOGIN_TO_JOIN']; + $s_hidden_fields = ''; + } + else + { + if ($group_info['group_type'] == GROUP_OPEN) + { + $template->assign_var('SHOW_SUBSCRIBE_CONTROLS'); + + $group_details = $lang['THIS_OPEN_GROUP']; + $s_hidden_fields = ''; + } + else if ($group_info['group_type'] == GROUP_CLOSED) + { + $group_details = $lang['THIS_CLOSED_GROUP']; + $s_hidden_fields = ''; + } + else if ($group_info['group_type'] == GROUP_HIDDEN) + { + $group_details = $lang['THIS_HIDDEN_GROUP']; + $s_hidden_fields = ''; + } + } + + // Add the moderator + $username = $group_moderator['username']; + $user_id = $group_moderator['user_id']; + + generate_user_info($group_moderator, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); + + $group_type = ''; + if ($group_info['group_type'] == GROUP_OPEN) + { + $group_type = $lang['GROUP_OPEN']; + } + elseif ($group_info['group_type'] == GROUP_CLOSED) + { + $group_type = $lang['GROUP_CLOSED']; + } + elseif ($group_info['group_type'] == GROUP_HIDDEN) + { + $group_type = $lang['GROUP_HIDDEN']; + } + + $i = 0; + $template->assign_vars(array( + 'ROW_NUMBER' => $i + ($start + 1), + 'GROUP_INFO' => true, + 'PAGE_TITLE' => $lang['GROUP_CONTROL_PANEL'], + 'GROUP_NAME' => htmlCHR($group_info['group_name']), + 'GROUP_DESCRIPTION' => bbcode2html($group_info['group_description']), + 'GROUP_DETAILS' => $group_details, + 'MOD_USER' => profile_url($group_moderator), + 'MOD_AVATAR' => $avatar, + 'MOD_FROM' => $from, + 'MOD_JOINED' => $joined, + 'MOD_POSTS' => $posts, + 'MOD_PM' => $pm, + 'MOD_EMAIL' => $email, + 'MOD_WWW' => $www, + 'MOD_TIME' => (!empty($group_info['group_time'])) ? bb_date($group_info['group_time']) : $lang['NONE'], + 'U_SEARCH_USER' => "search.php?mode=searchuser", + + 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", + 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, + 'GROUP_TYPE' => $group_type, + + 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, + 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED, + 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN, + 'S_GROUP_OPEN_CHECKED' => ($group_info['group_type'] == GROUP_OPEN) ? ' checked="checked"' : '', + 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? ' checked="checked"' : '', + 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN) ? ' checked="checked"' : '', + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_MODE_SELECT' => $select_sort_mode, + 'S_ORDER_SELECT' => $select_sort_order, + 'S_GROUPCP_ACTION' => "groupcp.php?" . POST_GROUPS_URL . "=$group_id", + )); + + // Dump out the remaining users + foreach ($group_members as $i => $member) + { + $user_id = $member['user_id']; + + generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); + + if ($group_info['group_type'] != GROUP_HIDDEN || $is_group_member || $is_moderator) + { + $row_class = !($i % 2) ? 'row1' : 'row2'; + + $template->assign_block_vars('member', array( + 'ROW_NUMBER' => $i + ( $start + 1 ), + 'ROW_CLASS' => $row_class, + 'USER' => profile_url($member), + 'AVATAR_IMG' => $avatar, + 'FROM' => $from, + 'JOINED' => $joined, + 'POSTS' => $posts, + 'USER_ID' => $user_id, + 'PM' => $pm, + 'EMAIL' => $email, + 'WWW' => $www, + 'TIME' => $user_time, + )); + + if ($is_moderator) + { + $template->assign_block_vars('member.switch_mod_option', array()); + } + } + } + + // No group members + if (!$members_count) + { + $template->assign_block_vars('switch_no_members', array()); + } + + // No group members + if ($group_info['group_type'] == GROUP_HIDDEN && !$is_group_member && !$is_moderator) + { + $template->assign_block_vars('switch_hidden_group', array()); + } + + // + // We've displayed the members who belong to the group, now we + // do that pending memebers... + // + if ($is_moderator && $modgroup_pending_list) + { + foreach ($modgroup_pending_list as $i => $member) + { + $user_id = $member['user_id']; + + generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); + + $row_class = !($i % 2) ? 'row1' : 'row2'; + + $user_select = ''; + + $template->assign_block_vars('pending', array( + 'ROW_CLASS' => $row_class, + 'AVATAR_IMG'=> $avatar, + 'USER' => profile_url($member), + 'FROM' => $from, + 'JOINED' => $joined, + 'POSTS' => $posts, + 'USER_ID' => $user_id, + 'PM' => $pm, + 'EMAIL' => $email, + )); + } + + $template->assign_vars(array( + 'PENDING_USERS' => true, + )); + } + + if ($is_moderator) + { + $template->assign_block_vars('switch_mod_option', array()); + $template->assign_block_vars('switch_add_member', array()); + } +} + print_page('groupcp.tpl'); \ No newline at end of file diff --git a/upload/includes/captcha/captcha.php b/upload/includes/captcha/captcha.php index 59b11ec11..61fe023d3 100644 --- a/upload/includes/captcha/captcha.php +++ b/upload/includes/captcha/captcha.php @@ -1,400 +1,400 @@ -cfg = $cfg; - $this->can_bypass = !empty($_POST[$this->cfg['secret_key']]); - $this->curr_code_key = $this->get_key_name(TIMENOW); - $this->prev_code_key = $this->get_key_name(TIMENOW - $this->key_ttl); - } - - function verify_code () - { - // обход - if ($this->can_bypass || $this->cfg['disabled']) - { - if (!empty($_POST[$this->cfg['secret_key']])) log_get('cap/off', @$_POST['login_username']); - return true; - } - // cap_sid - if (isset($_POST[$this->cap_sid_key]) && verify_id($_POST[$this->cap_sid_key], $this->cap_sid_len)) - { - $this->cap_sid_val = $_POST[$this->cap_sid_key]; - } - else - { - return false; - } - // code - $entered_code = ''; - if (isset($_POST[$this->curr_code_key])) - { - $entered_code = (string) $_POST[$this->curr_code_key]; - } - else if (isset($_POST[$this->prev_code_key])) - { - $entered_code = (string) $_POST[$this->prev_code_key]; - } - - $entered_code = strtolower(trim($entered_code)); - - $valid_code = $this->get_code(); - - if ($entered_code === $valid_code) - { - $this->del_sid(); - return true; - } - else - { - $this->del_sid(); - return false; - } - } - - function get_html () - { - if ($this->cfg['disabled']) return ''; - - $this->gen_cap_sid(); - $this->new_img_url = $this->get_img_url($this->new_cap_id); - $this->new_code_key = $this->get_key_name(TIMENOW); - - return ' -
        pic
        - - - '; - } - - function get_code () - { - if ($this->cap_sid_val AND $code = CACHE('bb_cap_sid')->get('c_sid_'. $this->cap_sid_val)) - { - return strtolower(trim($code)); - } - else - { - return null; - } - } - - function del_sid () - { - if ($this->cap_sid_val) - { - CACHE('bb_cap_sid')->rm('c_sid_'. $this->cap_sid_val); - } - } - - function gen_cap_sid () - { - $row = DB('cap')->fetch_row("SELECT MIN(cap_id) AS min_id, MAX(cap_id) AS max_id FROM ". BB_CAPTCHA ." WHERE cap_id > 0"); - - $min_id = intval($row['min_id']) + $this->new_per_minute; - $max_id = intval($row['max_id']); - - $this->new_cap_id = ($min_id < $max_id) ? mt_rand($min_id, $max_id) : $max_id; - - $this->new_cap_code = (string) DB('cap')->fetch_row("SELECT cap_code FROM ". BB_CAPTCHA ." WHERE cap_id = {$this->new_cap_id}", 'cap_code'); - - $this->new_cap_sid = make_rand_str($this->cap_sid_len); - - CACHE('bb_cap_sid')->set('c_sid_'. $this->new_cap_sid, $this->new_cap_code, $this->key_ttl*2); - } - - function get_img_url ($id) - { - return $this->get_path($id, $this->cfg['img_url']); - } - - function get_img_path ($id) - { - return $this->get_path($id, $this->cfg['img_path']); - } - - function get_path ($id, $base) - { - $path = $base . ($id % 50) .'/'. $id .'.'. $this->img_ext; - return preg_replace("#/($id)(\.{$this->img_ext})\$#", '/'. md5($this->cfg['secret_key'] . md5($id)) .'$2', $path); - } - - /** - * Генерит валидное имя ключа для получения введенного кода капчи из $_POST - */ - function get_key_name ($tm) - { - return 'cap_code_'. md5($this->cfg['secret_key'] . md5($tm - ($tm % $this->key_ttl))); - } -} - -class captcha_kcaptcha extends captcha_common -{ - // generates keystring and image - function gen_img ($cap_id) - { - global $bb_cfg; - - // do not change without changing font files! - $alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"; - - # symbols used to draw CAPTCHA - alphabet without similar symbols (o=0, 1=l, i=j, t=f) - $allowed_symbols = "23456789abcdeghkmnpqsuvxyz"; - - # folder with fonts - $fontsdir = INC_DIR .'captcha/kcaptcha/fonts/'; - - $fonts = array( - 'antiqua.png', - 'baskerville.png', - 'batang.png', - 'bookman.png', - 'calisto.png', - 'cambria.png', - 'centaur.png', - 'century.png', - 'chaparral.png', - 'constantia.png', - 'footlight.png', - 'garamond.png', - 'georgia.png', - 'goudy_old.png', - 'kozuka.png', - 'lucida.png', - 'minion.png', - 'palatino.png', - 'perpetua.png', - 'rockwell.png', - 'times.png', - 'warnock.png', - ); - - # CAPTCHA string length - $length = mt_rand($this->cap_min_chars, $this->cap_max_chars); - - # CAPTCHA image size (you do not need to change it, whis parameters is optimal) - $width = 120; - $height = 60; - - # symbol's vertical fluctuation amplitude divided by 2 - $fluctuation_amplitude = 5; - - # increase safety by prevention of spaces between symbols - $no_spaces = true; - - # show credits - $show_credits = true; # set to false to remove credits line. Credits adds 12 pixels to image height - $credits = $bb_cfg['server_name']; # if empty, HTTP_HOST will be shown - - # CAPTCHA image colors (RGB, 0-255) - //$foreground_color = array(0, 0, 0); - //$background_color = array(220, 230, 255); - $foreground_color = array(mt_rand(0,100), mt_rand(0,100), mt_rand(0,100)); - $background_color = array(mt_rand(200,255), mt_rand(200,255), mt_rand(200,255)); - - # JPEG quality of CAPTCHA image (bigger is better quality, but larger file size) - $jpeg_quality = 90; - - $alphabet_length=strlen($alphabet); - - do{ - // generating random keystring - while(true){ - $this->keystring=''; - for($i=0;$i<$length;$i++){ - $this->keystring.=$allowed_symbols[mt_rand(0,strlen($allowed_symbols)-1)]; - } - if(!preg_match('/cp|cb|ck|c6|c9|rn|rm|mm|co|do|cl|db|qp|qb|dp|ww/', $this->keystring)) break; - } - - $font_file = $fontsdir . $fonts[mt_rand(0, count($fonts)-1)]; - $font=imagecreatefrompng($font_file); - imagealphablending($font, true); - $fontfile_width=imagesx($font); - $fontfile_height=imagesy($font)-1; - $font_metrics=array(); - $symbol=0; - $reading_symbol=false; - - // loading font - for($i=0;$i<$fontfile_width && $symbol<$alphabet_length;$i++){ - $transparent = (imagecolorat($font, $i, 0) >> 24) == 127; - - if(!$reading_symbol && !$transparent){ - $font_metrics[$alphabet[$symbol]]=array('start'=>$i); - $reading_symbol=true; - continue; - } - - if($reading_symbol && $transparent){ - $font_metrics[$alphabet[$symbol]]['end']=$i; - $reading_symbol=false; - $symbol++; - continue; - } - } - - $img=imagecreatetruecolor($width, $height); - imagealphablending($img, true); - $white=imagecolorallocate($img, 255, 255, 255); - $black=imagecolorallocate($img, 0, 0, 0); - - imagefilledrectangle($img, 0, 0, $width-1, $height-1, $white); - - // draw text - $x=1; - for($i=0;$i<$length;$i++){ - $m=$font_metrics[$this->keystring[$i]]; - - $y=mt_rand(-$fluctuation_amplitude, $fluctuation_amplitude)+($height-$fontfile_height)/2+2; - - if($no_spaces){ - $shift=0; - if($i>0){ - $shift=10000; - for($sy=7;$sy<$fontfile_height-20;$sy+=1){ - for($sx=$m['start']-1;$sx<$m['end'];$sx+=1){ - $rgb=imagecolorat($font, $sx, $sy); - $opacity=$rgb>>24; - if($opacity<127){ - $left=$sx-$m['start']+$x; - $py=$sy+$y; - if($py>$height) break; - for($px=min($left,$width-1);$px>$left-12 && $px>=0;$px-=1){ - $color=imagecolorat($img, $px, $py) & 0xff; - if($color+$opacity<190){ - if($shift>$left-$px){ - $shift=$left-$px; - } - break; - } - } - break; - } - } - } - if($shift==10000){ - $shift=mt_rand(4,6); - } - - } - }else{ - $shift=1; - } - imagecopy($img, $font, $x-$shift, $y, $m['start'], 1, $m['end']-$m['start'], $fontfile_height); - $x+=$m['end']-$m['start']-$shift; - } - }while($x>=$width-10); // while not fit in canvas - - $center=$x/2; - - // credits. To remove, see configuration file - $img2=imagecreatetruecolor($width, $height+($show_credits?12:0)); - $foreground=imagecolorallocate($img2, $foreground_color[0], $foreground_color[1], $foreground_color[2]); - $background=imagecolorallocate($img2, $background_color[0], $background_color[1], $background_color[2]); - imagefilledrectangle($img2, 0, 0, $width-1, $height-1, $background); - imagefilledrectangle($img2, 0, $height, $width-1, $height+12, $foreground); - $credits=empty($credits)?$bb_cfg['server_name']:$credits; - imagestring($img2, 2, $width/2-imagefontwidth(2)*strlen($credits)/2, $height-2, $credits, $background); - - // periods - $rand1=mt_rand(750000,1200000)/10000000; - $rand2=mt_rand(750000,1200000)/10000000; - $rand3=mt_rand(750000,1200000)/10000000; - $rand4=mt_rand(750000,1200000)/10000000; - // phases - $rand5=mt_rand(0,31415926)/10000000; - $rand6=mt_rand(0,31415926)/10000000; - $rand7=mt_rand(0,31415926)/10000000; - $rand8=mt_rand(0,31415926)/10000000; - // amplitudes - $rand9=mt_rand(330,420)/110; - $rand10=mt_rand(330,450)/110; - - //wave distortion - - for($x=0;$x<$width;$x++){ - for($y=0;$y<$height;$y++){ - $sx=$x+(sin($x*$rand1+$rand5)+sin($y*$rand3+$rand6))*$rand9-$width/2+$center+1; - $sy=$y+(sin($x*$rand2+$rand7)+sin($y*$rand4+$rand8))*$rand10; - - if($sx<0 || $sy<0 || $sx>=$width-1 || $sy>=$height-1){ - continue; - }else{ - $color=imagecolorat($img, $sx, $sy) & 0xFF; - $color_x=imagecolorat($img, $sx+1, $sy) & 0xFF; - $color_y=imagecolorat($img, $sx, $sy+1) & 0xFF; - $color_xy=imagecolorat($img, $sx+1, $sy+1) & 0xFF; - } - - if($color==255 && $color_x==255 && $color_y==255 && $color_xy==255){ - continue; - }else if($color==0 && $color_x==0 && $color_y==0 && $color_xy==0){ - $newred=$foreground_color[0]; - $newgreen=$foreground_color[1]; - $newblue=$foreground_color[2]; - }else{ - $frsx=$sx-floor($sx); - $frsy=$sy-floor($sy); - $frsx1=1-$frsx; - $frsy1=1-$frsy; - - $newcolor=( - $color*$frsx1*$frsy1+ - $color_x*$frsx*$frsy1+ - $color_y*$frsx1*$frsy+ - $color_xy*$frsx*$frsy); - - if($newcolor>255) $newcolor=255; - $newcolor=$newcolor/255; - $newcolor0=1-$newcolor; - - $newred=$newcolor0*$foreground_color[0]+$newcolor*$background_color[0]; - $newgreen=$newcolor0*$foreground_color[1]+$newcolor*$background_color[1]; - $newblue=$newcolor0*$foreground_color[2]+$newcolor*$background_color[2]; - } - - imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue)); - } - } - - $img_path = $this->get_img_path($cap_id); - file_write('', $img_path, null, true, true); - - imagejpeg($img2, $img_path, $jpeg_quality); -# imagegif($img2, $img_path); -# imagepng($img2, $img_path); - - imagedestroy($img2); - - return $this->keystring; - } +cfg = $cfg; + $this->can_bypass = !empty($_POST[$this->cfg['secret_key']]); + $this->curr_code_key = $this->get_key_name(TIMENOW); + $this->prev_code_key = $this->get_key_name(TIMENOW - $this->key_ttl); + } + + function verify_code () + { + // обход + if ($this->can_bypass || $this->cfg['disabled']) + { + if (!empty($_POST[$this->cfg['secret_key']])) log_get('cap/off', @$_POST['login_username']); + return true; + } + // cap_sid + if (isset($_POST[$this->cap_sid_key]) && verify_id($_POST[$this->cap_sid_key], $this->cap_sid_len)) + { + $this->cap_sid_val = $_POST[$this->cap_sid_key]; + } + else + { + return false; + } + // code + $entered_code = ''; + if (isset($_POST[$this->curr_code_key])) + { + $entered_code = (string) $_POST[$this->curr_code_key]; + } + else if (isset($_POST[$this->prev_code_key])) + { + $entered_code = (string) $_POST[$this->prev_code_key]; + } + + $entered_code = strtolower(trim($entered_code)); + + $valid_code = $this->get_code(); + + if ($entered_code === $valid_code) + { + $this->del_sid(); + return true; + } + else + { + $this->del_sid(); + return false; + } + } + + function get_html () + { + if ($this->cfg['disabled']) return ''; + + $this->gen_cap_sid(); + $this->new_img_url = $this->get_img_url($this->new_cap_id); + $this->new_code_key = $this->get_key_name(TIMENOW); + + return ' +
        pic
        + + + '; + } + + function get_code () + { + if ($this->cap_sid_val AND $code = CACHE('bb_cap_sid')->get('c_sid_'. $this->cap_sid_val)) + { + return strtolower(trim($code)); + } + else + { + return null; + } + } + + function del_sid () + { + if ($this->cap_sid_val) + { + CACHE('bb_cap_sid')->rm('c_sid_'. $this->cap_sid_val); + } + } + + function gen_cap_sid () + { + $row = DB('cap')->fetch_row("SELECT MIN(cap_id) AS min_id, MAX(cap_id) AS max_id FROM ". BB_CAPTCHA ." WHERE cap_id > 0"); + + $min_id = intval($row['min_id']) + $this->new_per_minute; + $max_id = intval($row['max_id']); + + $this->new_cap_id = ($min_id < $max_id) ? mt_rand($min_id, $max_id) : $max_id; + + $this->new_cap_code = (string) DB('cap')->fetch_row("SELECT cap_code FROM ". BB_CAPTCHA ." WHERE cap_id = {$this->new_cap_id}", 'cap_code'); + + $this->new_cap_sid = make_rand_str($this->cap_sid_len); + + CACHE('bb_cap_sid')->set('c_sid_'. $this->new_cap_sid, $this->new_cap_code, $this->key_ttl*2); + } + + function get_img_url ($id) + { + return $this->get_path($id, $this->cfg['img_url']); + } + + function get_img_path ($id) + { + return $this->get_path($id, $this->cfg['img_path']); + } + + function get_path ($id, $base) + { + $path = $base . ($id % 50) .'/'. $id .'.'. $this->img_ext; + return preg_replace("#/($id)(\.{$this->img_ext})\$#", '/'. md5($this->cfg['secret_key'] . md5($id)) .'$2', $path); + } + + /** + * Генерит валидное имя ключа для получения введенного кода капчи из $_POST + */ + function get_key_name ($tm) + { + return 'cap_code_'. md5($this->cfg['secret_key'] . md5($tm - ($tm % $this->key_ttl))); + } +} + +class captcha_kcaptcha extends captcha_common +{ + // generates keystring and image + function gen_img ($cap_id) + { + global $bb_cfg; + + // do not change without changing font files! + $alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"; + + # symbols used to draw CAPTCHA - alphabet without similar symbols (o=0, 1=l, i=j, t=f) + $allowed_symbols = "23456789abcdeghkmnpqsuvxyz"; + + # folder with fonts + $fontsdir = INC_DIR .'captcha/kcaptcha/fonts/'; + + $fonts = array( + 'antiqua.png', + 'baskerville.png', + 'batang.png', + 'bookman.png', + 'calisto.png', + 'cambria.png', + 'centaur.png', + 'century.png', + 'chaparral.png', + 'constantia.png', + 'footlight.png', + 'garamond.png', + 'georgia.png', + 'goudy_old.png', + 'kozuka.png', + 'lucida.png', + 'minion.png', + 'palatino.png', + 'perpetua.png', + 'rockwell.png', + 'times.png', + 'warnock.png', + ); + + # CAPTCHA string length + $length = mt_rand($this->cap_min_chars, $this->cap_max_chars); + + # CAPTCHA image size (you do not need to change it, whis parameters is optimal) + $width = 120; + $height = 60; + + # symbol's vertical fluctuation amplitude divided by 2 + $fluctuation_amplitude = 5; + + # increase safety by prevention of spaces between symbols + $no_spaces = true; + + # show credits + $show_credits = true; # set to false to remove credits line. Credits adds 12 pixels to image height + $credits = $bb_cfg['server_name']; # if empty, HTTP_HOST will be shown + + # CAPTCHA image colors (RGB, 0-255) + //$foreground_color = array(0, 0, 0); + //$background_color = array(220, 230, 255); + $foreground_color = array(mt_rand(0,100), mt_rand(0,100), mt_rand(0,100)); + $background_color = array(mt_rand(200,255), mt_rand(200,255), mt_rand(200,255)); + + # JPEG quality of CAPTCHA image (bigger is better quality, but larger file size) + $jpeg_quality = 90; + + $alphabet_length=strlen($alphabet); + + do{ + // generating random keystring + while(true){ + $this->keystring=''; + for($i=0;$i<$length;$i++){ + $this->keystring.=$allowed_symbols[mt_rand(0,strlen($allowed_symbols)-1)]; + } + if(!preg_match('/cp|cb|ck|c6|c9|rn|rm|mm|co|do|cl|db|qp|qb|dp|ww/', $this->keystring)) break; + } + + $font_file = $fontsdir . $fonts[mt_rand(0, count($fonts)-1)]; + $font=imagecreatefrompng($font_file); + imagealphablending($font, true); + $fontfile_width=imagesx($font); + $fontfile_height=imagesy($font)-1; + $font_metrics=array(); + $symbol=0; + $reading_symbol=false; + + // loading font + for($i=0;$i<$fontfile_width && $symbol<$alphabet_length;$i++){ + $transparent = (imagecolorat($font, $i, 0) >> 24) == 127; + + if(!$reading_symbol && !$transparent){ + $font_metrics[$alphabet[$symbol]]=array('start'=>$i); + $reading_symbol=true; + continue; + } + + if($reading_symbol && $transparent){ + $font_metrics[$alphabet[$symbol]]['end']=$i; + $reading_symbol=false; + $symbol++; + continue; + } + } + + $img=imagecreatetruecolor($width, $height); + imagealphablending($img, true); + $white=imagecolorallocate($img, 255, 255, 255); + $black=imagecolorallocate($img, 0, 0, 0); + + imagefilledrectangle($img, 0, 0, $width-1, $height-1, $white); + + // draw text + $x=1; + for($i=0;$i<$length;$i++){ + $m=$font_metrics[$this->keystring[$i]]; + + $y=mt_rand(-$fluctuation_amplitude, $fluctuation_amplitude)+($height-$fontfile_height)/2+2; + + if($no_spaces){ + $shift=0; + if($i>0){ + $shift=10000; + for($sy=7;$sy<$fontfile_height-20;$sy+=1){ + for($sx=$m['start']-1;$sx<$m['end'];$sx+=1){ + $rgb=imagecolorat($font, $sx, $sy); + $opacity=$rgb>>24; + if($opacity<127){ + $left=$sx-$m['start']+$x; + $py=$sy+$y; + if($py>$height) break; + for($px=min($left,$width-1);$px>$left-12 && $px>=0;$px-=1){ + $color=imagecolorat($img, $px, $py) & 0xff; + if($color+$opacity<190){ + if($shift>$left-$px){ + $shift=$left-$px; + } + break; + } + } + break; + } + } + } + if($shift==10000){ + $shift=mt_rand(4,6); + } + + } + }else{ + $shift=1; + } + imagecopy($img, $font, $x-$shift, $y, $m['start'], 1, $m['end']-$m['start'], $fontfile_height); + $x+=$m['end']-$m['start']-$shift; + } + }while($x>=$width-10); // while not fit in canvas + + $center=$x/2; + + // credits. To remove, see configuration file + $img2=imagecreatetruecolor($width, $height+($show_credits?12:0)); + $foreground=imagecolorallocate($img2, $foreground_color[0], $foreground_color[1], $foreground_color[2]); + $background=imagecolorallocate($img2, $background_color[0], $background_color[1], $background_color[2]); + imagefilledrectangle($img2, 0, 0, $width-1, $height-1, $background); + imagefilledrectangle($img2, 0, $height, $width-1, $height+12, $foreground); + $credits=empty($credits)?$bb_cfg['server_name']:$credits; + imagestring($img2, 2, $width/2-imagefontwidth(2)*strlen($credits)/2, $height-2, $credits, $background); + + // periods + $rand1=mt_rand(750000,1200000)/10000000; + $rand2=mt_rand(750000,1200000)/10000000; + $rand3=mt_rand(750000,1200000)/10000000; + $rand4=mt_rand(750000,1200000)/10000000; + // phases + $rand5=mt_rand(0,31415926)/10000000; + $rand6=mt_rand(0,31415926)/10000000; + $rand7=mt_rand(0,31415926)/10000000; + $rand8=mt_rand(0,31415926)/10000000; + // amplitudes + $rand9=mt_rand(330,420)/110; + $rand10=mt_rand(330,450)/110; + + //wave distortion + + for($x=0;$x<$width;$x++){ + for($y=0;$y<$height;$y++){ + $sx=$x+(sin($x*$rand1+$rand5)+sin($y*$rand3+$rand6))*$rand9-$width/2+$center+1; + $sy=$y+(sin($x*$rand2+$rand7)+sin($y*$rand4+$rand8))*$rand10; + + if($sx<0 || $sy<0 || $sx>=$width-1 || $sy>=$height-1){ + continue; + }else{ + $color=imagecolorat($img, $sx, $sy) & 0xFF; + $color_x=imagecolorat($img, $sx+1, $sy) & 0xFF; + $color_y=imagecolorat($img, $sx, $sy+1) & 0xFF; + $color_xy=imagecolorat($img, $sx+1, $sy+1) & 0xFF; + } + + if($color==255 && $color_x==255 && $color_y==255 && $color_xy==255){ + continue; + }else if($color==0 && $color_x==0 && $color_y==0 && $color_xy==0){ + $newred=$foreground_color[0]; + $newgreen=$foreground_color[1]; + $newblue=$foreground_color[2]; + }else{ + $frsx=$sx-floor($sx); + $frsy=$sy-floor($sy); + $frsx1=1-$frsx; + $frsy1=1-$frsy; + + $newcolor=( + $color*$frsx1*$frsy1+ + $color_x*$frsx*$frsy1+ + $color_y*$frsx1*$frsy+ + $color_xy*$frsx*$frsy); + + if($newcolor>255) $newcolor=255; + $newcolor=$newcolor/255; + $newcolor0=1-$newcolor; + + $newred=$newcolor0*$foreground_color[0]+$newcolor*$background_color[0]; + $newgreen=$newcolor0*$foreground_color[1]+$newcolor*$background_color[1]; + $newblue=$newcolor0*$foreground_color[2]+$newcolor*$background_color[2]; + } + + imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue)); + } + } + + $img_path = $this->get_img_path($cap_id); + file_write('', $img_path, null, true, true); + + imagejpeg($img2, $img_path, $jpeg_quality); +# imagegif($img2, $img_path); +# imagepng($img2, $img_path); + + imagedestroy($img2); + + return $this->keystring; + } } \ No newline at end of file diff --git a/upload/includes/class.correct.php b/upload/includes/class.correct.php index e7552b557..4056e5f01 100644 --- a/upload/includes/class.correct.php +++ b/upload/includes/class.correct.php @@ -1,3104 +1,3104 @@ - 'cosmo' (2 первых и последняя буква — ошибочные) - * "\x78\x70\x65н" => 'хрен' (первые 3 буквы — ошибочные) - * "вебvfcnth" => 'вебмастер' - * "webьфыеук" => 'webmaster' - * "цццюмуыеш.ru" => 'www.vesti.ru' - * "\x54.\x43.\x48\x61вка" => 'Т.С.Навка' - * - * Hints - * Типичный пример алгоритма работы для поля ввода с автодополнением: - * 1. Сделать выборку по исходному запросу; - * 2. Если есть результат, возвратить его и исходный запрос; - * 3. Иначе скорректировать исходный запрос через Text_LangCorrect; - * 4. Если исходный и скорректированный запрос совпадает, возвратить пустой результат и исходный запрос; - * 5. Иначе сделать выборку по скорректированному запросу; - * 6. Возвратить результат. Если результат не пустой, возвратить скорректированный запрос, иначе исходный. - * - * License - * Только для некоммерческого использования! - * - * @link http://code.google.com/p/php-lang-correct/ - * @license http://creativecommons.org/licenses/by-nc-sa/3.0/ - * @author Nasibullin Rinat - * @version 1.4.3 - */ -class Text_LangCorrect -{ - /** - * Флаг для исправления ошибочно набранных букв в словах, - * которые выглядят одинаково в разных раскладках клавиатуры. - * Алгоритм работает достаточно надёжно и быстро. - */ - const SIMILAR_CHARS = 1; - - /** - * Флаг для исправления ошибочно набранных слов в другой раскладке клавиатуры. - * Алгоритм может иногда ошибаться, работает в разы медленнее, чем SIMILAR_CHARS. - */ - const KEYBOARD_LAYOUT = 2; - - /** - * Флаг для добавления исправлений, если влючён флаг KEYBOARD_LAYOUT - * Синтаксис и пример: "(,.cn=>бюст)" - * ^ ^^ ^ - */ - const ADD_FIX = 4; - - #английский (all) - private $en = '[a-zA-Z]'; - - #английский (uppercase) - private $en_uc = '[A-Z]'; - - #английский + символы, которые м.б. набраны по ошибке в английской раскладке клавиатуры вместо русских букв (all) - private $en_sc = '[a-zA-Z\'`~<>,.:;{}\[\]"]'; - - #символы, которые м.б. набраны по ошибке в английской раскладке клавиатуры вместо русских букв - private $sc = '[\'`~<>,.:;{}\[\]"]'; - private $no_sc = '[^\'`~<>,.:;{}\[\]"]'; - - #русский + татарский (all) - private $tt = '[\xd0-\xd3][\x80-\xbf] - (?<=\xd0[\x90-\xbf\x81]|\xd1[\x80-\x8f\x91]|\xd2[\x96\x97\xa2\xa3\xae\xaf\xba\xbb]|\xd3[\x98\x99\xa8\xa9])'; - - #русский + татарский (uppercase) - private $tt_uc = '[\xd0\xd2\xd3][\x81-\xba] - (?<=\xd0[\x90-\xaf\x81]|\xd2[\x96\xa2\xae\xba]|\xd3[\x98\xa8])'; - - #русский + татарский (для фильтрованных текстов) (all) - private $tt_f = '[\xd0-\xd3][\x80-\xbf] - #комментируем для увеличения скорости, т.к. остальные символы отфильтрованы - #(?<=\xd0[\x90-\xbf\x81]|\xd1[\x80-\x8f\x91]|\xd2[\x96\x97\xa2\xa3\xae\xaf\xba\xbb]|\xd3[\x98\x99\xa8\xa9]) - '; - - #гласная (vowel) (lowercase) - private $vowel_lc = array( - 'tt' => '\xd0[\xb0\xb5\xb8\xbe]|\xd1[\x83\x8b\x8d\x8e\x8f\x91] #аеиоуыэюяё (гласные, 10 шт.) - #| \xd0[\x90\x95\x98\x9e\xa3\xab\xad\xae\xaf\x81] #АЕИОУЫЭЮЯЁ (гласные, 10 шт.) - ', - 'en' => '[aeiouy]', #латинских 6 шт. - ); - - #согласная (consonant) + графические знаки для русского языка (ъ, ь) (lowercase) - private $consonant_lc = array( - 'tt' => '\xd0[\xb1-\xb4\xb6\xb7\xb9\xba-\xbd\xbf]|\xd1[\x80\x81\x82\x84-\x89\x8a\x8c] #бвгджзйклмнпрстфхцчшщ ъь (согласные, 21+2 шт.) - #| \xd0[\x91-\x94\x96\x97\x99\x9a-\x9d\x9f-\xa2\xa4-\xa9\xaa\xac] #БВГДЖЗЙКЛМНПРСТФХЦЧШЩ ЪЬ (согласные, 21+2 шт.) - ', - 'en' => '[bcdfghjklmnpqrstvwxz]', #латинских 20 шт. - ); - - private $words_exceptions = array( - 'tt' => array( - 'трлн' => null, - 'ющенко' => null, - 'мебельград' => null, - 'дэнис' => null, - ), - 'en' => array( - 'heuer' => null, - ), - ); - - #русские буквы, похожие на англ. (uppercase) - private $ru_similar_uc = "\xd0[\x90\x92\x95\x9a\x9c\x9d\x9e\xa0-\xa3\xa5]"; - - #русские буквы, похожие на англ. (all) - private $ru_similar = "\xd0[\x90\x92\x95\x9a\x9c\x9d\x9e\xa0-\xa3\xa5\xb0\xb5\xbe]|\xd1[\x80\x81\x83\x85]"; - - #англ. буквы, похожие на русские (uppercase) - private $en_similar_uc = '[ABEKMHOPCTYX]'; - - /* - #$tt_fake = '\xd0[\xb0\xb5\xbe\x90\x92\x95\x9a\x9c\x9d\x9e\xa0\xa1\xa2\xa3\xa5]|\xd1[\x80\x81\x83\x85]'; - $tt_fake = '[\xd0\xd1][\x80-\xbe] - (?<=\xd0[\xb0\xb5\xbe\x90\x92\x95\x9a\x9c\x9d\x9e\xa0\xa1\xa2\xa3\xa5]|\xd1[\x80\x81\x83\x85])'; - $en_fake = '[aeopcyxABEKMHOPCTYX]'; - */ - - #уникальные русские буквы - /* - CASE_UPPER, case_lower - "\xd0\x81", "\xd1\x91", #Ё ё - "\xd0\x91", "\xd0\xb1", #Б б - "\xd0\x92", "\xd0\xb2", #В в - "\xd0\x93", "\xd0\xb3", #Г г - "\xd0\x94", "\xd0\xb4", #Д д - "\xd0\x96", "\xd0\xb6", #Ж ж - "\xd0\x97", "\xd0\xb7", #З з - "\xd0\x98", "\xd0\xb8", #И и - "\xd0\x99", "\xd0\xb9", #Й й - "\xd0\xba", #К к - "\xd0\x9b", "\xd0\xbb", #Л л - "\xd0\xbd", #Н н - "\xd0\x9f", "\xd0\xbf", #П п - "\xd1\x82", #Т т - "\xd0\xa4", "\xd1\x84", #Ф ф - "\xd0\xa6", "\xd1\x86", #Ц ц - "\xd0\xa7", "\xd1\x87", #Ч ч - "\xd0\xa8", "\xd1\x88", #Ш ш - "\xd0\xa9", "\xd1\x89", #Щ щ - "\xd0\xaa", "\xd1\x8a", #Ъ ъ - "\xd0\xab", "\xd1\x8b", #Ы ы - "\xd0\xac", "\xd1\x8c", #Ь ь - "\xd0\xad", "\xd1\x8d", #Э э - "\xd0\xae", "\xd1\x8e", #Ю ю - "\xd0\xaf", "\xd1\x8f", #Я я - */ - #$tt_uniq = "\xd0[\xb1-\xb4\xb6-\xbb\xbd\xbf\x81\x91-\x94\x96-\x99\x9b\x9f\xa4\xa6-\xaf]|\xd1[\x82\x84\x86-\x8f\x91]"; - private $tt_uniq = "[\xd0\xd1][\x82-\xbf] - (?<=\xd0[\xb1-\xb4\xb6-\xbb\xbd\xbf\x81\x91-\x94\x96-\x99\x9b\x9f\xa4\xa6-\xaf]|\xd1[\x82\x84\x86-\x8f\x91])"; - - #уникальные латинские буквы - /* - CASE_UPPER, case_lower - "\x42", "\x62", #B b - "\x44", "\x64", #D d - "\x46", "\x66", #F f - "\x68", #H h - "\x49", "\x69", #I i - "\x4a", "\x6a", #J j - "\x6b", #K k - "\x4c", "\x6c", #L l - "\x6d", #M m - "\x4e", "\x6e", #N n - "\x51", "\x71", #Q q - "\x52", "\x72", #R r - "\x53", "\x73", #S s - "\x74", #T t - "\x55", "\x75", #U u - "\x56", "\x76", #V v - "\x57", "\x77", #W w - "\x5a", "\x7a", #Z z - */ - private $en_uniq = "[\x42\x44\x46\x49\x4a\x4c\x4e\x51\x52\x53\x55\x57\x56\x5a\x62\x64\x66\x68\x69\x6a-\x6e\x71-\x77\x7a]"; - - private $table_flip; #array - private $words; #corrected words - private $en_correct; #string - private $tt_correct; #string - private $mode; #bool - - private $is_flip = false; - private $method = 0; - - private $table = array( - #метод 0: таблица исправления ошибочно набранных букв, которые выглядят одинаково (русский <--> английский) - 0 => array( - #lowercase #UPPERCASE - "\xd0\xb0" => 'a', "\xd0\x90" => 'A', - "\xd0\x92" => 'B', - "\xd0\xb5" => 'e', "\xd0\x95" => 'E', - "\xd0\x9a" => 'K', - "\xd0\x9c" => 'M', - "\xd0\x9d" => 'H', - "\xd0\xbe" => 'o', "\xd0\x9e" => 'O', - "\xd1\x80" => 'p', "\xd0\xa0" => 'P', - "\xd1\x81" => 'c', "\xd0\xa1" => 'C', - "\xd0\xa2" => 'T', - "\xd1\x83" => 'y', "\xd0\xa3" => 'Y', - "\xd1\x85" => 'x', "\xd0\xa5" => 'X', - ), - #метод 1: таблица исправления ошибочно набранных букв в другой раскладке клавиатуры (русский <--> английский) - 1 => array( - #CASE_UPPER #case_lower - "\xd0\x81" => '~', "\xd1\x91" => '`', #Ё ё - "\xd0\x90" => 'F', "\xd0\xb0" => 'f', #А а - "\xd0\x91" => '<', "\xd0\xb1" => ',', #Б б - "\xd0\x92" => 'D', "\xd0\xb2" => 'd', #В в - "\xd0\x93" => 'U', "\xd0\xb3" => 'u', #Г г - "\xd0\x94" => 'L', "\xd0\xb4" => 'l', #Д д - "\xd0\x95" => 'T', "\xd0\xb5" => 't', #Е е - "\xd0\x96" => ':', "\xd0\xb6" => ';', #Ж ж - "\xd0\x97" => 'P', "\xd0\xb7" => 'p', #З з - "\xd0\x98" => 'B', "\xd0\xb8" => 'b', #И и - "\xd0\x99" => 'Q', "\xd0\xb9" => 'q', #Й й - "\xd0\x9a" => 'R', "\xd0\xba" => 'r', #К к - "\xd0\x9b" => 'K', "\xd0\xbb" => 'k', #Л л - "\xd0\x9c" => 'V', "\xd0\xbc" => 'v', #М м - "\xd0\x9d" => 'Y', "\xd0\xbd" => 'y', #Н н - "\xd0\x9e" => 'J', "\xd0\xbe" => 'j', #О о - "\xd0\x9f" => 'G', "\xd0\xbf" => 'g', #П п - #CASE_UPPER #case_lower - "\xd0\xa0" => 'H', "\xd1\x80" => 'h', #Р р - "\xd0\xa1" => 'C', "\xd1\x81" => 'c', #С с - "\xd0\xa2" => 'N', "\xd1\x82" => 'n', #Т т - "\xd0\xa3" => 'E', "\xd1\x83" => 'e', #У у - "\xd0\xa4" => 'A', "\xd1\x84" => 'a', #Ф ф - "\xd0\xa5" => '{', "\xd1\x85" => '[', #Х х - "\xd0\xa6" => 'W', "\xd1\x86" => 'w', #Ц ц - "\xd0\xa7" => 'X', "\xd1\x87" => 'x', #Ч ч - "\xd0\xa8" => 'I', "\xd1\x88" => 'i', #Ш ш - "\xd0\xa9" => 'O', "\xd1\x89" => 'o', #Щ щ - "\xd0\xaa" => '}', "\xd1\x8a" => ']', #Ъ ъ - "\xd0\xab" => 'S', "\xd1\x8b" => 's', #Ы ы - "\xd0\xac" => 'M', "\xd1\x8c" => 'm', #Ь ь - "\xd0\xad" => '"', "\xd1\x8d" => "'", #Э э - "\xd0\xae" => '>', "\xd1\x8e" => '.', #Ю ю - "\xd0\xaf" => 'Z', "\xd1\x8f" => 'z', #Я я - ), - ); - - #несуществующие N-граммы для гласных букв - private $vowels3_lc = array( - 'en' => array( - 'aea' => 0, - 'aei' => 1, - 'aeo' => 2, - 'aeu' => 3, - 'aia' => 4, - 'aie' => 5, - 'aii' => 6, - 'aoi' => 7, - 'aou' => 8, - 'aue' => 9, - 'aya' => 10, - 'aye' => 11, - 'ayi' => 12, - 'ayo' => 13, - 'ayu' => 14, - 'eae' => 15, - 'eau' => 16, - 'eea' => 17, - 'eei' => 18, - 'eeu' => 19, - 'eia' => 20, - 'eiu' => 21, - 'eoi' => 22, - 'eou' => 23, - 'eya' => 24, - 'eye' => 25, - 'eyi' => 26, - 'eyo' => 27, - 'iae' => 28, - 'iai' => 29, - 'iao' => 30, - 'iau' => 31, - 'iei' => 32, - 'ieu' => 33, - 'ioa' => 34, - 'ioe' => 35, - 'iou' => 36, - 'iya' => 37, - 'oae' => 38, - 'oea' => 39, - 'oei' => 40, - 'oeo' => 41, - 'oeu' => 42, - 'oey' => 43, - 'oia' => 44, - 'oie' => 45, - 'ooe' => 46, - 'ooi' => 47, - 'oou' => 48, - 'oua' => 49, - 'oue' => 50, - 'oui' => 51, - 'oya' => 52, - 'oye' => 53, - 'oyi' => 54, - 'oyo' => 55, - 'uae' => 56, - 'uai' => 57, - 'uay' => 58, - 'uea' => 59, - 'uee' => 60, - 'uei' => 61, - 'ueo' => 62, - 'ueu' => 63, - 'uey' => 64, - 'uia' => 65, - 'uie' => 66, - 'uio' => 67, - 'uiu' => 68, - 'uoa' => 69, - 'uoi' => 70, - 'uou' => 71, - 'uoy' => 72, - 'uya' => 73, - 'uye' => 74, - 'uyi' => 75, - 'yae' => 76, - 'yao' => 77, - 'yau' => 78, - 'yea' => 79, - 'yei' => 80, - 'yeo' => 81, - 'yey' => 82, - 'yie' => 83, - 'yoi' => 84, - 'you' => 85, - 'yoy' => 86, - 'yua' => 87, - ), - 'tt' => array( - 'аау' => 0, - 'аео' => 1, - 'аеу' => 2, - 'аиа' => 3, - 'аио' => 4, - 'аиу' => 5, - 'аои' => 6, - 'ауэ' => 7, - 'аяя' => 8, - 'еаэ' => 9, - 'еее' => 10, - 'еео' => 11, - 'еоа' => 12, - 'еои' => 13, - 'еоо' => 14, - 'еую' => 15, - 'еуя' => 16, - 'еуё' => 17, - 'иау' => 18, - 'иео' => 19, - 'иие' => 20, - 'иоа' => 21, - 'иои' => 22, - 'иоу' => 23, - 'иоэ' => 24, - 'ияе' => 25, - 'ияи' => 26, - 'ияю' => 27, - 'оаэ' => 28, - 'оео' => 29, - 'оею' => 30, - 'оие' => 31, - 'оуе' => 32, - 'оуя' => 33, - 'оюе' => 34, - 'оюю' => 35, - 'ояе' => 36, - 'уео' => 37, - 'уюю' => 38, - ), - ); - - #несуществующие N-граммы для согласных букв - private $consonants4_lc = array( - 'en' => array( - 'bldg' => 0, - 'blvd' => 1, - 'bscr' => 2, - 'bstr' => 3, - 'cbcm' => 4, - 'cbft' => 5, - 'chfr' => 6, - 'chmn' => 7, - 'chsc' => 8, - 'chsh' => 9, - 'chst' => 10, - 'chth' => 11, - 'chts' => 12, - 'ckbr' => 13, - 'ckch' => 14, - 'ckcl' => 15, - 'ckdr' => 16, - 'ckgr' => 17, - 'cksc' => 18, - 'cksf' => 19, - 'cksh' => 20, - 'cksk' => 21, - 'cksl' => 22, - 'cksm' => 23, - 'cksn' => 24, - 'cksp' => 25, - 'ckst' => 26, - 'cksw' => 27, - 'ckth' => 28, - 'cktr' => 29, - 'ckwh' => 30, - 'cmps' => 31, - 'dspr' => 32, - 'dstr' => 33, - 'dthw' => 34, - 'ffsc' => 35, - 'ffsh' => 36, - 'ffsp' => 37, - 'fthl' => 38, - 'ftsm' => 39, - 'ftsp' => 40, - 'gdns' => 41, - 'ghbr' => 42, - 'ghfl' => 43, - 'ghsh' => 44, - 'ghtb' => 45, - 'ghtc' => 46, - 'ghtf' => 47, - 'ghth' => 48, - 'ghtj' => 49, - 'ghtl' => 50, - 'ghtm' => 51, - 'ghtn' => 52, - 'ghtr' => 53, - 'ghts' => 54, - 'ghtw' => 55, - 'hdbk' => 56, - 'hnst' => 57, - 'jctn' => 58, - 'khsh' => 59, - 'khst' => 60, - 'lchr' => 61, - 'ldpr' => 62, - 'ldsh' => 63, - 'ldsm' => 64, - 'ldsp' => 65, - 'ldst' => 66, - 'lfsk' => 67, - 'lfth' => 68, - 'lgth' => 69, - 'llfl' => 70, - 'llfr' => 71, - 'llph' => 72, - 'llpl' => 73, - 'llsh' => 74, - 'llsp' => 75, - 'llst' => 76, - 'lltr' => 77, - 'llwr' => 78, - 'lmcr' => 79, - 'lmsm' => 80, - 'lnrk' => 81, - 'lnsh' => 82, - 'lptr' => 83, - 'lsgr' => 84, - 'lshm' => 85, - 'lshw' => 86, - 'lstr' => 87, - 'lthf' => 88, - 'ltsf' => 89, - 'ltsh' => 90, - 'ltst' => 91, - 'mbsc' => 92, - 'mbsh' => 93, - 'mbsk' => 94, - 'mbst' => 95, - 'mddx' => 96, - 'mdnt' => 97, - 'mpbl' => 98, - 'mpgr' => 99, - 'mphl' => 100, - 'mphr' => 101, - 'mpsh' => 102, - 'mpst' => 103, - 'mptl' => 104, - 'mptn' => 105, - 'mptr' => 106, - 'mpts' => 107, - 'mscr' => 108, - 'mstr' => 109, - 'nchb' => 110, - 'nchl' => 111, - 'nchm' => 112, - 'nchn' => 113, - 'nchp' => 114, - 'nchr' => 115, - 'nchw' => 116, - 'nctl' => 117, - 'nctn' => 118, - 'ndbk' => 119, - 'ndbr' => 120, - 'ndch' => 121, - 'ndfl' => 122, - 'ndgl' => 123, - 'ndgr' => 124, - 'ndsc' => 125, - 'ndsh' => 126, - 'ndsl' => 127, - 'ndsm' => 128, - 'ndsp' => 129, - 'ndst' => 130, - 'ndsw' => 131, - 'ndth' => 132, - 'ndwr' => 133, - 'ngcr' => 134, - 'ngsg' => 135, - 'ngsh' => 136, - 'ngsm' => 137, - 'ngsp' => 138, - 'ngst' => 139, - 'ngth' => 140, - 'ngtz' => 141, - 'nksg' => 142, - 'nksh' => 143, - 'nksm' => 144, - 'nkst' => 145, - 'nsch' => 146, - 'nscr' => 147, - 'nsgr' => 148, - 'nshr' => 149, - 'nskr' => 150, - 'nspl' => 151, - 'nspr' => 152, - 'nssh' => 153, - 'nstr' => 154, - 'ntbr' => 155, - 'nthl' => 156, - 'nthr' => 157, - 'nths' => 158, - 'ntsh' => 159, - 'ntsm' => 160, - 'phth' => 161, - 'pstr' => 162, - 'pthr' => 163, - 'pths' => 164, - 'ptwr' => 165, - 'rbst' => 166, - 'rchb' => 167, - 'rchd' => 168, - 'rchl' => 169, - 'rchm' => 170, - 'rchn' => 171, - 'rchp' => 172, - 'rchw' => 173, - 'rdsh' => 174, - 'rdsm' => 175, - 'rdst' => 176, - 'rghs' => 177, - 'rkpl' => 178, - 'rksc' => 179, - 'rksh' => 180, - 'rksk' => 181, - 'rksm' => 182, - 'rksp' => 183, - 'rkst' => 184, - 'rldl' => 185, - 'rldw' => 186, - 'rlfr' => 187, - 'rmch' => 188, - 'rmst' => 189, - 'rmth' => 190, - 'rnbl' => 191, - 'rndl' => 192, - 'rnsk' => 193, - 'rnsp' => 194, - 'rnst' => 195, - 'rsch' => 196, - 'rscr' => 197, - 'rshl' => 198, - 'rshn' => 199, - 'rspr' => 200, - 'rstl' => 201, - 'rstr' => 202, - 'rsts' => 203, - 'rstw' => 204, - 'rtbr' => 205, - 'rtch' => 206, - 'rtcr' => 207, - 'rthb' => 208, - 'rthc' => 209, - 'rthd' => 210, - 'rthf' => 211, - 'rthl' => 212, - 'rthm' => 213, - 'rthq' => 214, - 'rthr' => 215, - 'rths' => 216, - 'rthw' => 217, - 'rtsh' => 218, - 'rtsm' => 219, - 'rtsp' => 220, - 'rtsw' => 221, - 'schl' => 222, - 'schm' => 223, - 'schn' => 224, - 'schw' => 225, - 'scrp' => 226, - 'sgmt' => 227, - 'shcl' => 228, - 'shkh' => 229, - 'shpr' => 230, - 'shpt' => 231, - 'shst' => 232, - 'shtr' => 233, - 'shwh' => 234, - 'smth' => 235, - 'ssrs' => 236, - 'ssst' => 237, - 'sstd' => 238, - 'sstr' => 239, - 'stcr' => 240, - 'sthm' => 241, - 'stpl' => 242, - 'stpr' => 243, - 'stsc' => 244, - 'stwr' => 245, - 'tblt' => 246, - 'tchb' => 247, - 'tchc' => 248, - 'tchd' => 249, - 'tchf' => 250, - 'tchl' => 251, - 'tchm' => 252, - 'tchp' => 253, - 'tchw' => 254, - 'thdr' => 255, - 'thsh' => 256, - 'thsk' => 257, - 'thsp' => 258, - 'thst' => 259, - 'tsch' => 260, - 'tspr' => 261, - 'tstr' => 262, - 'tthr' => 263, - 'ttsb' => 264, - 'tzkr' => 265, - 'whsl' => 266, - 'wnbr' => 267, - 'wnpl' => 268, - 'wnsf' => 269, - 'wnsh' => 270, - 'wnsm' => 271, - 'wnsp' => 272, - 'wnst' => 273, - 'wnsw' => 274, - 'wnth' => 275, - 'wntr' => 276, - 'wrnt' => 277, - 'wsfl' => 278, - 'wspr' => 279, - 'wstr' => 280, - 'xthl' => 281, - ), - 'tt' => array( - 'блзд' => 0, - 'бльд' => 1, - 'брьс' => 2, - 'бств' => 3, - 'бстр' => 4, - 'взбл' => 5, - 'взбр' => 6, - 'взгл' => 7, - 'взгр' => 8, - 'вздв' => 9, - 'вздр' => 10, - 'врвг' => 11, - 'врск' => 12, - 'вскл' => 13, - 'вскр' => 14, - 'вспл' => 15, - 'вспр' => 16, - 'вств' => 17, - 'встр' => 18, - 'всхл' => 19, - 'всхр' => 20, - 'втск' => 21, - 'вхск' => 22, - 'грск' => 23, - 'гств' => 24, - 'гтст' => 25, - 'гшпр' => 26, - 'двзд' => 27, - 'джск' => 28, - 'дрст' => 29, - 'дскр' => 30, - 'дств' => 31, - 'дстр' => 32, - 'дтск' => 33, - 'жств' => 34, - 'звзд' => 35, - 'знст' => 36, - 'зтьс' => 37, - 'йздр' => 38, - 'йкбр' => 39, - 'йльн' => 40, - 'йншт' => 41, - 'йпфр' => 42, - 'йств' => 43, - 'йстр' => 44, - 'йтск' => 45, - 'йфст' => 46, - 'йхсв' => 47, - 'йхск' => 48, - 'йхср' => 49, - 'йхст' => 50, - 'кскл' => 51, - 'кскр' => 52, - 'кспл' => 53, - 'кспр' => 54, - 'кств' => 55, - 'кстн' => 56, - 'кстр' => 57, - 'лвст' => 58, - 'лжск' => 59, - 'лльн' => 60, - 'лльс' => 61, - 'лстр' => 62, - 'лсть' => 63, - 'льгв' => 64, - 'льдж' => 65, - 'льдк' => 66, - 'льдм' => 67, - 'льдс' => 68, - 'льдф' => 69, - 'льдц' => 70, - 'льдш' => 71, - 'льдъ' => 72, - 'льдь' => 73, - 'льзк' => 74, - 'льзн' => 75, - 'льзь' => 76, - 'лькл' => 77, - 'лькн' => 78, - 'льпн' => 79, - 'льпт' => 80, - 'льск' => 81, - 'льсн' => 82, - 'льст' => 83, - 'льтк' => 84, - 'льтм' => 85, - 'льтн' => 86, - 'льтп' => 87, - 'льтр' => 88, - 'льтс' => 89, - 'льтт' => 90, - 'льтф' => 91, - 'льфр' => 92, - 'льцг' => 93, - 'льчс' => 94, - 'льшб' => 95, - 'льшк' => 96, - 'льшн' => 97, - 'льшп' => 98, - 'льшф' => 99, - 'льшь' => 100, - 'мбль' => 101, - 'мбрс' => 102, - 'мвзв' => 103, - 'мздр' => 104, - 'мств' => 105, - 'мтск' => 106, - 'нгль' => 107, - 'нгст' => 108, - 'ндгр' => 109, - 'ндск' => 110, - 'ндсп' => 111, - 'ндшп' => 112, - 'ндшт' => 113, - 'нкск' => 114, - 'нктн' => 115, - 'нктс' => 116, - 'нсгр' => 117, - 'нскм' => 118, - 'нскр' => 119, - 'нспл' => 120, - 'нств' => 121, - 'нстк' => 122, - 'нстр' => 123, - 'нтгл' => 124, - 'нтль' => 125, - 'нтрб' => 126, - 'нтрв' => 127, - 'нтрг' => 128, - 'нтрд' => 129, - 'нтрм' => 130, - 'нтрн' => 131, - 'нтрп' => 132, - 'нтрр' => 133, - 'нтрф' => 134, - 'нтск' => 135, - 'нтст' => 136, - 'нфск' => 137, - 'нцкл' => 138, - 'нцпл' => 139, - 'нькн' => 140, - 'ньск' => 141, - 'ньчж' => 142, - 'псск' => 143, - 'пств' => 144, - 'птск' => 145, - 'рбск' => 146, - 'ргпр' => 147, - 'ргск' => 148, - 'ргфл' => 149, - 'рдск' => 150, - 'рдсм' => 151, - 'рдст' => 152, - 'рздр' => 153, - 'рзть' => 154, - 'ркгр' => 155, - 'ркск' => 156, - 'рктн' => 157, - 'рльс' => 158, - 'рмск' => 159, - 'рмтр' => 160, - 'рнск' => 161, - 'рпск' => 162, - 'рсдр' => 163, - 'рсск' => 164, - 'рств' => 165, - 'рстк' => 166, - 'рстн' => 167, - 'рстр' => 168, - 'рстс' => 169, - 'рсть' => 170, - 'ртвл' => 171, - 'ртвр' => 172, - 'ртгр' => 173, - 'рткр' => 174, - 'ртпл' => 175, - 'ртпр' => 176, - 'ртск' => 177, - 'ртсм' => 178, - 'ртшк' => 179, - 'ртьф' => 180, - 'рхзв' => 181, - 'рхпл' => 182, - 'рхпр' => 183, - 'рхсв' => 184, - 'рхск' => 185, - 'рхсм' => 186, - 'рхср' => 187, - 'рхтв' => 188, - 'рхшт' => 189, - 'рщвл' => 190, - 'рьмл' => 191, - 'скск' => 192, - 'спрь' => 193, - 'сспр' => 194, - 'ссср' => 195, - 'сств' => 196, - 'сстр' => 197, - 'ссшп' => 198, - 'ствл' => 199, - 'стрс' => 200, - 'стрш' => 201, - 'стск' => 202, - 'стьб' => 203, - 'стьд' => 204, - 'стьс' => 205, - 'ськн' => 206, - 'сьмн' => 207, - 'тмст' => 208, - 'тпрр' => 209, - 'трст' => 210, - 'тскр' => 211, - 'тств' => 212, - 'тстр' => 213, - 'ттль' => 214, - 'ттск' => 215, - 'тхск' => 216, - 'фств' => 217, - 'фстр' => 218, - 'хств' => 219, - 'хстр' => 220, - 'хткл' => 221, - 'хтск' => 222, - 'хтсм' => 223, - 'цстр' => 224, - ), - ); - - #несуществующие биграммы в начале и конце слов - private $bigrams = array( - #ru - ' ёё' => 0, - ' ёа' => 0, - ' ёб' => 0, - ' ёв' => 0, - ' ёг' => 0, - ' ёд' => 0, - ' ёе' => 0, - ' ёз' => 0, - ' ёи' => 0, - ' ёй' => 0, - ' ён' => 0, - ' ёо' => 0, - ' ёп' => 0, - ' ёс' => 0, - ' ёт' => 0, - ' ёу' => 0, - ' ёф' => 0, - ' ёц' => 0, - ' ёч' => 0, - ' ёщ' => 0, - ' ёъ' => 0, - ' ёы' => 0, - ' ёь' => 0, - ' ёэ' => 0, - ' ёю' => 0, - ' ёя' => 0, - ' аё' => 0, - ' аа' => 0, - ' ае' => 0, - ' ач' => 0, - ' аъ' => 0, - ' аы' => 0, - ' аь' => 0, - ' аю' => 0, - ' ая' => 0, - ' бб' => 0, - ' бв' => 0, - ' бг' => 0, - ' бж' => 0, - ' бй' => 0, - ' бк' => 0, - ' бм' => 0, - ' бн' => 0, - ' бп' => 0, - ' бс' => 0, - ' бт' => 0, - ' бф' => 0, - ' бх' => 0, - ' бц' => 0, - ' бч' => 0, - ' бш' => 0, - ' бщ' => 0, - ' бъ' => 0, - ' вй' => 0, - ' вф' => 0, - ' вщ' => 0, - ' вэ' => 0, - ' вю' => 0, - ' гё' => 0, - ' гб' => 0, - ' гз' => 0, - ' гй' => 0, - ' гк' => 0, - ' гп' => 0, - ' гс' => 0, - ' гт' => 0, - ' гф' => 0, - ' гх' => 0, - ' гц' => 0, - ' гч' => 0, - ' гш' => 0, - ' гщ' => 0, - ' гъ' => 0, - ' гь' => 0, - ' гэ' => 0, - ' дб' => 0, - ' дг' => 0, - ' дд' => 0, - ' дй' => 0, - ' дк' => 0, - ' дп' => 0, - ' дс' => 0, - ' дт' => 0, - ' дф' => 0, - ' дх' => 0, - ' дц' => 0, - ' дч' => 0, - ' дш' => 0, - ' дъ' => 0, - ' дэ' => 0, - ' еа' => 0, - ' еб' => 0, - ' еи' => 0, - ' ео' => 0, - ' ет' => 0, - ' еу' => 0, - ' ец' => 0, - #' еш' => 0, - ' еъ' => 0, - ' еы' => 0, - ' еь' => 0, - ' еэ' => 0, - ' ея' => 0, - ' жз' => 0, - ' жй' => 0, - ' жк' => 0, - ' жл' => 0, - ' жп' => 0, - ' жс' => 0, - ' жт' => 0, - ' жф' => 0, - ' жх' => 0, - ' жц' => 0, - ' жч' => 0, - ' жш' => 0, - ' жщ' => 0, - ' жъ' => 0, - ' жы' => 0, - ' жь' => 0, - ' жэ' => 0, - #' жю' => 0, - ' жя' => 0, - ' зб' => 0, - ' зж' => 0, - ' зз' => 0, - ' зй' => 0, - ' зк' => 0, - ' зп' => 0, - ' зс' => 0, - ' зт' => 0, - ' зф' => 0, - ' зх' => 0, - ' зц' => 0, - ' зч' => 0, - ' зш' => 0, - ' зщ' => 0, - ' зъ' => 0, - ' зь' => 0, - ' зэ' => 0, - ' иё' => 0, - ' иа' => 0, - ' иф' => 0, - ' иц' => 0, - ' иъ' => 0, - ' иы' => 0, - ' иь' => 0, - ' иэ' => 0, - ' ия' => 0, - ' йё' => 0, - ' йа' => 0, - ' йб' => 0, - ' йв' => 0, - ' йг' => 0, - ' йд' => 0, - ' йж' => 0, - ' йз' => 0, - ' йи' => 0, - ' йй' => 0, - ' йк' => 0, - ' йл' => 0, - ' йм' => 0, - ' йн' => 0, - ' йп' => 0, - ' йр' => 0, - ' йс' => 0, - ' йт' => 0, - ' йу' => 0, - ' йф' => 0, - ' йх' => 0, - ' йц' => 0, - ' йч' => 0, - ' йш' => 0, - ' йщ' => 0, - ' йъ' => 0, - ' йы' => 0, - ' йь' => 0, - ' йэ' => 0, - ' йю' => 0, - ' йя' => 0, - ' кё' => 0, - ' кб' => 0, - ' кд' => 0, - ' кж' => 0, - ' кй' => 0, - ' кк' => 0, - ' кф' => 0, - ' кц' => 0, - ' кч' => 0, - ' кщ' => 0, - ' къ' => 0, - ' кя' => 0, - ' лв' => 0, - ' лд' => 0, - ' лз' => 0, - ' лй' => 0, - ' лк' => 0, - ' лл' => 0, - ' лм' => 0, - ' лн' => 0, - ' лп' => 0, - ' лр' => 0, - ' лс' => 0, - ' лт' => 0, - ' лф' => 0, - ' лх' => 0, - ' лц' => 0, - ' лч' => 0, - ' лш' => 0, - ' лщ' => 0, - ' лъ' => 0, - ' лэ' => 0, - ' мб' => 0, - ' мв' => 0, - ' мд' => 0, - ' мж' => 0, - ' мй' => 0, - ' мк' => 0, - ' мп' => 0, - ' мт' => 0, - ' мф' => 0, - ' мц' => 0, - ' мъ' => 0, - ' мь' => 0, - ' нб' => 0, - ' нв' => 0, - ' нг' => 0, - ' нд' => 0, - ' нж' => 0, - ' нз' => 0, - ' нй' => 0, - ' нк' => 0, - ' нл' => 0, - ' нм' => 0, - ' нн' => 0, - ' нп' => 0, - ' нс' => 0, - ' нт' => 0, - ' нф' => 0, - ' нх' => 0, - ' нц' => 0, - ' нч' => 0, - ' нш' => 0, - ' нщ' => 0, - ' нъ' => 0, - ' оё' => 0, - ' ои' => 0, - ' оу' => 0, - ' оъ' => 0, - ' оы' => 0, - ' оь' => 0, - ' оэ' => 0, - ' оя' => 0, - ' пб' => 0, - ' пв' => 0, - ' пг' => 0, - ' пд' => 0, - ' пж' => 0, - ' пз' => 0, - ' пй' => 0, - ' пк' => 0, - ' пм' => 0, - ' пп' => 0, - ' пц' => 0, - ' пщ' => 0, - ' пъ' => 0, - ' рб' => 0, - ' рг' => 0, - ' рз' => 0, - ' рй' => 0, - ' рк' => 0, - ' рл' => 0, - ' рм' => 0, - ' рн' => 0, - ' рп' => 0, - ' рр' => 0, - ' рф' => 0, - ' рх' => 0, - ' рч' => 0, - ' рш' => 0, - ' рщ' => 0, - ' ръ' => 0, - ' сй' => 0, - ' сщ' => 0, - ' тб' => 0, - ' тг' => 0, - ' тд' => 0, - ' тж' => 0, - ' тз' => 0, - ' тй' => 0, - ' тн' => 0, - ' тт' => 0, - ' тх' => 0, - ' тц' => 0, - ' тч' => 0, - ' тш' => 0, - ' тъ' => 0, - ' уу' => 0, - ' уъ' => 0, - ' уы' => 0, - ' уь' => 0, - ' фб' => 0, - ' фв' => 0, - ' фг' => 0, - ' фд' => 0, - ' фж' => 0, - ' фз' => 0, - ' фй' => 0, - ' фк' => 0, - ' фм' => 0, - ' фн' => 0, - ' фп' => 0, - ' фс' => 0, - ' фх' => 0, - ' фц' => 0, - ' фч' => 0, - ' фш' => 0, - ' фщ' => 0, - ' фъ' => 0, - ' фэ' => 0, - ' фя' => 0, - ' хё' => 0, - ' хб' => 0, - ' хг' => 0, - ' хд' => 0, - ' хж' => 0, - ' хз' => 0, - ' хй' => 0, - ' хк' => 0, - ' хп' => 0, - ' хс' => 0, - ' хт' => 0, - ' хф' => 0, - ' хц' => 0, - ' хч' => 0, - ' хш' => 0, - ' хщ' => 0, - ' хъ' => 0, - ' хы' => 0, - ' хь' => 0, - #' хэ' => 0, - ' хю' => 0, - ' хя' => 0, - ' цё' => 0, - ' цб' => 0, - ' цг' => 0, - ' цд' => 0, - ' цж' => 0, - ' цй' => 0, - ' цл' => 0, - ' цм' => 0, - ' цн' => 0, - ' цп' => 0, - ' цр' => 0, - ' цс' => 0, - ' цт' => 0, - ' цф' => 0, - ' цх' => 0, - ' цц' => 0, - ' цч' => 0, - ' цш' => 0, - ' цщ' => 0, - ' цъ' => 0, - ' ць' => 0, - ' цэ' => 0, - ' цю' => 0, - ' ця' => 0, - ' чб' => 0, - ' чг' => 0, - ' чд' => 0, - ' чж' => 0, - ' чз' => 0, - ' чй' => 0, - ' чн' => 0, - ' чп' => 0, - ' чс' => 0, - ' чф' => 0, - ' чц' => 0, - ' чч' => 0, - ' чщ' => 0, - ' чъ' => 0, - ' чы' => 0, - ' чэ' => 0, - ' чю' => 0, - ' чя' => 0, - ' шб' => 0, - ' шг' => 0, - ' шд' => 0, - ' шж' => 0, - ' шз' => 0, - ' шй' => 0, - ' шс' => 0, - ' шф' => 0, - ' шц' => 0, - ' шч' => 0, - ' шщ' => 0, - ' шъ' => 0, - ' шы' => 0, - ' шэ' => 0, - ' шю' => 0, - ' шя' => 0, - ' щб' => 0, - ' щв' => 0, - ' щг' => 0, - ' щд' => 0, - ' щж' => 0, - ' щз' => 0, - ' щй' => 0, - ' щк' => 0, - ' щл' => 0, - ' щм' => 0, - ' щн' => 0, - ' що' => 0, - ' щп' => 0, - ' щр' => 0, - ' щс' => 0, - ' щт' => 0, - ' щф' => 0, - ' щх' => 0, - ' щц' => 0, - ' щч' => 0, - ' щш' => 0, - ' щщ' => 0, - ' щъ' => 0, - ' щы' => 0, - ' щь' => 0, - ' щэ' => 0, - ' щю' => 0, - ' щя' => 0, - ' ъё' => 0, - ' ъа' => 0, - ' ъб' => 0, - ' ъв' => 0, - ' ъг' => 0, - ' ъд' => 0, - ' ъе' => 0, - ' ъж' => 0, - ' ъз' => 0, - ' ъи' => 0, - ' ъй' => 0, - ' ък' => 0, - ' ъл' => 0, - ' ъм' => 0, - ' ън' => 0, - ' ъо' => 0, - ' ъп' => 0, - ' ър' => 0, - ' ъс' => 0, - ' ът' => 0, - ' ъу' => 0, - ' ъф' => 0, - ' ъх' => 0, - ' ъц' => 0, - ' ъч' => 0, - ' ъш' => 0, - ' ъщ' => 0, - ' ъъ' => 0, - ' ъы' => 0, - ' ъь' => 0, - ' ъэ' => 0, - ' ъю' => 0, - ' ъя' => 0, - ' ыё' => 0, - ' ыа' => 0, - ' ыб' => 0, - ' ыв' => 0, - ' ыг' => 0, - ' ыд' => 0, - ' ые' => 0, - ' ыж' => 0, - ' ыз' => 0, - ' ыи' => 0, - ' ый' => 0, - ' ык' => 0, - ' ыл' => 0, - ' ын' => 0, - ' ыо' => 0, - ' ып' => 0, - ' ыр' => 0, - ' ыс' => 0, - ' ыт' => 0, - ' ыу' => 0, - ' ыф' => 0, - ' ых' => 0, - ' ыц' => 0, - ' ыч' => 0, - ' ыш' => 0, - ' ыщ' => 0, - ' ыъ' => 0, - ' ыы' => 0, - ' ыь' => 0, - ' ыэ' => 0, - ' ыю' => 0, - ' ыя' => 0, - ' ьё' => 0, - ' ьа' => 0, - ' ьб' => 0, - ' ьв' => 0, - ' ьг' => 0, - ' ьд' => 0, - ' ье' => 0, - ' ьж' => 0, - ' ьз' => 0, - ' ьи' => 0, - ' ьй' => 0, - ' ьк' => 0, - ' ьл' => 0, - ' ьм' => 0, - ' ьн' => 0, - ' ьо' => 0, - ' ьп' => 0, - ' ьр' => 0, - ' ьс' => 0, - ' ьт' => 0, - ' ьу' => 0, - ' ьф' => 0, - ' ьх' => 0, - ' ьц' => 0, - ' ьч' => 0, - ' ьш' => 0, - ' ьщ' => 0, - ' ьъ' => 0, - ' ьы' => 0, - ' ьь' => 0, - ' ьэ' => 0, - ' ью' => 0, - ' ья' => 0, - ' эё' => 0, - ' эа' => 0, - ' эе' => 0, - ' эи' => 0, - ' эц' => 0, - ' эч' => 0, - ' эщ' => 0, - ' эъ' => 0, - ' эы' => 0, - ' эь' => 0, - ' ээ' => 0, - ' эю' => 0, - ' юё' => 0, - ' юе' => 0, - ' юи' => 0, - ' юй' => 0, - ' юо' => 0, - ' юу' => 0, - ' юц' => 0, - ' юш' => 0, - ' ющ' => 0, - ' юъ' => 0, - ' юы' => 0, - ' юь' => 0, - ' юэ' => 0, - ' юя' => 0, - ' яё' => 0, - ' яа' => 0, - ' яе' => 0, - ' яж' => 0, - ' яо' => 0, - ' яу' => 0, - ' яф' => 0, - ' яц' => 0, - ' яъ' => 0, - ' яы' => 0, - ' яь' => 0, - ' яэ' => 0, - ' яю' => 0, - ' яя' => 0, - 'ёё' => 0, - 'ёё ' => 0, - 'ёа' => 0, - 'ёа ' => 0, - 'ёг ' => 0, - 'ёе' => 0, - 'ёе ' => 0, - 'ёи' => 0, - 'ёи ' => 0, - 'ёй' => 0, - 'ёо' => 0, - 'ёо ' => 0, - 'ёу' => 0, - 'ёу ' => 0, - 'ёф' => 0, - 'ёф ' => 0, - 'ёц ' => 0, - 'ёч ' => 0, - 'ёщ ' => 0, - 'ёъ' => 0, - 'ёъ ' => 0, - 'ёы' => 0, - 'ёы ' => 0, - 'ёь' => 0, - 'ёь ' => 0, - 'ёэ' => 0, - 'ёэ ' => 0, - 'ёю' => 0, - 'ёя' => 0, - 'ёя ' => 0, - 'аё ' => 0, - 'аа ' => 0, - 'аъ' => 0, - 'аъ ' => 0, - 'аы' => 0, - 'аы ' => 0, - 'аь' => 0, - 'аь ' => 0, - 'аэ ' => 0, - 'бё ' => 0, - 'бб ' => 0, - 'бв ' => 0, - 'бг ' => 0, - 'бд ' => 0, - 'бж ' => 0, - 'бз ' => 0, - 'бй' => 0, - 'бй ' => 0, - 'бк ' => 0, - 'бм ' => 0, - 'бн ' => 0, - 'бп ' => 0, - 'бт ' => 0, - 'бф ' => 0, - 'бх ' => 0, - 'бц ' => 0, - 'бч ' => 0, - 'бш ' => 0, - 'бщ ' => 0, - 'бъ ' => 0, - 'бэ ' => 0, - 'вё ' => 0, - 'вб ' => 0, - 'вв ' => 0, - 'вд ' => 0, - 'вж' => 0, - 'вж ' => 0, - 'вз ' => 0, - 'вй' => 0, - 'вй ' => 0, - 'вл ' => 0, - 'вп ' => 0, - 'вф ' => 0, - 'вц ' => 0, - 'вч ' => 0, - 'вщ ' => 0, - 'въ' => 0, - 'въ ' => 0, - 'вэ ' => 0, - 'гё' => 0, - 'гё ' => 0, - 'гб ' => 0, - 'гг ' => 0, - 'гж' => 0, - 'гж ' => 0, - 'гз ' => 0, - 'гй' => 0, - 'гй ' => 0, - 'гк ' => 0, - 'гн ' => 0, - 'гп ' => 0, - 'гф ' => 0, - 'гх' => 0, - 'гх ' => 0, - 'гц' => 0, - 'гц ' => 0, - 'гч ' => 0, - 'гш ' => 0, - 'гщ ' => 0, - 'гъ' => 0, - 'гъ ' => 0, - 'гы ' => 0, - 'гь' => 0, - 'гь ' => 0, - 'гэ ' => 0, - 'гю' => 0, - 'гю ' => 0, - 'гя' => 0, - 'гя ' => 0, - 'дё ' => 0, - 'дб ' => 0, - 'дг ' => 0, - 'дд ' => 0, - 'дй' => 0, - 'дй ' => 0, - 'дк ' => 0, - 'дм ' => 0, - 'дн ' => 0, - 'дп ' => 0, - 'дс ' => 0, - 'дф ' => 0, - 'дх ' => 0, - 'дц ' => 0, - 'дч ' => 0, - 'дш ' => 0, - 'дщ ' => 0, - 'дъ ' => 0, - 'еа ' => 0, - 'еу ' => 0, - 'еъ' => 0, - 'еъ ' => 0, - 'еы' => 0, - 'еы ' => 0, - 'еь' => 0, - 'еь ' => 0, - 'еэ ' => 0, - 'жё ' => 0, - 'жв ' => 0, - 'жг ' => 0, - 'жж ' => 0, - 'жз ' => 0, - 'жй' => 0, - 'жй ' => 0, - 'жк ' => 0, - 'жл ' => 0, - 'жн ' => 0, - 'жп ' => 0, - 'жр ' => 0, - 'жс ' => 0, - 'жт ' => 0, - 'жф ' => 0, - 'жх ' => 0, - 'жц ' => 0, - 'жч ' => 0, - 'жш' => 0, - 'жш ' => 0, - 'жщ' => 0, - 'жщ ' => 0, - 'жъ' => 0, - 'жъ ' => 0, - 'жы ' => 0, - 'жэ ' => 0, - 'жю' => 0, - 'жю ' => 0, - 'жя' => 0, - 'жя ' => 0, - 'зё ' => 0, - 'зж ' => 0, - 'зз ' => 0, - 'зй' => 0, - 'зй ' => 0, - 'зк ' => 0, - 'зп ' => 0, - 'зр ' => 0, - 'зс ' => 0, - 'зт ' => 0, - 'зф' => 0, - 'зф ' => 0, - 'зх' => 0, - 'зх ' => 0, - 'зц ' => 0, - 'зч ' => 0, - 'зш ' => 0, - 'зщ' => 0, - 'зщ ' => 0, - 'зъ ' => 0, - 'зэ ' => 0, - 'иъ' => 0, - 'иъ ' => 0, - 'иы' => 0, - 'иы ' => 0, - 'иь' => 0, - 'иь ' => 0, - 'иэ ' => 0, - 'йё' => 0, - 'йё ' => 0, - 'йа ' => 0, - 'йв ' => 0, - 'йг ' => 0, - 'йж' => 0, - 'йж ' => 0, - 'йз ' => 0, - 'йи ' => 0, - 'йй' => 0, - 'йй ' => 0, - 'йо ' => 0, - 'йу' => 0, - 'йу ' => 0, - 'йч ' => 0, - 'йш ' => 0, - 'йщ ' => 0, - 'йъ' => 0, - 'йъ ' => 0, - 'йы' => 0, - 'йы ' => 0, - 'йь' => 0, - 'йь ' => 0, - 'йэ' => 0, - 'йэ ' => 0, - 'йю' => 0, - 'йю ' => 0, - 'йя' => 0, - 'кё ' => 0, - 'кб ' => 0, - 'кг ' => 0, - 'кд ' => 0, - 'кж ' => 0, - 'кз ' => 0, - 'кй' => 0, - 'кй ' => 0, - 'км ' => 0, - 'кн ' => 0, - 'кф ' => 0, - 'кц ' => 0, - 'кч ' => 0, - 'кш ' => 0, - 'кщ' => 0, - 'кщ ' => 0, - 'къ' => 0, - 'къ ' => 0, - 'кы ' => 0, - 'кь ' => 0, - 'кэ' => 0, - 'кэ ' => 0, - 'кя' => 0, - 'кя ' => 0, - 'лв ' => 0, - 'лж ' => 0, - 'лз ' => 0, - 'лй' => 0, - 'лй ' => 0, - 'лр ' => 0, - 'лф ' => 0, - 'лх ' => 0, - 'лц ' => 0, - 'лч ' => 0, - 'лш ' => 0, - 'лщ ' => 0, - 'лъ' => 0, - 'лъ ' => 0, - 'лэ' => 0, - 'лэ ' => 0, - 'мё ' => 0, - 'мв ' => 0, - 'мг ' => 0, - 'мд ' => 0, - 'мз ' => 0, - 'мй' => 0, - 'мк ' => 0, - 'мл ' => 0, - 'мр ' => 0, - 'мх ' => 0, - 'мц ' => 0, - 'мч ' => 0, - 'мш ' => 0, - 'мщ ' => 0, - 'мъ' => 0, - 'мъ ' => 0, - 'мэ ' => 0, - 'мю ' => 0, - 'нё ' => 0, - 'нб ' => 0, - 'нв ' => 0, - 'нй' => 0, - 'нл ' => 0, - 'нп ' => 0, - 'нщ ' => 0, - 'нъ ' => 0, - 'нэ ' => 0, - 'оъ' => 0, - 'оъ ' => 0, - 'оы' => 0, - 'оы ' => 0, - 'оь' => 0, - 'оь ' => 0, - 'пё ' => 0, - 'пб ' => 0, - 'пв' => 0, - 'пв ' => 0, - 'пг' => 0, - 'пг ' => 0, - 'пд ' => 0, - 'пж' => 0, - 'пж ' => 0, - 'пз' => 0, - 'пз ' => 0, - 'пй' => 0, - 'пй ' => 0, - 'пк ' => 0, - 'пл ' => 0, - 'пм ' => 0, - 'пн ' => 0, - 'пф ' => 0, - 'пх ' => 0, - 'пц ' => 0, - 'пч ' => 0, - 'пш ' => 0, - 'пщ ' => 0, - 'пъ' => 0, - 'пъ ' => 0, - 'пэ' => 0, - 'пэ ' => 0, - 'пю ' => 0, - 'рё ' => 0, - 'рй' => 0, - 'рй ' => 0, - 'ръ' => 0, - 'ръ ' => 0, - 'рэ ' => 0, - 'сб ' => 0, - 'св ' => 0, - 'сг ' => 0, - 'сд ' => 0, - 'сж ' => 0, - 'сз' => 0, - 'сз ' => 0, - 'сй' => 0, - 'сй ' => 0, - 'сн ' => 0, - 'сп ' => 0, - 'сф ' => 0, - 'сц ' => 0, - 'сч ' => 0, - 'сш ' => 0, - 'сщ ' => 0, - 'съ ' => 0, - 'сэ ' => 0, - 'тб ' => 0, - 'тг ' => 0, - 'тд ' => 0, - 'тж ' => 0, - 'тз ' => 0, - 'тй' => 0, - 'тй ' => 0, - 'тк ' => 0, - 'тл ' => 0, - 'тп ' => 0, - 'тф ' => 0, - 'тх ' => 0, - 'тц ' => 0, - 'тш ' => 0, - 'тщ ' => 0, - 'тъ ' => 0, - 'уё ' => 0, - 'уо ' => 0, - 'уу ' => 0, - 'уц ' => 0, - 'уъ' => 0, - 'уъ ' => 0, - 'уы' => 0, - 'уы ' => 0, - 'уь' => 0, - 'уь ' => 0, - 'уэ ' => 0, - 'фё ' => 0, - 'фб ' => 0, - 'фв ' => 0, - 'фг ' => 0, - 'фд ' => 0, - 'фж' => 0, - 'фж ' => 0, - 'фз' => 0, - 'фз ' => 0, - 'фй' => 0, - 'фй ' => 0, - 'фк ' => 0, - 'фл ' => 0, - 'фн ' => 0, - 'фп' => 0, - 'фп ' => 0, - 'фс ' => 0, - 'фх' => 0, - 'фх ' => 0, - 'фц' => 0, - 'фц ' => 0, - 'фч ' => 0, - 'фш ' => 0, - 'фщ ' => 0, - 'фъ' => 0, - 'фъ ' => 0, - 'фэ' => 0, - 'фэ ' => 0, - 'фю ' => 0, - 'хё' => 0, - 'хё ' => 0, - 'хб ' => 0, - 'хг ' => 0, - 'хд ' => 0, - 'хж ' => 0, - 'хз ' => 0, - 'хй' => 0, - 'хй ' => 0, - 'хк ' => 0, - 'хн ' => 0, - 'хп ' => 0, - 'хр ' => 0, - 'хс ' => 0, - 'хф ' => 0, - 'хх ' => 0, - 'хц ' => 0, - 'хч ' => 0, - 'хш ' => 0, - 'хщ' => 0, - 'хщ ' => 0, - 'хъ ' => 0, - 'хы' => 0, - 'хы ' => 0, - 'хь' => 0, - 'хь ' => 0, - 'хэ ' => 0, - 'хю' => 0, - 'хю ' => 0, - 'хя' => 0, - 'хя ' => 0, - 'цё' => 0, - 'цё ' => 0, - 'цб' => 0, - 'цб ' => 0, - 'цв ' => 0, - 'цг ' => 0, - 'цд ' => 0, - 'цж' => 0, - 'цж ' => 0, - 'цз ' => 0, - 'цй' => 0, - 'цй ' => 0, - 'цк ' => 0, - 'цл ' => 0, - 'цм ' => 0, - 'цн ' => 0, - 'цп ' => 0, - 'цр ' => 0, - 'цс ' => 0, - 'цт ' => 0, - 'цф' => 0, - 'цф ' => 0, - 'цх' => 0, - 'цх ' => 0, - 'цц ' => 0, - 'цч' => 0, - 'цч ' => 0, - 'цш ' => 0, - 'цщ' => 0, - 'цщ ' => 0, - 'цъ' => 0, - 'цъ ' => 0, - 'ць' => 0, - 'ць ' => 0, - 'цэ' => 0, - 'цэ ' => 0, - 'цю' => 0, - 'цю ' => 0, - 'ця' => 0, - 'ця ' => 0, - 'чё ' => 0, - 'чб ' => 0, - 'чг' => 0, - 'чг ' => 0, - 'чд' => 0, - 'чд ' => 0, - 'чж ' => 0, - 'чз' => 0, - 'чз ' => 0, - 'чй' => 0, - 'чй ' => 0, - 'чк ' => 0, - 'чл ' => 0, - 'чм ' => 0, - 'чн ' => 0, - 'чп' => 0, - 'чп ' => 0, - 'чр ' => 0, - 'чс ' => 0, - 'чф' => 0, - 'чф ' => 0, - 'чх ' => 0, - 'чц ' => 0, - 'чч ' => 0, - 'чш ' => 0, - 'чщ' => 0, - 'чщ ' => 0, - 'чъ' => 0, - 'чъ ' => 0, - 'чы' => 0, - 'чы ' => 0, - 'чэ' => 0, - 'чэ ' => 0, - 'чю' => 0, - 'чю ' => 0, - 'чя' => 0, - 'чя ' => 0, - 'шё ' => 0, - 'шб ' => 0, - 'шг ' => 0, - 'шд' => 0, - 'шд ' => 0, - 'шж' => 0, - 'шж ' => 0, - 'шз' => 0, - 'шз ' => 0, - 'шй' => 0, - 'шй ' => 0, - 'шк ' => 0, - 'шл ' => 0, - 'шм ' => 0, - 'шн ' => 0, - 'шп ' => 0, - 'шр ' => 0, - 'шс ' => 0, - 'шф ' => 0, - 'шх' => 0, - 'шх ' => 0, - 'шч ' => 0, - 'шш' => 0, - 'шш ' => 0, - 'шщ' => 0, - 'шщ ' => 0, - 'шъ' => 0, - 'шъ ' => 0, - 'шы' => 0, - 'шы ' => 0, - 'шэ' => 0, - 'шэ ' => 0, - 'шя' => 0, - 'шя ' => 0, - 'щб' => 0, - 'щб ' => 0, - 'щв ' => 0, - 'щг' => 0, - 'щг ' => 0, - 'щд' => 0, - 'щд ' => 0, - 'щж' => 0, - 'щж ' => 0, - 'щз' => 0, - 'щз ' => 0, - 'щй' => 0, - 'щй ' => 0, - 'щк' => 0, - 'щк ' => 0, - 'щл' => 0, - 'щл ' => 0, - 'щм ' => 0, - 'щн ' => 0, - 'щп' => 0, - 'щп ' => 0, - 'щр ' => 0, - 'щс' => 0, - 'щс ' => 0, - 'щт' => 0, - 'щт ' => 0, - 'щф' => 0, - 'щф ' => 0, - 'щх' => 0, - 'щх ' => 0, - 'щц' => 0, - 'щц ' => 0, - 'щч' => 0, - 'щч ' => 0, - 'щш' => 0, - 'щш ' => 0, - 'щщ' => 0, - 'щщ ' => 0, - 'щъ' => 0, - 'щъ ' => 0, - 'щы' => 0, - 'щы ' => 0, - 'щэ' => 0, - 'щэ ' => 0, - 'щю' => 0, - 'щю ' => 0, - 'щя' => 0, - 'щя ' => 0, - 'ъё ' => 0, - 'ъа' => 0, - 'ъа ' => 0, - 'ъб' => 0, - 'ъб ' => 0, - 'ъв' => 0, - 'ъв ' => 0, - 'ъг' => 0, - 'ъг ' => 0, - 'ъд' => 0, - 'ъд ' => 0, - 'ъе ' => 0, - 'ъж' => 0, - 'ъж ' => 0, - 'ъз' => 0, - 'ъз ' => 0, - 'ъи' => 0, - 'ъи ' => 0, - 'ъй' => 0, - 'ъй ' => 0, - 'ък' => 0, - 'ък ' => 0, - 'ъл' => 0, - 'ъл ' => 0, - 'ъм' => 0, - 'ъм ' => 0, - 'ън' => 0, - 'ън ' => 0, - 'ъо' => 0, - 'ъо ' => 0, - 'ъп' => 0, - 'ъп ' => 0, - 'ър' => 0, - 'ър ' => 0, - 'ъс' => 0, - 'ъс ' => 0, - 'ът' => 0, - 'ът ' => 0, - 'ъу' => 0, - 'ъу ' => 0, - 'ъф' => 0, - 'ъф ' => 0, - 'ъх' => 0, - 'ъх ' => 0, - 'ъц' => 0, - 'ъц ' => 0, - 'ъч' => 0, - 'ъч ' => 0, - 'ъш' => 0, - 'ъш ' => 0, - 'ъщ' => 0, - 'ъщ ' => 0, - 'ъъ' => 0, - 'ъъ ' => 0, - 'ъы' => 0, - 'ъы ' => 0, - 'ъь' => 0, - 'ъь ' => 0, - 'ъэ' => 0, - 'ъэ ' => 0, - 'ъю ' => 0, - 'ъя ' => 0, - 'ыё' => 0, - 'ыё ' => 0, - 'ыа' => 0, - 'ыа ' => 0, - 'ыи ' => 0, - 'ыо ' => 0, - 'ыу ' => 0, - 'ыф ' => 0, - 'ыъ' => 0, - 'ыъ ' => 0, - 'ыы' => 0, - 'ыы ' => 0, - 'ыь' => 0, - 'ыь ' => 0, - 'ыэ' => 0, - 'ыэ ' => 0, - 'ыю ' => 0, - 'ьа' => 0, - 'ьа ' => 0, - 'ьв ' => 0, - 'ьг ' => 0, - 'ьж ' => 0, - 'ьз ' => 0, - 'ьй' => 0, - 'ьй ' => 0, - 'ьл ' => 0, - 'ьн ' => 0, - 'ьр ' => 0, - 'ьу' => 0, - 'ьу ' => 0, - 'ьх ' => 0, - 'ьщ ' => 0, - 'ьъ' => 0, - 'ьъ ' => 0, - 'ьы ' => 0, - 'ьь' => 0, - 'ьь ' => 0, - 'ьэ ' => 0, - 'эё' => 0, - 'эё ' => 0, - 'эа' => 0, - 'эа ' => 0, - 'эб' => 0, - 'эб ' => 0, - 'эв ' => 0, - 'эг ' => 0, - 'эд ' => 0, - 'эе' => 0, - 'эе ' => 0, - 'эж' => 0, - 'эж ' => 0, - 'эз ' => 0, - 'эи ' => 0, - 'эй ' => 0, - 'эл ' => 0, - 'эм ' => 0, - 'эн ' => 0, - 'эо' => 0, - 'эо ' => 0, - 'эу' => 0, - 'эу ' => 0, - 'эф ' => 0, - 'эх ' => 0, - 'эц' => 0, - 'эц ' => 0, - 'эч' => 0, - 'эч ' => 0, - 'эш ' => 0, - 'эщ' => 0, - 'эщ ' => 0, - 'эъ' => 0, - 'эъ ' => 0, - 'эы' => 0, - 'эы ' => 0, - 'эь' => 0, - 'эь ' => 0, - 'ээ ' => 0, - 'эю' => 0, - 'эю ' => 0, - 'эя' => 0, - 'эя ' => 0, - 'юё' => 0, - 'юё ' => 0, - 'юа ' => 0, - 'юе ' => 0, - 'юж ' => 0, - 'юи ' => 0, - 'юл ' => 0, - 'юо ' => 0, - 'юу' => 0, - 'юу ' => 0, - 'юц ' => 0, - 'юъ' => 0, - 'юъ ' => 0, - 'юы' => 0, - 'юы ' => 0, - 'юь' => 0, - 'юь ' => 0, - 'юэ ' => 0, - 'юя' => 0, - 'яё' => 0, - 'яё ' => 0, - 'яа' => 0, - 'яа ' => 0, - 'яе ' => 0, - 'яо ' => 0, - 'яф' => 0, - 'яф ' => 0, - 'яъ' => 0, - 'яъ ' => 0, - 'яы' => 0, - 'яы ' => 0, - 'яь' => 0, - 'яь ' => 0, - 'яэ' => 0, - 'яэ ' => 0, - #en - ' \'f' => 0, - ' \'p' => 0, - ' \'q' => 0, - ' \'r' => 0, - ' \'x' => 0, - ' \'y' => 0, - ' \'z' => 0, - ' bj' => 0, - ' bq' => 0, - ' bz' => 0, - ' c\'' => 0, - ' cq' => 0, - ' cv' => 0, - ' cx' => 0, - ' dq' => 0, - ' dx' => 0, - ' ez' => 0, - ' f\'' => 0, - ' fh' => 0, - ' fk' => 0, - ' fq' => 0, - ' fv' => 0, - ' fw' => 0, - ' fz' => 0, - ' g\'' => 0, - ' gf' => 0, - ' gg' => 0, - ' gj' => 0, - ' gv' => 0, - ' gx' => 0, - ' gz' => 0, - ' h\'' => 0, - ' hj' => 0, - ' hk' => 0, - ' hn' => 0, - ' hq' => 0, - ' hx' => 0, - ' iq' => 0, - ' iw' => 0, - ' iy' => 0, - ' jb' => 0, - ' jf' => 0, - ' jh' => 0, - ' jj' => 0, - ' jk' => 0, - ' jl' => 0, - ' jm' => 0, - ' jq' => 0, - ' jw' => 0, - ' jx' => 0, - ' jy' => 0, - ' jz' => 0, - ' k\'' => 0, - ' kf' => 0, - ' kj' => 0, - ' kq' => 0, - ' kt' => 0, - ' kx' => 0, - ' kz' => 0, - ' lj' => 0, - ' lk' => 0, - ' lq' => 0, - ' lv' => 0, - ' mj' => 0, - ' mq' => 0, - ' mz' => 0, - ' nj' => 0, - ' nk' => 0, - ' nq' => 0, - ' nz' => 0, - ' oq' => 0, - ' pj' => 0, - ' pz' => 0, - ' qb' => 0, - ' qe' => 0, - ' qf' => 0, - ' qg' => 0, - ' qh' => 0, - ' qj' => 0, - ' qk' => 0, - ' qo' => 0, - ' qp' => 0, - ' qs' => 0, - ' qv' => 0, - ' qx' => 0, - ' qy' => 0, - ' qz' => 0, - ' rb' => 0, - ' rk' => 0, - ' rq' => 0, - ' rv' => 0, - ' rx' => 0, - ' rz' => 0, - ' sz' => 0, - ' tf' => 0, - ' tg' => 0, - ' tj' => 0, - ' tq' => 0, - ' u\'' => 0, - ' ue' => 0, - ' uj' => 0, - ' uo' => 0, - ' uq' => 0, - ' uu' => 0, - ' uy' => 0, - ' vb' => 0, - ' vj' => 0, - ' vk' => 0, - ' vn' => 0, - ' vq' => 0, - ' vr' => 0, - ' vv' => 0, - ' vw' => 0, - ' vx' => 0, - ' vy' => 0, - ' vz' => 0, - ' wj' => 0, - ' wl' => 0, - ' wn' => 0, - ' wq' => 0, - ' wx' => 0, - ' wz' => 0, - ' xb' => 0, - ' xf' => 0, - ' xg' => 0, - ' xh' => 0, - ' xj' => 0, - ' xk' => 0, - ' xq' => 0, - ' xt' => 0, - ' xu' => 0, - ' xz' => 0, - ' yf' => 0, - ' yg' => 0, - ' yh' => 0, - ' yj' => 0, - ' yk' => 0, - ' yl' => 0, - ' yn' => 0, - ' yq' => 0, - ' yv' => 0, - ' yx' => 0, - ' yy' => 0, - ' yz' => 0, - ' z\'' => 0, - ' zb' => 0, - ' zc' => 0, - ' zd' => 0, - ' zf' => 0, - ' zg' => 0, - ' zh' => 0, - ' zj' => 0, - ' zk' => 0, - ' zl' => 0, - ' zm' => 0, - ' zq' => 0, - ' zr' => 0, - ' zv' => 0, - ' zw' => 0, - ' zx' => 0, - ' zz' => 0, - '\'a ' => 0, - '\'b' => 0, - '\'b ' => 0, - '\'c ' => 0, - '\'f' => 0, - '\'f ' => 0, - '\'g' => 0, - '\'g ' => 0, - '\'h ' => 0, - '\'i ' => 0, - '\'j' => 0, - '\'j ' => 0, - '\'k' => 0, - '\'k ' => 0, - '\'l ' => 0, - '\'n ' => 0, - '\'o ' => 0, - '\'p ' => 0, - '\'q' => 0, - '\'q ' => 0, - '\'r ' => 0, - '\'u' => 0, - '\'u ' => 0, - '\'v ' => 0, - '\'w ' => 0, - '\'x' => 0, - '\'x ' => 0, - '\'z' => 0, - '\'z ' => 0, - 'b\' ' => 0, - 'bg ' => 0, - 'bh ' => 0, - 'bp ' => 0, - 'bq' => 0, - 'bq ' => 0, - 'bv ' => 0, - 'bx' => 0, - 'bz' => 0, - 'bz ' => 0, - 'c\' ' => 0, - 'cf ' => 0, - 'cj' => 0, - 'cn ' => 0, - 'cq ' => 0, - 'cv' => 0, - 'cw' => 0, - 'cx' => 0, - 'cx ' => 0, - 'cz ' => 0, - 'db ' => 0, - 'dj ' => 0, - 'dk ' => 0, - 'dw ' => 0, - 'dx' => 0, - 'eh ' => 0, - 'ej ' => 0, - 'f\' ' => 0, - 'fg ' => 0, - 'fh ' => 0, - 'fj' => 0, - 'fj ' => 0, - 'fk' => 0, - 'fk ' => 0, - 'fq' => 0, - 'fq ' => 0, - 'fv ' => 0, - 'fw ' => 0, - 'fx' => 0, - 'fx ' => 0, - 'fz' => 0, - 'fz ' => 0, - 'g\' ' => 0, - 'gc ' => 0, - 'gf ' => 0, - 'gj ' => 0, - 'gk ' => 0, - 'gl ' => 0, - 'gq' => 0, - 'gq ' => 0, - 'gv' => 0, - 'gv ' => 0, - 'gw ' => 0, - 'gx' => 0, - 'gx ' => 0, - 'gz ' => 0, - 'hb ' => 0, - 'hc ' => 0, - 'hg ' => 0, - 'hh ' => 0, - 'hj' => 0, - 'hj ' => 0, - 'hk ' => 0, - 'hv' => 0, - 'hv ' => 0, - 'hw ' => 0, - 'hx' => 0, - 'hx ' => 0, - 'hz' => 0, - 'i\' ' => 0, - 'ih ' => 0, - 'iq ' => 0, - 'iw ' => 0, - 'j\'' => 0, - 'j\' ' => 0, - 'jb' => 0, - 'jb ' => 0, - 'jc' => 0, - 'jc ' => 0, - 'jd' => 0, - 'jf' => 0, - 'jg' => 0, - 'jg ' => 0, - 'jh' => 0, - 'jh ' => 0, - 'jj' => 0, - 'jj ' => 0, - 'jk ' => 0, - 'jl ' => 0, - 'jm' => 0, - 'jm ' => 0, - 'jn' => 0, - 'jn ' => 0, - 'jp ' => 0, - 'jq' => 0, - 'jq ' => 0, - 'jr' => 0, - 'jr ' => 0, - 'js' => 0, - 'js ' => 0, - 'jt' => 0, - 'ju ' => 0, - 'jv' => 0, - 'jv ' => 0, - 'jw' => 0, - 'jw ' => 0, - 'jx' => 0, - 'jx ' => 0, - 'jy' => 0, - 'jy ' => 0, - 'jz' => 0, - 'jz ' => 0, - 'kb ' => 0, - 'kc ' => 0, - 'kd ' => 0, - 'kj ' => 0, - 'km ' => 0, - 'kp ' => 0, - 'kq' => 0, - 'kq ' => 0, - 'kv' => 0, - 'kv ' => 0, - 'kx' => 0, - 'kx ' => 0, - 'kz' => 0, - 'kz ' => 0, - 'lg ' => 0, - 'lh ' => 0, - 'lj ' => 0, - 'lq ' => 0, - 'lr ' => 0, - 'lv ' => 0, - 'lw ' => 0, - 'lx' => 0, - 'lz ' => 0, - 'm\' ' => 0, - 'mg ' => 0, - 'mh ' => 0, - 'mj ' => 0, - 'mk ' => 0, - 'mq' => 0, - 'mq ' => 0, - 'mx' => 0, - 'mx ' => 0, - 'mz' => 0, - 'nb ' => 0, - 'nm ' => 0, - 'pj ' => 0, - 'pk ' => 0, - 'pq' => 0, - 'pq ' => 0, - 'pv' => 0, - 'pw ' => 0, - 'px' => 0, - 'px ' => 0, - 'pz ' => 0, - 'q\'' => 0, - 'q\' ' => 0, - 'qa ' => 0, - 'qb' => 0, - 'qb ' => 0, - 'qc' => 0, - 'qc ' => 0, - 'qd' => 0, - 'qd ' => 0, - 'qe' => 0, - 'qe ' => 0, - 'qf' => 0, - 'qf ' => 0, - 'qg' => 0, - 'qg ' => 0, - 'qh' => 0, - 'qh ' => 0, - 'qi' => 0, - 'qj' => 0, - 'qj ' => 0, - 'qk' => 0, - 'qk ' => 0, - 'ql' => 0, - 'ql ' => 0, - 'qm' => 0, - 'qm ' => 0, - 'qn' => 0, - 'qn ' => 0, - 'qo' => 0, - 'qo ' => 0, - 'qp' => 0, - 'qp ' => 0, - 'qq' => 0, - 'qq ' => 0, - 'qr' => 0, - 'qs' => 0, - 'qs ' => 0, - 'qt' => 0, - 'qt ' => 0, - 'qu ' => 0, - 'qv' => 0, - 'qv ' => 0, - 'qw' => 0, - 'qw ' => 0, - 'qx' => 0, - 'qx ' => 0, - 'qy' => 0, - 'qy ' => 0, - 'qz' => 0, - 'qz ' => 0, - 'rq ' => 0, - 'rz ' => 0, - 'sg ' => 0, - 'sj ' => 0, - 'sx' => 0, - 'sx ' => 0, - 'sz' => 0, - 'sz ' => 0, - 'tg ' => 0, - 'tj ' => 0, - 'tq' => 0, - 'tq ' => 0, - 'tx' => 0, - 'tx ' => 0, - 'uj ' => 0, - 'uq ' => 0, - 'uu ' => 0, - 'uw ' => 0, - 'v\' ' => 0, - 'vb' => 0, - 'vb ' => 0, - 'vc' => 0, - 'vf' => 0, - 'vf ' => 0, - 'vg' => 0, - 'vh' => 0, - 'vh ' => 0, - 'vj' => 0, - 'vj ' => 0, - 'vk' => 0, - 'vk ' => 0, - 'vl ' => 0, - 'vm' => 0, - 'vn ' => 0, - 'vp' => 0, - 'vp ' => 0, - 'vq' => 0, - 'vq ' => 0, - 'vr ' => 0, - 'vv ' => 0, - 'vw' => 0, - 'vw ' => 0, - 'vx' => 0, - 'vz' => 0, - 'vz ' => 0, - 'w\' ' => 0, - 'wb ' => 0, - 'wc ' => 0, - 'wf ' => 0, - 'wg ' => 0, - 'wj' => 0, - 'wj ' => 0, - 'wq' => 0, - 'wq ' => 0, - 'wr ' => 0, - 'wv' => 0, - 'wv ' => 0, - 'wx' => 0, - 'wz ' => 0, - 'x\'' => 0, - 'x\' ' => 0, - 'xa ' => 0, - 'xb ' => 0, - 'xc ' => 0, - 'xd' => 0, - 'xd ' => 0, - 'xf ' => 0, - 'xg ' => 0, - 'xh ' => 0, - 'xj' => 0, - 'xj ' => 0, - 'xk' => 0, - 'xk ' => 0, - 'xl ' => 0, - 'xm ' => 0, - 'xn' => 0, - 'xn ' => 0, - 'xp ' => 0, - 'xq ' => 0, - 'xr' => 0, - 'xr ' => 0, - 'xs ' => 0, - 'xu ' => 0, - 'xv' => 0, - 'xv ' => 0, - 'xw ' => 0, - 'xx' => 0, - 'xz' => 0, - 'xz ' => 0, - 'yb ' => 0, - 'yc ' => 0, - 'yd ' => 0, - 'yf ' => 0, - 'yg ' => 0, - 'yh ' => 0, - 'yj ' => 0, - 'yq' => 0, - 'yq ' => 0, - 'yu ' => 0, - 'yv ' => 0, - 'yw ' => 0, - 'yy' => 0, - 'yy ' => 0, - 'yz ' => 0, - 'z\'' => 0, - 'z\' ' => 0, - 'zb ' => 0, - 'zc' => 0, - 'zc ' => 0, - 'zd' => 0, - 'zd ' => 0, - 'zf' => 0, - 'zf ' => 0, - 'zg ' => 0, - 'zh' => 0, - 'zh ' => 0, - 'zj' => 0, - 'zj ' => 0, - 'zk ' => 0, - 'zl ' => 0, - 'zn' => 0, - 'zn ' => 0, - 'zp ' => 0, - 'zq' => 0, - 'zq ' => 0, - 'zr' => 0, - 'zr ' => 0, - 'zs' => 0, - 'zs ' => 0, - 'zt' => 0, - 'zt ' => 0, - 'zu ' => 0, - 'zv ' => 0, - 'zw ' => 0, - 'zx' => 0, - 'zx ' => 0, - ); - - /** - * - * @param array|null $words_exceptions - */ - public function __construct(array $words_exceptions = null) - { - if (! ReflectionTypeHint::isValid()) return false; - #русский --> английский: - $this->en_correct = '/(?: (?:' . $this->tt_f . ') - (?: (?:' . $this->en_uniq . ') | (?:' . $this->en_sc . '){2} ) - | (?:' . $this->en_sc . ') - (?:' . $this->tt_f . ') - (?:' . $this->en_sc . ') - | (?: (?:' . $this->en_uniq . ') | (?:' . $this->en_sc . '){2} ) - (?:' . $this->tt_f . ') - ) - /sxSX'; - #английский --> русский: - $this->tt_correct = '/(?: (?:' . $this->en_sc . ') - (?: (?:' . $this->tt_uniq . ') | (?:' . $this->tt_f . '){2} ) - | (?:' . $this->tt_f . ') - (?:' . $this->en_sc . ') - (?:' . $this->tt_f . ') - | (?: (?:' . $this->tt_uniq . ') | (?:' . $this->tt_f . '){2} ) - (?:' . $this->en_sc . ') - ) - /sxSX'; - $this->table_flip = array( - 0 => array_flip($this->table[0]), - 1 => array_flip($this->table[1]), - ); - if (is_array($words_exceptions)) $this->words_exceptions += $words_exceptions; - } - - /** - * Исправляет клавиатурные опечатки в тексте. - * - * @param scalar|null $s Текст в кодировке UTF-8. - * @param int $mode Константы self::SIMILAR_CHARS и/или self::KEYBOARD_LAYOUT, - * (их можно комбинировать). Описание констант см. выше. - * При использовании self::KEYBOARD_LAYOUT время работы увеличивается примерно в 10 раз. - * @param array &$words Ассоц. массив со словами, которые были исправлены: - * в ключах оригиналы, в значениях исправленные слова. - * @return string|bool Returns FALSE if error occured - */ - public function parse($s, $mode = self::SIMILAR_CHARS, array &$words = null) - { - if (! ReflectionTypeHint::isValid()) return false; - if (! is_string($s)) return $s; - - if ($mode < self::SIMILAR_CHARS || $mode > (self::SIMILAR_CHARS | self::KEYBOARD_LAYOUT | self::ADD_FIX)) - { - trigger_error('Unknown mode', E_USER_WARNING); - return false; - } - - $this->mode = $mode; - - #вырезаем и заменяем некоторые символы - $additional_chars = array( - "\xc2\xad", #"мягкие" переносы строк (­) - ); - #http://ru.wikipedia.org/wiki/Диакритические_знаки - $s = UTF8::diactrical_remove($s, $additional_chars, $is_can_restored = true, $restore_table); - - $this->words = array(); - $s = $this->_parse1($s); - $s = $this->_parse2($s); - $s = UTF8::diactrical_restore($s, $restore_table); - $words = $this->words; - return $s; - } - - private function _parse1($s) - { - #заменяем слова из текста, минимальная длина -- 3 символа, меньше нельзя - return preg_replace_callback('/(?> (' . $this->en . ') #1 латинские буквы - | (' . $this->tt . ') #2 русские буквы - | (' . $this->sc . ') #3 символы, которые м.б. набраны по ошибке в английской раскладке клавиатуры вместо русских букв - ){3,}+ - /sxSX', array($this, '_word'), $s); - } - - private function _parse2($s) - { - #исправляем русские буквы (похожие на латинские) с рядом стоящими цифрами на латинские - #например, это м. б. каталожные номера автозапчастей, в которых есть русские буквы: 1500A023, 52511-60900-H0, K2305, XA527672 - #корректно обрабатываем вхождения '1-ое', 'Ту-134', 'А19-3107/06-43-Ф02-4227/06-С1' - if (version_compare(PHP_VERSION, '5.2.0', '<')) return $s; - return preg_replace_callback('~(?: (?<=[^-_/]|^) - (?:' . $this->ru_similar . ')++ - (?= (?:' . $this->en . '|[-_/])*+ (?<=[^-_/]|' . $this->en . '[-_/]) - \d [\d-_/]*+ (?!' . $this->tt_uniq . ') - ) - | (?<=[^-_/]|^) - \d (?:' . $this->en . '|[-_/])*+ (?<=[^-_/]|' . $this->en . '[-_/]) - \K - (?:' . $this->ru_similar . ')++ - (?= [\d-_/]*+ (?!' . $this->tt_uniq . ') ) - ) - ~sxSX', array($this, '_entry'), $s); - } - - private function _entry(array &$a) - { - $entry =& $a[0]; - $s = strtr($entry, $this->table[0]); - if ($s !== $entry) $this->words[$entry] = $s; - return $s; - } - - private function _word(array &$a) - { - $word = $a[0]; - #var_export($a); - - $suggestions = array(); - - #если найдено слово из мешанины русских и латинских букв - if (! empty($a[1]) && ! empty($a[2])) - { - if (($this->mode & self::SIMILAR_CHARS) === 0) return $word; - #ВНИМАНИЕ! порядок следования правил преобразования имеет значение! - - /* - Исправляем ошибочно набранные буквы, которые выглядят одинаково - в инициалах перед фамилиями (русский <--> английский), например: Т.С.Навка - */ - - #0a. английский --> русский: - if (substr($word, 1, 1) === '.' #оптимизация - && preg_match('/^ ( ' . $this->en_similar_uc . '\. #первый инициал - (?:' . $this->en_similar_uc . '\.)? #второй инициал (необязательно) - ) #1 инициалы - (' . $this->no_sc . '{2,}+) #2 фамилия (английские и русские буквы) - $/sxSX', $word, $m)) - { - $m[2] = $this->_parse1($m[2]); - #фамилия по-русски? - if (preg_match('/^ (?:' . $this->tt_uc . ') #первая буква д.б. большая - (?:' . $this->tt_f . ')+ #минимальное кол-во букв в фамилии = 2 - $/sxSX', $m[2])) return strtr($m[1], $this->table_flip[0]) . $m[2]; - } - - #0b. русский --> английский: - if (substr($word, 2, 1) === '.' #оптимизация - && preg_match('/^ ( ' . $this->ru_similar_uc . '\. #первый инициал - (?:' . $this->ru_similar_uc . '\.)? #второй инициал (необязательно) - ) #1 инициалы - (' . $this->no_sc . '{2,}+) #2 фамилия (английские и русские буквы) - $/sxSX', $word, $m)) - { - $m[2] = $this->_parse1($m[2]); - #фамилия по-англ.? - if (preg_match('/^ ' . $this->en_uc . ' #первая буква д.б. большая - ' . $this->en . '++ #минимальное кол-во букв в фамилии = 2 - $/sxSX', $m[2])) return strtr($m[1], $this->table[0]) . $m[2]; - } - - #1. английский --> русский: - $this->method = 0; #буквы, которые выглядят одинаково - $this->is_flip = true; - $s = $this->_replace($word, $this->tt_correct); - if ($word !== $s && ! $this->_is_mixed($s)) $suggestions['tt0'] = $s; - - #2. английский --> русский: - $this->method = 1; #буквы в другой раскладке клавиатуры - $this->is_flip = true; - $s = $this->_replace($word, $this->tt_correct); - if ($word !== $s) $suggestions['tt1'] = $s; - - #3. русский --> английский: - $this->method = 0; #буквы, которые выглядят одинаково - $this->is_flip = false; - $s = $this->_replace($word, $this->en_correct); - if ($word !== $s && ! $this->_is_mixed($s)) $suggestions['en0'] = $s; - - #4. русский --> английский: - $this->method = 1; #буквы в другой раскладке клавиатуры - $this->is_flip = false; - $s = $this->_replace($word, $this->en_correct); - if ($word !== $s) $suggestions['en1'] = $s; - - } - #если найдено слово только из латинских букв; минимальная длина -- 4 буквы! - elseif (! empty($a[1]) && strlen($word) >= 4) - { - if (($this->mode & self::KEYBOARD_LAYOUT) === 0) return $word; - - #не обрабатываем аббревиатуры, пример: AMPAS - if (preg_match('/^(?:' . $this->en_uc . '|' . $this->sc . '){1,6}+$/sxSX', $word)) return $word; - - #английский --> русский: - $suggestions['en1'] = $word; - $suggestions['tt1'] = strtr($word, $this->table_flip[1]); - } - #если найдено слово только из русских букв; минимальная длина -- 4 буквы! - elseif (! empty($a[2]) && strlen($word) >= 8) - { - if (($this->mode & self::KEYBOARD_LAYOUT) === 0) return $word; - - #не обрабатываем аббревиатуры, пример: ДОСААФ - if (preg_match('/^(?:' . $this->tt_uc . '|' . $this->sc . '){1,6}+$/sxSX', $word)) return $word; - - #русский --> английский: - $suggestions['tt1'] = $word; - $suggestions['en1'] = strtr($word, $this->table[1]); - } - #найдены спецсимволы или длина слова слишком мала - else return $word; - - $suggestions = array_unique($suggestions); - #var_export($suggestions); - - $c = count($suggestions); - if ($c === 0) $s = $word; - else $s = $this->_detect($word, $suggestions, ! empty($a[3])); - if ($s !== $word) - { - $this->words[$word] = $s; - if ($this->mode >= (self::KEYBOARD_LAYOUT | self::ADD_FIX)) $s = '(' . $word . '=>' . $s . ')'; - } - return $s; - } - - private function _replace($word, $regexp) - { - do $word = preg_replace_callback($regexp, array(&$this, '_strtr'), $w = $word); - while ($w !== $word); - return $word; - } - - private function _strtr(array $a) - { - $word =& $a[0]; - return strtr($word, $this->is_flip ? $this->table_flip[$this->method] : $this->table[$this->method]); - } - - private function _is_mixed($word) - { - return preg_match('/(?:' . $this->en . ')/sxSX', $word) && - preg_match('/(?:' . $this->tt_f . ')/sxSX', $word); - } - - #выбираем из нескольких вариантов один - private function _detect($word, array $suggestions, $is_sc) - { - if (0) #DEBUG - { - //$suggestions['?'] = $word; - var_export($suggestions); - } - #не д. б. несуществующих N-грамм - foreach ($suggestions as $type => $w) - { - $lang = substr($type, 0, 2); - if ($this->_bigram_exists($w, $lang)) unset($suggestions[$type]); - } - if (0) #DEBUG - { - //$suggestions['?'] = $word; - var_export($suggestions); - } - if (count($suggestions) === 0) return $word; - - $s = end($suggestions); - - #если в $word были спецсимволы, а в $s их уже нет, возвращаем $s - if ($is_sc && ! preg_match('/' . $this->sc . '/sSX', $s)) return $s; - - #если в $s спецсимволов больше чем букв, возвращаем $word - $sc_count = 0; - $s = preg_replace('/' . $this->sc . '/sSX', '', $s, -1, $sc_count); - if ($sc_count > 0 && $sc_count > UTF8::strlen($s)) return $word; - - return reset($suggestions); - } - - #анализ на основе N-грамм русского и английского языка - private function _bigram_exists($word, $lang) - { - $word = ($lang === 'en') ? strtolower($word) : UTF8::lowercase($word); - - #шаг 0. - #проверяем слова в списке слов-исключений - if (array_key_exists($word, $this->words_exceptions[$lang])) return false; - - #шаг 1. - #проверка на 4 согласные буквы подряд; пример: больши{нств}о, юрисконсу{льтс}тво - if (preg_match('/(?:' . $this->consonant_lc[$lang] . '){4}/sxSX', $word, $m) - #проверяем список исключений - && ! array_key_exists($m[0], $this->consonants4_lc[$lang])) return true; - - #шаг 2. - #проверка на 3 гласные буквы подряд; пример: длиннош{еее}, зм{еео}бразный - if (preg_match('/(?:' . $this->vowel_lc[$lang] . '){3}/sxSX', $word, $m) - #проверяем список исключений - && ! array_key_exists($m[0], $this->vowels3_lc[$lang])) return true; - - #шаг 3. - $length = UTF8::strlen($word); - for ($pos = 0, $limit = $length - 1; $pos < $limit; $pos++) - { - /* - TODO Качество проверки по несуществующим биграммам можно немного повысить, - если учитывать не только начало и конец слова, но и все позиции биграмм в слове. - */ - $ss = UTF8::substr($word, $pos, 2); - if ($pos === 0) $ss = ' ' . $ss; #beginning of word - elseif ($pos === $limit - 1) $ss = $ss . ' '; #ending of word - if (array_key_exists($ss, $this->bigrams)) return true; - } - - return false; - } + 'cosmo' (2 первых и последняя буква — ошибочные) + * "\x78\x70\x65н" => 'хрен' (первые 3 буквы — ошибочные) + * "вебvfcnth" => 'вебмастер' + * "webьфыеук" => 'webmaster' + * "цццюмуыеш.ru" => 'www.vesti.ru' + * "\x54.\x43.\x48\x61вка" => 'Т.С.Навка' + * + * Hints + * Типичный пример алгоритма работы для поля ввода с автодополнением: + * 1. Сделать выборку по исходному запросу; + * 2. Если есть результат, возвратить его и исходный запрос; + * 3. Иначе скорректировать исходный запрос через Text_LangCorrect; + * 4. Если исходный и скорректированный запрос совпадает, возвратить пустой результат и исходный запрос; + * 5. Иначе сделать выборку по скорректированному запросу; + * 6. Возвратить результат. Если результат не пустой, возвратить скорректированный запрос, иначе исходный. + * + * License + * Только для некоммерческого использования! + * + * @link http://code.google.com/p/php-lang-correct/ + * @license http://creativecommons.org/licenses/by-nc-sa/3.0/ + * @author Nasibullin Rinat + * @version 1.4.3 + */ +class Text_LangCorrect +{ + /** + * Флаг для исправления ошибочно набранных букв в словах, + * которые выглядят одинаково в разных раскладках клавиатуры. + * Алгоритм работает достаточно надёжно и быстро. + */ + const SIMILAR_CHARS = 1; + + /** + * Флаг для исправления ошибочно набранных слов в другой раскладке клавиатуры. + * Алгоритм может иногда ошибаться, работает в разы медленнее, чем SIMILAR_CHARS. + */ + const KEYBOARD_LAYOUT = 2; + + /** + * Флаг для добавления исправлений, если влючён флаг KEYBOARD_LAYOUT + * Синтаксис и пример: "(,.cn=>бюст)" + * ^ ^^ ^ + */ + const ADD_FIX = 4; + + #английский (all) + private $en = '[a-zA-Z]'; + + #английский (uppercase) + private $en_uc = '[A-Z]'; + + #английский + символы, которые м.б. набраны по ошибке в английской раскладке клавиатуры вместо русских букв (all) + private $en_sc = '[a-zA-Z\'`~<>,.:;{}\[\]"]'; + + #символы, которые м.б. набраны по ошибке в английской раскладке клавиатуры вместо русских букв + private $sc = '[\'`~<>,.:;{}\[\]"]'; + private $no_sc = '[^\'`~<>,.:;{}\[\]"]'; + + #русский + татарский (all) + private $tt = '[\xd0-\xd3][\x80-\xbf] + (?<=\xd0[\x90-\xbf\x81]|\xd1[\x80-\x8f\x91]|\xd2[\x96\x97\xa2\xa3\xae\xaf\xba\xbb]|\xd3[\x98\x99\xa8\xa9])'; + + #русский + татарский (uppercase) + private $tt_uc = '[\xd0\xd2\xd3][\x81-\xba] + (?<=\xd0[\x90-\xaf\x81]|\xd2[\x96\xa2\xae\xba]|\xd3[\x98\xa8])'; + + #русский + татарский (для фильтрованных текстов) (all) + private $tt_f = '[\xd0-\xd3][\x80-\xbf] + #комментируем для увеличения скорости, т.к. остальные символы отфильтрованы + #(?<=\xd0[\x90-\xbf\x81]|\xd1[\x80-\x8f\x91]|\xd2[\x96\x97\xa2\xa3\xae\xaf\xba\xbb]|\xd3[\x98\x99\xa8\xa9]) + '; + + #гласная (vowel) (lowercase) + private $vowel_lc = array( + 'tt' => '\xd0[\xb0\xb5\xb8\xbe]|\xd1[\x83\x8b\x8d\x8e\x8f\x91] #аеиоуыэюяё (гласные, 10 шт.) + #| \xd0[\x90\x95\x98\x9e\xa3\xab\xad\xae\xaf\x81] #АЕИОУЫЭЮЯЁ (гласные, 10 шт.) + ', + 'en' => '[aeiouy]', #латинских 6 шт. + ); + + #согласная (consonant) + графические знаки для русского языка (ъ, ь) (lowercase) + private $consonant_lc = array( + 'tt' => '\xd0[\xb1-\xb4\xb6\xb7\xb9\xba-\xbd\xbf]|\xd1[\x80\x81\x82\x84-\x89\x8a\x8c] #бвгджзйклмнпрстфхцчшщ ъь (согласные, 21+2 шт.) + #| \xd0[\x91-\x94\x96\x97\x99\x9a-\x9d\x9f-\xa2\xa4-\xa9\xaa\xac] #БВГДЖЗЙКЛМНПРСТФХЦЧШЩ ЪЬ (согласные, 21+2 шт.) + ', + 'en' => '[bcdfghjklmnpqrstvwxz]', #латинских 20 шт. + ); + + private $words_exceptions = array( + 'tt' => array( + 'трлн' => null, + 'ющенко' => null, + 'мебельград' => null, + 'дэнис' => null, + ), + 'en' => array( + 'heuer' => null, + ), + ); + + #русские буквы, похожие на англ. (uppercase) + private $ru_similar_uc = "\xd0[\x90\x92\x95\x9a\x9c\x9d\x9e\xa0-\xa3\xa5]"; + + #русские буквы, похожие на англ. (all) + private $ru_similar = "\xd0[\x90\x92\x95\x9a\x9c\x9d\x9e\xa0-\xa3\xa5\xb0\xb5\xbe]|\xd1[\x80\x81\x83\x85]"; + + #англ. буквы, похожие на русские (uppercase) + private $en_similar_uc = '[ABEKMHOPCTYX]'; + + /* + #$tt_fake = '\xd0[\xb0\xb5\xbe\x90\x92\x95\x9a\x9c\x9d\x9e\xa0\xa1\xa2\xa3\xa5]|\xd1[\x80\x81\x83\x85]'; + $tt_fake = '[\xd0\xd1][\x80-\xbe] + (?<=\xd0[\xb0\xb5\xbe\x90\x92\x95\x9a\x9c\x9d\x9e\xa0\xa1\xa2\xa3\xa5]|\xd1[\x80\x81\x83\x85])'; + $en_fake = '[aeopcyxABEKMHOPCTYX]'; + */ + + #уникальные русские буквы + /* + CASE_UPPER, case_lower + "\xd0\x81", "\xd1\x91", #Ё ё + "\xd0\x91", "\xd0\xb1", #Б б + "\xd0\x92", "\xd0\xb2", #В в + "\xd0\x93", "\xd0\xb3", #Г г + "\xd0\x94", "\xd0\xb4", #Д д + "\xd0\x96", "\xd0\xb6", #Ж ж + "\xd0\x97", "\xd0\xb7", #З з + "\xd0\x98", "\xd0\xb8", #И и + "\xd0\x99", "\xd0\xb9", #Й й + "\xd0\xba", #К к + "\xd0\x9b", "\xd0\xbb", #Л л + "\xd0\xbd", #Н н + "\xd0\x9f", "\xd0\xbf", #П п + "\xd1\x82", #Т т + "\xd0\xa4", "\xd1\x84", #Ф ф + "\xd0\xa6", "\xd1\x86", #Ц ц + "\xd0\xa7", "\xd1\x87", #Ч ч + "\xd0\xa8", "\xd1\x88", #Ш ш + "\xd0\xa9", "\xd1\x89", #Щ щ + "\xd0\xaa", "\xd1\x8a", #Ъ ъ + "\xd0\xab", "\xd1\x8b", #Ы ы + "\xd0\xac", "\xd1\x8c", #Ь ь + "\xd0\xad", "\xd1\x8d", #Э э + "\xd0\xae", "\xd1\x8e", #Ю ю + "\xd0\xaf", "\xd1\x8f", #Я я + */ + #$tt_uniq = "\xd0[\xb1-\xb4\xb6-\xbb\xbd\xbf\x81\x91-\x94\x96-\x99\x9b\x9f\xa4\xa6-\xaf]|\xd1[\x82\x84\x86-\x8f\x91]"; + private $tt_uniq = "[\xd0\xd1][\x82-\xbf] + (?<=\xd0[\xb1-\xb4\xb6-\xbb\xbd\xbf\x81\x91-\x94\x96-\x99\x9b\x9f\xa4\xa6-\xaf]|\xd1[\x82\x84\x86-\x8f\x91])"; + + #уникальные латинские буквы + /* + CASE_UPPER, case_lower + "\x42", "\x62", #B b + "\x44", "\x64", #D d + "\x46", "\x66", #F f + "\x68", #H h + "\x49", "\x69", #I i + "\x4a", "\x6a", #J j + "\x6b", #K k + "\x4c", "\x6c", #L l + "\x6d", #M m + "\x4e", "\x6e", #N n + "\x51", "\x71", #Q q + "\x52", "\x72", #R r + "\x53", "\x73", #S s + "\x74", #T t + "\x55", "\x75", #U u + "\x56", "\x76", #V v + "\x57", "\x77", #W w + "\x5a", "\x7a", #Z z + */ + private $en_uniq = "[\x42\x44\x46\x49\x4a\x4c\x4e\x51\x52\x53\x55\x57\x56\x5a\x62\x64\x66\x68\x69\x6a-\x6e\x71-\x77\x7a]"; + + private $table_flip; #array + private $words; #corrected words + private $en_correct; #string + private $tt_correct; #string + private $mode; #bool + + private $is_flip = false; + private $method = 0; + + private $table = array( + #метод 0: таблица исправления ошибочно набранных букв, которые выглядят одинаково (русский <--> английский) + 0 => array( + #lowercase #UPPERCASE + "\xd0\xb0" => 'a', "\xd0\x90" => 'A', + "\xd0\x92" => 'B', + "\xd0\xb5" => 'e', "\xd0\x95" => 'E', + "\xd0\x9a" => 'K', + "\xd0\x9c" => 'M', + "\xd0\x9d" => 'H', + "\xd0\xbe" => 'o', "\xd0\x9e" => 'O', + "\xd1\x80" => 'p', "\xd0\xa0" => 'P', + "\xd1\x81" => 'c', "\xd0\xa1" => 'C', + "\xd0\xa2" => 'T', + "\xd1\x83" => 'y', "\xd0\xa3" => 'Y', + "\xd1\x85" => 'x', "\xd0\xa5" => 'X', + ), + #метод 1: таблица исправления ошибочно набранных букв в другой раскладке клавиатуры (русский <--> английский) + 1 => array( + #CASE_UPPER #case_lower + "\xd0\x81" => '~', "\xd1\x91" => '`', #Ё ё + "\xd0\x90" => 'F', "\xd0\xb0" => 'f', #А а + "\xd0\x91" => '<', "\xd0\xb1" => ',', #Б б + "\xd0\x92" => 'D', "\xd0\xb2" => 'd', #В в + "\xd0\x93" => 'U', "\xd0\xb3" => 'u', #Г г + "\xd0\x94" => 'L', "\xd0\xb4" => 'l', #Д д + "\xd0\x95" => 'T', "\xd0\xb5" => 't', #Е е + "\xd0\x96" => ':', "\xd0\xb6" => ';', #Ж ж + "\xd0\x97" => 'P', "\xd0\xb7" => 'p', #З з + "\xd0\x98" => 'B', "\xd0\xb8" => 'b', #И и + "\xd0\x99" => 'Q', "\xd0\xb9" => 'q', #Й й + "\xd0\x9a" => 'R', "\xd0\xba" => 'r', #К к + "\xd0\x9b" => 'K', "\xd0\xbb" => 'k', #Л л + "\xd0\x9c" => 'V', "\xd0\xbc" => 'v', #М м + "\xd0\x9d" => 'Y', "\xd0\xbd" => 'y', #Н н + "\xd0\x9e" => 'J', "\xd0\xbe" => 'j', #О о + "\xd0\x9f" => 'G', "\xd0\xbf" => 'g', #П п + #CASE_UPPER #case_lower + "\xd0\xa0" => 'H', "\xd1\x80" => 'h', #Р р + "\xd0\xa1" => 'C', "\xd1\x81" => 'c', #С с + "\xd0\xa2" => 'N', "\xd1\x82" => 'n', #Т т + "\xd0\xa3" => 'E', "\xd1\x83" => 'e', #У у + "\xd0\xa4" => 'A', "\xd1\x84" => 'a', #Ф ф + "\xd0\xa5" => '{', "\xd1\x85" => '[', #Х х + "\xd0\xa6" => 'W', "\xd1\x86" => 'w', #Ц ц + "\xd0\xa7" => 'X', "\xd1\x87" => 'x', #Ч ч + "\xd0\xa8" => 'I', "\xd1\x88" => 'i', #Ш ш + "\xd0\xa9" => 'O', "\xd1\x89" => 'o', #Щ щ + "\xd0\xaa" => '}', "\xd1\x8a" => ']', #Ъ ъ + "\xd0\xab" => 'S', "\xd1\x8b" => 's', #Ы ы + "\xd0\xac" => 'M', "\xd1\x8c" => 'm', #Ь ь + "\xd0\xad" => '"', "\xd1\x8d" => "'", #Э э + "\xd0\xae" => '>', "\xd1\x8e" => '.', #Ю ю + "\xd0\xaf" => 'Z', "\xd1\x8f" => 'z', #Я я + ), + ); + + #несуществующие N-граммы для гласных букв + private $vowels3_lc = array( + 'en' => array( + 'aea' => 0, + 'aei' => 1, + 'aeo' => 2, + 'aeu' => 3, + 'aia' => 4, + 'aie' => 5, + 'aii' => 6, + 'aoi' => 7, + 'aou' => 8, + 'aue' => 9, + 'aya' => 10, + 'aye' => 11, + 'ayi' => 12, + 'ayo' => 13, + 'ayu' => 14, + 'eae' => 15, + 'eau' => 16, + 'eea' => 17, + 'eei' => 18, + 'eeu' => 19, + 'eia' => 20, + 'eiu' => 21, + 'eoi' => 22, + 'eou' => 23, + 'eya' => 24, + 'eye' => 25, + 'eyi' => 26, + 'eyo' => 27, + 'iae' => 28, + 'iai' => 29, + 'iao' => 30, + 'iau' => 31, + 'iei' => 32, + 'ieu' => 33, + 'ioa' => 34, + 'ioe' => 35, + 'iou' => 36, + 'iya' => 37, + 'oae' => 38, + 'oea' => 39, + 'oei' => 40, + 'oeo' => 41, + 'oeu' => 42, + 'oey' => 43, + 'oia' => 44, + 'oie' => 45, + 'ooe' => 46, + 'ooi' => 47, + 'oou' => 48, + 'oua' => 49, + 'oue' => 50, + 'oui' => 51, + 'oya' => 52, + 'oye' => 53, + 'oyi' => 54, + 'oyo' => 55, + 'uae' => 56, + 'uai' => 57, + 'uay' => 58, + 'uea' => 59, + 'uee' => 60, + 'uei' => 61, + 'ueo' => 62, + 'ueu' => 63, + 'uey' => 64, + 'uia' => 65, + 'uie' => 66, + 'uio' => 67, + 'uiu' => 68, + 'uoa' => 69, + 'uoi' => 70, + 'uou' => 71, + 'uoy' => 72, + 'uya' => 73, + 'uye' => 74, + 'uyi' => 75, + 'yae' => 76, + 'yao' => 77, + 'yau' => 78, + 'yea' => 79, + 'yei' => 80, + 'yeo' => 81, + 'yey' => 82, + 'yie' => 83, + 'yoi' => 84, + 'you' => 85, + 'yoy' => 86, + 'yua' => 87, + ), + 'tt' => array( + 'аау' => 0, + 'аео' => 1, + 'аеу' => 2, + 'аиа' => 3, + 'аио' => 4, + 'аиу' => 5, + 'аои' => 6, + 'ауэ' => 7, + 'аяя' => 8, + 'еаэ' => 9, + 'еее' => 10, + 'еео' => 11, + 'еоа' => 12, + 'еои' => 13, + 'еоо' => 14, + 'еую' => 15, + 'еуя' => 16, + 'еуё' => 17, + 'иау' => 18, + 'иео' => 19, + 'иие' => 20, + 'иоа' => 21, + 'иои' => 22, + 'иоу' => 23, + 'иоэ' => 24, + 'ияе' => 25, + 'ияи' => 26, + 'ияю' => 27, + 'оаэ' => 28, + 'оео' => 29, + 'оею' => 30, + 'оие' => 31, + 'оуе' => 32, + 'оуя' => 33, + 'оюе' => 34, + 'оюю' => 35, + 'ояе' => 36, + 'уео' => 37, + 'уюю' => 38, + ), + ); + + #несуществующие N-граммы для согласных букв + private $consonants4_lc = array( + 'en' => array( + 'bldg' => 0, + 'blvd' => 1, + 'bscr' => 2, + 'bstr' => 3, + 'cbcm' => 4, + 'cbft' => 5, + 'chfr' => 6, + 'chmn' => 7, + 'chsc' => 8, + 'chsh' => 9, + 'chst' => 10, + 'chth' => 11, + 'chts' => 12, + 'ckbr' => 13, + 'ckch' => 14, + 'ckcl' => 15, + 'ckdr' => 16, + 'ckgr' => 17, + 'cksc' => 18, + 'cksf' => 19, + 'cksh' => 20, + 'cksk' => 21, + 'cksl' => 22, + 'cksm' => 23, + 'cksn' => 24, + 'cksp' => 25, + 'ckst' => 26, + 'cksw' => 27, + 'ckth' => 28, + 'cktr' => 29, + 'ckwh' => 30, + 'cmps' => 31, + 'dspr' => 32, + 'dstr' => 33, + 'dthw' => 34, + 'ffsc' => 35, + 'ffsh' => 36, + 'ffsp' => 37, + 'fthl' => 38, + 'ftsm' => 39, + 'ftsp' => 40, + 'gdns' => 41, + 'ghbr' => 42, + 'ghfl' => 43, + 'ghsh' => 44, + 'ghtb' => 45, + 'ghtc' => 46, + 'ghtf' => 47, + 'ghth' => 48, + 'ghtj' => 49, + 'ghtl' => 50, + 'ghtm' => 51, + 'ghtn' => 52, + 'ghtr' => 53, + 'ghts' => 54, + 'ghtw' => 55, + 'hdbk' => 56, + 'hnst' => 57, + 'jctn' => 58, + 'khsh' => 59, + 'khst' => 60, + 'lchr' => 61, + 'ldpr' => 62, + 'ldsh' => 63, + 'ldsm' => 64, + 'ldsp' => 65, + 'ldst' => 66, + 'lfsk' => 67, + 'lfth' => 68, + 'lgth' => 69, + 'llfl' => 70, + 'llfr' => 71, + 'llph' => 72, + 'llpl' => 73, + 'llsh' => 74, + 'llsp' => 75, + 'llst' => 76, + 'lltr' => 77, + 'llwr' => 78, + 'lmcr' => 79, + 'lmsm' => 80, + 'lnrk' => 81, + 'lnsh' => 82, + 'lptr' => 83, + 'lsgr' => 84, + 'lshm' => 85, + 'lshw' => 86, + 'lstr' => 87, + 'lthf' => 88, + 'ltsf' => 89, + 'ltsh' => 90, + 'ltst' => 91, + 'mbsc' => 92, + 'mbsh' => 93, + 'mbsk' => 94, + 'mbst' => 95, + 'mddx' => 96, + 'mdnt' => 97, + 'mpbl' => 98, + 'mpgr' => 99, + 'mphl' => 100, + 'mphr' => 101, + 'mpsh' => 102, + 'mpst' => 103, + 'mptl' => 104, + 'mptn' => 105, + 'mptr' => 106, + 'mpts' => 107, + 'mscr' => 108, + 'mstr' => 109, + 'nchb' => 110, + 'nchl' => 111, + 'nchm' => 112, + 'nchn' => 113, + 'nchp' => 114, + 'nchr' => 115, + 'nchw' => 116, + 'nctl' => 117, + 'nctn' => 118, + 'ndbk' => 119, + 'ndbr' => 120, + 'ndch' => 121, + 'ndfl' => 122, + 'ndgl' => 123, + 'ndgr' => 124, + 'ndsc' => 125, + 'ndsh' => 126, + 'ndsl' => 127, + 'ndsm' => 128, + 'ndsp' => 129, + 'ndst' => 130, + 'ndsw' => 131, + 'ndth' => 132, + 'ndwr' => 133, + 'ngcr' => 134, + 'ngsg' => 135, + 'ngsh' => 136, + 'ngsm' => 137, + 'ngsp' => 138, + 'ngst' => 139, + 'ngth' => 140, + 'ngtz' => 141, + 'nksg' => 142, + 'nksh' => 143, + 'nksm' => 144, + 'nkst' => 145, + 'nsch' => 146, + 'nscr' => 147, + 'nsgr' => 148, + 'nshr' => 149, + 'nskr' => 150, + 'nspl' => 151, + 'nspr' => 152, + 'nssh' => 153, + 'nstr' => 154, + 'ntbr' => 155, + 'nthl' => 156, + 'nthr' => 157, + 'nths' => 158, + 'ntsh' => 159, + 'ntsm' => 160, + 'phth' => 161, + 'pstr' => 162, + 'pthr' => 163, + 'pths' => 164, + 'ptwr' => 165, + 'rbst' => 166, + 'rchb' => 167, + 'rchd' => 168, + 'rchl' => 169, + 'rchm' => 170, + 'rchn' => 171, + 'rchp' => 172, + 'rchw' => 173, + 'rdsh' => 174, + 'rdsm' => 175, + 'rdst' => 176, + 'rghs' => 177, + 'rkpl' => 178, + 'rksc' => 179, + 'rksh' => 180, + 'rksk' => 181, + 'rksm' => 182, + 'rksp' => 183, + 'rkst' => 184, + 'rldl' => 185, + 'rldw' => 186, + 'rlfr' => 187, + 'rmch' => 188, + 'rmst' => 189, + 'rmth' => 190, + 'rnbl' => 191, + 'rndl' => 192, + 'rnsk' => 193, + 'rnsp' => 194, + 'rnst' => 195, + 'rsch' => 196, + 'rscr' => 197, + 'rshl' => 198, + 'rshn' => 199, + 'rspr' => 200, + 'rstl' => 201, + 'rstr' => 202, + 'rsts' => 203, + 'rstw' => 204, + 'rtbr' => 205, + 'rtch' => 206, + 'rtcr' => 207, + 'rthb' => 208, + 'rthc' => 209, + 'rthd' => 210, + 'rthf' => 211, + 'rthl' => 212, + 'rthm' => 213, + 'rthq' => 214, + 'rthr' => 215, + 'rths' => 216, + 'rthw' => 217, + 'rtsh' => 218, + 'rtsm' => 219, + 'rtsp' => 220, + 'rtsw' => 221, + 'schl' => 222, + 'schm' => 223, + 'schn' => 224, + 'schw' => 225, + 'scrp' => 226, + 'sgmt' => 227, + 'shcl' => 228, + 'shkh' => 229, + 'shpr' => 230, + 'shpt' => 231, + 'shst' => 232, + 'shtr' => 233, + 'shwh' => 234, + 'smth' => 235, + 'ssrs' => 236, + 'ssst' => 237, + 'sstd' => 238, + 'sstr' => 239, + 'stcr' => 240, + 'sthm' => 241, + 'stpl' => 242, + 'stpr' => 243, + 'stsc' => 244, + 'stwr' => 245, + 'tblt' => 246, + 'tchb' => 247, + 'tchc' => 248, + 'tchd' => 249, + 'tchf' => 250, + 'tchl' => 251, + 'tchm' => 252, + 'tchp' => 253, + 'tchw' => 254, + 'thdr' => 255, + 'thsh' => 256, + 'thsk' => 257, + 'thsp' => 258, + 'thst' => 259, + 'tsch' => 260, + 'tspr' => 261, + 'tstr' => 262, + 'tthr' => 263, + 'ttsb' => 264, + 'tzkr' => 265, + 'whsl' => 266, + 'wnbr' => 267, + 'wnpl' => 268, + 'wnsf' => 269, + 'wnsh' => 270, + 'wnsm' => 271, + 'wnsp' => 272, + 'wnst' => 273, + 'wnsw' => 274, + 'wnth' => 275, + 'wntr' => 276, + 'wrnt' => 277, + 'wsfl' => 278, + 'wspr' => 279, + 'wstr' => 280, + 'xthl' => 281, + ), + 'tt' => array( + 'блзд' => 0, + 'бльд' => 1, + 'брьс' => 2, + 'бств' => 3, + 'бстр' => 4, + 'взбл' => 5, + 'взбр' => 6, + 'взгл' => 7, + 'взгр' => 8, + 'вздв' => 9, + 'вздр' => 10, + 'врвг' => 11, + 'врск' => 12, + 'вскл' => 13, + 'вскр' => 14, + 'вспл' => 15, + 'вспр' => 16, + 'вств' => 17, + 'встр' => 18, + 'всхл' => 19, + 'всхр' => 20, + 'втск' => 21, + 'вхск' => 22, + 'грск' => 23, + 'гств' => 24, + 'гтст' => 25, + 'гшпр' => 26, + 'двзд' => 27, + 'джск' => 28, + 'дрст' => 29, + 'дскр' => 30, + 'дств' => 31, + 'дстр' => 32, + 'дтск' => 33, + 'жств' => 34, + 'звзд' => 35, + 'знст' => 36, + 'зтьс' => 37, + 'йздр' => 38, + 'йкбр' => 39, + 'йльн' => 40, + 'йншт' => 41, + 'йпфр' => 42, + 'йств' => 43, + 'йстр' => 44, + 'йтск' => 45, + 'йфст' => 46, + 'йхсв' => 47, + 'йхск' => 48, + 'йхср' => 49, + 'йхст' => 50, + 'кскл' => 51, + 'кскр' => 52, + 'кспл' => 53, + 'кспр' => 54, + 'кств' => 55, + 'кстн' => 56, + 'кстр' => 57, + 'лвст' => 58, + 'лжск' => 59, + 'лльн' => 60, + 'лльс' => 61, + 'лстр' => 62, + 'лсть' => 63, + 'льгв' => 64, + 'льдж' => 65, + 'льдк' => 66, + 'льдм' => 67, + 'льдс' => 68, + 'льдф' => 69, + 'льдц' => 70, + 'льдш' => 71, + 'льдъ' => 72, + 'льдь' => 73, + 'льзк' => 74, + 'льзн' => 75, + 'льзь' => 76, + 'лькл' => 77, + 'лькн' => 78, + 'льпн' => 79, + 'льпт' => 80, + 'льск' => 81, + 'льсн' => 82, + 'льст' => 83, + 'льтк' => 84, + 'льтм' => 85, + 'льтн' => 86, + 'льтп' => 87, + 'льтр' => 88, + 'льтс' => 89, + 'льтт' => 90, + 'льтф' => 91, + 'льфр' => 92, + 'льцг' => 93, + 'льчс' => 94, + 'льшб' => 95, + 'льшк' => 96, + 'льшн' => 97, + 'льшп' => 98, + 'льшф' => 99, + 'льшь' => 100, + 'мбль' => 101, + 'мбрс' => 102, + 'мвзв' => 103, + 'мздр' => 104, + 'мств' => 105, + 'мтск' => 106, + 'нгль' => 107, + 'нгст' => 108, + 'ндгр' => 109, + 'ндск' => 110, + 'ндсп' => 111, + 'ндшп' => 112, + 'ндшт' => 113, + 'нкск' => 114, + 'нктн' => 115, + 'нктс' => 116, + 'нсгр' => 117, + 'нскм' => 118, + 'нскр' => 119, + 'нспл' => 120, + 'нств' => 121, + 'нстк' => 122, + 'нстр' => 123, + 'нтгл' => 124, + 'нтль' => 125, + 'нтрб' => 126, + 'нтрв' => 127, + 'нтрг' => 128, + 'нтрд' => 129, + 'нтрм' => 130, + 'нтрн' => 131, + 'нтрп' => 132, + 'нтрр' => 133, + 'нтрф' => 134, + 'нтск' => 135, + 'нтст' => 136, + 'нфск' => 137, + 'нцкл' => 138, + 'нцпл' => 139, + 'нькн' => 140, + 'ньск' => 141, + 'ньчж' => 142, + 'псск' => 143, + 'пств' => 144, + 'птск' => 145, + 'рбск' => 146, + 'ргпр' => 147, + 'ргск' => 148, + 'ргфл' => 149, + 'рдск' => 150, + 'рдсм' => 151, + 'рдст' => 152, + 'рздр' => 153, + 'рзть' => 154, + 'ркгр' => 155, + 'ркск' => 156, + 'рктн' => 157, + 'рльс' => 158, + 'рмск' => 159, + 'рмтр' => 160, + 'рнск' => 161, + 'рпск' => 162, + 'рсдр' => 163, + 'рсск' => 164, + 'рств' => 165, + 'рстк' => 166, + 'рстн' => 167, + 'рстр' => 168, + 'рстс' => 169, + 'рсть' => 170, + 'ртвл' => 171, + 'ртвр' => 172, + 'ртгр' => 173, + 'рткр' => 174, + 'ртпл' => 175, + 'ртпр' => 176, + 'ртск' => 177, + 'ртсм' => 178, + 'ртшк' => 179, + 'ртьф' => 180, + 'рхзв' => 181, + 'рхпл' => 182, + 'рхпр' => 183, + 'рхсв' => 184, + 'рхск' => 185, + 'рхсм' => 186, + 'рхср' => 187, + 'рхтв' => 188, + 'рхшт' => 189, + 'рщвл' => 190, + 'рьмл' => 191, + 'скск' => 192, + 'спрь' => 193, + 'сспр' => 194, + 'ссср' => 195, + 'сств' => 196, + 'сстр' => 197, + 'ссшп' => 198, + 'ствл' => 199, + 'стрс' => 200, + 'стрш' => 201, + 'стск' => 202, + 'стьб' => 203, + 'стьд' => 204, + 'стьс' => 205, + 'ськн' => 206, + 'сьмн' => 207, + 'тмст' => 208, + 'тпрр' => 209, + 'трст' => 210, + 'тскр' => 211, + 'тств' => 212, + 'тстр' => 213, + 'ттль' => 214, + 'ттск' => 215, + 'тхск' => 216, + 'фств' => 217, + 'фстр' => 218, + 'хств' => 219, + 'хстр' => 220, + 'хткл' => 221, + 'хтск' => 222, + 'хтсм' => 223, + 'цстр' => 224, + ), + ); + + #несуществующие биграммы в начале и конце слов + private $bigrams = array( + #ru + ' ёё' => 0, + ' ёа' => 0, + ' ёб' => 0, + ' ёв' => 0, + ' ёг' => 0, + ' ёд' => 0, + ' ёе' => 0, + ' ёз' => 0, + ' ёи' => 0, + ' ёй' => 0, + ' ён' => 0, + ' ёо' => 0, + ' ёп' => 0, + ' ёс' => 0, + ' ёт' => 0, + ' ёу' => 0, + ' ёф' => 0, + ' ёц' => 0, + ' ёч' => 0, + ' ёщ' => 0, + ' ёъ' => 0, + ' ёы' => 0, + ' ёь' => 0, + ' ёэ' => 0, + ' ёю' => 0, + ' ёя' => 0, + ' аё' => 0, + ' аа' => 0, + ' ае' => 0, + ' ач' => 0, + ' аъ' => 0, + ' аы' => 0, + ' аь' => 0, + ' аю' => 0, + ' ая' => 0, + ' бб' => 0, + ' бв' => 0, + ' бг' => 0, + ' бж' => 0, + ' бй' => 0, + ' бк' => 0, + ' бм' => 0, + ' бн' => 0, + ' бп' => 0, + ' бс' => 0, + ' бт' => 0, + ' бф' => 0, + ' бх' => 0, + ' бц' => 0, + ' бч' => 0, + ' бш' => 0, + ' бщ' => 0, + ' бъ' => 0, + ' вй' => 0, + ' вф' => 0, + ' вщ' => 0, + ' вэ' => 0, + ' вю' => 0, + ' гё' => 0, + ' гб' => 0, + ' гз' => 0, + ' гй' => 0, + ' гк' => 0, + ' гп' => 0, + ' гс' => 0, + ' гт' => 0, + ' гф' => 0, + ' гх' => 0, + ' гц' => 0, + ' гч' => 0, + ' гш' => 0, + ' гщ' => 0, + ' гъ' => 0, + ' гь' => 0, + ' гэ' => 0, + ' дб' => 0, + ' дг' => 0, + ' дд' => 0, + ' дй' => 0, + ' дк' => 0, + ' дп' => 0, + ' дс' => 0, + ' дт' => 0, + ' дф' => 0, + ' дх' => 0, + ' дц' => 0, + ' дч' => 0, + ' дш' => 0, + ' дъ' => 0, + ' дэ' => 0, + ' еа' => 0, + ' еб' => 0, + ' еи' => 0, + ' ео' => 0, + ' ет' => 0, + ' еу' => 0, + ' ец' => 0, + #' еш' => 0, + ' еъ' => 0, + ' еы' => 0, + ' еь' => 0, + ' еэ' => 0, + ' ея' => 0, + ' жз' => 0, + ' жй' => 0, + ' жк' => 0, + ' жл' => 0, + ' жп' => 0, + ' жс' => 0, + ' жт' => 0, + ' жф' => 0, + ' жх' => 0, + ' жц' => 0, + ' жч' => 0, + ' жш' => 0, + ' жщ' => 0, + ' жъ' => 0, + ' жы' => 0, + ' жь' => 0, + ' жэ' => 0, + #' жю' => 0, + ' жя' => 0, + ' зб' => 0, + ' зж' => 0, + ' зз' => 0, + ' зй' => 0, + ' зк' => 0, + ' зп' => 0, + ' зс' => 0, + ' зт' => 0, + ' зф' => 0, + ' зх' => 0, + ' зц' => 0, + ' зч' => 0, + ' зш' => 0, + ' зщ' => 0, + ' зъ' => 0, + ' зь' => 0, + ' зэ' => 0, + ' иё' => 0, + ' иа' => 0, + ' иф' => 0, + ' иц' => 0, + ' иъ' => 0, + ' иы' => 0, + ' иь' => 0, + ' иэ' => 0, + ' ия' => 0, + ' йё' => 0, + ' йа' => 0, + ' йб' => 0, + ' йв' => 0, + ' йг' => 0, + ' йд' => 0, + ' йж' => 0, + ' йз' => 0, + ' йи' => 0, + ' йй' => 0, + ' йк' => 0, + ' йл' => 0, + ' йм' => 0, + ' йн' => 0, + ' йп' => 0, + ' йр' => 0, + ' йс' => 0, + ' йт' => 0, + ' йу' => 0, + ' йф' => 0, + ' йх' => 0, + ' йц' => 0, + ' йч' => 0, + ' йш' => 0, + ' йщ' => 0, + ' йъ' => 0, + ' йы' => 0, + ' йь' => 0, + ' йэ' => 0, + ' йю' => 0, + ' йя' => 0, + ' кё' => 0, + ' кб' => 0, + ' кд' => 0, + ' кж' => 0, + ' кй' => 0, + ' кк' => 0, + ' кф' => 0, + ' кц' => 0, + ' кч' => 0, + ' кщ' => 0, + ' къ' => 0, + ' кя' => 0, + ' лв' => 0, + ' лд' => 0, + ' лз' => 0, + ' лй' => 0, + ' лк' => 0, + ' лл' => 0, + ' лм' => 0, + ' лн' => 0, + ' лп' => 0, + ' лр' => 0, + ' лс' => 0, + ' лт' => 0, + ' лф' => 0, + ' лх' => 0, + ' лц' => 0, + ' лч' => 0, + ' лш' => 0, + ' лщ' => 0, + ' лъ' => 0, + ' лэ' => 0, + ' мб' => 0, + ' мв' => 0, + ' мд' => 0, + ' мж' => 0, + ' мй' => 0, + ' мк' => 0, + ' мп' => 0, + ' мт' => 0, + ' мф' => 0, + ' мц' => 0, + ' мъ' => 0, + ' мь' => 0, + ' нб' => 0, + ' нв' => 0, + ' нг' => 0, + ' нд' => 0, + ' нж' => 0, + ' нз' => 0, + ' нй' => 0, + ' нк' => 0, + ' нл' => 0, + ' нм' => 0, + ' нн' => 0, + ' нп' => 0, + ' нс' => 0, + ' нт' => 0, + ' нф' => 0, + ' нх' => 0, + ' нц' => 0, + ' нч' => 0, + ' нш' => 0, + ' нщ' => 0, + ' нъ' => 0, + ' оё' => 0, + ' ои' => 0, + ' оу' => 0, + ' оъ' => 0, + ' оы' => 0, + ' оь' => 0, + ' оэ' => 0, + ' оя' => 0, + ' пб' => 0, + ' пв' => 0, + ' пг' => 0, + ' пд' => 0, + ' пж' => 0, + ' пз' => 0, + ' пй' => 0, + ' пк' => 0, + ' пм' => 0, + ' пп' => 0, + ' пц' => 0, + ' пщ' => 0, + ' пъ' => 0, + ' рб' => 0, + ' рг' => 0, + ' рз' => 0, + ' рй' => 0, + ' рк' => 0, + ' рл' => 0, + ' рм' => 0, + ' рн' => 0, + ' рп' => 0, + ' рр' => 0, + ' рф' => 0, + ' рх' => 0, + ' рч' => 0, + ' рш' => 0, + ' рщ' => 0, + ' ръ' => 0, + ' сй' => 0, + ' сщ' => 0, + ' тб' => 0, + ' тг' => 0, + ' тд' => 0, + ' тж' => 0, + ' тз' => 0, + ' тй' => 0, + ' тн' => 0, + ' тт' => 0, + ' тх' => 0, + ' тц' => 0, + ' тч' => 0, + ' тш' => 0, + ' тъ' => 0, + ' уу' => 0, + ' уъ' => 0, + ' уы' => 0, + ' уь' => 0, + ' фб' => 0, + ' фв' => 0, + ' фг' => 0, + ' фд' => 0, + ' фж' => 0, + ' фз' => 0, + ' фй' => 0, + ' фк' => 0, + ' фм' => 0, + ' фн' => 0, + ' фп' => 0, + ' фс' => 0, + ' фх' => 0, + ' фц' => 0, + ' фч' => 0, + ' фш' => 0, + ' фщ' => 0, + ' фъ' => 0, + ' фэ' => 0, + ' фя' => 0, + ' хё' => 0, + ' хб' => 0, + ' хг' => 0, + ' хд' => 0, + ' хж' => 0, + ' хз' => 0, + ' хй' => 0, + ' хк' => 0, + ' хп' => 0, + ' хс' => 0, + ' хт' => 0, + ' хф' => 0, + ' хц' => 0, + ' хч' => 0, + ' хш' => 0, + ' хщ' => 0, + ' хъ' => 0, + ' хы' => 0, + ' хь' => 0, + #' хэ' => 0, + ' хю' => 0, + ' хя' => 0, + ' цё' => 0, + ' цб' => 0, + ' цг' => 0, + ' цд' => 0, + ' цж' => 0, + ' цй' => 0, + ' цл' => 0, + ' цм' => 0, + ' цн' => 0, + ' цп' => 0, + ' цр' => 0, + ' цс' => 0, + ' цт' => 0, + ' цф' => 0, + ' цх' => 0, + ' цц' => 0, + ' цч' => 0, + ' цш' => 0, + ' цщ' => 0, + ' цъ' => 0, + ' ць' => 0, + ' цэ' => 0, + ' цю' => 0, + ' ця' => 0, + ' чб' => 0, + ' чг' => 0, + ' чд' => 0, + ' чж' => 0, + ' чз' => 0, + ' чй' => 0, + ' чн' => 0, + ' чп' => 0, + ' чс' => 0, + ' чф' => 0, + ' чц' => 0, + ' чч' => 0, + ' чщ' => 0, + ' чъ' => 0, + ' чы' => 0, + ' чэ' => 0, + ' чю' => 0, + ' чя' => 0, + ' шб' => 0, + ' шг' => 0, + ' шд' => 0, + ' шж' => 0, + ' шз' => 0, + ' шй' => 0, + ' шс' => 0, + ' шф' => 0, + ' шц' => 0, + ' шч' => 0, + ' шщ' => 0, + ' шъ' => 0, + ' шы' => 0, + ' шэ' => 0, + ' шю' => 0, + ' шя' => 0, + ' щб' => 0, + ' щв' => 0, + ' щг' => 0, + ' щд' => 0, + ' щж' => 0, + ' щз' => 0, + ' щй' => 0, + ' щк' => 0, + ' щл' => 0, + ' щм' => 0, + ' щн' => 0, + ' що' => 0, + ' щп' => 0, + ' щр' => 0, + ' щс' => 0, + ' щт' => 0, + ' щф' => 0, + ' щх' => 0, + ' щц' => 0, + ' щч' => 0, + ' щш' => 0, + ' щщ' => 0, + ' щъ' => 0, + ' щы' => 0, + ' щь' => 0, + ' щэ' => 0, + ' щю' => 0, + ' щя' => 0, + ' ъё' => 0, + ' ъа' => 0, + ' ъб' => 0, + ' ъв' => 0, + ' ъг' => 0, + ' ъд' => 0, + ' ъе' => 0, + ' ъж' => 0, + ' ъз' => 0, + ' ъи' => 0, + ' ъй' => 0, + ' ък' => 0, + ' ъл' => 0, + ' ъм' => 0, + ' ън' => 0, + ' ъо' => 0, + ' ъп' => 0, + ' ър' => 0, + ' ъс' => 0, + ' ът' => 0, + ' ъу' => 0, + ' ъф' => 0, + ' ъх' => 0, + ' ъц' => 0, + ' ъч' => 0, + ' ъш' => 0, + ' ъщ' => 0, + ' ъъ' => 0, + ' ъы' => 0, + ' ъь' => 0, + ' ъэ' => 0, + ' ъю' => 0, + ' ъя' => 0, + ' ыё' => 0, + ' ыа' => 0, + ' ыб' => 0, + ' ыв' => 0, + ' ыг' => 0, + ' ыд' => 0, + ' ые' => 0, + ' ыж' => 0, + ' ыз' => 0, + ' ыи' => 0, + ' ый' => 0, + ' ык' => 0, + ' ыл' => 0, + ' ын' => 0, + ' ыо' => 0, + ' ып' => 0, + ' ыр' => 0, + ' ыс' => 0, + ' ыт' => 0, + ' ыу' => 0, + ' ыф' => 0, + ' ых' => 0, + ' ыц' => 0, + ' ыч' => 0, + ' ыш' => 0, + ' ыщ' => 0, + ' ыъ' => 0, + ' ыы' => 0, + ' ыь' => 0, + ' ыэ' => 0, + ' ыю' => 0, + ' ыя' => 0, + ' ьё' => 0, + ' ьа' => 0, + ' ьб' => 0, + ' ьв' => 0, + ' ьг' => 0, + ' ьд' => 0, + ' ье' => 0, + ' ьж' => 0, + ' ьз' => 0, + ' ьи' => 0, + ' ьй' => 0, + ' ьк' => 0, + ' ьл' => 0, + ' ьм' => 0, + ' ьн' => 0, + ' ьо' => 0, + ' ьп' => 0, + ' ьр' => 0, + ' ьс' => 0, + ' ьт' => 0, + ' ьу' => 0, + ' ьф' => 0, + ' ьх' => 0, + ' ьц' => 0, + ' ьч' => 0, + ' ьш' => 0, + ' ьщ' => 0, + ' ьъ' => 0, + ' ьы' => 0, + ' ьь' => 0, + ' ьэ' => 0, + ' ью' => 0, + ' ья' => 0, + ' эё' => 0, + ' эа' => 0, + ' эе' => 0, + ' эи' => 0, + ' эц' => 0, + ' эч' => 0, + ' эщ' => 0, + ' эъ' => 0, + ' эы' => 0, + ' эь' => 0, + ' ээ' => 0, + ' эю' => 0, + ' юё' => 0, + ' юе' => 0, + ' юи' => 0, + ' юй' => 0, + ' юо' => 0, + ' юу' => 0, + ' юц' => 0, + ' юш' => 0, + ' ющ' => 0, + ' юъ' => 0, + ' юы' => 0, + ' юь' => 0, + ' юэ' => 0, + ' юя' => 0, + ' яё' => 0, + ' яа' => 0, + ' яе' => 0, + ' яж' => 0, + ' яо' => 0, + ' яу' => 0, + ' яф' => 0, + ' яц' => 0, + ' яъ' => 0, + ' яы' => 0, + ' яь' => 0, + ' яэ' => 0, + ' яю' => 0, + ' яя' => 0, + 'ёё' => 0, + 'ёё ' => 0, + 'ёа' => 0, + 'ёа ' => 0, + 'ёг ' => 0, + 'ёе' => 0, + 'ёе ' => 0, + 'ёи' => 0, + 'ёи ' => 0, + 'ёй' => 0, + 'ёо' => 0, + 'ёо ' => 0, + 'ёу' => 0, + 'ёу ' => 0, + 'ёф' => 0, + 'ёф ' => 0, + 'ёц ' => 0, + 'ёч ' => 0, + 'ёщ ' => 0, + 'ёъ' => 0, + 'ёъ ' => 0, + 'ёы' => 0, + 'ёы ' => 0, + 'ёь' => 0, + 'ёь ' => 0, + 'ёэ' => 0, + 'ёэ ' => 0, + 'ёю' => 0, + 'ёя' => 0, + 'ёя ' => 0, + 'аё ' => 0, + 'аа ' => 0, + 'аъ' => 0, + 'аъ ' => 0, + 'аы' => 0, + 'аы ' => 0, + 'аь' => 0, + 'аь ' => 0, + 'аэ ' => 0, + 'бё ' => 0, + 'бб ' => 0, + 'бв ' => 0, + 'бг ' => 0, + 'бд ' => 0, + 'бж ' => 0, + 'бз ' => 0, + 'бй' => 0, + 'бй ' => 0, + 'бк ' => 0, + 'бм ' => 0, + 'бн ' => 0, + 'бп ' => 0, + 'бт ' => 0, + 'бф ' => 0, + 'бх ' => 0, + 'бц ' => 0, + 'бч ' => 0, + 'бш ' => 0, + 'бщ ' => 0, + 'бъ ' => 0, + 'бэ ' => 0, + 'вё ' => 0, + 'вб ' => 0, + 'вв ' => 0, + 'вд ' => 0, + 'вж' => 0, + 'вж ' => 0, + 'вз ' => 0, + 'вй' => 0, + 'вй ' => 0, + 'вл ' => 0, + 'вп ' => 0, + 'вф ' => 0, + 'вц ' => 0, + 'вч ' => 0, + 'вщ ' => 0, + 'въ' => 0, + 'въ ' => 0, + 'вэ ' => 0, + 'гё' => 0, + 'гё ' => 0, + 'гб ' => 0, + 'гг ' => 0, + 'гж' => 0, + 'гж ' => 0, + 'гз ' => 0, + 'гй' => 0, + 'гй ' => 0, + 'гк ' => 0, + 'гн ' => 0, + 'гп ' => 0, + 'гф ' => 0, + 'гх' => 0, + 'гх ' => 0, + 'гц' => 0, + 'гц ' => 0, + 'гч ' => 0, + 'гш ' => 0, + 'гщ ' => 0, + 'гъ' => 0, + 'гъ ' => 0, + 'гы ' => 0, + 'гь' => 0, + 'гь ' => 0, + 'гэ ' => 0, + 'гю' => 0, + 'гю ' => 0, + 'гя' => 0, + 'гя ' => 0, + 'дё ' => 0, + 'дб ' => 0, + 'дг ' => 0, + 'дд ' => 0, + 'дй' => 0, + 'дй ' => 0, + 'дк ' => 0, + 'дм ' => 0, + 'дн ' => 0, + 'дп ' => 0, + 'дс ' => 0, + 'дф ' => 0, + 'дх ' => 0, + 'дц ' => 0, + 'дч ' => 0, + 'дш ' => 0, + 'дщ ' => 0, + 'дъ ' => 0, + 'еа ' => 0, + 'еу ' => 0, + 'еъ' => 0, + 'еъ ' => 0, + 'еы' => 0, + 'еы ' => 0, + 'еь' => 0, + 'еь ' => 0, + 'еэ ' => 0, + 'жё ' => 0, + 'жв ' => 0, + 'жг ' => 0, + 'жж ' => 0, + 'жз ' => 0, + 'жй' => 0, + 'жй ' => 0, + 'жк ' => 0, + 'жл ' => 0, + 'жн ' => 0, + 'жп ' => 0, + 'жр ' => 0, + 'жс ' => 0, + 'жт ' => 0, + 'жф ' => 0, + 'жх ' => 0, + 'жц ' => 0, + 'жч ' => 0, + 'жш' => 0, + 'жш ' => 0, + 'жщ' => 0, + 'жщ ' => 0, + 'жъ' => 0, + 'жъ ' => 0, + 'жы ' => 0, + 'жэ ' => 0, + 'жю' => 0, + 'жю ' => 0, + 'жя' => 0, + 'жя ' => 0, + 'зё ' => 0, + 'зж ' => 0, + 'зз ' => 0, + 'зй' => 0, + 'зй ' => 0, + 'зк ' => 0, + 'зп ' => 0, + 'зр ' => 0, + 'зс ' => 0, + 'зт ' => 0, + 'зф' => 0, + 'зф ' => 0, + 'зх' => 0, + 'зх ' => 0, + 'зц ' => 0, + 'зч ' => 0, + 'зш ' => 0, + 'зщ' => 0, + 'зщ ' => 0, + 'зъ ' => 0, + 'зэ ' => 0, + 'иъ' => 0, + 'иъ ' => 0, + 'иы' => 0, + 'иы ' => 0, + 'иь' => 0, + 'иь ' => 0, + 'иэ ' => 0, + 'йё' => 0, + 'йё ' => 0, + 'йа ' => 0, + 'йв ' => 0, + 'йг ' => 0, + 'йж' => 0, + 'йж ' => 0, + 'йз ' => 0, + 'йи ' => 0, + 'йй' => 0, + 'йй ' => 0, + 'йо ' => 0, + 'йу' => 0, + 'йу ' => 0, + 'йч ' => 0, + 'йш ' => 0, + 'йщ ' => 0, + 'йъ' => 0, + 'йъ ' => 0, + 'йы' => 0, + 'йы ' => 0, + 'йь' => 0, + 'йь ' => 0, + 'йэ' => 0, + 'йэ ' => 0, + 'йю' => 0, + 'йю ' => 0, + 'йя' => 0, + 'кё ' => 0, + 'кб ' => 0, + 'кг ' => 0, + 'кд ' => 0, + 'кж ' => 0, + 'кз ' => 0, + 'кй' => 0, + 'кй ' => 0, + 'км ' => 0, + 'кн ' => 0, + 'кф ' => 0, + 'кц ' => 0, + 'кч ' => 0, + 'кш ' => 0, + 'кщ' => 0, + 'кщ ' => 0, + 'къ' => 0, + 'къ ' => 0, + 'кы ' => 0, + 'кь ' => 0, + 'кэ' => 0, + 'кэ ' => 0, + 'кя' => 0, + 'кя ' => 0, + 'лв ' => 0, + 'лж ' => 0, + 'лз ' => 0, + 'лй' => 0, + 'лй ' => 0, + 'лр ' => 0, + 'лф ' => 0, + 'лх ' => 0, + 'лц ' => 0, + 'лч ' => 0, + 'лш ' => 0, + 'лщ ' => 0, + 'лъ' => 0, + 'лъ ' => 0, + 'лэ' => 0, + 'лэ ' => 0, + 'мё ' => 0, + 'мв ' => 0, + 'мг ' => 0, + 'мд ' => 0, + 'мз ' => 0, + 'мй' => 0, + 'мк ' => 0, + 'мл ' => 0, + 'мр ' => 0, + 'мх ' => 0, + 'мц ' => 0, + 'мч ' => 0, + 'мш ' => 0, + 'мщ ' => 0, + 'мъ' => 0, + 'мъ ' => 0, + 'мэ ' => 0, + 'мю ' => 0, + 'нё ' => 0, + 'нб ' => 0, + 'нв ' => 0, + 'нй' => 0, + 'нл ' => 0, + 'нп ' => 0, + 'нщ ' => 0, + 'нъ ' => 0, + 'нэ ' => 0, + 'оъ' => 0, + 'оъ ' => 0, + 'оы' => 0, + 'оы ' => 0, + 'оь' => 0, + 'оь ' => 0, + 'пё ' => 0, + 'пб ' => 0, + 'пв' => 0, + 'пв ' => 0, + 'пг' => 0, + 'пг ' => 0, + 'пд ' => 0, + 'пж' => 0, + 'пж ' => 0, + 'пз' => 0, + 'пз ' => 0, + 'пй' => 0, + 'пй ' => 0, + 'пк ' => 0, + 'пл ' => 0, + 'пм ' => 0, + 'пн ' => 0, + 'пф ' => 0, + 'пх ' => 0, + 'пц ' => 0, + 'пч ' => 0, + 'пш ' => 0, + 'пщ ' => 0, + 'пъ' => 0, + 'пъ ' => 0, + 'пэ' => 0, + 'пэ ' => 0, + 'пю ' => 0, + 'рё ' => 0, + 'рй' => 0, + 'рй ' => 0, + 'ръ' => 0, + 'ръ ' => 0, + 'рэ ' => 0, + 'сб ' => 0, + 'св ' => 0, + 'сг ' => 0, + 'сд ' => 0, + 'сж ' => 0, + 'сз' => 0, + 'сз ' => 0, + 'сй' => 0, + 'сй ' => 0, + 'сн ' => 0, + 'сп ' => 0, + 'сф ' => 0, + 'сц ' => 0, + 'сч ' => 0, + 'сш ' => 0, + 'сщ ' => 0, + 'съ ' => 0, + 'сэ ' => 0, + 'тб ' => 0, + 'тг ' => 0, + 'тд ' => 0, + 'тж ' => 0, + 'тз ' => 0, + 'тй' => 0, + 'тй ' => 0, + 'тк ' => 0, + 'тл ' => 0, + 'тп ' => 0, + 'тф ' => 0, + 'тх ' => 0, + 'тц ' => 0, + 'тш ' => 0, + 'тщ ' => 0, + 'тъ ' => 0, + 'уё ' => 0, + 'уо ' => 0, + 'уу ' => 0, + 'уц ' => 0, + 'уъ' => 0, + 'уъ ' => 0, + 'уы' => 0, + 'уы ' => 0, + 'уь' => 0, + 'уь ' => 0, + 'уэ ' => 0, + 'фё ' => 0, + 'фб ' => 0, + 'фв ' => 0, + 'фг ' => 0, + 'фд ' => 0, + 'фж' => 0, + 'фж ' => 0, + 'фз' => 0, + 'фз ' => 0, + 'фй' => 0, + 'фй ' => 0, + 'фк ' => 0, + 'фл ' => 0, + 'фн ' => 0, + 'фп' => 0, + 'фп ' => 0, + 'фс ' => 0, + 'фх' => 0, + 'фх ' => 0, + 'фц' => 0, + 'фц ' => 0, + 'фч ' => 0, + 'фш ' => 0, + 'фщ ' => 0, + 'фъ' => 0, + 'фъ ' => 0, + 'фэ' => 0, + 'фэ ' => 0, + 'фю ' => 0, + 'хё' => 0, + 'хё ' => 0, + 'хб ' => 0, + 'хг ' => 0, + 'хд ' => 0, + 'хж ' => 0, + 'хз ' => 0, + 'хй' => 0, + 'хй ' => 0, + 'хк ' => 0, + 'хн ' => 0, + 'хп ' => 0, + 'хр ' => 0, + 'хс ' => 0, + 'хф ' => 0, + 'хх ' => 0, + 'хц ' => 0, + 'хч ' => 0, + 'хш ' => 0, + 'хщ' => 0, + 'хщ ' => 0, + 'хъ ' => 0, + 'хы' => 0, + 'хы ' => 0, + 'хь' => 0, + 'хь ' => 0, + 'хэ ' => 0, + 'хю' => 0, + 'хю ' => 0, + 'хя' => 0, + 'хя ' => 0, + 'цё' => 0, + 'цё ' => 0, + 'цб' => 0, + 'цб ' => 0, + 'цв ' => 0, + 'цг ' => 0, + 'цд ' => 0, + 'цж' => 0, + 'цж ' => 0, + 'цз ' => 0, + 'цй' => 0, + 'цй ' => 0, + 'цк ' => 0, + 'цл ' => 0, + 'цм ' => 0, + 'цн ' => 0, + 'цп ' => 0, + 'цр ' => 0, + 'цс ' => 0, + 'цт ' => 0, + 'цф' => 0, + 'цф ' => 0, + 'цх' => 0, + 'цх ' => 0, + 'цц ' => 0, + 'цч' => 0, + 'цч ' => 0, + 'цш ' => 0, + 'цщ' => 0, + 'цщ ' => 0, + 'цъ' => 0, + 'цъ ' => 0, + 'ць' => 0, + 'ць ' => 0, + 'цэ' => 0, + 'цэ ' => 0, + 'цю' => 0, + 'цю ' => 0, + 'ця' => 0, + 'ця ' => 0, + 'чё ' => 0, + 'чб ' => 0, + 'чг' => 0, + 'чг ' => 0, + 'чд' => 0, + 'чд ' => 0, + 'чж ' => 0, + 'чз' => 0, + 'чз ' => 0, + 'чй' => 0, + 'чй ' => 0, + 'чк ' => 0, + 'чл ' => 0, + 'чм ' => 0, + 'чн ' => 0, + 'чп' => 0, + 'чп ' => 0, + 'чр ' => 0, + 'чс ' => 0, + 'чф' => 0, + 'чф ' => 0, + 'чх ' => 0, + 'чц ' => 0, + 'чч ' => 0, + 'чш ' => 0, + 'чщ' => 0, + 'чщ ' => 0, + 'чъ' => 0, + 'чъ ' => 0, + 'чы' => 0, + 'чы ' => 0, + 'чэ' => 0, + 'чэ ' => 0, + 'чю' => 0, + 'чю ' => 0, + 'чя' => 0, + 'чя ' => 0, + 'шё ' => 0, + 'шб ' => 0, + 'шг ' => 0, + 'шд' => 0, + 'шд ' => 0, + 'шж' => 0, + 'шж ' => 0, + 'шз' => 0, + 'шз ' => 0, + 'шй' => 0, + 'шй ' => 0, + 'шк ' => 0, + 'шл ' => 0, + 'шм ' => 0, + 'шн ' => 0, + 'шп ' => 0, + 'шр ' => 0, + 'шс ' => 0, + 'шф ' => 0, + 'шх' => 0, + 'шх ' => 0, + 'шч ' => 0, + 'шш' => 0, + 'шш ' => 0, + 'шщ' => 0, + 'шщ ' => 0, + 'шъ' => 0, + 'шъ ' => 0, + 'шы' => 0, + 'шы ' => 0, + 'шэ' => 0, + 'шэ ' => 0, + 'шя' => 0, + 'шя ' => 0, + 'щб' => 0, + 'щб ' => 0, + 'щв ' => 0, + 'щг' => 0, + 'щг ' => 0, + 'щд' => 0, + 'щд ' => 0, + 'щж' => 0, + 'щж ' => 0, + 'щз' => 0, + 'щз ' => 0, + 'щй' => 0, + 'щй ' => 0, + 'щк' => 0, + 'щк ' => 0, + 'щл' => 0, + 'щл ' => 0, + 'щм ' => 0, + 'щн ' => 0, + 'щп' => 0, + 'щп ' => 0, + 'щр ' => 0, + 'щс' => 0, + 'щс ' => 0, + 'щт' => 0, + 'щт ' => 0, + 'щф' => 0, + 'щф ' => 0, + 'щх' => 0, + 'щх ' => 0, + 'щц' => 0, + 'щц ' => 0, + 'щч' => 0, + 'щч ' => 0, + 'щш' => 0, + 'щш ' => 0, + 'щщ' => 0, + 'щщ ' => 0, + 'щъ' => 0, + 'щъ ' => 0, + 'щы' => 0, + 'щы ' => 0, + 'щэ' => 0, + 'щэ ' => 0, + 'щю' => 0, + 'щю ' => 0, + 'щя' => 0, + 'щя ' => 0, + 'ъё ' => 0, + 'ъа' => 0, + 'ъа ' => 0, + 'ъб' => 0, + 'ъб ' => 0, + 'ъв' => 0, + 'ъв ' => 0, + 'ъг' => 0, + 'ъг ' => 0, + 'ъд' => 0, + 'ъд ' => 0, + 'ъе ' => 0, + 'ъж' => 0, + 'ъж ' => 0, + 'ъз' => 0, + 'ъз ' => 0, + 'ъи' => 0, + 'ъи ' => 0, + 'ъй' => 0, + 'ъй ' => 0, + 'ък' => 0, + 'ък ' => 0, + 'ъл' => 0, + 'ъл ' => 0, + 'ъм' => 0, + 'ъм ' => 0, + 'ън' => 0, + 'ън ' => 0, + 'ъо' => 0, + 'ъо ' => 0, + 'ъп' => 0, + 'ъп ' => 0, + 'ър' => 0, + 'ър ' => 0, + 'ъс' => 0, + 'ъс ' => 0, + 'ът' => 0, + 'ът ' => 0, + 'ъу' => 0, + 'ъу ' => 0, + 'ъф' => 0, + 'ъф ' => 0, + 'ъх' => 0, + 'ъх ' => 0, + 'ъц' => 0, + 'ъц ' => 0, + 'ъч' => 0, + 'ъч ' => 0, + 'ъш' => 0, + 'ъш ' => 0, + 'ъщ' => 0, + 'ъщ ' => 0, + 'ъъ' => 0, + 'ъъ ' => 0, + 'ъы' => 0, + 'ъы ' => 0, + 'ъь' => 0, + 'ъь ' => 0, + 'ъэ' => 0, + 'ъэ ' => 0, + 'ъю ' => 0, + 'ъя ' => 0, + 'ыё' => 0, + 'ыё ' => 0, + 'ыа' => 0, + 'ыа ' => 0, + 'ыи ' => 0, + 'ыо ' => 0, + 'ыу ' => 0, + 'ыф ' => 0, + 'ыъ' => 0, + 'ыъ ' => 0, + 'ыы' => 0, + 'ыы ' => 0, + 'ыь' => 0, + 'ыь ' => 0, + 'ыэ' => 0, + 'ыэ ' => 0, + 'ыю ' => 0, + 'ьа' => 0, + 'ьа ' => 0, + 'ьв ' => 0, + 'ьг ' => 0, + 'ьж ' => 0, + 'ьз ' => 0, + 'ьй' => 0, + 'ьй ' => 0, + 'ьл ' => 0, + 'ьн ' => 0, + 'ьр ' => 0, + 'ьу' => 0, + 'ьу ' => 0, + 'ьх ' => 0, + 'ьщ ' => 0, + 'ьъ' => 0, + 'ьъ ' => 0, + 'ьы ' => 0, + 'ьь' => 0, + 'ьь ' => 0, + 'ьэ ' => 0, + 'эё' => 0, + 'эё ' => 0, + 'эа' => 0, + 'эа ' => 0, + 'эб' => 0, + 'эб ' => 0, + 'эв ' => 0, + 'эг ' => 0, + 'эд ' => 0, + 'эе' => 0, + 'эе ' => 0, + 'эж' => 0, + 'эж ' => 0, + 'эз ' => 0, + 'эи ' => 0, + 'эй ' => 0, + 'эл ' => 0, + 'эм ' => 0, + 'эн ' => 0, + 'эо' => 0, + 'эо ' => 0, + 'эу' => 0, + 'эу ' => 0, + 'эф ' => 0, + 'эх ' => 0, + 'эц' => 0, + 'эц ' => 0, + 'эч' => 0, + 'эч ' => 0, + 'эш ' => 0, + 'эщ' => 0, + 'эщ ' => 0, + 'эъ' => 0, + 'эъ ' => 0, + 'эы' => 0, + 'эы ' => 0, + 'эь' => 0, + 'эь ' => 0, + 'ээ ' => 0, + 'эю' => 0, + 'эю ' => 0, + 'эя' => 0, + 'эя ' => 0, + 'юё' => 0, + 'юё ' => 0, + 'юа ' => 0, + 'юе ' => 0, + 'юж ' => 0, + 'юи ' => 0, + 'юл ' => 0, + 'юо ' => 0, + 'юу' => 0, + 'юу ' => 0, + 'юц ' => 0, + 'юъ' => 0, + 'юъ ' => 0, + 'юы' => 0, + 'юы ' => 0, + 'юь' => 0, + 'юь ' => 0, + 'юэ ' => 0, + 'юя' => 0, + 'яё' => 0, + 'яё ' => 0, + 'яа' => 0, + 'яа ' => 0, + 'яе ' => 0, + 'яо ' => 0, + 'яф' => 0, + 'яф ' => 0, + 'яъ' => 0, + 'яъ ' => 0, + 'яы' => 0, + 'яы ' => 0, + 'яь' => 0, + 'яь ' => 0, + 'яэ' => 0, + 'яэ ' => 0, + #en + ' \'f' => 0, + ' \'p' => 0, + ' \'q' => 0, + ' \'r' => 0, + ' \'x' => 0, + ' \'y' => 0, + ' \'z' => 0, + ' bj' => 0, + ' bq' => 0, + ' bz' => 0, + ' c\'' => 0, + ' cq' => 0, + ' cv' => 0, + ' cx' => 0, + ' dq' => 0, + ' dx' => 0, + ' ez' => 0, + ' f\'' => 0, + ' fh' => 0, + ' fk' => 0, + ' fq' => 0, + ' fv' => 0, + ' fw' => 0, + ' fz' => 0, + ' g\'' => 0, + ' gf' => 0, + ' gg' => 0, + ' gj' => 0, + ' gv' => 0, + ' gx' => 0, + ' gz' => 0, + ' h\'' => 0, + ' hj' => 0, + ' hk' => 0, + ' hn' => 0, + ' hq' => 0, + ' hx' => 0, + ' iq' => 0, + ' iw' => 0, + ' iy' => 0, + ' jb' => 0, + ' jf' => 0, + ' jh' => 0, + ' jj' => 0, + ' jk' => 0, + ' jl' => 0, + ' jm' => 0, + ' jq' => 0, + ' jw' => 0, + ' jx' => 0, + ' jy' => 0, + ' jz' => 0, + ' k\'' => 0, + ' kf' => 0, + ' kj' => 0, + ' kq' => 0, + ' kt' => 0, + ' kx' => 0, + ' kz' => 0, + ' lj' => 0, + ' lk' => 0, + ' lq' => 0, + ' lv' => 0, + ' mj' => 0, + ' mq' => 0, + ' mz' => 0, + ' nj' => 0, + ' nk' => 0, + ' nq' => 0, + ' nz' => 0, + ' oq' => 0, + ' pj' => 0, + ' pz' => 0, + ' qb' => 0, + ' qe' => 0, + ' qf' => 0, + ' qg' => 0, + ' qh' => 0, + ' qj' => 0, + ' qk' => 0, + ' qo' => 0, + ' qp' => 0, + ' qs' => 0, + ' qv' => 0, + ' qx' => 0, + ' qy' => 0, + ' qz' => 0, + ' rb' => 0, + ' rk' => 0, + ' rq' => 0, + ' rv' => 0, + ' rx' => 0, + ' rz' => 0, + ' sz' => 0, + ' tf' => 0, + ' tg' => 0, + ' tj' => 0, + ' tq' => 0, + ' u\'' => 0, + ' ue' => 0, + ' uj' => 0, + ' uo' => 0, + ' uq' => 0, + ' uu' => 0, + ' uy' => 0, + ' vb' => 0, + ' vj' => 0, + ' vk' => 0, + ' vn' => 0, + ' vq' => 0, + ' vr' => 0, + ' vv' => 0, + ' vw' => 0, + ' vx' => 0, + ' vy' => 0, + ' vz' => 0, + ' wj' => 0, + ' wl' => 0, + ' wn' => 0, + ' wq' => 0, + ' wx' => 0, + ' wz' => 0, + ' xb' => 0, + ' xf' => 0, + ' xg' => 0, + ' xh' => 0, + ' xj' => 0, + ' xk' => 0, + ' xq' => 0, + ' xt' => 0, + ' xu' => 0, + ' xz' => 0, + ' yf' => 0, + ' yg' => 0, + ' yh' => 0, + ' yj' => 0, + ' yk' => 0, + ' yl' => 0, + ' yn' => 0, + ' yq' => 0, + ' yv' => 0, + ' yx' => 0, + ' yy' => 0, + ' yz' => 0, + ' z\'' => 0, + ' zb' => 0, + ' zc' => 0, + ' zd' => 0, + ' zf' => 0, + ' zg' => 0, + ' zh' => 0, + ' zj' => 0, + ' zk' => 0, + ' zl' => 0, + ' zm' => 0, + ' zq' => 0, + ' zr' => 0, + ' zv' => 0, + ' zw' => 0, + ' zx' => 0, + ' zz' => 0, + '\'a ' => 0, + '\'b' => 0, + '\'b ' => 0, + '\'c ' => 0, + '\'f' => 0, + '\'f ' => 0, + '\'g' => 0, + '\'g ' => 0, + '\'h ' => 0, + '\'i ' => 0, + '\'j' => 0, + '\'j ' => 0, + '\'k' => 0, + '\'k ' => 0, + '\'l ' => 0, + '\'n ' => 0, + '\'o ' => 0, + '\'p ' => 0, + '\'q' => 0, + '\'q ' => 0, + '\'r ' => 0, + '\'u' => 0, + '\'u ' => 0, + '\'v ' => 0, + '\'w ' => 0, + '\'x' => 0, + '\'x ' => 0, + '\'z' => 0, + '\'z ' => 0, + 'b\' ' => 0, + 'bg ' => 0, + 'bh ' => 0, + 'bp ' => 0, + 'bq' => 0, + 'bq ' => 0, + 'bv ' => 0, + 'bx' => 0, + 'bz' => 0, + 'bz ' => 0, + 'c\' ' => 0, + 'cf ' => 0, + 'cj' => 0, + 'cn ' => 0, + 'cq ' => 0, + 'cv' => 0, + 'cw' => 0, + 'cx' => 0, + 'cx ' => 0, + 'cz ' => 0, + 'db ' => 0, + 'dj ' => 0, + 'dk ' => 0, + 'dw ' => 0, + 'dx' => 0, + 'eh ' => 0, + 'ej ' => 0, + 'f\' ' => 0, + 'fg ' => 0, + 'fh ' => 0, + 'fj' => 0, + 'fj ' => 0, + 'fk' => 0, + 'fk ' => 0, + 'fq' => 0, + 'fq ' => 0, + 'fv ' => 0, + 'fw ' => 0, + 'fx' => 0, + 'fx ' => 0, + 'fz' => 0, + 'fz ' => 0, + 'g\' ' => 0, + 'gc ' => 0, + 'gf ' => 0, + 'gj ' => 0, + 'gk ' => 0, + 'gl ' => 0, + 'gq' => 0, + 'gq ' => 0, + 'gv' => 0, + 'gv ' => 0, + 'gw ' => 0, + 'gx' => 0, + 'gx ' => 0, + 'gz ' => 0, + 'hb ' => 0, + 'hc ' => 0, + 'hg ' => 0, + 'hh ' => 0, + 'hj' => 0, + 'hj ' => 0, + 'hk ' => 0, + 'hv' => 0, + 'hv ' => 0, + 'hw ' => 0, + 'hx' => 0, + 'hx ' => 0, + 'hz' => 0, + 'i\' ' => 0, + 'ih ' => 0, + 'iq ' => 0, + 'iw ' => 0, + 'j\'' => 0, + 'j\' ' => 0, + 'jb' => 0, + 'jb ' => 0, + 'jc' => 0, + 'jc ' => 0, + 'jd' => 0, + 'jf' => 0, + 'jg' => 0, + 'jg ' => 0, + 'jh' => 0, + 'jh ' => 0, + 'jj' => 0, + 'jj ' => 0, + 'jk ' => 0, + 'jl ' => 0, + 'jm' => 0, + 'jm ' => 0, + 'jn' => 0, + 'jn ' => 0, + 'jp ' => 0, + 'jq' => 0, + 'jq ' => 0, + 'jr' => 0, + 'jr ' => 0, + 'js' => 0, + 'js ' => 0, + 'jt' => 0, + 'ju ' => 0, + 'jv' => 0, + 'jv ' => 0, + 'jw' => 0, + 'jw ' => 0, + 'jx' => 0, + 'jx ' => 0, + 'jy' => 0, + 'jy ' => 0, + 'jz' => 0, + 'jz ' => 0, + 'kb ' => 0, + 'kc ' => 0, + 'kd ' => 0, + 'kj ' => 0, + 'km ' => 0, + 'kp ' => 0, + 'kq' => 0, + 'kq ' => 0, + 'kv' => 0, + 'kv ' => 0, + 'kx' => 0, + 'kx ' => 0, + 'kz' => 0, + 'kz ' => 0, + 'lg ' => 0, + 'lh ' => 0, + 'lj ' => 0, + 'lq ' => 0, + 'lr ' => 0, + 'lv ' => 0, + 'lw ' => 0, + 'lx' => 0, + 'lz ' => 0, + 'm\' ' => 0, + 'mg ' => 0, + 'mh ' => 0, + 'mj ' => 0, + 'mk ' => 0, + 'mq' => 0, + 'mq ' => 0, + 'mx' => 0, + 'mx ' => 0, + 'mz' => 0, + 'nb ' => 0, + 'nm ' => 0, + 'pj ' => 0, + 'pk ' => 0, + 'pq' => 0, + 'pq ' => 0, + 'pv' => 0, + 'pw ' => 0, + 'px' => 0, + 'px ' => 0, + 'pz ' => 0, + 'q\'' => 0, + 'q\' ' => 0, + 'qa ' => 0, + 'qb' => 0, + 'qb ' => 0, + 'qc' => 0, + 'qc ' => 0, + 'qd' => 0, + 'qd ' => 0, + 'qe' => 0, + 'qe ' => 0, + 'qf' => 0, + 'qf ' => 0, + 'qg' => 0, + 'qg ' => 0, + 'qh' => 0, + 'qh ' => 0, + 'qi' => 0, + 'qj' => 0, + 'qj ' => 0, + 'qk' => 0, + 'qk ' => 0, + 'ql' => 0, + 'ql ' => 0, + 'qm' => 0, + 'qm ' => 0, + 'qn' => 0, + 'qn ' => 0, + 'qo' => 0, + 'qo ' => 0, + 'qp' => 0, + 'qp ' => 0, + 'qq' => 0, + 'qq ' => 0, + 'qr' => 0, + 'qs' => 0, + 'qs ' => 0, + 'qt' => 0, + 'qt ' => 0, + 'qu ' => 0, + 'qv' => 0, + 'qv ' => 0, + 'qw' => 0, + 'qw ' => 0, + 'qx' => 0, + 'qx ' => 0, + 'qy' => 0, + 'qy ' => 0, + 'qz' => 0, + 'qz ' => 0, + 'rq ' => 0, + 'rz ' => 0, + 'sg ' => 0, + 'sj ' => 0, + 'sx' => 0, + 'sx ' => 0, + 'sz' => 0, + 'sz ' => 0, + 'tg ' => 0, + 'tj ' => 0, + 'tq' => 0, + 'tq ' => 0, + 'tx' => 0, + 'tx ' => 0, + 'uj ' => 0, + 'uq ' => 0, + 'uu ' => 0, + 'uw ' => 0, + 'v\' ' => 0, + 'vb' => 0, + 'vb ' => 0, + 'vc' => 0, + 'vf' => 0, + 'vf ' => 0, + 'vg' => 0, + 'vh' => 0, + 'vh ' => 0, + 'vj' => 0, + 'vj ' => 0, + 'vk' => 0, + 'vk ' => 0, + 'vl ' => 0, + 'vm' => 0, + 'vn ' => 0, + 'vp' => 0, + 'vp ' => 0, + 'vq' => 0, + 'vq ' => 0, + 'vr ' => 0, + 'vv ' => 0, + 'vw' => 0, + 'vw ' => 0, + 'vx' => 0, + 'vz' => 0, + 'vz ' => 0, + 'w\' ' => 0, + 'wb ' => 0, + 'wc ' => 0, + 'wf ' => 0, + 'wg ' => 0, + 'wj' => 0, + 'wj ' => 0, + 'wq' => 0, + 'wq ' => 0, + 'wr ' => 0, + 'wv' => 0, + 'wv ' => 0, + 'wx' => 0, + 'wz ' => 0, + 'x\'' => 0, + 'x\' ' => 0, + 'xa ' => 0, + 'xb ' => 0, + 'xc ' => 0, + 'xd' => 0, + 'xd ' => 0, + 'xf ' => 0, + 'xg ' => 0, + 'xh ' => 0, + 'xj' => 0, + 'xj ' => 0, + 'xk' => 0, + 'xk ' => 0, + 'xl ' => 0, + 'xm ' => 0, + 'xn' => 0, + 'xn ' => 0, + 'xp ' => 0, + 'xq ' => 0, + 'xr' => 0, + 'xr ' => 0, + 'xs ' => 0, + 'xu ' => 0, + 'xv' => 0, + 'xv ' => 0, + 'xw ' => 0, + 'xx' => 0, + 'xz' => 0, + 'xz ' => 0, + 'yb ' => 0, + 'yc ' => 0, + 'yd ' => 0, + 'yf ' => 0, + 'yg ' => 0, + 'yh ' => 0, + 'yj ' => 0, + 'yq' => 0, + 'yq ' => 0, + 'yu ' => 0, + 'yv ' => 0, + 'yw ' => 0, + 'yy' => 0, + 'yy ' => 0, + 'yz ' => 0, + 'z\'' => 0, + 'z\' ' => 0, + 'zb ' => 0, + 'zc' => 0, + 'zc ' => 0, + 'zd' => 0, + 'zd ' => 0, + 'zf' => 0, + 'zf ' => 0, + 'zg ' => 0, + 'zh' => 0, + 'zh ' => 0, + 'zj' => 0, + 'zj ' => 0, + 'zk ' => 0, + 'zl ' => 0, + 'zn' => 0, + 'zn ' => 0, + 'zp ' => 0, + 'zq' => 0, + 'zq ' => 0, + 'zr' => 0, + 'zr ' => 0, + 'zs' => 0, + 'zs ' => 0, + 'zt' => 0, + 'zt ' => 0, + 'zu ' => 0, + 'zv ' => 0, + 'zw ' => 0, + 'zx' => 0, + 'zx ' => 0, + ); + + /** + * + * @param array|null $words_exceptions + */ + public function __construct(array $words_exceptions = null) + { + if (! ReflectionTypeHint::isValid()) return false; + #русский --> английский: + $this->en_correct = '/(?: (?:' . $this->tt_f . ') + (?: (?:' . $this->en_uniq . ') | (?:' . $this->en_sc . '){2} ) + | (?:' . $this->en_sc . ') + (?:' . $this->tt_f . ') + (?:' . $this->en_sc . ') + | (?: (?:' . $this->en_uniq . ') | (?:' . $this->en_sc . '){2} ) + (?:' . $this->tt_f . ') + ) + /sxSX'; + #английский --> русский: + $this->tt_correct = '/(?: (?:' . $this->en_sc . ') + (?: (?:' . $this->tt_uniq . ') | (?:' . $this->tt_f . '){2} ) + | (?:' . $this->tt_f . ') + (?:' . $this->en_sc . ') + (?:' . $this->tt_f . ') + | (?: (?:' . $this->tt_uniq . ') | (?:' . $this->tt_f . '){2} ) + (?:' . $this->en_sc . ') + ) + /sxSX'; + $this->table_flip = array( + 0 => array_flip($this->table[0]), + 1 => array_flip($this->table[1]), + ); + if (is_array($words_exceptions)) $this->words_exceptions += $words_exceptions; + } + + /** + * Исправляет клавиатурные опечатки в тексте. + * + * @param scalar|null $s Текст в кодировке UTF-8. + * @param int $mode Константы self::SIMILAR_CHARS и/или self::KEYBOARD_LAYOUT, + * (их можно комбинировать). Описание констант см. выше. + * При использовании self::KEYBOARD_LAYOUT время работы увеличивается примерно в 10 раз. + * @param array &$words Ассоц. массив со словами, которые были исправлены: + * в ключах оригиналы, в значениях исправленные слова. + * @return string|bool Returns FALSE if error occured + */ + public function parse($s, $mode = self::SIMILAR_CHARS, array &$words = null) + { + if (! ReflectionTypeHint::isValid()) return false; + if (! is_string($s)) return $s; + + if ($mode < self::SIMILAR_CHARS || $mode > (self::SIMILAR_CHARS | self::KEYBOARD_LAYOUT | self::ADD_FIX)) + { + trigger_error('Unknown mode', E_USER_WARNING); + return false; + } + + $this->mode = $mode; + + #вырезаем и заменяем некоторые символы + $additional_chars = array( + "\xc2\xad", #"мягкие" переносы строк (­) + ); + #http://ru.wikipedia.org/wiki/Диакритические_знаки + $s = UTF8::diactrical_remove($s, $additional_chars, $is_can_restored = true, $restore_table); + + $this->words = array(); + $s = $this->_parse1($s); + $s = $this->_parse2($s); + $s = UTF8::diactrical_restore($s, $restore_table); + $words = $this->words; + return $s; + } + + private function _parse1($s) + { + #заменяем слова из текста, минимальная длина -- 3 символа, меньше нельзя + return preg_replace_callback('/(?> (' . $this->en . ') #1 латинские буквы + | (' . $this->tt . ') #2 русские буквы + | (' . $this->sc . ') #3 символы, которые м.б. набраны по ошибке в английской раскладке клавиатуры вместо русских букв + ){3,}+ + /sxSX', array($this, '_word'), $s); + } + + private function _parse2($s) + { + #исправляем русские буквы (похожие на латинские) с рядом стоящими цифрами на латинские + #например, это м. б. каталожные номера автозапчастей, в которых есть русские буквы: 1500A023, 52511-60900-H0, K2305, XA527672 + #корректно обрабатываем вхождения '1-ое', 'Ту-134', 'А19-3107/06-43-Ф02-4227/06-С1' + if (version_compare(PHP_VERSION, '5.2.0', '<')) return $s; + return preg_replace_callback('~(?: (?<=[^-_/]|^) + (?:' . $this->ru_similar . ')++ + (?= (?:' . $this->en . '|[-_/])*+ (?<=[^-_/]|' . $this->en . '[-_/]) + \d [\d-_/]*+ (?!' . $this->tt_uniq . ') + ) + | (?<=[^-_/]|^) + \d (?:' . $this->en . '|[-_/])*+ (?<=[^-_/]|' . $this->en . '[-_/]) + \K + (?:' . $this->ru_similar . ')++ + (?= [\d-_/]*+ (?!' . $this->tt_uniq . ') ) + ) + ~sxSX', array($this, '_entry'), $s); + } + + private function _entry(array &$a) + { + $entry =& $a[0]; + $s = strtr($entry, $this->table[0]); + if ($s !== $entry) $this->words[$entry] = $s; + return $s; + } + + private function _word(array &$a) + { + $word = $a[0]; + #var_export($a); + + $suggestions = array(); + + #если найдено слово из мешанины русских и латинских букв + if (! empty($a[1]) && ! empty($a[2])) + { + if (($this->mode & self::SIMILAR_CHARS) === 0) return $word; + #ВНИМАНИЕ! порядок следования правил преобразования имеет значение! + + /* + Исправляем ошибочно набранные буквы, которые выглядят одинаково + в инициалах перед фамилиями (русский <--> английский), например: Т.С.Навка + */ + + #0a. английский --> русский: + if (substr($word, 1, 1) === '.' #оптимизация + && preg_match('/^ ( ' . $this->en_similar_uc . '\. #первый инициал + (?:' . $this->en_similar_uc . '\.)? #второй инициал (необязательно) + ) #1 инициалы + (' . $this->no_sc . '{2,}+) #2 фамилия (английские и русские буквы) + $/sxSX', $word, $m)) + { + $m[2] = $this->_parse1($m[2]); + #фамилия по-русски? + if (preg_match('/^ (?:' . $this->tt_uc . ') #первая буква д.б. большая + (?:' . $this->tt_f . ')+ #минимальное кол-во букв в фамилии = 2 + $/sxSX', $m[2])) return strtr($m[1], $this->table_flip[0]) . $m[2]; + } + + #0b. русский --> английский: + if (substr($word, 2, 1) === '.' #оптимизация + && preg_match('/^ ( ' . $this->ru_similar_uc . '\. #первый инициал + (?:' . $this->ru_similar_uc . '\.)? #второй инициал (необязательно) + ) #1 инициалы + (' . $this->no_sc . '{2,}+) #2 фамилия (английские и русские буквы) + $/sxSX', $word, $m)) + { + $m[2] = $this->_parse1($m[2]); + #фамилия по-англ.? + if (preg_match('/^ ' . $this->en_uc . ' #первая буква д.б. большая + ' . $this->en . '++ #минимальное кол-во букв в фамилии = 2 + $/sxSX', $m[2])) return strtr($m[1], $this->table[0]) . $m[2]; + } + + #1. английский --> русский: + $this->method = 0; #буквы, которые выглядят одинаково + $this->is_flip = true; + $s = $this->_replace($word, $this->tt_correct); + if ($word !== $s && ! $this->_is_mixed($s)) $suggestions['tt0'] = $s; + + #2. английский --> русский: + $this->method = 1; #буквы в другой раскладке клавиатуры + $this->is_flip = true; + $s = $this->_replace($word, $this->tt_correct); + if ($word !== $s) $suggestions['tt1'] = $s; + + #3. русский --> английский: + $this->method = 0; #буквы, которые выглядят одинаково + $this->is_flip = false; + $s = $this->_replace($word, $this->en_correct); + if ($word !== $s && ! $this->_is_mixed($s)) $suggestions['en0'] = $s; + + #4. русский --> английский: + $this->method = 1; #буквы в другой раскладке клавиатуры + $this->is_flip = false; + $s = $this->_replace($word, $this->en_correct); + if ($word !== $s) $suggestions['en1'] = $s; + + } + #если найдено слово только из латинских букв; минимальная длина -- 4 буквы! + elseif (! empty($a[1]) && strlen($word) >= 4) + { + if (($this->mode & self::KEYBOARD_LAYOUT) === 0) return $word; + + #не обрабатываем аббревиатуры, пример: AMPAS + if (preg_match('/^(?:' . $this->en_uc . '|' . $this->sc . '){1,6}+$/sxSX', $word)) return $word; + + #английский --> русский: + $suggestions['en1'] = $word; + $suggestions['tt1'] = strtr($word, $this->table_flip[1]); + } + #если найдено слово только из русских букв; минимальная длина -- 4 буквы! + elseif (! empty($a[2]) && strlen($word) >= 8) + { + if (($this->mode & self::KEYBOARD_LAYOUT) === 0) return $word; + + #не обрабатываем аббревиатуры, пример: ДОСААФ + if (preg_match('/^(?:' . $this->tt_uc . '|' . $this->sc . '){1,6}+$/sxSX', $word)) return $word; + + #русский --> английский: + $suggestions['tt1'] = $word; + $suggestions['en1'] = strtr($word, $this->table[1]); + } + #найдены спецсимволы или длина слова слишком мала + else return $word; + + $suggestions = array_unique($suggestions); + #var_export($suggestions); + + $c = count($suggestions); + if ($c === 0) $s = $word; + else $s = $this->_detect($word, $suggestions, ! empty($a[3])); + if ($s !== $word) + { + $this->words[$word] = $s; + if ($this->mode >= (self::KEYBOARD_LAYOUT | self::ADD_FIX)) $s = '(' . $word . '=>' . $s . ')'; + } + return $s; + } + + private function _replace($word, $regexp) + { + do $word = preg_replace_callback($regexp, array(&$this, '_strtr'), $w = $word); + while ($w !== $word); + return $word; + } + + private function _strtr(array $a) + { + $word =& $a[0]; + return strtr($word, $this->is_flip ? $this->table_flip[$this->method] : $this->table[$this->method]); + } + + private function _is_mixed($word) + { + return preg_match('/(?:' . $this->en . ')/sxSX', $word) && + preg_match('/(?:' . $this->tt_f . ')/sxSX', $word); + } + + #выбираем из нескольких вариантов один + private function _detect($word, array $suggestions, $is_sc) + { + if (0) #DEBUG + { + //$suggestions['?'] = $word; + var_export($suggestions); + } + #не д. б. несуществующих N-грамм + foreach ($suggestions as $type => $w) + { + $lang = substr($type, 0, 2); + if ($this->_bigram_exists($w, $lang)) unset($suggestions[$type]); + } + if (0) #DEBUG + { + //$suggestions['?'] = $word; + var_export($suggestions); + } + if (count($suggestions) === 0) return $word; + + $s = end($suggestions); + + #если в $word были спецсимволы, а в $s их уже нет, возвращаем $s + if ($is_sc && ! preg_match('/' . $this->sc . '/sSX', $s)) return $s; + + #если в $s спецсимволов больше чем букв, возвращаем $word + $sc_count = 0; + $s = preg_replace('/' . $this->sc . '/sSX', '', $s, -1, $sc_count); + if ($sc_count > 0 && $sc_count > UTF8::strlen($s)) return $word; + + return reset($suggestions); + } + + #анализ на основе N-грамм русского и английского языка + private function _bigram_exists($word, $lang) + { + $word = ($lang === 'en') ? strtolower($word) : UTF8::lowercase($word); + + #шаг 0. + #проверяем слова в списке слов-исключений + if (array_key_exists($word, $this->words_exceptions[$lang])) return false; + + #шаг 1. + #проверка на 4 согласные буквы подряд; пример: больши{нств}о, юрисконсу{льтс}тво + if (preg_match('/(?:' . $this->consonant_lc[$lang] . '){4}/sxSX', $word, $m) + #проверяем список исключений + && ! array_key_exists($m[0], $this->consonants4_lc[$lang])) return true; + + #шаг 2. + #проверка на 3 гласные буквы подряд; пример: длиннош{еее}, зм{еео}бразный + if (preg_match('/(?:' . $this->vowel_lc[$lang] . '){3}/sxSX', $word, $m) + #проверяем список исключений + && ! array_key_exists($m[0], $this->vowels3_lc[$lang])) return true; + + #шаг 3. + $length = UTF8::strlen($word); + for ($pos = 0, $limit = $length - 1; $pos < $limit; $pos++) + { + /* + TODO Качество проверки по несуществующим биграммам можно немного повысить, + если учитывать не только начало и конец слова, но и все позиции биграмм в слове. + */ + $ss = UTF8::substr($word, $pos, 2); + if ($pos === 0) $ss = ' ' . $ss; #beginning of word + elseif ($pos === $limit - 1) $ss = $ss . ' '; #ending of word + if (array_key_exists($ss, $this->bigrams)) return true; + } + + return false; + } } \ No newline at end of file diff --git a/upload/includes/class.reflection.php b/upload/includes/class.reflection.php index 653314da5..49b113a7c 100644 --- a/upload/includes/class.reflection.php +++ b/upload/includes/class.reflection.php @@ -1,183 +1,183 @@ - 'is_int', - 'integer' => 'is_int', - 'digit' => 'ctype_digit', - 'number' => 'ctype_digit', - 'float' => 'is_float', - 'double' => 'is_float', - 'real' => 'is_float', - 'numeric' => 'is_numeric', - 'str' => 'is_string', - 'string' => 'is_string', - 'char' => 'is_string', - 'bool' => 'is_bool', - 'boolean' => 'is_bool', - 'null' => 'is_null', - 'array' => 'is_array', - 'obj' => 'is_object', - 'object' => 'is_object', - 'res' => 'is_resource', - 'resource' => 'is_resource', - 'scalar' => 'is_scalar', #integer, float, string or boolean - 'cb' => 'is_callable', - 'callback' => 'is_callable', - ); - - #calling the methods of this class only statically! - private function __construct() {} - - public static function isValid() - { - if (! assert_options(ASSERT_ACTIVE)) return true; - $bt = self::debugBacktrace(null, 1); - extract($bt); //to $file, $line, $function, $class, $object, $type, $args - if (! $args) return true; #speed improve - $r = new ReflectionMethod($class, $function); - $doc = $r->getDocComment(); - $cache_id = $class. $type. $function; - preg_match_all('~ [\r\n]++ [\x20\t]++ \* [\x20\t]++ - @param - [\x20\t]++ - \K #memory reduce - ( [_a-z]++[_a-z\d]*+ - (?>[|/,][_a-z]+[_a-z\d]*)*+ - ) #1 types - [\x20\t]++ - &?+\$([_a-z]++[_a-z\d]*+) #2 name - ~sixSX', $doc, $params, PREG_SET_ORDER); - $parameters = $r->getParameters(); - //d($args, $params, $parameters); - if (count($parameters) > count($params)) - { - $message = 'phpDoc %d piece(s) @param description expected in %s%s%s(), %s given, ' . PHP_EOL - . 'called in %s on line %d ' . PHP_EOL - . 'and defined in %s on line %d'; - $message = sprintf($message, count($parameters), $class, $type, $function, count($params), $file, $line, $r->getFileName(), $r->getStartLine()); - trigger_error($message, E_USER_NOTICE); - } - foreach ($args as $i => $value) - { - if (! isset($params[$i])) return true; - if ($parameters[$i]->name !== $params[$i][2]) - { - $param_num = $i + 1; - $message = 'phpDoc @param %d in %s%s%s() must be named as $%s, $%s given, ' . PHP_EOL - . 'called in %s on line %d ' . PHP_EOL - . 'and defined in %s on line %d'; - $message = sprintf($message, $param_num, $class, $type, $function, $parameters[$i]->name, $params[$i][2], $file, $line, $r->getFileName(), $r->getStartLine()); - trigger_error($message, E_USER_NOTICE); - } - - $hints = preg_split('~[|/,]~sSX', $params[$i][1]); - if (! self::checkValueTypes($hints, $value)) - { - $param_num = $i + 1; - $message = 'Argument %d passed to %s%s%s() must be an %s, %s given, ' . PHP_EOL - . 'called in %s on line %d ' . PHP_EOL - . 'and defined in %s on line %d'; - $message = sprintf($message, $param_num, $class, $type, $function, implode('|', $hints), (is_object($value) ? get_class($value) . ' ' : '') . gettype($value), $file, $line, $r->getFileName(), $r->getStartLine()); - trigger_error($message, E_USER_WARNING); - return false; - } - } - return true; - } - - /** - * Return stacktrace. Correctly work with call_user_func*() - * (totally skip them correcting caller references). - * If $return_frame is present, return only $return_frame matched caller, not all stacktrace. - * - * @param string|null $re_ignore example: '~^' . preg_quote(__CLASS__, '~') . '(?![a-zA-Z\d])~sSX' - * @param int|null $return_frame - * @return array - */ - public static function debugBacktrace($re_ignore = null, $return_frame = null) - { - $trace = debug_backtrace(); - - $a = array(); - $frames = 0; - for ($i = 0, $n = count($trace); $i < $n; $i++) - { - $t = $trace[$i]; - if (! $t) continue; - - // Next frame. - $next = isset($trace[$i+1])? $trace[$i+1] : null; - - // Dummy frame before call_user_func*() frames. - if (! isset($t['file']) && $next) - { - $t['over_function'] = $trace[$i+1]['function']; - $t = $t + $trace[$i+1]; - $trace[$i+1] = null; // skip call_user_func on next iteration - } - - // Skip myself frame. - if (++$frames < 2) continue; - - // 'class' and 'function' field of next frame define where this frame function situated. - // Skip frames for functions situated in ignored places. - if ($re_ignore && $next) - { - // Name of function "inside which" frame was generated. - $frame_caller = (isset($next['class']) ? $next['class'] . $next['type'] : '') - . (isset($next['function']) ? $next['function'] : ''); - if (preg_match($re_ignore, $frame_caller)) continue; - } - - // On each iteration we consider ability to add PREVIOUS frame to $a stack. - if (count($a) === $return_frame) return $t; - $a[] = $t; - } - return $a; - } - - /** - * Checks a value to the allowed types - * - * @param array $types - * @param mixed $value - * @return bool - */ - public static function checkValueTypes(array $types, $value) - { - foreach ($types as $type) - { - $type = strtolower($type); - if (array_key_exists($type, self::$hints) && call_user_func(self::$hints[$type], $value)) return true; - if (is_object($value) && @is_a($value, $type)) return true; - if ($type === 'mixed') return true; - } - return false; - } + 'is_int', + 'integer' => 'is_int', + 'digit' => 'ctype_digit', + 'number' => 'ctype_digit', + 'float' => 'is_float', + 'double' => 'is_float', + 'real' => 'is_float', + 'numeric' => 'is_numeric', + 'str' => 'is_string', + 'string' => 'is_string', + 'char' => 'is_string', + 'bool' => 'is_bool', + 'boolean' => 'is_bool', + 'null' => 'is_null', + 'array' => 'is_array', + 'obj' => 'is_object', + 'object' => 'is_object', + 'res' => 'is_resource', + 'resource' => 'is_resource', + 'scalar' => 'is_scalar', #integer, float, string or boolean + 'cb' => 'is_callable', + 'callback' => 'is_callable', + ); + + #calling the methods of this class only statically! + private function __construct() {} + + public static function isValid() + { + if (! assert_options(ASSERT_ACTIVE)) return true; + $bt = self::debugBacktrace(null, 1); + extract($bt); //to $file, $line, $function, $class, $object, $type, $args + if (! $args) return true; #speed improve + $r = new ReflectionMethod($class, $function); + $doc = $r->getDocComment(); + $cache_id = $class. $type. $function; + preg_match_all('~ [\r\n]++ [\x20\t]++ \* [\x20\t]++ + @param + [\x20\t]++ + \K #memory reduce + ( [_a-z]++[_a-z\d]*+ + (?>[|/,][_a-z]+[_a-z\d]*)*+ + ) #1 types + [\x20\t]++ + &?+\$([_a-z]++[_a-z\d]*+) #2 name + ~sixSX', $doc, $params, PREG_SET_ORDER); + $parameters = $r->getParameters(); + //d($args, $params, $parameters); + if (count($parameters) > count($params)) + { + $message = 'phpDoc %d piece(s) @param description expected in %s%s%s(), %s given, ' . PHP_EOL + . 'called in %s on line %d ' . PHP_EOL + . 'and defined in %s on line %d'; + $message = sprintf($message, count($parameters), $class, $type, $function, count($params), $file, $line, $r->getFileName(), $r->getStartLine()); + trigger_error($message, E_USER_NOTICE); + } + foreach ($args as $i => $value) + { + if (! isset($params[$i])) return true; + if ($parameters[$i]->name !== $params[$i][2]) + { + $param_num = $i + 1; + $message = 'phpDoc @param %d in %s%s%s() must be named as $%s, $%s given, ' . PHP_EOL + . 'called in %s on line %d ' . PHP_EOL + . 'and defined in %s on line %d'; + $message = sprintf($message, $param_num, $class, $type, $function, $parameters[$i]->name, $params[$i][2], $file, $line, $r->getFileName(), $r->getStartLine()); + trigger_error($message, E_USER_NOTICE); + } + + $hints = preg_split('~[|/,]~sSX', $params[$i][1]); + if (! self::checkValueTypes($hints, $value)) + { + $param_num = $i + 1; + $message = 'Argument %d passed to %s%s%s() must be an %s, %s given, ' . PHP_EOL + . 'called in %s on line %d ' . PHP_EOL + . 'and defined in %s on line %d'; + $message = sprintf($message, $param_num, $class, $type, $function, implode('|', $hints), (is_object($value) ? get_class($value) . ' ' : '') . gettype($value), $file, $line, $r->getFileName(), $r->getStartLine()); + trigger_error($message, E_USER_WARNING); + return false; + } + } + return true; + } + + /** + * Return stacktrace. Correctly work with call_user_func*() + * (totally skip them correcting caller references). + * If $return_frame is present, return only $return_frame matched caller, not all stacktrace. + * + * @param string|null $re_ignore example: '~^' . preg_quote(__CLASS__, '~') . '(?![a-zA-Z\d])~sSX' + * @param int|null $return_frame + * @return array + */ + public static function debugBacktrace($re_ignore = null, $return_frame = null) + { + $trace = debug_backtrace(); + + $a = array(); + $frames = 0; + for ($i = 0, $n = count($trace); $i < $n; $i++) + { + $t = $trace[$i]; + if (! $t) continue; + + // Next frame. + $next = isset($trace[$i+1])? $trace[$i+1] : null; + + // Dummy frame before call_user_func*() frames. + if (! isset($t['file']) && $next) + { + $t['over_function'] = $trace[$i+1]['function']; + $t = $t + $trace[$i+1]; + $trace[$i+1] = null; // skip call_user_func on next iteration + } + + // Skip myself frame. + if (++$frames < 2) continue; + + // 'class' and 'function' field of next frame define where this frame function situated. + // Skip frames for functions situated in ignored places. + if ($re_ignore && $next) + { + // Name of function "inside which" frame was generated. + $frame_caller = (isset($next['class']) ? $next['class'] . $next['type'] : '') + . (isset($next['function']) ? $next['function'] : ''); + if (preg_match($re_ignore, $frame_caller)) continue; + } + + // On each iteration we consider ability to add PREVIOUS frame to $a stack. + if (count($a) === $return_frame) return $t; + $a[] = $t; + } + return $a; + } + + /** + * Checks a value to the allowed types + * + * @param array $types + * @param mixed $value + * @return bool + */ + public static function checkValueTypes(array $types, $value) + { + foreach ($types as $type) + { + $type = strtolower($type); + if (array_key_exists($type, self::$hints) && call_user_func(self::$hints[$type], $value)) return true; + if (is_object($value) && @is_a($value, $type)) return true; + if ($type === 'mixed') return true; + } + return false; + } } \ No newline at end of file diff --git a/upload/includes/class.utf8.php b/upload/includes/class.utf8.php index 6dacc5f9e..ad740d657 100644 --- a/upload/includes/class.utf8.php +++ b/upload/includes/class.utf8.php @@ -1,4071 +1,4071 @@ - = 5.3.x - * - * In Russian: - * - * Поддержка UTF-8 в PHP 5. - * - * Возможности и преимущества использования этого класса - * * Совместимость с интерфейсом стандартных PHP функций, работающих с однобайтовыми кодировками - * * Возможность работы без PHP расширений ICONV и MBSTRING, если они есть, то активно используются! - * * Полезные функции, отсутствующие в ICONV и MBSTRING - * * Методы, которые принимают и возвращают строку, умеют принимать и возвращать null (удобно при выборках значений из базы данных) - * * Несколько методов умеют обрабатывать массивы рекурсивно - * * Единый интерфейс и инкапсуляция (можно унаследоваться и переопределить методы) - * * Высокая производительность, надёжность и качественный код - * * PHP >= 5.3.x - * - * Example: - * $s = 'Hello, Привет'; - * if (UTF8::is_utf8($s)) echo UTF8::strlen($s); - * - * UTF-8 encoding scheme: - * 2^7 0x00000000 — 0x0000007F 0xxxxxxx - * 2^11 0x00000080 — 0x000007FF 110xxxxx 10xxxxxx - * 2^16 0x00000800 — 0x0000FFFF 1110xxxx 10xxxxxx 10xxxxxx - * 2^21 0x00010000 — 0x001FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - * 1-4 bytes length: 2^7 + 2^11 + 2^16 + 2^21 = 2 164 864 - * - * If I was a owner of the world, I would leave only 2 encoding: UTF-8 and UTF-32 ;-) - * - * Useful links - * http://ru.wikipedia.org/wiki/UTF8 - * http://www.madore.org/~david/misc/unitest/ A Unicode Test Page - * http://www.unicode.org/ - * http://www.unicode.org/reports/ - * http://www.unicode.org/reports/tr10/ Unicode Collation Algorithm - * http://www.unicode.org/Public/UCA/6.0.0/ Unicode Collation Algorithm - * http://www.unicode.org/reports/tr6/ A Standard Compression Scheme for Unicode - * http://www.fileformat.info/info/unicode/char/search.htm Unicode Character Search - * - * @link http://code.google.com/p/php5-utf8/ - * @license http://creativecommons.org/licenses/by-sa/3.0/ - * @author Nasibullin Rinat - * @version 2.2.2 - */ -class UTF8 -{ - #REPLACEMENT CHARACTER (for broken char) - const REPLACEMENT_CHAR = "\xEF\xBF\xBD"; #U+FFFD - - /** - * Regular expression for a character in UTF-8 without the use of a flag /u - * @deprecated Instead, use a dot (".") and the flag /u, it works faster! - * @var string - */ - public static $char_re = ' [\x09\x0A\x0D\x20-\x7E] # ASCII strict - # [\x00-\x7F] # ASCII non-strict (including control chars) - | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte - | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs - | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte - | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates - | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 - | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 - | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 - '; - - /** - * Combining diactrical marks (Unicode 5.1). - * - * For example, russian letters in composed form: "Ё" (U+0401), "Й" (U+0419), - * decomposed form: (U+0415 U+0308), (U+0418 U+0306) - * - * @link http://www.unicode.org/charts/PDF/U0300.pdf - * @link http://www.unicode.org/charts/PDF/U1DC0.pdf - * @link http://www.unicode.org/charts/PDF/UFE20.pdf - * @var string - */ - #public static $diactrical_re = '\p{M}'; #alternative, but only with /u flag - public static $diactrical_re = ' \xcc[\x80-\xb9]|\xcd[\x80-\xaf] #UNICODE range: U+0300 — U+036F (for letters) - | \xe2\x83[\x90-\xbf] #UNICODE range: U+20D0 — U+20FF (for symbols) - | \xe1\xb7[\x80-\xbf] #UNICODE range: U+1DC0 — U+1DFF (supplement) - | \xef\xb8[\xa0-\xaf] #UNICODE range: U+FE20 — U+FE2F (combining half marks) - '; - - /** - * @var array - */ - public static $html_special_chars_table = array( - '"' => "\x22", #U+0022 ["] " quotation mark = APL quote - '&' => "\x26", #U+0026 [&] & ampersand - '<' => "\x3c", #U+003C [<] < less-than sign - '>' => "\x3e", #U+003E [>] > greater-than sign - ); - - /** - * @link http://www.fileformat.info/format/w3c/entitytest.htm?sort=Unicode%20Character HTML Entity Browser Test Page - * @var array - */ - public static $html_entity_table = array( - #Latin-1 Entities: - ' ' => "\xc2\xa0", #U+00A0 [ ] no-break space = non-breaking space - '¡' => "\xc2\xa1", #U+00A1 [¡] inverted exclamation mark - '¢' => "\xc2\xa2", #U+00A2 [¢] cent sign - '£' => "\xc2\xa3", #U+00A3 [£] pound sign - '¤' => "\xc2\xa4", #U+00A4 [¤] currency sign - '¥' => "\xc2\xa5", #U+00A5 [¥] yen sign = yuan sign - '¦' => "\xc2\xa6", #U+00A6 [¦] broken bar = broken vertical bar - '§' => "\xc2\xa7", #U+00A7 [§] section sign - '¨' => "\xc2\xa8", #U+00A8 [¨] diaeresis = spacing diaeresis - '©' => "\xc2\xa9", #U+00A9 [©] copyright sign - 'ª' => "\xc2\xaa", #U+00AA [ª] feminine ordinal indicator - '«' => "\xc2\xab", #U+00AB [«] left-pointing double angle quotation mark = left pointing guillemet - '¬' => "\xc2\xac", #U+00AC [¬] not sign - '­' => "\xc2\xad", #U+00AD [ ] soft hyphen = discretionary hyphen - '®' => "\xc2\xae", #U+00AE [®] registered sign = registered trade mark sign - '¯' => "\xc2\xaf", #U+00AF [¯] macron = spacing macron = overline = APL overbar - '°' => "\xc2\xb0", #U+00B0 [°] degree sign - '±' => "\xc2\xb1", #U+00B1 [±] plus-minus sign = plus-or-minus sign - '²' => "\xc2\xb2", #U+00B2 [²] superscript two = superscript digit two = squared - '³' => "\xc2\xb3", #U+00B3 [³] superscript three = superscript digit three = cubed - '´' => "\xc2\xb4", #U+00B4 [´] acute accent = spacing acute - 'µ' => "\xc2\xb5", #U+00B5 [µ] micro sign - '¶' => "\xc2\xb6", #U+00B6 [¶] pilcrow sign = paragraph sign - '·' => "\xc2\xb7", #U+00B7 [·] middle dot = Georgian comma = Greek middle dot - '¸' => "\xc2\xb8", #U+00B8 [¸] cedilla = spacing cedilla - '¹' => "\xc2\xb9", #U+00B9 [¹] superscript one = superscript digit one - 'º' => "\xc2\xba", #U+00BA [º] masculine ordinal indicator - '»' => "\xc2\xbb", #U+00BB [»] right-pointing double angle quotation mark = right pointing guillemet - '¼' => "\xc2\xbc", #U+00BC [¼] vulgar fraction one quarter = fraction one quarter - '½' => "\xc2\xbd", #U+00BD [½] vulgar fraction one half = fraction one half - '¾' => "\xc2\xbe", #U+00BE [¾] vulgar fraction three quarters = fraction three quarters - '¿' => "\xc2\xbf", #U+00BF [¿] inverted question mark = turned question mark - #Latin capital letter - 'À' => "\xc3\x80", #Latin capital letter A with grave = Latin capital letter A grave - 'Á' => "\xc3\x81", #Latin capital letter A with acute - 'Â' => "\xc3\x82", #Latin capital letter A with circumflex - 'Ã' => "\xc3\x83", #Latin capital letter A with tilde - 'Ä' => "\xc3\x84", #Latin capital letter A with diaeresis - 'Å' => "\xc3\x85", #Latin capital letter A with ring above = Latin capital letter A ring - 'Æ' => "\xc3\x86", #Latin capital letter AE = Latin capital ligature AE - 'Ç' => "\xc3\x87", #Latin capital letter C with cedilla - 'È' => "\xc3\x88", #Latin capital letter E with grave - 'É' => "\xc3\x89", #Latin capital letter E with acute - 'Ê' => "\xc3\x8a", #Latin capital letter E with circumflex - 'Ë' => "\xc3\x8b", #Latin capital letter E with diaeresis - 'Ì' => "\xc3\x8c", #Latin capital letter I with grave - 'Í' => "\xc3\x8d", #Latin capital letter I with acute - 'Î' => "\xc3\x8e", #Latin capital letter I with circumflex - 'Ï' => "\xc3\x8f", #Latin capital letter I with diaeresis - 'Ð' => "\xc3\x90", #Latin capital letter ETH - 'Ñ' => "\xc3\x91", #Latin capital letter N with tilde - 'Ò' => "\xc3\x92", #Latin capital letter O with grave - 'Ó' => "\xc3\x93", #Latin capital letter O with acute - 'Ô' => "\xc3\x94", #Latin capital letter O with circumflex - 'Õ' => "\xc3\x95", #Latin capital letter O with tilde - 'Ö' => "\xc3\x96", #Latin capital letter O with diaeresis - '×' => "\xc3\x97", #U+00D7 [×] multiplication sign - 'Ø' => "\xc3\x98", #Latin capital letter O with stroke = Latin capital letter O slash - 'Ù' => "\xc3\x99", #Latin capital letter U with grave - 'Ú' => "\xc3\x9a", #Latin capital letter U with acute - 'Û' => "\xc3\x9b", #Latin capital letter U with circumflex - 'Ü' => "\xc3\x9c", #Latin capital letter U with diaeresis - 'Ý' => "\xc3\x9d", #Latin capital letter Y with acute - 'Þ' => "\xc3\x9e", #Latin capital letter THORN - #Latin small letter - 'ß' => "\xc3\x9f", #Latin small letter sharp s = ess-zed - 'à' => "\xc3\xa0", #Latin small letter a with grave = Latin small letter a grave - 'á' => "\xc3\xa1", #Latin small letter a with acute - 'â' => "\xc3\xa2", #Latin small letter a with circumflex - 'ã' => "\xc3\xa3", #Latin small letter a with tilde - 'ä' => "\xc3\xa4", #Latin small letter a with diaeresis - 'å' => "\xc3\xa5", #Latin small letter a with ring above = Latin small letter a ring - 'æ' => "\xc3\xa6", #Latin small letter ae = Latin small ligature ae - 'ç' => "\xc3\xa7", #Latin small letter c with cedilla - 'è' => "\xc3\xa8", #Latin small letter e with grave - 'é' => "\xc3\xa9", #Latin small letter e with acute - 'ê' => "\xc3\xaa", #Latin small letter e with circumflex - 'ë' => "\xc3\xab", #Latin small letter e with diaeresis - 'ì' => "\xc3\xac", #Latin small letter i with grave - 'í' => "\xc3\xad", #Latin small letter i with acute - 'î' => "\xc3\xae", #Latin small letter i with circumflex - 'ï' => "\xc3\xaf", #Latin small letter i with diaeresis - 'ð' => "\xc3\xb0", #Latin small letter eth - 'ñ' => "\xc3\xb1", #Latin small letter n with tilde - 'ò' => "\xc3\xb2", #Latin small letter o with grave - 'ó' => "\xc3\xb3", #Latin small letter o with acute - 'ô' => "\xc3\xb4", #Latin small letter o with circumflex - 'õ' => "\xc3\xb5", #Latin small letter o with tilde - 'ö' => "\xc3\xb6", #Latin small letter o with diaeresis - '÷' => "\xc3\xb7", #U+00F7 [÷] division sign - 'ø' => "\xc3\xb8", #Latin small letter o with stroke = Latin small letter o slash - 'ù' => "\xc3\xb9", #Latin small letter u with grave - 'ú' => "\xc3\xba", #Latin small letter u with acute - 'û' => "\xc3\xbb", #Latin small letter u with circumflex - 'ü' => "\xc3\xbc", #Latin small letter u with diaeresis - 'ý' => "\xc3\xbd", #Latin small letter y with acute - 'þ' => "\xc3\xbe", #Latin small letter thorn - 'ÿ' => "\xc3\xbf", #Latin small letter y with diaeresis - #Symbols and Greek Letters: - 'ƒ' => "\xc6\x92", #U+0192 [ƒ] Latin small f with hook = function = florin - 'Α' => "\xce\x91", #Greek capital letter alpha - 'Β' => "\xce\x92", #Greek capital letter beta - 'Γ' => "\xce\x93", #Greek capital letter gamma - 'Δ' => "\xce\x94", #Greek capital letter delta - 'Ε' => "\xce\x95", #Greek capital letter epsilon - 'Ζ' => "\xce\x96", #Greek capital letter zeta - 'Η' => "\xce\x97", #Greek capital letter eta - 'Θ' => "\xce\x98", #Greek capital letter theta - 'Ι' => "\xce\x99", #Greek capital letter iota - 'Κ' => "\xce\x9a", #Greek capital letter kappa - 'Λ' => "\xce\x9b", #Greek capital letter lambda - 'Μ' => "\xce\x9c", #Greek capital letter mu - 'Ν' => "\xce\x9d", #Greek capital letter nu - 'Ξ' => "\xce\x9e", #Greek capital letter xi - 'Ο' => "\xce\x9f", #Greek capital letter omicron - 'Π' => "\xce\xa0", #Greek capital letter pi - 'Ρ' => "\xce\xa1", #Greek capital letter rho - 'Σ' => "\xce\xa3", #Greek capital letter sigma - 'Τ' => "\xce\xa4", #Greek capital letter tau - 'Υ' => "\xce\xa5", #Greek capital letter upsilon - 'Φ' => "\xce\xa6", #Greek capital letter phi - 'Χ' => "\xce\xa7", #Greek capital letter chi - 'Ψ' => "\xce\xa8", #Greek capital letter psi - 'Ω' => "\xce\xa9", #Greek capital letter omega - 'α' => "\xce\xb1", #Greek small letter alpha - 'β' => "\xce\xb2", #Greek small letter beta - 'γ' => "\xce\xb3", #Greek small letter gamma - 'δ' => "\xce\xb4", #Greek small letter delta - 'ε' => "\xce\xb5", #Greek small letter epsilon - 'ζ' => "\xce\xb6", #Greek small letter zeta - 'η' => "\xce\xb7", #Greek small letter eta - 'θ' => "\xce\xb8", #Greek small letter theta - 'ι' => "\xce\xb9", #Greek small letter iota - 'κ' => "\xce\xba", #Greek small letter kappa - 'λ' => "\xce\xbb", #Greek small letter lambda - 'μ' => "\xce\xbc", #Greek small letter mu - 'ν' => "\xce\xbd", #Greek small letter nu - 'ξ' => "\xce\xbe", #Greek small letter xi - 'ο' => "\xce\xbf", #Greek small letter omicron - 'π' => "\xcf\x80", #Greek small letter pi - 'ρ' => "\xcf\x81", #Greek small letter rho - 'ς' => "\xcf\x82", #Greek small letter final sigma - 'σ' => "\xcf\x83", #Greek small letter sigma - 'τ' => "\xcf\x84", #Greek small letter tau - 'υ' => "\xcf\x85", #Greek small letter upsilon - 'φ' => "\xcf\x86", #Greek small letter phi - 'χ' => "\xcf\x87", #Greek small letter chi - 'ψ' => "\xcf\x88", #Greek small letter psi - 'ω' => "\xcf\x89", #Greek small letter omega - 'ϑ'=> "\xcf\x91", #Greek small letter theta symbol - 'ϒ' => "\xcf\x92", #Greek upsilon with hook symbol - 'ϖ' => "\xcf\x96", #U+03D6 [ϖ] Greek pi symbol - - '•' => "\xe2\x80\xa2", #U+2022 [•] bullet = black small circle - '…' => "\xe2\x80\xa6", #U+2026 […] horizontal ellipsis = three dot leader - '′' => "\xe2\x80\xb2", #U+2032 [′] prime = minutes = feet (для обозначения минут и футов) - '″' => "\xe2\x80\xb3", #U+2033 [″] double prime = seconds = inches (для обозначения секунд и дюймов). - '‾' => "\xe2\x80\xbe", #U+203E [‾] overline = spacing overscore - '⁄' => "\xe2\x81\x84", #U+2044 [⁄] fraction slash - '℘' => "\xe2\x84\x98", #U+2118 [℘] script capital P = power set = Weierstrass p - 'ℑ' => "\xe2\x84\x91", #U+2111 [ℑ] blackletter capital I = imaginary part - 'ℜ' => "\xe2\x84\x9c", #U+211C [ℜ] blackletter capital R = real part symbol - '™' => "\xe2\x84\xa2", #U+2122 [™] trade mark sign - 'ℵ' => "\xe2\x84\xb5", #U+2135 [ℵ] alef symbol = first transfinite cardinal - '←' => "\xe2\x86\x90", #U+2190 [←] leftwards arrow - '↑' => "\xe2\x86\x91", #U+2191 [↑] upwards arrow - '→' => "\xe2\x86\x92", #U+2192 [→] rightwards arrow - '↓' => "\xe2\x86\x93", #U+2193 [↓] downwards arrow - '↔' => "\xe2\x86\x94", #U+2194 [↔] left right arrow - '↵' => "\xe2\x86\xb5", #U+21B5 [↵] downwards arrow with corner leftwards = carriage return - '⇐' => "\xe2\x87\x90", #U+21D0 [⇐] leftwards double arrow - '⇑' => "\xe2\x87\x91", #U+21D1 [⇑] upwards double arrow - '⇒' => "\xe2\x87\x92", #U+21D2 [⇒] rightwards double arrow - '⇓' => "\xe2\x87\x93", #U+21D3 [⇓] downwards double arrow - '⇔' => "\xe2\x87\x94", #U+21D4 [⇔] left right double arrow - '∀' => "\xe2\x88\x80", #U+2200 [∀] for all - '∂' => "\xe2\x88\x82", #U+2202 [∂] partial differential - '∃' => "\xe2\x88\x83", #U+2203 [∃] there exists - '∅' => "\xe2\x88\x85", #U+2205 [∅] empty set = null set = diameter - '∇' => "\xe2\x88\x87", #U+2207 [∇] nabla = backward difference - '∈' => "\xe2\x88\x88", #U+2208 [∈] element of - '∉' => "\xe2\x88\x89", #U+2209 [∉] not an element of - '∋' => "\xe2\x88\x8b", #U+220B [∋] contains as member - '∏' => "\xe2\x88\x8f", #U+220F [∏] n-ary product = product sign - '∑' => "\xe2\x88\x91", #U+2211 [∑] n-ary sumation - '−' => "\xe2\x88\x92", #U+2212 [−] minus sign - '∗' => "\xe2\x88\x97", #U+2217 [∗] asterisk operator - '√' => "\xe2\x88\x9a", #U+221A [√] square root = radical sign - '∝' => "\xe2\x88\x9d", #U+221D [∝] proportional to - '∞' => "\xe2\x88\x9e", #U+221E [∞] infinity - '∠' => "\xe2\x88\xa0", #U+2220 [∠] angle - '∧' => "\xe2\x88\xa7", #U+2227 [∧] logical and = wedge - '∨' => "\xe2\x88\xa8", #U+2228 [∨] logical or = vee - '∩' => "\xe2\x88\xa9", #U+2229 [∩] intersection = cap - '∪' => "\xe2\x88\xaa", #U+222A [∪] union = cup - '∫' => "\xe2\x88\xab", #U+222B [∫] integral - '∴' => "\xe2\x88\xb4", #U+2234 [∴] therefore - '∼' => "\xe2\x88\xbc", #U+223C [∼] tilde operator = varies with = similar to - '≅' => "\xe2\x89\x85", #U+2245 [≅] approximately equal to - '≈' => "\xe2\x89\x88", #U+2248 [≈] almost equal to = asymptotic to - '≠' => "\xe2\x89\xa0", #U+2260 [≠] not equal to - '≡' => "\xe2\x89\xa1", #U+2261 [≡] identical to - '≤' => "\xe2\x89\xa4", #U+2264 [≤] less-than or equal to - '≥' => "\xe2\x89\xa5", #U+2265 [≥] greater-than or equal to - '⊂' => "\xe2\x8a\x82", #U+2282 [⊂] subset of - '⊃' => "\xe2\x8a\x83", #U+2283 [⊃] superset of - '⊄' => "\xe2\x8a\x84", #U+2284 [⊄] not a subset of - '⊆' => "\xe2\x8a\x86", #U+2286 [⊆] subset of or equal to - '⊇' => "\xe2\x8a\x87", #U+2287 [⊇] superset of or equal to - '⊕' => "\xe2\x8a\x95", #U+2295 [⊕] circled plus = direct sum - '⊗' => "\xe2\x8a\x97", #U+2297 [⊗] circled times = vector product - '⊥' => "\xe2\x8a\xa5", #U+22A5 [⊥] up tack = orthogonal to = perpendicular - '⋅' => "\xe2\x8b\x85", #U+22C5 [⋅] dot operator - '⌈' => "\xe2\x8c\x88", #U+2308 [⌈] left ceiling = APL upstile - '⌉' => "\xe2\x8c\x89", #U+2309 [⌉] right ceiling - '⌊' => "\xe2\x8c\x8a", #U+230A [⌊] left floor = APL downstile - '⌋' => "\xe2\x8c\x8b", #U+230B [⌋] right floor - '⟨' => "\xe2\x8c\xa9", #U+2329 [〈] left-pointing angle bracket = bra - '⟩' => "\xe2\x8c\xaa", #U+232A [〉] right-pointing angle bracket = ket - '◊' => "\xe2\x97\x8a", #U+25CA [◊] lozenge - '♠' => "\xe2\x99\xa0", #U+2660 [♠] black spade suit - '♣' => "\xe2\x99\xa3", #U+2663 [♣] black club suit = shamrock - '♥' => "\xe2\x99\xa5", #U+2665 [♥] black heart suit = valentine - '♦' => "\xe2\x99\xa6", #U+2666 [♦] black diamond suit - #Other Special Characters: - 'Œ' => "\xc5\x92", #U+0152 [Œ] Latin capital ligature OE - 'œ' => "\xc5\x93", #U+0153 [œ] Latin small ligature oe - 'Š' => "\xc5\xa0", #U+0160 [Š] Latin capital letter S with caron - 'š' => "\xc5\xa1", #U+0161 [š] Latin small letter s with caron - 'Ÿ' => "\xc5\xb8", #U+0178 [Ÿ] Latin capital letter Y with diaeresis - 'ˆ' => "\xcb\x86", #U+02C6 [ˆ] modifier letter circumflex accent - '˜' => "\xcb\x9c", #U+02DC [˜] small tilde - ' ' => "\xe2\x80\x82", #U+2002 [ ] en space - ' ' => "\xe2\x80\x83", #U+2003 [ ] em space - ' ' => "\xe2\x80\x89", #U+2009 [ ] thin space - '‌' => "\xe2\x80\x8c", #U+200C [‌] zero width non-joiner - '‍' => "\xe2\x80\x8d", #U+200D [‍] zero width joiner - '‎' => "\xe2\x80\x8e", #U+200E [‎] left-to-right mark - '‏' => "\xe2\x80\x8f", #U+200F [‏] right-to-left mark - '–' => "\xe2\x80\x93", #U+2013 [–] en dash - '—' => "\xe2\x80\x94", #U+2014 [—] em dash - '‘' => "\xe2\x80\x98", #U+2018 [‘] left single quotation mark - '’' => "\xe2\x80\x99", #U+2019 [’] right single quotation mark (and apostrophe!) - '‚' => "\xe2\x80\x9a", #U+201A [‚] single low-9 quotation mark - '“' => "\xe2\x80\x9c", #U+201C [“] left double quotation mark - '”' => "\xe2\x80\x9d", #U+201D [”] right double quotation mark - '„' => "\xe2\x80\x9e", #U+201E [„] double low-9 quotation mark - '†' => "\xe2\x80\xa0", #U+2020 [†] dagger - '‡' => "\xe2\x80\xa1", #U+2021 [‡] double dagger - '‰' => "\xe2\x80\xb0", #U+2030 [‰] per mille sign - '‹' => "\xe2\x80\xb9", #U+2039 [‹] single left-pointing angle quotation mark - '›' => "\xe2\x80\xba", #U+203A [›] single right-pointing angle quotation mark - '€' => "\xe2\x82\xac", #U+20AC [€] euro sign - ); - - /** - * This table contains the data on how cp1259 characters map into Unicode (UTF-8). - * The cp1259 map describes standart tatarish cyrillic charset and based on the cp1251 table. - * cp1259 -- this is an outdated one byte encoding of the Tatar language, - * which includes all the Russian letters from cp1251. - * - * @link http://search.cpan.org/CPAN/authors/id/A/AM/AMICHAUER/Lingua-TT-Yanalif-0.08.tar.gz - * @link http://www.unicode.org/charts/PDF/U0400.pdf - */ - public static $cp1259_table = array( - #bytes from 0x00 to 0x7F (ASCII) saved as is - "\x80" => "\xd3\x98", #U+04d8 CYRILLIC CAPITAL LETTER SCHWA - "\x81" => "\xd0\x83", #U+0403 CYRILLIC CAPITAL LETTER GJE - "\x82" => "\xe2\x80\x9a", #U+201a SINGLE LOW-9 QUOTATION MARK - "\x83" => "\xd1\x93", #U+0453 CYRILLIC SMALL LETTER GJE - "\x84" => "\xe2\x80\x9e", #U+201e DOUBLE LOW-9 QUOTATION MARK - "\x85" => "\xe2\x80\xa6", #U+2026 HORIZONTAL ELLIPSIS - "\x86" => "\xe2\x80\xa0", #U+2020 DAGGER - "\x87" => "\xe2\x80\xa1", #U+2021 DOUBLE DAGGER - "\x88" => "\xe2\x82\xac", #U+20ac EURO SIGN - "\x89" => "\xe2\x80\xb0", #U+2030 PER MILLE SIGN - "\x8a" => "\xd3\xa8", #U+04e8 CYRILLIC CAPITAL LETTER BARRED O - "\x8b" => "\xe2\x80\xb9", #U+2039 SINGLE LEFT-POINTING ANGLE QUOTATION MARK - "\x8c" => "\xd2\xae", #U+04ae CYRILLIC CAPITAL LETTER STRAIGHT U - "\x8d" => "\xd2\x96", #U+0496 CYRILLIC CAPITAL LETTER ZHE WITH DESCENDER - "\x8e" => "\xd2\xa2", #U+04a2 CYRILLIC CAPITAL LETTER EN WITH HOOK - "\x8f" => "\xd2\xba", #U+04ba CYRILLIC CAPITAL LETTER SHHA - "\x90" => "\xd3\x99", #U+04d9 CYRILLIC SMALL LETTER SCHWA - "\x91" => "\xe2\x80\x98", #U+2018 LEFT SINGLE QUOTATION MARK - "\x92" => "\xe2\x80\x99", #U+2019 RIGHT SINGLE QUOTATION MARK - "\x93" => "\xe2\x80\x9c", #U+201c LEFT DOUBLE QUOTATION MARK - "\x94" => "\xe2\x80\x9d", #U+201d RIGHT DOUBLE QUOTATION MARK - "\x95" => "\xe2\x80\xa2", #U+2022 BULLET - "\x96" => "\xe2\x80\x93", #U+2013 EN DASH - "\x97" => "\xe2\x80\x94", #U+2014 EM DASH - #"\x98" #UNDEFINED - "\x99" => "\xe2\x84\xa2", #U+2122 TRADE MARK SIGN - "\x9a" => "\xd3\xa9", #U+04e9 CYRILLIC SMALL LETTER BARRED O - "\x9b" => "\xe2\x80\xba", #U+203a SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - "\x9c" => "\xd2\xaf", #U+04af CYRILLIC SMALL LETTER STRAIGHT U - "\x9d" => "\xd2\x97", #U+0497 CYRILLIC SMALL LETTER ZHE WITH DESCENDER - "\x9e" => "\xd2\xa3", #U+04a3 CYRILLIC SMALL LETTER EN WITH HOOK - "\x9f" => "\xd2\xbb", #U+04bb CYRILLIC SMALL LETTER SHHA - "\xa0" => "\xc2\xa0", #U+00a0 NO-BREAK SPACE - "\xa1" => "\xd0\x8e", #U+040e CYRILLIC CAPITAL LETTER SHORT U - "\xa2" => "\xd1\x9e", #U+045e CYRILLIC SMALL LETTER SHORT U - "\xa3" => "\xd0\x88", #U+0408 CYRILLIC CAPITAL LETTER JE - "\xa4" => "\xc2\xa4", #U+00a4 CURRENCY SIGN - "\xa5" => "\xd2\x90", #U+0490 CYRILLIC CAPITAL LETTER GHE WITH UPTURN - "\xa6" => "\xc2\xa6", #U+00a6 BROKEN BAR - "\xa7" => "\xc2\xa7", #U+00a7 SECTION SIGN - "\xa8" => "\xd0\x81", #U+0401 CYRILLIC CAPITAL LETTER IO - "\xa9" => "\xc2\xa9", #U+00a9 COPYRIGHT SIGN - "\xaa" => "\xd0\x84", #U+0404 CYRILLIC CAPITAL LETTER UKRAINIAN IE - "\xab" => "\xc2\xab", #U+00ab LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - "\xac" => "\xc2\xac", #U+00ac NOT SIGN - "\xad" => "\xc2\xad", #U+00ad SOFT HYPHEN - "\xae" => "\xc2\xae", #U+00ae REGISTERED SIGN - "\xaf" => "\xd0\x87", #U+0407 CYRILLIC CAPITAL LETTER YI - "\xb0" => "\xc2\xb0", #U+00b0 DEGREE SIGN - "\xb1" => "\xc2\xb1", #U+00b1 PLUS-MINUS SIGN - "\xb2" => "\xd0\x86", #U+0406 CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I - "\xb3" => "\xd1\x96", #U+0456 CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I - "\xb4" => "\xd2\x91", #U+0491 CYRILLIC SMALL LETTER GHE WITH UPTURN - "\xb5" => "\xc2\xb5", #U+00b5 MICRO SIGN - "\xb6" => "\xc2\xb6", #U+00b6 PILCROW SIGN - "\xb7" => "\xc2\xb7", #U+00b7 MIDDLE DOT - "\xb8" => "\xd1\x91", #U+0451 CYRILLIC SMALL LETTER IO - "\xb9" => "\xe2\x84\x96", #U+2116 NUMERO SIGN - "\xba" => "\xd1\x94", #U+0454 CYRILLIC SMALL LETTER UKRAINIAN IE - "\xbb" => "\xc2\xbb", #U+00bb RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - "\xbc" => "\xd1\x98", #U+0458 CYRILLIC SMALL LETTER JE - "\xbd" => "\xd0\x85", #U+0405 CYRILLIC CAPITAL LETTER DZE - "\xbe" => "\xd1\x95", #U+0455 CYRILLIC SMALL LETTER DZE - "\xbf" => "\xd1\x97", #U+0457 CYRILLIC SMALL LETTER YI - "\xc0" => "\xd0\x90", #U+0410 CYRILLIC CAPITAL LETTER A - "\xc1" => "\xd0\x91", #U+0411 CYRILLIC CAPITAL LETTER BE - "\xc2" => "\xd0\x92", #U+0412 CYRILLIC CAPITAL LETTER VE - "\xc3" => "\xd0\x93", #U+0413 CYRILLIC CAPITAL LETTER GHE - "\xc4" => "\xd0\x94", #U+0414 CYRILLIC CAPITAL LETTER DE - "\xc5" => "\xd0\x95", #U+0415 CYRILLIC CAPITAL LETTER IE - "\xc6" => "\xd0\x96", #U+0416 CYRILLIC CAPITAL LETTER ZHE - "\xc7" => "\xd0\x97", #U+0417 CYRILLIC CAPITAL LETTER ZE - "\xc8" => "\xd0\x98", #U+0418 CYRILLIC CAPITAL LETTER I - "\xc9" => "\xd0\x99", #U+0419 CYRILLIC CAPITAL LETTER SHORT I - "\xca" => "\xd0\x9a", #U+041a CYRILLIC CAPITAL LETTER KA - "\xcb" => "\xd0\x9b", #U+041b CYRILLIC CAPITAL LETTER EL - "\xcc" => "\xd0\x9c", #U+041c CYRILLIC CAPITAL LETTER EM - "\xcd" => "\xd0\x9d", #U+041d CYRILLIC CAPITAL LETTER EN - "\xce" => "\xd0\x9e", #U+041e CYRILLIC CAPITAL LETTER O - "\xcf" => "\xd0\x9f", #U+041f CYRILLIC CAPITAL LETTER PE - "\xd0" => "\xd0\xa0", #U+0420 CYRILLIC CAPITAL LETTER ER - "\xd1" => "\xd0\xa1", #U+0421 CYRILLIC CAPITAL LETTER ES - "\xd2" => "\xd0\xa2", #U+0422 CYRILLIC CAPITAL LETTER TE - "\xd3" => "\xd0\xa3", #U+0423 CYRILLIC CAPITAL LETTER U - "\xd4" => "\xd0\xa4", #U+0424 CYRILLIC CAPITAL LETTER EF - "\xd5" => "\xd0\xa5", #U+0425 CYRILLIC CAPITAL LETTER HA - "\xd6" => "\xd0\xa6", #U+0426 CYRILLIC CAPITAL LETTER TSE - "\xd7" => "\xd0\xa7", #U+0427 CYRILLIC CAPITAL LETTER CHE - "\xd8" => "\xd0\xa8", #U+0428 CYRILLIC CAPITAL LETTER SHA - "\xd9" => "\xd0\xa9", #U+0429 CYRILLIC CAPITAL LETTER SHCHA - "\xda" => "\xd0\xaa", #U+042a CYRILLIC CAPITAL LETTER HARD SIGN - "\xdb" => "\xd0\xab", #U+042b CYRILLIC CAPITAL LETTER YERU - "\xdc" => "\xd0\xac", #U+042c CYRILLIC CAPITAL LETTER SOFT SIGN - "\xdd" => "\xd0\xad", #U+042d CYRILLIC CAPITAL LETTER E - "\xde" => "\xd0\xae", #U+042e CYRILLIC CAPITAL LETTER YU - "\xdf" => "\xd0\xaf", #U+042f CYRILLIC CAPITAL LETTER YA - "\xe0" => "\xd0\xb0", #U+0430 CYRILLIC SMALL LETTER A - "\xe1" => "\xd0\xb1", #U+0431 CYRILLIC SMALL LETTER BE - "\xe2" => "\xd0\xb2", #U+0432 CYRILLIC SMALL LETTER VE - "\xe3" => "\xd0\xb3", #U+0433 CYRILLIC SMALL LETTER GHE - "\xe4" => "\xd0\xb4", #U+0434 CYRILLIC SMALL LETTER DE - "\xe5" => "\xd0\xb5", #U+0435 CYRILLIC SMALL LETTER IE - "\xe6" => "\xd0\xb6", #U+0436 CYRILLIC SMALL LETTER ZHE - "\xe7" => "\xd0\xb7", #U+0437 CYRILLIC SMALL LETTER ZE - "\xe8" => "\xd0\xb8", #U+0438 CYRILLIC SMALL LETTER I - "\xe9" => "\xd0\xb9", #U+0439 CYRILLIC SMALL LETTER SHORT I - "\xea" => "\xd0\xba", #U+043a CYRILLIC SMALL LETTER KA - "\xeb" => "\xd0\xbb", #U+043b CYRILLIC SMALL LETTER EL - "\xec" => "\xd0\xbc", #U+043c CYRILLIC SMALL LETTER EM - "\xed" => "\xd0\xbd", #U+043d CYRILLIC SMALL LETTER EN - "\xee" => "\xd0\xbe", #U+043e CYRILLIC SMALL LETTER O - "\xef" => "\xd0\xbf", #U+043f CYRILLIC SMALL LETTER PE - "\xf0" => "\xd1\x80", #U+0440 CYRILLIC SMALL LETTER ER - "\xf1" => "\xd1\x81", #U+0441 CYRILLIC SMALL LETTER ES - "\xf2" => "\xd1\x82", #U+0442 CYRILLIC SMALL LETTER TE - "\xf3" => "\xd1\x83", #U+0443 CYRILLIC SMALL LETTER U - "\xf4" => "\xd1\x84", #U+0444 CYRILLIC SMALL LETTER EF - "\xf5" => "\xd1\x85", #U+0445 CYRILLIC SMALL LETTER HA - "\xf6" => "\xd1\x86", #U+0446 CYRILLIC SMALL LETTER TSE - "\xf7" => "\xd1\x87", #U+0447 CYRILLIC SMALL LETTER CHE - "\xf8" => "\xd1\x88", #U+0448 CYRILLIC SMALL LETTER SHA - "\xf9" => "\xd1\x89", #U+0449 CYRILLIC SMALL LETTER SHCHA - "\xfa" => "\xd1\x8a", #U+044a CYRILLIC SMALL LETTER HARD SIGN - "\xfb" => "\xd1\x8b", #U+044b CYRILLIC SMALL LETTER YERU - "\xfc" => "\xd1\x8c", #U+044c CYRILLIC SMALL LETTER SOFT SIGN - "\xfd" => "\xd1\x8d", #U+044d CYRILLIC SMALL LETTER E - "\xfe" => "\xd1\x8e", #U+044e CYRILLIC SMALL LETTER YU - "\xff" => "\xd1\x8f", #U+044f CYRILLIC SMALL LETTER YA - ); - - /** - * UTF-8 Case lookup table - * - * This lookuptable defines the upper case letters to their correspponding - * lower case letter in UTF-8 - * - * @author Andreas Gohr - */ - public static $convert_case_table = array( - #CASE_UPPER => case_lower - "\x41" => "\x61", #A a - "\x42" => "\x62", #B b - "\x43" => "\x63", #C c - "\x44" => "\x64", #D d - "\x45" => "\x65", #E e - "\x46" => "\x66", #F f - "\x47" => "\x67", #G g - "\x48" => "\x68", #H h - "\x49" => "\x69", #I i - "\x4a" => "\x6a", #J j - "\x4b" => "\x6b", #K k - "\x4c" => "\x6c", #L l - "\x4d" => "\x6d", #M m - "\x4e" => "\x6e", #N n - "\x4f" => "\x6f", #O o - "\x50" => "\x70", #P p - "\x51" => "\x71", #Q q - "\x52" => "\x72", #R r - "\x53" => "\x73", #S s - "\x54" => "\x74", #T t - "\x55" => "\x75", #U u - "\x56" => "\x76", #V v - "\x57" => "\x77", #W w - "\x58" => "\x78", #X x - "\x59" => "\x79", #Y y - "\x5a" => "\x7a", #Z z - "\xc3\x80" => "\xc3\xa0", - "\xc3\x81" => "\xc3\xa1", - "\xc3\x82" => "\xc3\xa2", - "\xc3\x83" => "\xc3\xa3", - "\xc3\x84" => "\xc3\xa4", - "\xc3\x85" => "\xc3\xa5", - "\xc3\x86" => "\xc3\xa6", - "\xc3\x87" => "\xc3\xa7", - "\xc3\x88" => "\xc3\xa8", - "\xc3\x89" => "\xc3\xa9", - "\xc3\x8a" => "\xc3\xaa", - "\xc3\x8b" => "\xc3\xab", - "\xc3\x8c" => "\xc3\xac", - "\xc3\x8d" => "\xc3\xad", - "\xc3\x8e" => "\xc3\xae", - "\xc3\x8f" => "\xc3\xaf", - "\xc3\x90" => "\xc3\xb0", - "\xc3\x91" => "\xc3\xb1", - "\xc3\x92" => "\xc3\xb2", - "\xc3\x93" => "\xc3\xb3", - "\xc3\x94" => "\xc3\xb4", - "\xc3\x95" => "\xc3\xb5", - "\xc3\x96" => "\xc3\xb6", - "\xc3\x98" => "\xc3\xb8", - "\xc3\x99" => "\xc3\xb9", - "\xc3\x9a" => "\xc3\xba", - "\xc3\x9b" => "\xc3\xbb", - "\xc3\x9c" => "\xc3\xbc", - "\xc3\x9d" => "\xc3\xbd", - "\xc3\x9e" => "\xc3\xbe", - "\xc4\x80" => "\xc4\x81", - "\xc4\x82" => "\xc4\x83", - "\xc4\x84" => "\xc4\x85", - "\xc4\x86" => "\xc4\x87", - "\xc4\x88" => "\xc4\x89", - "\xc4\x8a" => "\xc4\x8b", - "\xc4\x8c" => "\xc4\x8d", - "\xc4\x8e" => "\xc4\x8f", - "\xc4\x90" => "\xc4\x91", - "\xc4\x92" => "\xc4\x93", - "\xc4\x94" => "\xc4\x95", - "\xc4\x96" => "\xc4\x97", - "\xc4\x98" => "\xc4\x99", - "\xc4\x9a" => "\xc4\x9b", - "\xc4\x9c" => "\xc4\x9d", - "\xc4\x9e" => "\xc4\x9f", - "\xc4\xa0" => "\xc4\xa1", - "\xc4\xa2" => "\xc4\xa3", - "\xc4\xa4" => "\xc4\xa5", - "\xc4\xa6" => "\xc4\xa7", - "\xc4\xa8" => "\xc4\xa9", - "\xc4\xaa" => "\xc4\xab", - "\xc4\xac" => "\xc4\xad", - "\xc4\xae" => "\xc4\xaf", - "\xc4\xb2" => "\xc4\xb3", - "\xc4\xb4" => "\xc4\xb5", - "\xc4\xb6" => "\xc4\xb7", - "\xc4\xb9" => "\xc4\xba", - "\xc4\xbb" => "\xc4\xbc", - "\xc4\xbd" => "\xc4\xbe", - "\xc4\xbf" => "\xc5\x80", - "\xc5\x81" => "\xc5\x82", - "\xc5\x83" => "\xc5\x84", - "\xc5\x85" => "\xc5\x86", - "\xc5\x87" => "\xc5\x88", - "\xc5\x8a" => "\xc5\x8b", - "\xc5\x8c" => "\xc5\x8d", - "\xc5\x8e" => "\xc5\x8f", - "\xc5\x90" => "\xc5\x91", - "\xc5\x92" => "\xc5\x93", - "\xc5\x94" => "\xc5\x95", - "\xc5\x96" => "\xc5\x97", - "\xc5\x98" => "\xc5\x99", - "\xc5\x9a" => "\xc5\x9b", - "\xc5\x9c" => "\xc5\x9d", - "\xc5\x9e" => "\xc5\x9f", - "\xc5\xa0" => "\xc5\xa1", - "\xc5\xa2" => "\xc5\xa3", - "\xc5\xa4" => "\xc5\xa5", - "\xc5\xa6" => "\xc5\xa7", - "\xc5\xa8" => "\xc5\xa9", - "\xc5\xaa" => "\xc5\xab", - "\xc5\xac" => "\xc5\xad", - "\xc5\xae" => "\xc5\xaf", - "\xc5\xb0" => "\xc5\xb1", - "\xc5\xb2" => "\xc5\xb3", - "\xc5\xb4" => "\xc5\xb5", - "\xc5\xb6" => "\xc5\xb7", - "\xc5\xb8" => "\xc3\xbf", - "\xc5\xb9" => "\xc5\xba", - "\xc5\xbb" => "\xc5\xbc", - "\xc5\xbd" => "\xc5\xbe", - "\xc6\x81" => "\xc9\x93", - "\xc6\x82" => "\xc6\x83", - "\xc6\x84" => "\xc6\x85", - "\xc6\x86" => "\xc9\x94", - "\xc6\x87" => "\xc6\x88", - "\xc6\x89" => "\xc9\x96", - "\xc6\x8a" => "\xc9\x97", - "\xc6\x8b" => "\xc6\x8c", - "\xc6\x8e" => "\xc7\x9d", - "\xc6\x8f" => "\xc9\x99", - "\xc6\x90" => "\xc9\x9b", - "\xc6\x91" => "\xc6\x92", - "\xc6\x94" => "\xc9\xa3", - "\xc6\x96" => "\xc9\xa9", - "\xc6\x97" => "\xc9\xa8", - "\xc6\x98" => "\xc6\x99", - "\xc6\x9c" => "\xc9\xaf", - "\xc6\x9d" => "\xc9\xb2", - "\xc6\x9f" => "\xc9\xb5", - "\xc6\xa0" => "\xc6\xa1", - "\xc6\xa2" => "\xc6\xa3", - "\xc6\xa4" => "\xc6\xa5", - "\xc6\xa6" => "\xca\x80", - "\xc6\xa7" => "\xc6\xa8", - "\xc6\xa9" => "\xca\x83", - "\xc6\xac" => "\xc6\xad", - "\xc6\xae" => "\xca\x88", - "\xc6\xaf" => "\xc6\xb0", - "\xc6\xb1" => "\xca\x8a", - "\xc6\xb2" => "\xca\x8b", - "\xc6\xb3" => "\xc6\xb4", - "\xc6\xb5" => "\xc6\xb6", - "\xc6\xb7" => "\xca\x92", - "\xc6\xb8" => "\xc6\xb9", - "\xc6\xbc" => "\xc6\xbd", - "\xc7\x85" => "\xc7\x86", - "\xc7\x88" => "\xc7\x89", - "\xc7\x8b" => "\xc7\x8c", - "\xc7\x8d" => "\xc7\x8e", - "\xc7\x8f" => "\xc7\x90", - "\xc7\x91" => "\xc7\x92", - "\xc7\x93" => "\xc7\x94", - "\xc7\x95" => "\xc7\x96", - "\xc7\x97" => "\xc7\x98", - "\xc7\x99" => "\xc7\x9a", - "\xc7\x9b" => "\xc7\x9c", - "\xc7\x9e" => "\xc7\x9f", - "\xc7\xa0" => "\xc7\xa1", - "\xc7\xa2" => "\xc7\xa3", - "\xc7\xa4" => "\xc7\xa5", - "\xc7\xa6" => "\xc7\xa7", - "\xc7\xa8" => "\xc7\xa9", - "\xc7\xaa" => "\xc7\xab", - "\xc7\xac" => "\xc7\xad", - "\xc7\xae" => "\xc7\xaf", - "\xc7\xb2" => "\xc7\xb3", - "\xc7\xb4" => "\xc7\xb5", - "\xc7\xb6" => "\xc6\x95", - "\xc7\xb7" => "\xc6\xbf", - "\xc7\xb8" => "\xc7\xb9", - "\xc7\xba" => "\xc7\xbb", - "\xc7\xbc" => "\xc7\xbd", - "\xc7\xbe" => "\xc7\xbf", - "\xc8\x80" => "\xc8\x81", - "\xc8\x82" => "\xc8\x83", - "\xc8\x84" => "\xc8\x85", - "\xc8\x86" => "\xc8\x87", - "\xc8\x88" => "\xc8\x89", - "\xc8\x8a" => "\xc8\x8b", - "\xc8\x8c" => "\xc8\x8d", - "\xc8\x8e" => "\xc8\x8f", - "\xc8\x90" => "\xc8\x91", - "\xc8\x92" => "\xc8\x93", - "\xc8\x94" => "\xc8\x95", - "\xc8\x96" => "\xc8\x97", - "\xc8\x98" => "\xc8\x99", - "\xc8\x9a" => "\xc8\x9b", - "\xc8\x9c" => "\xc8\x9d", - "\xc8\x9e" => "\xc8\x9f", - "\xc8\xa0" => "\xc6\x9e", - "\xc8\xa2" => "\xc8\xa3", - "\xc8\xa4" => "\xc8\xa5", - "\xc8\xa6" => "\xc8\xa7", - "\xc8\xa8" => "\xc8\xa9", - "\xc8\xaa" => "\xc8\xab", - "\xc8\xac" => "\xc8\xad", - "\xc8\xae" => "\xc8\xaf", - "\xc8\xb0" => "\xc8\xb1", - "\xc8\xb2" => "\xc8\xb3", - "\xce\x86" => "\xce\xac", - "\xce\x88" => "\xce\xad", - "\xce\x89" => "\xce\xae", - "\xce\x8a" => "\xce\xaf", - "\xce\x8c" => "\xcf\x8c", - "\xce\x8e" => "\xcf\x8d", - "\xce\x8f" => "\xcf\x8e", - "\xce\x91" => "\xce\xb1", - "\xce\x92" => "\xce\xb2", - "\xce\x93" => "\xce\xb3", - "\xce\x94" => "\xce\xb4", - "\xce\x95" => "\xce\xb5", - "\xce\x96" => "\xce\xb6", - "\xce\x97" => "\xce\xb7", - "\xce\x98" => "\xce\xb8", - "\xce\x99" => "\xce\xb9", - "\xce\x9a" => "\xce\xba", - "\xce\x9b" => "\xce\xbb", - "\xce\x9c" => "\xc2\xb5", - "\xce\x9d" => "\xce\xbd", - "\xce\x9e" => "\xce\xbe", - "\xce\x9f" => "\xce\xbf", - "\xce\xa0" => "\xcf\x80", - "\xce\xa1" => "\xcf\x81", - "\xce\xa3" => "\xcf\x82", - "\xce\xa4" => "\xcf\x84", - "\xce\xa5" => "\xcf\x85", - "\xce\xa6" => "\xcf\x86", - "\xce\xa7" => "\xcf\x87", - "\xce\xa8" => "\xcf\x88", - "\xce\xa9" => "\xcf\x89", - "\xce\xaa" => "\xcf\x8a", - "\xce\xab" => "\xcf\x8b", - "\xcf\x98" => "\xcf\x99", - "\xcf\x9a" => "\xcf\x9b", - "\xcf\x9c" => "\xcf\x9d", - "\xcf\x9e" => "\xcf\x9f", - "\xcf\xa0" => "\xcf\xa1", - "\xcf\xa2" => "\xcf\xa3", - "\xcf\xa4" => "\xcf\xa5", - "\xcf\xa6" => "\xcf\xa7", - "\xcf\xa8" => "\xcf\xa9", - "\xcf\xaa" => "\xcf\xab", - "\xcf\xac" => "\xcf\xad", - "\xcf\xae" => "\xcf\xaf", - "\xd0\x80" => "\xd1\x90", - "\xd0\x81" => "\xd1\x91", - "\xd0\x82" => "\xd1\x92", - "\xd0\x83" => "\xd1\x93", - "\xd0\x84" => "\xd1\x94", - "\xd0\x85" => "\xd1\x95", - "\xd0\x86" => "\xd1\x96", - "\xd0\x87" => "\xd1\x97", - "\xd0\x88" => "\xd1\x98", - "\xd0\x89" => "\xd1\x99", - "\xd0\x8a" => "\xd1\x9a", - "\xd0\x8b" => "\xd1\x9b", - "\xd0\x8c" => "\xd1\x9c", - "\xd0\x8d" => "\xd1\x9d", - "\xd0\x8e" => "\xd1\x9e", - "\xd0\x8f" => "\xd1\x9f", - "\xd0\x90" => "\xd0\xb0", - "\xd0\x91" => "\xd0\xb1", - "\xd0\x92" => "\xd0\xb2", - "\xd0\x93" => "\xd0\xb3", - "\xd0\x94" => "\xd0\xb4", - "\xd0\x95" => "\xd0\xb5", - "\xd0\x96" => "\xd0\xb6", - "\xd0\x97" => "\xd0\xb7", - "\xd0\x98" => "\xd0\xb8", - "\xd0\x99" => "\xd0\xb9", - "\xd0\x9a" => "\xd0\xba", - "\xd0\x9b" => "\xd0\xbb", - "\xd0\x9c" => "\xd0\xbc", - "\xd0\x9d" => "\xd0\xbd", - "\xd0\x9e" => "\xd0\xbe", - "\xd0\x9f" => "\xd0\xbf", - "\xd0\xa0" => "\xd1\x80", - "\xd0\xa1" => "\xd1\x81", - "\xd0\xa2" => "\xd1\x82", - "\xd0\xa3" => "\xd1\x83", - "\xd0\xa4" => "\xd1\x84", - "\xd0\xa5" => "\xd1\x85", - "\xd0\xa6" => "\xd1\x86", - "\xd0\xa7" => "\xd1\x87", - "\xd0\xa8" => "\xd1\x88", - "\xd0\xa9" => "\xd1\x89", - "\xd0\xaa" => "\xd1\x8a", - "\xd0\xab" => "\xd1\x8b", - "\xd0\xac" => "\xd1\x8c", - "\xd0\xad" => "\xd1\x8d", - "\xd0\xae" => "\xd1\x8e", - "\xd0\xaf" => "\xd1\x8f", - "\xd1\xa0" => "\xd1\xa1", - "\xd1\xa2" => "\xd1\xa3", - "\xd1\xa4" => "\xd1\xa5", - "\xd1\xa6" => "\xd1\xa7", - "\xd1\xa8" => "\xd1\xa9", - "\xd1\xaa" => "\xd1\xab", - "\xd1\xac" => "\xd1\xad", - "\xd1\xae" => "\xd1\xaf", - "\xd1\xb0" => "\xd1\xb1", - "\xd1\xb2" => "\xd1\xb3", - "\xd1\xb4" => "\xd1\xb5", - "\xd1\xb6" => "\xd1\xb7", - "\xd1\xb8" => "\xd1\xb9", - "\xd1\xba" => "\xd1\xbb", - "\xd1\xbc" => "\xd1\xbd", - "\xd1\xbe" => "\xd1\xbf", - "\xd2\x80" => "\xd2\x81", - "\xd2\x8a" => "\xd2\x8b", - "\xd2\x8c" => "\xd2\x8d", - "\xd2\x8e" => "\xd2\x8f", - "\xd2\x90" => "\xd2\x91", - "\xd2\x92" => "\xd2\x93", - "\xd2\x94" => "\xd2\x95", - "\xd2\x96" => "\xd2\x97", - "\xd2\x98" => "\xd2\x99", - "\xd2\x9a" => "\xd2\x9b", - "\xd2\x9c" => "\xd2\x9d", - "\xd2\x9e" => "\xd2\x9f", - "\xd2\xa0" => "\xd2\xa1", - "\xd2\xa2" => "\xd2\xa3", - "\xd2\xa4" => "\xd2\xa5", - "\xd2\xa6" => "\xd2\xa7", - "\xd2\xa8" => "\xd2\xa9", - "\xd2\xaa" => "\xd2\xab", - "\xd2\xac" => "\xd2\xad", - "\xd2\xae" => "\xd2\xaf", - "\xd2\xb0" => "\xd2\xb1", - "\xd2\xb2" => "\xd2\xb3", - "\xd2\xb4" => "\xd2\xb5", - "\xd2\xb6" => "\xd2\xb7", - "\xd2\xb8" => "\xd2\xb9", - "\xd2\xba" => "\xd2\xbb", - "\xd2\xbc" => "\xd2\xbd", - "\xd2\xbe" => "\xd2\xbf", - "\xd3\x81" => "\xd3\x82", - "\xd3\x83" => "\xd3\x84", - "\xd3\x85" => "\xd3\x86", - "\xd3\x87" => "\xd3\x88", - "\xd3\x89" => "\xd3\x8a", - "\xd3\x8b" => "\xd3\x8c", - "\xd3\x8d" => "\xd3\x8e", - "\xd3\x90" => "\xd3\x91", - "\xd3\x92" => "\xd3\x93", - "\xd3\x94" => "\xd3\x95", - "\xd3\x96" => "\xd3\x97", - "\xd3\x98" => "\xd3\x99", - "\xd3\x9a" => "\xd3\x9b", - "\xd3\x9c" => "\xd3\x9d", - "\xd3\x9e" => "\xd3\x9f", - "\xd3\xa0" => "\xd3\xa1", - "\xd3\xa2" => "\xd3\xa3", - "\xd3\xa4" => "\xd3\xa5", - "\xd3\xa6" => "\xd3\xa7", - "\xd3\xa8" => "\xd3\xa9", - "\xd3\xaa" => "\xd3\xab", - "\xd3\xac" => "\xd3\xad", - "\xd3\xae" => "\xd3\xaf", - "\xd3\xb0" => "\xd3\xb1", - "\xd3\xb2" => "\xd3\xb3", - "\xd3\xb4" => "\xd3\xb5", - "\xd3\xb8" => "\xd3\xb9", - "\xd4\x80" => "\xd4\x81", - "\xd4\x82" => "\xd4\x83", - "\xd4\x84" => "\xd4\x85", - "\xd4\x86" => "\xd4\x87", - "\xd4\x88" => "\xd4\x89", - "\xd4\x8a" => "\xd4\x8b", - "\xd4\x8c" => "\xd4\x8d", - "\xd4\x8e" => "\xd4\x8f", - "\xd4\xb1" => "\xd5\xa1", - "\xd4\xb2" => "\xd5\xa2", - "\xd4\xb3" => "\xd5\xa3", - "\xd4\xb4" => "\xd5\xa4", - "\xd4\xb5" => "\xd5\xa5", - "\xd4\xb6" => "\xd5\xa6", - "\xd4\xb7" => "\xd5\xa7", - "\xd4\xb8" => "\xd5\xa8", - "\xd4\xb9" => "\xd5\xa9", - "\xd4\xba" => "\xd5\xaa", - "\xd4\xbb" => "\xd5\xab", - "\xd4\xbc" => "\xd5\xac", - "\xd4\xbd" => "\xd5\xad", - "\xd4\xbe" => "\xd5\xae", - "\xd4\xbf" => "\xd5\xaf", - "\xd5\x80" => "\xd5\xb0", - "\xd5\x81" => "\xd5\xb1", - "\xd5\x82" => "\xd5\xb2", - "\xd5\x83" => "\xd5\xb3", - "\xd5\x84" => "\xd5\xb4", - "\xd5\x85" => "\xd5\xb5", - "\xd5\x86" => "\xd5\xb6", - "\xd5\x87" => "\xd5\xb7", - "\xd5\x88" => "\xd5\xb8", - "\xd5\x89" => "\xd5\xb9", - "\xd5\x8a" => "\xd5\xba", - "\xd5\x8b" => "\xd5\xbb", - "\xd5\x8c" => "\xd5\xbc", - "\xd5\x8d" => "\xd5\xbd", - "\xd5\x8e" => "\xd5\xbe", - "\xd5\x8f" => "\xd5\xbf", - "\xd5\x90" => "\xd6\x80", - "\xd5\x91" => "\xd6\x81", - "\xd5\x92" => "\xd6\x82", - "\xd5\x93" => "\xd6\x83", - "\xd5\x94" => "\xd6\x84", - "\xd5\x95" => "\xd6\x85", - "\xd5\x96" => "\xd6\x86", - "\xe1\xb8\x80" => "\xe1\xb8\x81", - "\xe1\xb8\x82" => "\xe1\xb8\x83", - "\xe1\xb8\x84" => "\xe1\xb8\x85", - "\xe1\xb8\x86" => "\xe1\xb8\x87", - "\xe1\xb8\x88" => "\xe1\xb8\x89", - "\xe1\xb8\x8a" => "\xe1\xb8\x8b", - "\xe1\xb8\x8c" => "\xe1\xb8\x8d", - "\xe1\xb8\x8e" => "\xe1\xb8\x8f", - "\xe1\xb8\x90" => "\xe1\xb8\x91", - "\xe1\xb8\x92" => "\xe1\xb8\x93", - "\xe1\xb8\x94" => "\xe1\xb8\x95", - "\xe1\xb8\x96" => "\xe1\xb8\x97", - "\xe1\xb8\x98" => "\xe1\xb8\x99", - "\xe1\xb8\x9a" => "\xe1\xb8\x9b", - "\xe1\xb8\x9c" => "\xe1\xb8\x9d", - "\xe1\xb8\x9e" => "\xe1\xb8\x9f", - "\xe1\xb8\xa0" => "\xe1\xb8\xa1", - "\xe1\xb8\xa2" => "\xe1\xb8\xa3", - "\xe1\xb8\xa4" => "\xe1\xb8\xa5", - "\xe1\xb8\xa6" => "\xe1\xb8\xa7", - "\xe1\xb8\xa8" => "\xe1\xb8\xa9", - "\xe1\xb8\xaa" => "\xe1\xb8\xab", - "\xe1\xb8\xac" => "\xe1\xb8\xad", - "\xe1\xb8\xae" => "\xe1\xb8\xaf", - "\xe1\xb8\xb0" => "\xe1\xb8\xb1", - "\xe1\xb8\xb2" => "\xe1\xb8\xb3", - "\xe1\xb8\xb4" => "\xe1\xb8\xb5", - "\xe1\xb8\xb6" => "\xe1\xb8\xb7", - "\xe1\xb8\xb8" => "\xe1\xb8\xb9", - "\xe1\xb8\xba" => "\xe1\xb8\xbb", - "\xe1\xb8\xbc" => "\xe1\xb8\xbd", - "\xe1\xb8\xbe" => "\xe1\xb8\xbf", - "\xe1\xb9\x80" => "\xe1\xb9\x81", - "\xe1\xb9\x82" => "\xe1\xb9\x83", - "\xe1\xb9\x84" => "\xe1\xb9\x85", - "\xe1\xb9\x86" => "\xe1\xb9\x87", - "\xe1\xb9\x88" => "\xe1\xb9\x89", - "\xe1\xb9\x8a" => "\xe1\xb9\x8b", - "\xe1\xb9\x8c" => "\xe1\xb9\x8d", - "\xe1\xb9\x8e" => "\xe1\xb9\x8f", - "\xe1\xb9\x90" => "\xe1\xb9\x91", - "\xe1\xb9\x92" => "\xe1\xb9\x93", - "\xe1\xb9\x94" => "\xe1\xb9\x95", - "\xe1\xb9\x96" => "\xe1\xb9\x97", - "\xe1\xb9\x98" => "\xe1\xb9\x99", - "\xe1\xb9\x9a" => "\xe1\xb9\x9b", - "\xe1\xb9\x9c" => "\xe1\xb9\x9d", - "\xe1\xb9\x9e" => "\xe1\xb9\x9f", - "\xe1\xb9\xa0" => "\xe1\xb9\xa1", - "\xe1\xb9\xa2" => "\xe1\xb9\xa3", - "\xe1\xb9\xa4" => "\xe1\xb9\xa5", - "\xe1\xb9\xa6" => "\xe1\xb9\xa7", - "\xe1\xb9\xa8" => "\xe1\xb9\xa9", - "\xe1\xb9\xaa" => "\xe1\xb9\xab", - "\xe1\xb9\xac" => "\xe1\xb9\xad", - "\xe1\xb9\xae" => "\xe1\xb9\xaf", - "\xe1\xb9\xb0" => "\xe1\xb9\xb1", - "\xe1\xb9\xb2" => "\xe1\xb9\xb3", - "\xe1\xb9\xb4" => "\xe1\xb9\xb5", - "\xe1\xb9\xb6" => "\xe1\xb9\xb7", - "\xe1\xb9\xb8" => "\xe1\xb9\xb9", - "\xe1\xb9\xba" => "\xe1\xb9\xbb", - "\xe1\xb9\xbc" => "\xe1\xb9\xbd", - "\xe1\xb9\xbe" => "\xe1\xb9\xbf", - "\xe1\xba\x80" => "\xe1\xba\x81", - "\xe1\xba\x82" => "\xe1\xba\x83", - "\xe1\xba\x84" => "\xe1\xba\x85", - "\xe1\xba\x86" => "\xe1\xba\x87", - "\xe1\xba\x88" => "\xe1\xba\x89", - "\xe1\xba\x8a" => "\xe1\xba\x8b", - "\xe1\xba\x8c" => "\xe1\xba\x8d", - "\xe1\xba\x8e" => "\xe1\xba\x8f", - "\xe1\xba\x90" => "\xe1\xba\x91", - "\xe1\xba\x92" => "\xe1\xba\x93", - "\xe1\xba\x94" => "\xe1\xba\x95", - "\xe1\xba\xa0" => "\xe1\xba\xa1", - "\xe1\xba\xa2" => "\xe1\xba\xa3", - "\xe1\xba\xa4" => "\xe1\xba\xa5", - "\xe1\xba\xa6" => "\xe1\xba\xa7", - "\xe1\xba\xa8" => "\xe1\xba\xa9", - "\xe1\xba\xaa" => "\xe1\xba\xab", - "\xe1\xba\xac" => "\xe1\xba\xad", - "\xe1\xba\xae" => "\xe1\xba\xaf", - "\xe1\xba\xb0" => "\xe1\xba\xb1", - "\xe1\xba\xb2" => "\xe1\xba\xb3", - "\xe1\xba\xb4" => "\xe1\xba\xb5", - "\xe1\xba\xb6" => "\xe1\xba\xb7", - "\xe1\xba\xb8" => "\xe1\xba\xb9", - "\xe1\xba\xba" => "\xe1\xba\xbb", - "\xe1\xba\xbc" => "\xe1\xba\xbd", - "\xe1\xba\xbe" => "\xe1\xba\xbf", - "\xe1\xbb\x80" => "\xe1\xbb\x81", - "\xe1\xbb\x82" => "\xe1\xbb\x83", - "\xe1\xbb\x84" => "\xe1\xbb\x85", - "\xe1\xbb\x86" => "\xe1\xbb\x87", - "\xe1\xbb\x88" => "\xe1\xbb\x89", - "\xe1\xbb\x8a" => "\xe1\xbb\x8b", - "\xe1\xbb\x8c" => "\xe1\xbb\x8d", - "\xe1\xbb\x8e" => "\xe1\xbb\x8f", - "\xe1\xbb\x90" => "\xe1\xbb\x91", - "\xe1\xbb\x92" => "\xe1\xbb\x93", - "\xe1\xbb\x94" => "\xe1\xbb\x95", - "\xe1\xbb\x96" => "\xe1\xbb\x97", - "\xe1\xbb\x98" => "\xe1\xbb\x99", - "\xe1\xbb\x9a" => "\xe1\xbb\x9b", - "\xe1\xbb\x9c" => "\xe1\xbb\x9d", - "\xe1\xbb\x9e" => "\xe1\xbb\x9f", - "\xe1\xbb\xa0" => "\xe1\xbb\xa1", - "\xe1\xbb\xa2" => "\xe1\xbb\xa3", - "\xe1\xbb\xa4" => "\xe1\xbb\xa5", - "\xe1\xbb\xa6" => "\xe1\xbb\xa7", - "\xe1\xbb\xa8" => "\xe1\xbb\xa9", - "\xe1\xbb\xaa" => "\xe1\xbb\xab", - "\xe1\xbb\xac" => "\xe1\xbb\xad", - "\xe1\xbb\xae" => "\xe1\xbb\xaf", - "\xe1\xbb\xb0" => "\xe1\xbb\xb1", - "\xe1\xbb\xb2" => "\xe1\xbb\xb3", - "\xe1\xbb\xb4" => "\xe1\xbb\xb5", - "\xe1\xbb\xb6" => "\xe1\xbb\xb7", - "\xe1\xbb\xb8" => "\xe1\xbb\xb9", - "\xe1\xbc\x88" => "\xe1\xbc\x80", - "\xe1\xbc\x89" => "\xe1\xbc\x81", - "\xe1\xbc\x8a" => "\xe1\xbc\x82", - "\xe1\xbc\x8b" => "\xe1\xbc\x83", - "\xe1\xbc\x8c" => "\xe1\xbc\x84", - "\xe1\xbc\x8d" => "\xe1\xbc\x85", - "\xe1\xbc\x8e" => "\xe1\xbc\x86", - "\xe1\xbc\x8f" => "\xe1\xbc\x87", - "\xe1\xbc\x98" => "\xe1\xbc\x90", - "\xe1\xbc\x99" => "\xe1\xbc\x91", - "\xe1\xbc\x9a" => "\xe1\xbc\x92", - "\xe1\xbc\x9b" => "\xe1\xbc\x93", - "\xe1\xbc\x9c" => "\xe1\xbc\x94", - "\xe1\xbc\x9d" => "\xe1\xbc\x95", - "\xe1\xbc\xa9" => "\xe1\xbc\xa1", - "\xe1\xbc\xaa" => "\xe1\xbc\xa2", - "\xe1\xbc\xab" => "\xe1\xbc\xa3", - "\xe1\xbc\xac" => "\xe1\xbc\xa4", - "\xe1\xbc\xad" => "\xe1\xbc\xa5", - "\xe1\xbc\xae" => "\xe1\xbc\xa6", - "\xe1\xbc\xaf" => "\xe1\xbc\xa7", - "\xe1\xbc\xb8" => "\xe1\xbc\xb0", - "\xe1\xbc\xb9" => "\xe1\xbc\xb1", - "\xe1\xbc\xba" => "\xe1\xbc\xb2", - "\xe1\xbc\xbb" => "\xe1\xbc\xb3", - "\xe1\xbc\xbc" => "\xe1\xbc\xb4", - "\xe1\xbc\xbd" => "\xe1\xbc\xb5", - "\xe1\xbc\xbe" => "\xe1\xbc\xb6", - "\xe1\xbc\xbf" => "\xe1\xbc\xb7", - "\xe1\xbd\x88" => "\xe1\xbd\x80", - "\xe1\xbd\x89" => "\xe1\xbd\x81", - "\xe1\xbd\x8a" => "\xe1\xbd\x82", - "\xe1\xbd\x8b" => "\xe1\xbd\x83", - "\xe1\xbd\x8c" => "\xe1\xbd\x84", - "\xe1\xbd\x8d" => "\xe1\xbd\x85", - "\xe1\xbd\x99" => "\xe1\xbd\x91", - "\xe1\xbd\x9b" => "\xe1\xbd\x93", - "\xe1\xbd\x9d" => "\xe1\xbd\x95", - "\xe1\xbd\x9f" => "\xe1\xbd\x97", - "\xe1\xbd\xa9" => "\xe1\xbd\xa1", - "\xe1\xbd\xaa" => "\xe1\xbd\xa2", - "\xe1\xbd\xab" => "\xe1\xbd\xa3", - "\xe1\xbd\xac" => "\xe1\xbd\xa4", - "\xe1\xbd\xad" => "\xe1\xbd\xa5", - "\xe1\xbd\xae" => "\xe1\xbd\xa6", - "\xe1\xbd\xaf" => "\xe1\xbd\xa7", - "\xe1\xbe\x88" => "\xe1\xbe\x80", - "\xe1\xbe\x89" => "\xe1\xbe\x81", - "\xe1\xbe\x8a" => "\xe1\xbe\x82", - "\xe1\xbe\x8b" => "\xe1\xbe\x83", - "\xe1\xbe\x8c" => "\xe1\xbe\x84", - "\xe1\xbe\x8d" => "\xe1\xbe\x85", - "\xe1\xbe\x8e" => "\xe1\xbe\x86", - "\xe1\xbe\x8f" => "\xe1\xbe\x87", - "\xe1\xbe\x98" => "\xe1\xbe\x90", - "\xe1\xbe\x99" => "\xe1\xbe\x91", - "\xe1\xbe\x9a" => "\xe1\xbe\x92", - "\xe1\xbe\x9b" => "\xe1\xbe\x93", - "\xe1\xbe\x9c" => "\xe1\xbe\x94", - "\xe1\xbe\x9d" => "\xe1\xbe\x95", - "\xe1\xbe\x9e" => "\xe1\xbe\x96", - "\xe1\xbe\x9f" => "\xe1\xbe\x97", - "\xe1\xbe\xa9" => "\xe1\xbe\xa1", - "\xe1\xbe\xaa" => "\xe1\xbe\xa2", - "\xe1\xbe\xab" => "\xe1\xbe\xa3", - "\xe1\xbe\xac" => "\xe1\xbe\xa4", - "\xe1\xbe\xad" => "\xe1\xbe\xa5", - "\xe1\xbe\xae" => "\xe1\xbe\xa6", - "\xe1\xbe\xaf" => "\xe1\xbe\xa7", - "\xe1\xbe\xb8" => "\xe1\xbe\xb0", - "\xe1\xbe\xb9" => "\xe1\xbe\xb1", - "\xe1\xbe\xba" => "\xe1\xbd\xb0", - "\xe1\xbe\xbb" => "\xe1\xbd\xb1", - "\xe1\xbe\xbc" => "\xe1\xbe\xb3", - "\xe1\xbf\x88" => "\xe1\xbd\xb2", - "\xe1\xbf\x89" => "\xe1\xbd\xb3", - "\xe1\xbf\x8a" => "\xe1\xbd\xb4", - "\xe1\xbf\x8b" => "\xe1\xbd\xb5", - "\xe1\xbf\x8c" => "\xe1\xbf\x83", - "\xe1\xbf\x98" => "\xe1\xbf\x90", - "\xe1\xbf\x99" => "\xe1\xbf\x91", - "\xe1\xbf\x9a" => "\xe1\xbd\xb6", - "\xe1\xbf\x9b" => "\xe1\xbd\xb7", - "\xe1\xbf\xa9" => "\xe1\xbf\xa1", - "\xe1\xbf\xaa" => "\xe1\xbd\xba", - "\xe1\xbf\xab" => "\xe1\xbd\xbb", - "\xe1\xbf\xac" => "\xe1\xbf\xa5", - "\xe1\xbf\xb8" => "\xe1\xbd\xb8", - "\xe1\xbf\xb9" => "\xe1\xbd\xb9", - "\xe1\xbf\xba" => "\xe1\xbd\xbc", - "\xe1\xbf\xbb" => "\xe1\xbd\xbd", - "\xe1\xbf\xbc" => "\xe1\xbf\xb3", - "\xef\xbc\xa1" => "\xef\xbd\x81", - "\xef\xbc\xa2" => "\xef\xbd\x82", - "\xef\xbc\xa3" => "\xef\xbd\x83", - "\xef\xbc\xa4" => "\xef\xbd\x84", - "\xef\xbc\xa5" => "\xef\xbd\x85", - "\xef\xbc\xa6" => "\xef\xbd\x86", - "\xef\xbc\xa7" => "\xef\xbd\x87", - "\xef\xbc\xa8" => "\xef\xbd\x88", - "\xef\xbc\xa9" => "\xef\xbd\x89", - "\xef\xbc\xaa" => "\xef\xbd\x8a", - "\xef\xbc\xab" => "\xef\xbd\x8b", - "\xef\xbc\xac" => "\xef\xbd\x8c", - "\xef\xbc\xad" => "\xef\xbd\x8d", - "\xef\xbc\xae" => "\xef\xbd\x8e", - "\xef\xbc\xaf" => "\xef\xbd\x8f", - "\xef\xbc\xb0" => "\xef\xbd\x90", - "\xef\xbc\xb1" => "\xef\xbd\x91", - "\xef\xbc\xb2" => "\xef\xbd\x92", - "\xef\xbc\xb3" => "\xef\xbd\x93", - "\xef\xbc\xb4" => "\xef\xbd\x94", - "\xef\xbc\xb5" => "\xef\xbd\x95", - "\xef\xbc\xb6" => "\xef\xbd\x96", - "\xef\xbc\xb7" => "\xef\xbd\x97", - "\xef\xbc\xb8" => "\xef\xbd\x98", - "\xef\xbc\xb9" => "\xef\xbd\x99", - "\xef\xbc\xba" => "\xef\xbd\x9a", - ); - - #Unicode Character Database 6.0.0 (2010-06-04) - #autogenerated by unicode_blocks_txt2php() PHP function at 2011-06-04 00:19:39, 209 blocks total - public static $unicode_blocks = array( - 'Basic Latin' => array( - 0 => 0x0000, - 1 => 0x007F, - 2 => 0, - ), - 'Latin-1 Supplement' => array( - 0 => 0x0080, - 1 => 0x00FF, - 2 => 1, - ), - 'Latin Extended-A' => array( - 0 => 0x0100, - 1 => 0x017F, - 2 => 2, - ), - 'Latin Extended-B' => array( - 0 => 0x0180, - 1 => 0x024F, - 2 => 3, - ), - 'IPA Extensions' => array( - 0 => 0x0250, - 1 => 0x02AF, - 2 => 4, - ), - 'Spacing Modifier Letters' => array( - 0 => 0x02B0, - 1 => 0x02FF, - 2 => 5, - ), - 'Combining Diacritical Marks' => array( - 0 => 0x0300, - 1 => 0x036F, - 2 => 6, - ), - 'Greek and Coptic' => array( - 0 => 0x0370, - 1 => 0x03FF, - 2 => 7, - ), - 'Cyrillic' => array( - 0 => 0x0400, - 1 => 0x04FF, - 2 => 8, - ), - 'Cyrillic Supplement' => array( - 0 => 0x0500, - 1 => 0x052F, - 2 => 9, - ), - 'Armenian' => array( - 0 => 0x0530, - 1 => 0x058F, - 2 => 10, - ), - 'Hebrew' => array( - 0 => 0x0590, - 1 => 0x05FF, - 2 => 11, - ), - 'Arabic' => array( - 0 => 0x0600, - 1 => 0x06FF, - 2 => 12, - ), - 'Syriac' => array( - 0 => 0x0700, - 1 => 0x074F, - 2 => 13, - ), - 'Arabic Supplement' => array( - 0 => 0x0750, - 1 => 0x077F, - 2 => 14, - ), - 'Thaana' => array( - 0 => 0x0780, - 1 => 0x07BF, - 2 => 15, - ), - 'NKo' => array( - 0 => 0x07C0, - 1 => 0x07FF, - 2 => 16, - ), - 'Samaritan' => array( - 0 => 0x0800, - 1 => 0x083F, - 2 => 17, - ), - 'Mandaic' => array( - 0 => 0x0840, - 1 => 0x085F, - 2 => 18, - ), - 'Devanagari' => array( - 0 => 0x0900, - 1 => 0x097F, - 2 => 19, - ), - 'Bengali' => array( - 0 => 0x0980, - 1 => 0x09FF, - 2 => 20, - ), - 'Gurmukhi' => array( - 0 => 0x0A00, - 1 => 0x0A7F, - 2 => 21, - ), - 'Gujarati' => array( - 0 => 0x0A80, - 1 => 0x0AFF, - 2 => 22, - ), - 'Oriya' => array( - 0 => 0x0B00, - 1 => 0x0B7F, - 2 => 23, - ), - 'Tamil' => array( - 0 => 0x0B80, - 1 => 0x0BFF, - 2 => 24, - ), - 'Telugu' => array( - 0 => 0x0C00, - 1 => 0x0C7F, - 2 => 25, - ), - 'Kannada' => array( - 0 => 0x0C80, - 1 => 0x0CFF, - 2 => 26, - ), - 'Malayalam' => array( - 0 => 0x0D00, - 1 => 0x0D7F, - 2 => 27, - ), - 'Sinhala' => array( - 0 => 0x0D80, - 1 => 0x0DFF, - 2 => 28, - ), - 'Thai' => array( - 0 => 0x0E00, - 1 => 0x0E7F, - 2 => 29, - ), - 'Lao' => array( - 0 => 0x0E80, - 1 => 0x0EFF, - 2 => 30, - ), - 'Tibetan' => array( - 0 => 0x0F00, - 1 => 0x0FFF, - 2 => 31, - ), - 'Myanmar' => array( - 0 => 0x1000, - 1 => 0x109F, - 2 => 32, - ), - 'Georgian' => array( - 0 => 0x10A0, - 1 => 0x10FF, - 2 => 33, - ), - 'Hangul Jamo' => array( - 0 => 0x1100, - 1 => 0x11FF, - 2 => 34, - ), - 'Ethiopic' => array( - 0 => 0x1200, - 1 => 0x137F, - 2 => 35, - ), - 'Ethiopic Supplement' => array( - 0 => 0x1380, - 1 => 0x139F, - 2 => 36, - ), - 'Cherokee' => array( - 0 => 0x13A0, - 1 => 0x13FF, - 2 => 37, - ), - 'Unified Canadian Aboriginal Syllabics' => array( - 0 => 0x1400, - 1 => 0x167F, - 2 => 38, - ), - 'Ogham' => array( - 0 => 0x1680, - 1 => 0x169F, - 2 => 39, - ), - 'Runic' => array( - 0 => 0x16A0, - 1 => 0x16FF, - 2 => 40, - ), - 'Tagalog' => array( - 0 => 0x1700, - 1 => 0x171F, - 2 => 41, - ), - 'Hanunoo' => array( - 0 => 0x1720, - 1 => 0x173F, - 2 => 42, - ), - 'Buhid' => array( - 0 => 0x1740, - 1 => 0x175F, - 2 => 43, - ), - 'Tagbanwa' => array( - 0 => 0x1760, - 1 => 0x177F, - 2 => 44, - ), - 'Khmer' => array( - 0 => 0x1780, - 1 => 0x17FF, - 2 => 45, - ), - 'Mongolian' => array( - 0 => 0x1800, - 1 => 0x18AF, - 2 => 46, - ), - 'Unified Canadian Aboriginal Syllabics Extended' => array( - 0 => 0x18B0, - 1 => 0x18FF, - 2 => 47, - ), - 'Limbu' => array( - 0 => 0x1900, - 1 => 0x194F, - 2 => 48, - ), - 'Tai Le' => array( - 0 => 0x1950, - 1 => 0x197F, - 2 => 49, - ), - 'New Tai Lue' => array( - 0 => 0x1980, - 1 => 0x19DF, - 2 => 50, - ), - 'Khmer Symbols' => array( - 0 => 0x19E0, - 1 => 0x19FF, - 2 => 51, - ), - 'Buginese' => array( - 0 => 0x1A00, - 1 => 0x1A1F, - 2 => 52, - ), - 'Tai Tham' => array( - 0 => 0x1A20, - 1 => 0x1AAF, - 2 => 53, - ), - 'Balinese' => array( - 0 => 0x1B00, - 1 => 0x1B7F, - 2 => 54, - ), - 'Sundanese' => array( - 0 => 0x1B80, - 1 => 0x1BBF, - 2 => 55, - ), - 'Batak' => array( - 0 => 0x1BC0, - 1 => 0x1BFF, - 2 => 56, - ), - 'Lepcha' => array( - 0 => 0x1C00, - 1 => 0x1C4F, - 2 => 57, - ), - 'Ol Chiki' => array( - 0 => 0x1C50, - 1 => 0x1C7F, - 2 => 58, - ), - 'Vedic Extensions' => array( - 0 => 0x1CD0, - 1 => 0x1CFF, - 2 => 59, - ), - 'Phonetic Extensions' => array( - 0 => 0x1D00, - 1 => 0x1D7F, - 2 => 60, - ), - 'Phonetic Extensions Supplement' => array( - 0 => 0x1D80, - 1 => 0x1DBF, - 2 => 61, - ), - 'Combining Diacritical Marks Supplement' => array( - 0 => 0x1DC0, - 1 => 0x1DFF, - 2 => 62, - ), - 'Latin Extended Additional' => array( - 0 => 0x1E00, - 1 => 0x1EFF, - 2 => 63, - ), - 'Greek Extended' => array( - 0 => 0x1F00, - 1 => 0x1FFF, - 2 => 64, - ), - 'General Punctuation' => array( - 0 => 0x2000, - 1 => 0x206F, - 2 => 65, - ), - 'Superscripts and Subscripts' => array( - 0 => 0x2070, - 1 => 0x209F, - 2 => 66, - ), - 'Currency Symbols' => array( - 0 => 0x20A0, - 1 => 0x20CF, - 2 => 67, - ), - 'Combining Diacritical Marks for Symbols' => array( - 0 => 0x20D0, - 1 => 0x20FF, - 2 => 68, - ), - 'Letterlike Symbols' => array( - 0 => 0x2100, - 1 => 0x214F, - 2 => 69, - ), - 'Number Forms' => array( - 0 => 0x2150, - 1 => 0x218F, - 2 => 70, - ), - 'Arrows' => array( - 0 => 0x2190, - 1 => 0x21FF, - 2 => 71, - ), - 'Mathematical Operators' => array( - 0 => 0x2200, - 1 => 0x22FF, - 2 => 72, - ), - 'Miscellaneous Technical' => array( - 0 => 0x2300, - 1 => 0x23FF, - 2 => 73, - ), - 'Control Pictures' => array( - 0 => 0x2400, - 1 => 0x243F, - 2 => 74, - ), - 'Optical Character Recognition' => array( - 0 => 0x2440, - 1 => 0x245F, - 2 => 75, - ), - 'Enclosed Alphanumerics' => array( - 0 => 0x2460, - 1 => 0x24FF, - 2 => 76, - ), - 'Box Drawing' => array( - 0 => 0x2500, - 1 => 0x257F, - 2 => 77, - ), - 'Block Elements' => array( - 0 => 0x2580, - 1 => 0x259F, - 2 => 78, - ), - 'Geometric Shapes' => array( - 0 => 0x25A0, - 1 => 0x25FF, - 2 => 79, - ), - 'Miscellaneous Symbols' => array( - 0 => 0x2600, - 1 => 0x26FF, - 2 => 80, - ), - 'Dingbats' => array( - 0 => 0x2700, - 1 => 0x27BF, - 2 => 81, - ), - 'Miscellaneous Mathematical Symbols-A' => array( - 0 => 0x27C0, - 1 => 0x27EF, - 2 => 82, - ), - 'Supplemental Arrows-A' => array( - 0 => 0x27F0, - 1 => 0x27FF, - 2 => 83, - ), - 'Braille Patterns' => array( - 0 => 0x2800, - 1 => 0x28FF, - 2 => 84, - ), - 'Supplemental Arrows-B' => array( - 0 => 0x2900, - 1 => 0x297F, - 2 => 85, - ), - 'Miscellaneous Mathematical Symbols-B' => array( - 0 => 0x2980, - 1 => 0x29FF, - 2 => 86, - ), - 'Supplemental Mathematical Operators' => array( - 0 => 0x2A00, - 1 => 0x2AFF, - 2 => 87, - ), - 'Miscellaneous Symbols and Arrows' => array( - 0 => 0x2B00, - 1 => 0x2BFF, - 2 => 88, - ), - 'Glagolitic' => array( - 0 => 0x2C00, - 1 => 0x2C5F, - 2 => 89, - ), - 'Latin Extended-C' => array( - 0 => 0x2C60, - 1 => 0x2C7F, - 2 => 90, - ), - 'Coptic' => array( - 0 => 0x2C80, - 1 => 0x2CFF, - 2 => 91, - ), - 'Georgian Supplement' => array( - 0 => 0x2D00, - 1 => 0x2D2F, - 2 => 92, - ), - 'Tifinagh' => array( - 0 => 0x2D30, - 1 => 0x2D7F, - 2 => 93, - ), - 'Ethiopic Extended' => array( - 0 => 0x2D80, - 1 => 0x2DDF, - 2 => 94, - ), - 'Cyrillic Extended-A' => array( - 0 => 0x2DE0, - 1 => 0x2DFF, - 2 => 95, - ), - 'Supplemental Punctuation' => array( - 0 => 0x2E00, - 1 => 0x2E7F, - 2 => 96, - ), - 'CJK Radicals Supplement' => array( - 0 => 0x2E80, - 1 => 0x2EFF, - 2 => 97, - ), - 'Kangxi Radicals' => array( - 0 => 0x2F00, - 1 => 0x2FDF, - 2 => 98, - ), - 'Ideographic Description Characters' => array( - 0 => 0x2FF0, - 1 => 0x2FFF, - 2 => 99, - ), - 'CJK Symbols and Punctuation' => array( - 0 => 0x3000, - 1 => 0x303F, - 2 => 100, - ), - 'Hiragana' => array( - 0 => 0x3040, - 1 => 0x309F, - 2 => 101, - ), - 'Katakana' => array( - 0 => 0x30A0, - 1 => 0x30FF, - 2 => 102, - ), - 'Bopomofo' => array( - 0 => 0x3100, - 1 => 0x312F, - 2 => 103, - ), - 'Hangul Compatibility Jamo' => array( - 0 => 0x3130, - 1 => 0x318F, - 2 => 104, - ), - 'Kanbun' => array( - 0 => 0x3190, - 1 => 0x319F, - 2 => 105, - ), - 'Bopomofo Extended' => array( - 0 => 0x31A0, - 1 => 0x31BF, - 2 => 106, - ), - 'CJK Strokes' => array( - 0 => 0x31C0, - 1 => 0x31EF, - 2 => 107, - ), - 'Katakana Phonetic Extensions' => array( - 0 => 0x31F0, - 1 => 0x31FF, - 2 => 108, - ), - 'Enclosed CJK Letters and Months' => array( - 0 => 0x3200, - 1 => 0x32FF, - 2 => 109, - ), - 'CJK Compatibility' => array( - 0 => 0x3300, - 1 => 0x33FF, - 2 => 110, - ), - 'CJK Unified Ideographs Extension A' => array( - 0 => 0x3400, - 1 => 0x4DBF, - 2 => 111, - ), - 'Yijing Hexagram Symbols' => array( - 0 => 0x4DC0, - 1 => 0x4DFF, - 2 => 112, - ), - 'CJK Unified Ideographs' => array( - 0 => 0x4E00, - 1 => 0x9FFF, - 2 => 113, - ), - 'Yi Syllables' => array( - 0 => 0xA000, - 1 => 0xA48F, - 2 => 114, - ), - 'Yi Radicals' => array( - 0 => 0xA490, - 1 => 0xA4CF, - 2 => 115, - ), - 'Lisu' => array( - 0 => 0xA4D0, - 1 => 0xA4FF, - 2 => 116, - ), - 'Vai' => array( - 0 => 0xA500, - 1 => 0xA63F, - 2 => 117, - ), - 'Cyrillic Extended-B' => array( - 0 => 0xA640, - 1 => 0xA69F, - 2 => 118, - ), - 'Bamum' => array( - 0 => 0xA6A0, - 1 => 0xA6FF, - 2 => 119, - ), - 'Modifier Tone Letters' => array( - 0 => 0xA700, - 1 => 0xA71F, - 2 => 120, - ), - 'Latin Extended-D' => array( - 0 => 0xA720, - 1 => 0xA7FF, - 2 => 121, - ), - 'Syloti Nagri' => array( - 0 => 0xA800, - 1 => 0xA82F, - 2 => 122, - ), - 'Common Indic Number Forms' => array( - 0 => 0xA830, - 1 => 0xA83F, - 2 => 123, - ), - 'Phags-pa' => array( - 0 => 0xA840, - 1 => 0xA87F, - 2 => 124, - ), - 'Saurashtra' => array( - 0 => 0xA880, - 1 => 0xA8DF, - 2 => 125, - ), - 'Devanagari Extended' => array( - 0 => 0xA8E0, - 1 => 0xA8FF, - 2 => 126, - ), - 'Kayah Li' => array( - 0 => 0xA900, - 1 => 0xA92F, - 2 => 127, - ), - 'Rejang' => array( - 0 => 0xA930, - 1 => 0xA95F, - 2 => 128, - ), - 'Hangul Jamo Extended-A' => array( - 0 => 0xA960, - 1 => 0xA97F, - 2 => 129, - ), - 'Javanese' => array( - 0 => 0xA980, - 1 => 0xA9DF, - 2 => 130, - ), - 'Cham' => array( - 0 => 0xAA00, - 1 => 0xAA5F, - 2 => 131, - ), - 'Myanmar Extended-A' => array( - 0 => 0xAA60, - 1 => 0xAA7F, - 2 => 132, - ), - 'Tai Viet' => array( - 0 => 0xAA80, - 1 => 0xAADF, - 2 => 133, - ), - 'Ethiopic Extended-A' => array( - 0 => 0xAB00, - 1 => 0xAB2F, - 2 => 134, - ), - 'Meetei Mayek' => array( - 0 => 0xABC0, - 1 => 0xABFF, - 2 => 135, - ), - 'Hangul Syllables' => array( - 0 => 0xAC00, - 1 => 0xD7AF, - 2 => 136, - ), - 'Hangul Jamo Extended-B' => array( - 0 => 0xD7B0, - 1 => 0xD7FF, - 2 => 137, - ), - 'High Surrogates' => array( - 0 => 0xD800, - 1 => 0xDB7F, - 2 => 138, - ), - 'High Private Use Surrogates' => array( - 0 => 0xDB80, - 1 => 0xDBFF, - 2 => 139, - ), - 'Low Surrogates' => array( - 0 => 0xDC00, - 1 => 0xDFFF, - 2 => 140, - ), - 'Private Use Area' => array( - 0 => 0xE000, - 1 => 0xF8FF, - 2 => 141, - ), - 'CJK Compatibility Ideographs' => array( - 0 => 0xF900, - 1 => 0xFAFF, - 2 => 142, - ), - 'Alphabetic Presentation Forms' => array( - 0 => 0xFB00, - 1 => 0xFB4F, - 2 => 143, - ), - 'Arabic Presentation Forms-A' => array( - 0 => 0xFB50, - 1 => 0xFDFF, - 2 => 144, - ), - 'Variation Selectors' => array( - 0 => 0xFE00, - 1 => 0xFE0F, - 2 => 145, - ), - 'Vertical Forms' => array( - 0 => 0xFE10, - 1 => 0xFE1F, - 2 => 146, - ), - 'Combining Half Marks' => array( - 0 => 0xFE20, - 1 => 0xFE2F, - 2 => 147, - ), - 'CJK Compatibility Forms' => array( - 0 => 0xFE30, - 1 => 0xFE4F, - 2 => 148, - ), - 'Small Form Variants' => array( - 0 => 0xFE50, - 1 => 0xFE6F, - 2 => 149, - ), - 'Arabic Presentation Forms-B' => array( - 0 => 0xFE70, - 1 => 0xFEFF, - 2 => 150, - ), - 'Halfwidth and Fullwidth Forms' => array( - 0 => 0xFF00, - 1 => 0xFFEF, - 2 => 151, - ), - 'Specials' => array( - 0 => 0xFFF0, - 1 => 0xFFFF, - 2 => 152, - ), - 'Linear B Syllabary' => array( - 0 => 0x10000, - 1 => 0x1007F, - 2 => 153, - ), - 'Linear B Ideograms' => array( - 0 => 0x10080, - 1 => 0x100FF, - 2 => 154, - ), - 'Aegean Numbers' => array( - 0 => 0x10100, - 1 => 0x1013F, - 2 => 155, - ), - 'Ancient Greek Numbers' => array( - 0 => 0x10140, - 1 => 0x1018F, - 2 => 156, - ), - 'Ancient Symbols' => array( - 0 => 0x10190, - 1 => 0x101CF, - 2 => 157, - ), - 'Phaistos Disc' => array( - 0 => 0x101D0, - 1 => 0x101FF, - 2 => 158, - ), - 'Lycian' => array( - 0 => 0x10280, - 1 => 0x1029F, - 2 => 159, - ), - 'Carian' => array( - 0 => 0x102A0, - 1 => 0x102DF, - 2 => 160, - ), - 'Old Italic' => array( - 0 => 0x10300, - 1 => 0x1032F, - 2 => 161, - ), - 'Gothic' => array( - 0 => 0x10330, - 1 => 0x1034F, - 2 => 162, - ), - 'Ugaritic' => array( - 0 => 0x10380, - 1 => 0x1039F, - 2 => 163, - ), - 'Old Persian' => array( - 0 => 0x103A0, - 1 => 0x103DF, - 2 => 164, - ), - 'Deseret' => array( - 0 => 0x10400, - 1 => 0x1044F, - 2 => 165, - ), - 'Shavian' => array( - 0 => 0x10450, - 1 => 0x1047F, - 2 => 166, - ), - 'Osmanya' => array( - 0 => 0x10480, - 1 => 0x104AF, - 2 => 167, - ), - 'Cypriot Syllabary' => array( - 0 => 0x10800, - 1 => 0x1083F, - 2 => 168, - ), - 'Imperial Aramaic' => array( - 0 => 0x10840, - 1 => 0x1085F, - 2 => 169, - ), - 'Phoenician' => array( - 0 => 0x10900, - 1 => 0x1091F, - 2 => 170, - ), - 'Lydian' => array( - 0 => 0x10920, - 1 => 0x1093F, - 2 => 171, - ), - 'Kharoshthi' => array( - 0 => 0x10A00, - 1 => 0x10A5F, - 2 => 172, - ), - 'Old South Arabian' => array( - 0 => 0x10A60, - 1 => 0x10A7F, - 2 => 173, - ), - 'Avestan' => array( - 0 => 0x10B00, - 1 => 0x10B3F, - 2 => 174, - ), - 'Inscriptional Parthian' => array( - 0 => 0x10B40, - 1 => 0x10B5F, - 2 => 175, - ), - 'Inscriptional Pahlavi' => array( - 0 => 0x10B60, - 1 => 0x10B7F, - 2 => 176, - ), - 'Old Turkic' => array( - 0 => 0x10C00, - 1 => 0x10C4F, - 2 => 177, - ), - 'Rumi Numeral Symbols' => array( - 0 => 0x10E60, - 1 => 0x10E7F, - 2 => 178, - ), - 'Brahmi' => array( - 0 => 0x11000, - 1 => 0x1107F, - 2 => 179, - ), - 'Kaithi' => array( - 0 => 0x11080, - 1 => 0x110CF, - 2 => 180, - ), - 'Cuneiform' => array( - 0 => 0x12000, - 1 => 0x123FF, - 2 => 181, - ), - 'Cuneiform Numbers and Punctuation' => array( - 0 => 0x12400, - 1 => 0x1247F, - 2 => 182, - ), - 'Egyptian Hieroglyphs' => array( - 0 => 0x13000, - 1 => 0x1342F, - 2 => 183, - ), - 'Bamum Supplement' => array( - 0 => 0x16800, - 1 => 0x16A3F, - 2 => 184, - ), - 'Kana Supplement' => array( - 0 => 0x1B000, - 1 => 0x1B0FF, - 2 => 185, - ), - 'Byzantine Musical Symbols' => array( - 0 => 0x1D000, - 1 => 0x1D0FF, - 2 => 186, - ), - 'Musical Symbols' => array( - 0 => 0x1D100, - 1 => 0x1D1FF, - 2 => 187, - ), - 'Ancient Greek Musical Notation' => array( - 0 => 0x1D200, - 1 => 0x1D24F, - 2 => 188, - ), - 'Tai Xuan Jing Symbols' => array( - 0 => 0x1D300, - 1 => 0x1D35F, - 2 => 189, - ), - 'Counting Rod Numerals' => array( - 0 => 0x1D360, - 1 => 0x1D37F, - 2 => 190, - ), - 'Mathematical Alphanumeric Symbols' => array( - 0 => 0x1D400, - 1 => 0x1D7FF, - 2 => 191, - ), - 'Mahjong Tiles' => array( - 0 => 0x1F000, - 1 => 0x1F02F, - 2 => 192, - ), - 'Domino Tiles' => array( - 0 => 0x1F030, - 1 => 0x1F09F, - 2 => 193, - ), - 'Playing Cards' => array( - 0 => 0x1F0A0, - 1 => 0x1F0FF, - 2 => 194, - ), - 'Enclosed Alphanumeric Supplement' => array( - 0 => 0x1F100, - 1 => 0x1F1FF, - 2 => 195, - ), - 'Enclosed Ideographic Supplement' => array( - 0 => 0x1F200, - 1 => 0x1F2FF, - 2 => 196, - ), - 'Miscellaneous Symbols And Pictographs' => array( - 0 => 0x1F300, - 1 => 0x1F5FF, - 2 => 197, - ), - 'Emoticons' => array( - 0 => 0x1F600, - 1 => 0x1F64F, - 2 => 198, - ), - 'Transport And Map Symbols' => array( - 0 => 0x1F680, - 1 => 0x1F6FF, - 2 => 199, - ), - 'Alchemical Symbols' => array( - 0 => 0x1F700, - 1 => 0x1F77F, - 2 => 200, - ), - 'CJK Unified Ideographs Extension B' => array( - 0 => 0x20000, - 1 => 0x2A6DF, - 2 => 201, - ), - 'CJK Unified Ideographs Extension C' => array( - 0 => 0x2A700, - 1 => 0x2B73F, - 2 => 202, - ), - 'CJK Unified Ideographs Extension D' => array( - 0 => 0x2B740, - 1 => 0x2B81F, - 2 => 203, - ), - 'CJK Compatibility Ideographs Supplement' => array( - 0 => 0x2F800, - 1 => 0x2FA1F, - 2 => 204, - ), - 'Tags' => array( - 0 => 0xE0000, - 1 => 0xE007F, - 2 => 205, - ), - 'Variation Selectors Supplement' => array( - 0 => 0xE0100, - 1 => 0xE01EF, - 2 => 206, - ), - 'Supplementary Private Use Area-A' => array( - 0 => 0xF0000, - 1 => 0xFFFFF, - 2 => 207, - ), - 'Supplementary Private Use Area-B' => array( - 0 => 0x100000, - 1 => 0x10FFFF, - 2 => 208, - ), - ); - - #calling the methods of this class only statically! - private function __construct() {} - - /** - * Remove combining diactrical marks, with possibility of the restore - * Удаляет диакритические знаки в тексте, с возможностью восстановления (опция) - * - * @param string|null $s - * @param array|null $additional_chars for example: "\xc2\xad" #soft hyphen = discretionary hyphen - * @param bool $is_can_restored - * @param array|null &$restore_table - * @return string|bool|null Returns FALSE if error occurred - */ - public static function diactrical_remove($s, $additional_chars = null, $is_can_restored = false, &$restore_table = null) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - if ($additional_chars) - { - foreach ($additional_chars as $k => &$v) $v = preg_quote($v, '/'); - $re = '/((?>' . self::$diactrical_re . '|' . implode('|', $additional_chars) . ')+)/sxSX'; - } - else $re = '/((?>' . self::$diactrical_re . ')+)/sxSX'; - if (! $is_can_restored) return preg_replace($re, '', $s); - - $restore_table = array(); - $a = preg_split($re, $s, -1, PREG_SPLIT_DELIM_CAPTURE); - $c = count($a); - if ($c === 1) return $s; - $pos = 0; - $s2 = ''; - for ($i = 0; $i < $c - 1; $i += 2) - { - $s2 .= $a[$i]; - #запоминаем символьные (не байтовые!) позиции - $pos += self::strlen($a[$i]); - $restore_table['offsets'][$pos] = $a[$i + 1]; - } - $restore_table['length'] = $pos + self::strlen(end($a)); - return $s2 . end($a); - } - - /** - * Restore combining diactrical marks, removed by self::diactrical_remove() - * In Russian: - * Восстанавливает диакритические знаки в тексте, при условии, что их символьные позиции и кол-во символов не изменились! - * - * @see self::diactrical_remove() - * @param string|null $s - * @param array $restore_table - * @return string|bool|null Returns FALSE if error occurred (broken $restore_table) - */ - public static function diactrical_restore($s, array $restore_table) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - if (! $restore_table) return $s; - if (! is_int(@$restore_table['length']) || - ! is_array(@$restore_table['offsets']) || - $restore_table['length'] !== self::strlen($s)) return false; - $a = array(); - $length = $offset = 0; - $s2 = ''; - foreach ($restore_table['offsets'] as $pos => $diactricals) - { - $length = $pos - $offset; - $s2 .= self::substr($s, $offset, $length) . $diactricals; - $offset = $pos; - } - return $s2 . self::substr($s, $offset, strlen($s)); - } - - /** - * Encodes data from another character encoding to UTF-8. - * - * @param array|scalar|null $data - * @param string $charset - * @return array|scalar|null Returns FALSE if error occurred - */ - public static function convert_from($data, $charset = 'cp1251') - { - if (! ReflectionTypeHint::isValid()) return false; - return self::_convert($data, $charset, 'UTF-8'); - } - - /** - * Encodes data from UTF-8 to another character encoding. - * - * @param array|scalar|null $data - * @param string $charset - * @return array|scalar|null Returns FALSE if error occurred - */ - public static function convert_to($data, $charset = 'cp1251') - { - if (! ReflectionTypeHint::isValid()) return false; - return self::_convert($data, 'UTF-8', $charset); - } - - /** - * Recoding the data of any structure to/from UTF-8. - * Arrays traversed recursively, recoded keys and values. - * - * @see mb_encoding_aliases() - * @param array|scalar|null $data - * @param string $charset_from - * @param string $charset_to - * @return array|scalar|null Returns FALSE if error occurred - */ - private static function _convert($data, $charset_from, $charset_to) - { - if (! ReflectionTypeHint::isValid()) return false; #for recursive calls - if ($charset_from === $charset_to) return $data; - if (is_array($data)) - { - $d = array(); - foreach ($data as $k => &$v) - { - $k = self::_convert($k, $charset_from, $charset_to); - if ($k === false) return false; - $d[$k] = self::_convert($v, $charset_from, $charset_to); - if ($d[$k] === false && ! is_bool($v)) return false; - } - return $d; - } - if (is_string($data)) - { - #smart behaviour for errors protected + speed improve - if ($charset_from === 'UTF-8' && ! self::is_utf8($data)) return $data; - if ($charset_to === 'UTF-8' && self::is_utf8($data)) return $data; - - #since PHP-5.3.x iconv() faster then mb_convert_encoding() - if (function_exists('iconv')) return iconv($charset_from, $charset_to . '//IGNORE//TRANSLIT', $data); - if (function_exists('mb_convert_encoding')) return mb_convert_encoding($data, $charset_to, $charset_from); - - #charset_from - if ($charset_from === 'UTF-16' || $charset_from === 'UCS-2') return self::_convert_from_utf16($data); - if ($charset_from === 'cp1251' || $charset_from === 'cp1259') return strtr($data, self::$cp1259_table); - if ($charset_from === 'koi8-r' || $charset_from === 'KOI8-R') return strtr(convert_cyr_string($data, 'k', 'w'), self::$cp1259_table); - if ($charset_from === 'iso8859-5') return strtr(convert_cyr_string($data, 'i', 'w'), self::$cp1259_table); - if ($charset_from === 'cp866') return strtr(convert_cyr_string($data, 'a', 'w'), self::$cp1259_table); - if ($charset_from === 'mac-cyrillic') return strtr(convert_cyr_string($data, 'm', 'w'), self::$cp1259_table); - - #charset_to - if ($charset_to === 'cp1251' || $charset_to === 'cp1259') return strtr($data, array_flip(self::$cp1259_table)); - - #last trying - if (function_exists('recode_string')) - { - $s = @recode_string($charset_from . '..' . $charset_to, $data); - if (is_string($s)) return $s; - } - - trigger_error('Convert "' . $charset_from . '" --> "' . $charset_to . '" is not supported native, "iconv" or "mbstring" extension required', E_USER_WARNING); - return false; - } - return $data; - } - - /** - * Convert UTF-16 / UCS-2 encoding string to UTF-8. - * Surrogates UTF-16 are supported! - * - * In Russian: - * Преобразует строку из кодировки UTF-16 / UCS-2 в UTF-8. - * Суррогаты UTF-16 поддерживаются! - * - * @param string $s - * @param string $type 'BE' -- big endian byte order - * 'LE' -- little endian byte order - * @param bool $to_array returns array chars instead whole string? - * @return string|array|bool UTF-8 string, array chars or FALSE if error occurred - */ - private static function _convert_from_utf16($s, $type = 'BE', $to_array = false) - { - static $types = array( - 'BE' => 'n', #unsigned short (always 16 bit, big endian byte order) - 'LE' => 'v', #unsigned short (always 16 bit, little endian byte order) - ); - if (! array_key_exists($type, $types)) - { - trigger_error('Unexpected value in 2-nd parameter, "' . $type . '" given!', E_USER_WARNING); - return false; - } - #the fastest way: - if (function_exists('iconv') || function_exists('mb_convert_encoding')) - { - if (function_exists('iconv')) $s = iconv('UTF-16' . $type, 'UTF-8', $s); - elseif (function_exists('mb_convert_encoding')) $s = mb_convert_encoding($s, 'UTF-8', 'UTF-16' . $type); - if (! $to_array) return $s; - return self::str_split($s); - } - - /* - http://en.wikipedia.org/wiki/UTF-16 - - The improvement that UTF-16 made over UCS-2 is its ability to encode - characters in planes 1-16, not just those in plane 0 (BMP). - - UTF-16 represents non-BMP characters (those from U+10000 through U+10FFFF) - using a pair of 16-bit words, known as a surrogate pair. - First 1000016 is subtracted from the code point to give a 20-bit value. - This is then split into two separate 10-bit values each of which is represented - as a surrogate with the most significant half placed in the first surrogate. - To allow safe use of simple word-oriented string processing, separate ranges - of values are used for the two surrogates: 0xD800-0xDBFF for the first, most - significant surrogate and 0xDC00-0xDFFF for the second, least significant surrogate. - - For example, the character at code point U+10000 becomes the code unit sequence 0xD800 0xDC00, - and the character at U+10FFFD, the upper limit of Unicode, becomes the sequence 0xDBFF 0xDFFD. - Unicode and ISO/IEC 10646 do not, and will never, assign characters to any of the code points - in the U+D800-U+DFFF range, so an individual code value from a surrogate pair does not ever - represent a character. - - http://www.russellcottrell.com/greek/utilities/SurrogatePairCalculator.htm - http://www.russellcottrell.com/greek/utilities/UnicodeRanges.htm - - Conversion of a Unicode scalar value S to a surrogate pair : - H = Math.floor((S - 0x10000) / 0x400) + 0xD800; - L = ((S - 0x10000) % 0x400) + 0xDC00; - The conversion of a surrogate pair to a scalar value: - N = ((H - 0xD800) * 0x400) + (L - 0xDC00) + 0x10000; - */ - $a = array(); - $hi = false; - foreach (unpack($types[$type] . '*', $s) as $codepoint) - { - #surrogate process - if ($hi !== false) - { - $lo = $codepoint; - if ($lo < 0xDC00 || $lo > 0xDFFF) $a[] = "\xEF\xBF\xBD"; #U+FFFD REPLACEMENT CHARACTER (for broken char) - else - { - $codepoint = (($hi - 0xD800) * 0x400) + ($lo - 0xDC00) + 0x10000; - $a[] = self::chr($codepoint); - } - $hi = false; - } - elseif ($codepoint < 0xD800 || $codepoint > 0xDBFF) $a[] = self::chr($codepoint); #not surrogate - else $hi = $codepoint; #surrogate was found - } - return $to_array ? $a : implode('', $a); - } - - /** - * Strips out device control codes in the ASCII range. - * - * @param string|null String to clean - * @return string|bool|null Returns FALSE if error occurred - */ - public static function strict($s) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - return preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]+/sSX', '', $s); - } - - /** - * Check the data accessory to the class of characters ASCII. - * For null, integer, float, boolean returns TRUE. - * - * Массивы обходятся рекурсивно, если в хотябы одном элементе массива - * его значение не ASCII, возвращается FALSE. - * - * @param array|scalar|null $data - * @return bool - */ - public static function is_ascii($data) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_array($data)) - { - foreach ($data as $k => &$v) - { - if (! self::is_ascii($k) || ! self::is_ascii($v)) return false; - } - return true; - } - #ltrim() little faster then preg_match() - #if (is_string($data)) return preg_match('/^[\x00-\x7f]*$/sSX', $data); #deprecated - if (is_string($data)) return ltrim($data, "\x00..\x7f") === ''; - if (is_scalar($data) || is_null($data)) return true; #~ null, integer, float, boolean - return false; #object or resource - } - - /** - * Returns true if data is valid UTF-8 and false otherwise. - * For null, integer, float, boolean returns TRUE. - * - * The arrays are traversed recursively, if At least one element of the array - * its value is not in UTF-8, returns FALSE. - * - * @link http://www.w3.org/International/questions/qa-forms-utf-8.html - * @link http://ru3.php.net/mb_detect_encoding - * @link http://webtest.philigon.ru/articles/utf8/ - * @link http://unicode.coeurlumiere.com/ - * @param array|scalar|null $data - * @param bool $is_strict strict the range of ASCII? - * @return bool - */ - public static function is_utf8($data, $is_strict = true) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_array($data)) - { - foreach ($data as $k => &$v) - { - if (! self::is_utf8($k, $is_strict) || ! self::is_utf8($v, $is_strict)) return false; - } - return true; - } - if (is_string($data)) - { - if (! preg_match('~~suSX', $data)) return false; - if (function_exists('preg_last_error') && preg_last_error() !== PREG_NO_ERROR) return false; - #preg_match('~~suSX') much faster (up to 4 times), then mb_check_encoding($data, 'UTF-8')! - #if (function_exists('mb_check_encoding') && ! mb_check_encoding($data, 'UTF-8')) return false; #DEPRECATED - if ($is_strict && preg_match('/[^\x09\x0A\x0D\x20-\xBF\xC2-\xF7]/sSX', $data)) return false; - return true; - } - if (is_scalar($data) || is_null($data)) return true; #~ null, integer, float, boolean - return false; #object or resource - } - - /** - * Tries to detect if a string is in Unicode encoding - * - * @deprecated Slowly, use self::is_utf8() instead - * @see self::is_utf8() - * @param string $s текст - * @param bool $is_strict строгая проверка диапазона ASCII? - * @return bool - */ - public static function check($s, $is_strict = true) - { - if (! ReflectionTypeHint::isValid()) return false; - for ($i = 0, $len = strlen($s); $i < $len; $i++) - { - $c = ord($s[$i]); - if ($c < 0x80) #1 byte 0bbbbbbb - { - if ($is_strict === false || ($c > 0x1F && $c < 0x7F) || $c == 0x09 || $c == 0x0A || $c == 0x0D) continue; - } - if (($c & 0xE0) == 0xC0) $n = 1; #2 bytes 110bbbbb 10bbbbbb - elseif (($c & 0xF0) == 0xE0) $n = 2; #3 bytes 1110bbbb 10bbbbbb 10bbbbbb - elseif (($c & 0xF8) == 0xF0) $n = 3; #4 bytes 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb - elseif (($c & 0xFC) == 0xF8) $n = 4; #5 bytes 111110bb 10bbbbbb 10bbbbbb 10bbbbbb 10bbbbbb - elseif (($c & 0xFE) == 0xFC) $n = 5; #6 bytes 1111110b 10bbbbbb 10bbbbbb 10bbbbbb 10bbbbbb 10bbbbbb - else return false; #does not match any model - #n bytes matching 10bbbbbb follow ? - for ($j = 0; $j < $n; $j++) - { - $i++; - if ($i == $len || ((ord($s[$i]) & 0xC0) != 0x80) ) return false; - } - } - return true; - } - - /** - * Check the data in UTF-8 charset on given ranges of the standard UNICODE. - * The suitable alternative to regular expressions. - * - * For null, integer, float, boolean returns TRUE. - * - * Arrays traversed recursively (keys and values). - * At least if one array element value is not passed checking, it returns FALSE. - * - * @example - * #A simple check the standard named ranges: - * UTF8::blocks_check('поисковые системы Google и Yandex', array('Basic Latin', 'Cyrillic')); - * #You can check the named, direct ranges or codepoints together: - * UTF8::blocks_check('поисковые системы Google и Yandex', array(array(0x20, 0x7E), #[\x20-\x7E] - * array(0x0410, 0x044F), #[A-Яa-я] - * 0x0401, #russian yo (Ё) - * 0x0451, #russian ye (ё) - * 'Arrows', - * )); - * - * @link http://www.unicode.org/charts/ - * @param array|scalar|null $data - * @param array|string $blocks - * @return bool Возвращает TRUE, если все символы из текста принадлежат указанным диапазонам - * и FALSE в противном случае или для разбитого UTF-8. - */ - public static function blocks_check($data, $blocks) - { - if (! ReflectionTypeHint::isValid()) return false; - - if (is_array($data)) - { - foreach ($data as $k => &$v) - { - if (! self::blocks_check($k, $blocks) || ! self::blocks_check($v, $blocks)) return false; - } - return true; - } - - if (is_string($data)) - { - $chars = self::str_split($data); - if ($chars === false) return false; #broken UTF-8 - unset($data); #memory free - $skip = array(); #save to cache already checked symbols - foreach ($chars as $i => $char) - { - if (array_key_exists($char, $skip)) continue; #speed improve - $codepoint = self::ord($char); - if ($codepoint === false) return false; #broken UTF-8 - $is_valid = false; - $blocks = (array)$blocks; - foreach ($blocks as $j => $block) - { - if (is_string($block)) - { - if (! array_key_exists($block, self::$unicode_blocks)) - { - trigger_error('Unknown block "' . $block . '"!', E_USER_WARNING); - return false; - } - list ($min, $max) = self::$unicode_blocks[$block]; - } - elseif (is_array($block)) list ($min, $max) = $block; - elseif (is_int($block)) $min = $max = $block; - else trigger_error('A string/array/int type expected for block[' . $j . ']!', E_USER_ERROR); - if ($codepoint >= $min && $codepoint <= $max) - { - $is_valid = true; - break; - } - }#foreach - if (! $is_valid) return false; - $skip[$char] = null; - }#foreach - return true; - } - if (is_scalar($data) || is_null($data)) return true; #~ null, integer, float, boolean - return false; #object or resource - } - - /** - * Recode $_GET, $_POST, $_COOKIE, $_REQUEST, $_FILES from $charset encoding to UTF-8, if necessary. - * A side effect is a positive protection against XSS attacks with non-printable characters on the vulnerable PHP function. - * Thus web forms can be sent to the server in 2-encoding: $charset and UTF-8. - * For example: ?тест[тест]=тест - * - * Алгоритм работы: - * 1) Функция проверяет массивы $_GET, $_POST, $_COOKIE, $_REQUEST, $_FILES - * на корректность значений элементов кодировке UTF-8. - * 2) Значения не в UTF-8 принимаются как $charset и конвертируется в UTF-8, - * при этом байты от 0x00 до 0x7F (ASCII) сохраняются как есть. - * 3) Сконвертированные значения снова проверяются. - * Если данные опять не в кодировке UTF-8, то они считаются разбитыми и функция возвращает FALSE. - * - * NOTICE - * Функция должна вызываться после self::unescape_request()! - * - * @see self::unescape_request() - * @param bool $is_hex2bin Декодировать HEX-данные? - * Пример: 0xd09ec2a0d0bad0bed0bcd0bfd0b0d0bdd0b8d0b8 => О компании - * Параметры в URL адресах иногда бывает удобно кодировать не функцией rawurlencode(), - * а использовать следующий механизм (к тому же кодирующий данные более компактно): - * '0x' . bin2hex($string) - * @param string $charset - * @return bool Возвращает TRUE, если все значения элементов массивов в кодировке UTF-8 - * и FALSE + E_USER_WARNING в противном случае. - */ - public static function autoconvert_request($is_hex2bin = false, $charset = 'cp1251') - { - if (! ReflectionTypeHint::isValid()) return false; - $is_converted = false; - $is_broken = false; - foreach (array('_GET', '_POST', '_COOKIE', '_FILES') as $k => $v) - { - if (! array_key_exists($v, $GLOBALS)) continue; - #использовать array_walk_recursive() не предоставляется возможным, - #т.к. его callback функция не поддерживает передачу ключа по ссылке - $GLOBALS[$v] = self::_autoconvert_request_recursive($GLOBALS[$v], $is_converted, $is_broken, $is_hex2bin, $charset); - if ($is_broken) - { - trigger_error('Array $' . $v . ' does not have keys/values in UTF-8 charset!', E_USER_WARNING); - return false; - } - } - if ($is_converted) - { - $_REQUEST = - (isset($_COOKIE) ? $_COOKIE : array()) + - (isset($_POST) ? $_POST : array()) + - (isset($_GET) ? $_GET : array()); - } - return true; - } - - private static function _autoconvert_request_recursive(&$data, &$is_converted, &$is_broken, $is_hex2bin, $charset) - { - if ($is_broken) return $data; #speed improve - if (is_array($data)) - { - $d = array(); - foreach ($data as $k => &$v) - { - $k = self::_autoconvert_request($k, $is_converted, $is_broken, $is_hex2bin, $charset); - if ($is_broken) return $data; #speed improve - $d[$k] = self::_autoconvert_request_recursive($v, $is_converted, $is_broken, $is_hex2bin, $charset); - if ($is_broken) return $data; #speed improve - } - return $d; - } - return self::_autoconvert_request($data, $is_converted, $is_broken, $is_hex2bin, $charset); - } - - private static function _autoconvert_request(&$s, &$is_converted, &$is_broken, $is_hex2bin, $charset) - { - #regexp speed improve by using strpos() - if ($is_hex2bin && strpos($s, '0x') === 0 && preg_match('/^0x((?:[\da-fA-F]{2})+)$/sSX', $s, $m)) - { - $s = pack('H' . strlen($m[1]), $m[1]); #hex2bin() - $is_converted = true; - } - if (! self::is_utf8($s)) - { - $s = self::convert_from($s, $charset); - if ($s === false) $is_broken = true; - elseif (! self::is_utf8($s)) - { - trigger_error('String 0x ' . substr(bin2hex($s), 0, 100) . '... is not UTF-8!', E_USER_WARNING); - $is_broken = true; - } - else $is_converted = true; - } - return $s; - } - - /** - * Сравнение строк - * - * @param string|null $s1 - * @param string|null $s2 - * @param string $locale For example, 'en_CA', 'ru_RU' - * @return int|bool|null Returns FALSE if error occurred - * Returns < 0 if $s1 is less than $s2; - * > 0 if $s1 is greater than $s2; - * 0 if they are equal. - */ - public static function strcmp($s1, $s2, $locale = '') - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s1) || is_null($s2)) return null; - if (! function_exists('collator_create')) return strcmp($s1, $s2); - # PHP 5 >= 5.3.0, PECL intl >= 1.0.0 - # If empty string ("") or "root" are passed, UCA rules will be used. - $c = new Collator($locale); - if (! $c) - { - # Returns an "empty" object on error. You can use intl_get_error_code() and/or intl_get_error_message() to know what happened. - trigger_error(intl_get_error_message(), E_USER_WARNING); - return false; - } - return $c->compare($s1, $s2); - } - - /** - * Сравнение строк для N первых символов - * - * @param string|null $s1 - * @param string|null $s2 - * @param int $length - * @return int|bool|null Returns FALSE if error occurred - * Returns < 0 if $s1 is less than $s2; - * > 0 if $s1 is greater than $s2; - * 0 if they are equal. - */ - public static function strncmp($s1, $s2, $length) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s1) || is_null($s2)) return null; - return self::strcmp(self::substr($s1, 0, $length), self::substr($s2, 0, $length)); - } - - /** - * Implementation strcasecmp() function for UTF-8 encoding string. - * - * @param string|null $s1 - * @param string|null $s2 - * @return int|bool|null Returns FALSE if error occurred - * Returns < 0 if $s1 is less than $s2; - * > 0 if $s1 is greater than $s2; - * 0 if they are equal. - */ - public static function strcasecmp($s1, $s2) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s1) || is_null($s2)) return null; - return self::strcmp(self::lowercase($s1), self::lowercase($s2)); - } - - /** - * Converts a UTF-8 string to a UNICODE codepoints - * - * @param string|null $s UTF-8 string - * @return array|bool|null Unicode codepoints - * Returns FALSE if $s broken (not UTF-8) - */ - public static function to_unicode($s) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - $s2 = null; - #since PHP-5.3.x iconv() little faster then mb_convert_encoding() - if (function_exists('iconv')) $s2 = @iconv('UTF-8', 'UCS-4BE', $s); - elseif (function_exists('mb_convert_encoding')) $s2 = @mb_convert_encoding($s, 'UCS-4BE', 'UTF-8'); - if (is_string($s2)) return array_values(unpack('N*', $s2)); - if ($s2 !== null) return false; - - $a = self::str_split($s); - if ($a === false) return false; - return array_map(array(__CLASS__, 'ord'), $a); - } - - /** - * Converts a UNICODE codepoints to a UTF-8 string - * - * @param array|null $a Unicode codepoints - * @return string|bool|null UTF-8 string - * Returns FALSE if error occurred - */ - public static function from_unicode($a) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($a)) return $a; - - #since PHP-5.3.x iconv() little faster then mb_convert_encoding() - if (function_exists('iconv')) - { - array_walk($a, function(&$cp) { $cp = pack('N', $cp); }); - $s = @iconv('UCS-4BE', 'UTF-8', implode('', $a)); - if (! is_string($s)) return false; - return $s; - } - if (function_exists('mb_convert_encoding')) - { - array_walk($a, function(&$cp) { $cp = pack('N', $cp); }); - $s = mb_convert_encoding(implode('', $a), 'UTF-8', 'UCS-4BE'); - if (! is_string($s)) return false; - return $s; - } - - return implode('', array_map(array(__CLASS__, 'chr'), $a)); - } - - /** - * Converts a UTF-8 character to a UNICODE codepoint - * - * @param string|null $char UTF-8 character - * @return int|bool|null Unicode codepoint - * Returns FALSE if $char broken (not UTF-8) - */ - public static function ord($char) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($char)) return $char; - - static $cache = array(); - if (array_key_exists($char, $cache)) return $cache[$char]; #speed improve - - switch (strlen($char)) - { - case 1 : return $cache[$char] = ord($char); - case 2 : return $cache[$char] = (ord($char{1}) & 63) | - ((ord($char{0}) & 31) << 6); - case 3 : return $cache[$char] = (ord($char{2}) & 63) | - ((ord($char{1}) & 63) << 6) | - ((ord($char{0}) & 15) << 12); - case 4 : return $cache[$char] = (ord($char{3}) & 63) | - ((ord($char{2}) & 63) << 6) | - ((ord($char{1}) & 63) << 12) | - ((ord($char{0}) & 7) << 18); - default : - trigger_error('Character 0x' . bin2hex($char) . ' is not UTF-8!', E_USER_WARNING); - return false; - } - } - - /** - * Converts a UNICODE codepoint to a UTF-8 character - * - * @param int|digit|null $cp Unicode codepoint - * @return string|bool|null UTF-8 character - * Returns FALSE if error occurred - */ - public static function chr($cp) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($cp)) return $cp; - - static $cache = array(); - if (array_key_exists($cp, $cache)) return $cache[$cp]; #speed improve - - if ($cp <= 0x7f) return $cache[$cp] = chr($cp); - if ($cp <= 0x7ff) return $cache[$cp] = chr(0xc0 | ($cp >> 6)) . - chr(0x80 | ($cp & 0x3f)); - if ($cp <= 0xffff) return $cache[$cp] = chr(0xe0 | ($cp >> 12)) . - chr(0x80 | (($cp >> 6) & 0x3f)) . - chr(0x80 | ($cp & 0x3f)); - if ($cp <= 0x10ffff) return $cache[$cp] = chr(0xf0 | ($cp >> 18)) . - chr(0x80 | (($cp >> 12) & 0x3f)) . - chr(0x80 | (($cp >> 6) & 0x3f)) . - chr(0x80 | ($cp & 0x3f)); - #U+FFFD REPLACEMENT CHARACTER - return $cache[$cp] = "\xEF\xBF\xBD"; - } - - /** - * Implementation chunk_split() function for UTF-8 encoding string. - * - * @param string|null $s - * @param int|digit|null $length - * @param string|null $glue - * @return string|bool|null Returns FALSE if error occurred - */ - public static function chunk_split($s, $length = null, $glue = null) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - $length = intval($length); - $glue = strval($glue); - if ($length < 1) $length = 76; - if ($glue === '') $glue = "\r\n"; - if (! is_array($a = self::str_split($s, $length))) return false; - return implode($glue, $a); - } - - /** - * Changes all keys in an array - * - * @param array|null $a - * @param int $mode {CASE_LOWER|CASE_UPPER} - * @return array|bool|null Returns FALSE if error occurred - */ - public static function array_change_key_case($a, $mode) - { - if (! ReflectionTypeHint::isValid()) return false; - if (! is_array($a)) return $a; - $a2 = array(); - foreach ($a as $k => $v) - { - if (is_string($k)) - { - $k = self::convert_case($k, $mode); - if ($k === false) return false; - } - $a2[$k] = $v; - } - return $a2; - } - - /** - * Конвертирует регистр букв в данных в кодировке UTF-8. - * Массивы обходятся рекурсивно, при этом конвертируются только значения - * в элементах массива, а ключи остаются без изменений. - * Для конвертирования только ключей используйте метод self::array_change_key_case(). - * - * @see self::array_change_key_case() - * @link http://www.unicode.org/charts/PDF/U0400.pdf - * @link http://ru.wikipedia.org/wiki/ISO_639-1 - * @param array|scalar|null $data Данные произвольной структуры - * @param int $mode {CASE_LOWER|CASE_UPPER} - * @param bool $is_ascii_optimization for speed improve - * @return scalar|bool|null Returns FALSE if error occurred - */ - public static function convert_case($data, $mode, $is_ascii_optimization = true) - { - if (! ReflectionTypeHint::isValid()) return false; - - if (is_array($data)) - { - foreach ($data as $k => &$v) $v = self::convert_case($v, $mode); - return $data; - } - if (! is_string($data) || ! $data) return $data; - - if ($mode === CASE_UPPER) - { - if ($is_ascii_optimization && self::is_ascii($data)) return strtoupper($data); #speed improve! - #deprecated, since PHP-5.3.x strtr() 2-3 times faster then mb_strtolower() - #if (function_exists('mb_strtoupper')) return mb_strtoupper($data, 'utf-8'); - return strtr($data, array_flip(self::$convert_case_table)); - } - if ($mode === CASE_LOWER) - { - if ($is_ascii_optimization && self::is_ascii($data)) return strtolower($data); #speed improve! - #deprecated, since PHP-5.3.x strtr() 2-3 times faster then mb_strtolower() - #if (function_exists('mb_strtolower')) return mb_strtolower($data, 'utf-8'); - return strtr($data, self::$convert_case_table); - } - trigger_error('Parameter 2 should be a constant of CASE_LOWER or CASE_UPPER!', E_USER_WARNING); - return $data; - } - - /** - * Convert a data to lower case - * - * @param array|scalar|null $data - * @return scalar|bool|null Returns FALSE if error occurred */ - public static function lowercase($data) - { - if (! ReflectionTypeHint::isValid()) return false; - return self::convert_case($data, CASE_LOWER); - } - - /** - * Convert a data to upper case - * - * @param array|scalar|null $data - * @return scalar|null Returns FALSE if error occurred - */ - public static function uppercase($data) - { - if (! ReflectionTypeHint::isValid()) return false; - return self::convert_case($data, CASE_UPPER); - } - - /** - * Convert a data to lower case - * - * @param array|scalar|null $data - * @return scalar|bool|null Returns FALSE if error occurred - */ - public static function strtolower($data) - { - if (! ReflectionTypeHint::isValid()) return false; - return self::convert_case($data, CASE_LOWER); - } - - /** - * Convert a data to upper case - * - * @param array|scalar|null $data - * @return scalar|null Returns FALSE if error occurred - */ - public static function strtoupper($data) - { - if (! ReflectionTypeHint::isValid()) return false; - return self::convert_case($data, CASE_UPPER); - } - - /** - * Convert all HTML entities to native UTF-8 characters - * Функция декодирует гораздо больше именованных сущностей, чем стандартная html_entity_decode() - * Все dec и hex сущности так же переводятся в UTF-8. - * - * Example: '"' or '"' or '"' will be converted to '"'. - * - * @link http://www.htmlhelp.com/reference/html40/entities/ - * @link http://www.alanwood.net/demos/ent4_frame.html (HTML 4.01 Character Entity References) - * @link http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/charset1.asp?frame=true - * @link http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/charset2.asp?frame=true - * @link http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/charset3.asp?frame=true - * - * @param scalar|null $s - * @param bool $is_special_chars Дополнительно обрабатывать специальные html сущности? (< > & ") - * @return scalar|null Returns FALSE if error occurred - */ - public static function html_entity_decode($s, $is_special_chars = false) - { - if (! ReflectionTypeHint::isValid()) return false; - if (! is_string($s)) return $s; - - #speed improve - if (strlen($s) < 4 #по минимальной длине сущности - 4 байта: &#d; &xx; - || ($pos = strpos($s, '&') === false) || strpos($s, ';', $pos) === false) return $s; - - $table = self::$html_entity_table; - if ($is_special_chars) $table += self::$html_special_chars_table; - - #replace named entities - $s = strtr($s, $table); - #block below deprecated, since PHP-5.3.x strtr() 1.5 times faster - if (0 && preg_match_all('/&[a-zA-Z]++\d*+;/sSX', $s, $m, null, $pos)) - { - foreach (array_unique($m[0]) as $entity) - { - if (array_key_exists($entity, $table)) $s = str_replace($entity, $table[$entity], $s); - } - } - - #заменяем числовые dec и hex сущности: - if (strpos($s, '&#') !== false) #speed improve - { - $class = __CLASS__; - $html_special_chars_table_flipped = array_flip(self::$html_special_chars_table); - $s = preg_replace_callback('/&#((x)[\da-fA-F]{1,6}+|\d{1,7}+);/sSX', - function (array $m) use ($class, $html_special_chars_table_flipped, $is_special_chars) - { - $codepoint = isset($m[2]) && $m[2] === 'x' ? hexdec($m[1]) : $m[1]; - if (! $is_special_chars) - { - $char = pack('C', $codepoint); - if (array_key_exists($char, $html_special_chars_table_flipped)) return $html_special_chars_table_flipped[$char]; - } - return $class::chr($codepoint); - }, $s); - } - return $s; - } - - /** - * Convert special UTF-8 characters to HTML entities. - * Функция кодирует гораздо больше именованных сущностей, чем стандартная htmlentities() - * - * @link http://www.htmlhelp.com/reference/html40/entities/ - * @link http://www.alanwood.net/demos/ent4_frame.html (HTML 4.01 Character Entity References) - * @link http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/charset1.asp?frame=true - * @link http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/charset2.asp?frame=true - * @link http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/charset3.asp?frame=true - * - * @param scalar|null $s - * @param bool $is_special_chars_only Обрабатывать только специальные html сущности? (< > & ") - * @return scalar|null Returns FALSE if error occurred - */ - public static function html_entity_encode($s, $is_special_chars_only = false) - { - if (! ReflectionTypeHint::isValid()) return false; - if (! is_string($s)) return $s; - - #if ($is_special_chars_only) return strtr($s, array_flip(self::$html_special_chars_table)); - if ($is_special_chars_only) return htmlspecialchars($s); - - #replace UTF-8 chars to named entities: - $s = strtr($s, array_flip(self::$html_entity_table)); - #block below deprecated, since PHP-5.3.x strtr() 3 times faster - if (0 && preg_match_all('~(?> [\xc2\xc3\xc5\xc6\xcb\xce\xcf][\x80-\xbf] #2 bytes - | \xe2[\x80-\x99][\x82-\xac] #3 bytes - ) - ~sxSX', $s, $m)) - { - $table = array_flip(self::$html_entity_table); - foreach (array_unique($m[0]) as $char) - { - if (array_key_exists($char, $table)) $s = str_replace($char, $table[$char], $s); - } - } - - return $s; - } - - /** - * Make regular expression for case insensitive match - * Example (non ASCII): "123_слово_test" => "123_(с|С)(л|Л)(о|О)(в|В)(о|О)_[tT][eE][sS][tT]" - * Example (only ASCII): "123_test" => "(?i:123_test)" - * - * @param string $s - * @param string|null $delimiter If the optional delimiter is specified, it will also be escaped. - * This is useful for escaping the delimiter that is required by the PCRE functions. - * The / is the most commonly used delimiter. - * @return string|bool|null Returns FALSE if error occurred - */ - public static function preg_quote_case_insensitive($s, $delimiter = null) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - if (self::is_ascii($s)) return '(?i:' . preg_quote($s, $delimiter) . ')'; #speed improve - - $s_re = ''; - $s_lc = UTF8::lowercase($s); if ($s_lc === false) return false; - $s_uc = UTF8::uppercase($s); if ($s_uc === false) return false; - - $chars_lc = UTF8::str_split($s_lc); if ($chars_lc === false) return false; - $chars_uc = UTF8::str_split($s_uc); if ($chars_uc === false) return false; - - foreach ($chars_lc as $i => $char) - { - if ($chars_lc[$i] === $chars_uc[$i]) - $s_re .= preg_quote($chars_lc[$i], $delimiter); - elseif (self::is_ascii($chars_lc[$i])) - $s_re .= '[' . preg_quote($chars_lc[$i] . $chars_uc[$i], $delimiter) . ']'; - else - $s_re .= '(' . preg_quote($chars_lc[$i], $delimiter) . '|' - . preg_quote($chars_uc[$i], $delimiter) . ')'; - } - return $s_re; - } - - /** - * Call preg_match_all() and convert byte offsets into character offsets for PREG_OFFSET_CAPTURE flag. - * This is regardless of whether you use /u modifier. - * - * @link http://bolknote.ru/2010/09/08/~2704 - * - * @param string $pattern - * @param string|null $subject - * @param array $matches - * @param int $flags - * @param int $char_offset - * @return array|bool|null Returns FALSE if error occurred - */ - public static function preg_match_all($pattern, $subject, &$matches, $flags = PREG_PATTERN_ORDER, $char_offset = 0) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($subject)) return null; - - $byte_offset = ($char_offset > 0) ? strlen(self::substr($subject, 0, $char_offset)) : $char_offset; - - $return = preg_match_all($pattern, $subject, $matches, $flags, $byte_offset); - if ($return === false) return false; - - if ($flags & PREG_OFFSET_CAPTURE) - { - foreach ($matches as &$match) - { - foreach ($match as &$a) $a[1] = self::strlen(substr($subject, 0, $a[1])); - } - } - - return $return; - } - - #alias for self::str_limit() - public static function truncate($s, $maxlength = null, $continue = "\xe2\x80\xa6", &$is_cutted = null, $tail_min_length = 20) - { - return self::str_limit($s, $maxlength, $continue, $is_cutted, $tail_min_length); - } - - /** - * Обрезает текст в кодировке UTF-8 до заданной длины, - * причём последнее слово показывается целиком, а не обрывается на середине. - * Html сущности корректно обрабатываются. - * - * @param string|null $s Текст в кодировке UTF-8 - * @param int|null|digit $maxlength Ограничение длины текста - * @param string $continue Завершающая строка, которая будет вставлена после текста, если он обрежется - * @param bool|null &$is_cutted Текст был обрезан? - * @param int|digit $tail_min_length Если длина "хвоста", оставшегося после обрезки текста, меньше $tail_min_length, - * то текст возвращается без изменений - * @return string|bool|null Returns FALSE if error occurred - */ - public static function str_limit($s, $maxlength = null, $continue = "\xe2\x80\xa6", &$is_cutted = null, $tail_min_length = 20) #"\xe2\x80\xa6" = "…" - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - $is_cutted = false; - if ($continue === null) $continue = "\xe2\x80\xa6"; - if (! $maxlength) $maxlength = 256; - - #speed improve block - #{{{ - if (strlen($s) <= $maxlength) return $s; - $s2 = str_replace("\r\n", '?', $s); - $s2 = preg_replace('/&(?> [a-zA-Z][a-zA-Z\d]+ - | \#(?> \d{1,4} - | x[\da-fA-F]{2,4} - ) - ); # html сущности (< > & ") - /sxSX', '?', $s2); - if (strlen($s2) <= $maxlength || self::strlen($s2) <= $maxlength) return $s; - #}}} - - $r = preg_match_all('/(?> \r\n # переносы строк - | &(?> [a-zA-Z][a-zA-Z\d]+ - | \#(?> \d{1,4} - | x[\da-fA-F]{2,4} - ) - ); # html сущности (< > & ") - | . - ) - /sxuSX', $s, $m); - if ($r === false) return false; - - #d($m); - if (count($m[0]) <= $maxlength) return $s; - - $left = implode('', array_slice($m[0], 0, $maxlength)); - #из диапазона ASCII исключаем буквы, цифры, открывающие парные символы [a-zA-Z\d\(\{\[] и некоторые др. символы - #нельзя вырезать в конце строки символ ";", т.к. он используются в сущностях &xxx; - $left2 = rtrim($left, "\x00..\x28\x2A..\x2F\x3A\x3C..\x3E\x40\x5B\x5C\x5E..\x60\x7B\x7C\x7E\x7F"); - if (strlen($left) !== strlen($left2)) $return = $left2 . $continue; - else - { - #добавляем остаток к обрезанному слову - $right = implode('', array_slice($m[0], $maxlength)); - preg_match('/^(?> [\d\)\]\}\-\.:]+ #цифры, закрывающие парные символы, дефис для составных слов, дата, время, IP-адреса, URL типа www.ya.ru:80! - | \p{L}+ #буквы - | \xe2\x80\x9d #закрывающие кавычки - | \xe2\x80\x99 #закрывающие кавычки - | \xe2\x80\x9c #закрывающие кавычки - | \xc2\xbb #закрывающие кавычки - )+ - /suxSX', $right, $m); - #d($m); - $right = isset($m[0]) ? rtrim($m[0], '.-') : ''; - $return = $left . $right; - if (strlen($return) !== strlen($s)) $return .= $continue; - } - if (self::strlen($s) - self::strlen($return) < $tail_min_length) return $s; - - $is_cutted = true; - return $return; - } - - /** - * Implementation str_split() function for UTF-8 encoding string. - * - * @param string|null $s - * @param int|null|digit $length - * @return array|bool|null Returns FALSE if error occurred - */ - public static function str_split($s, $length = null) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - $length = ($length === null) ? 1 : intval($length); - if ($length < 1) return false; - #there are limits in regexp for {min,max}! - if (preg_match_all('~.~suSX', $s, $m) === false) return false; - if (function_exists('preg_last_error') && preg_last_error() !== PREG_NO_ERROR) return false; - if ($length === 1) $a = $m[0]; - else - { - $a = array(); - for ($i = 0, $c = count($m[0]); $i < $c; $i += $length) $a[] = implode('', array_slice($m[0], $i, $length)); - } - return $a; - } - - /** - * Implementation strlen() function for UTF-8 encoding string. - * - * @param string|null $s - * @return int|bool|null Returns FALSE if error occurred - */ - public static function strlen($s) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - //since PHP-5.3.x mb_strlen() faster then strlen(utf8_decode()) - if (function_exists('mb_strlen')) return mb_strlen($s, 'utf-8'); - - /* - utf8_decode() converts characters that are not in ISO-8859-1 to '?', which, for the purpose of counting, is quite alright. - It's much faster than iconv_strlen() - Note: this function does not count bad UTF-8 bytes in the string - these are simply ignored - */ - return strlen(utf8_decode($s)); - - /* - #slowly then strlen(utf8_decode()) - if (function_exists('iconv_strlen')) return iconv_strlen($s, 'utf-8'); - - #Do not count UTF-8 continuation bytes - #return strlen(preg_replace('/[\x80-\xBF]/sSX', '', $s)); - - #slowly then strlen(utf8_decode()) - preg_match_all('~.~suSX', $str, $m); - return count($m[0]); - - #slowly then preg_match_all() + count() - $n = 0; - for ($i = 0, $len = strlen($s); $i < $len; $i++) - { - $c = ord(substr($s, $i, 1)); - if ($c < 0x80) $n++; #single-byte (0xxxxxx) - elseif (($c & 0xC0) == 0xC0) $n++; #multi-byte starting byte (11xxxxxx) - } - return $n; - */ - } - - /** - * Implementation strpos() function for UTF-8 encoding string - * - * @param string|null $s The entire string - * @param string|int $needle The searched substring - * @param int|null $offset The optional offset parameter specifies the position from which the search should be performed - * @return int|bool|null Returns the numeric position of the first occurrence of needle in haystack. - * If needle is not found, will return FALSE. - */ - public static function strpos($s, $needle, $offset = null) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - if ($offset === null || $offset < 0) $offset = 0; - if (function_exists('mb_strpos')) return mb_strpos($s, $needle, $offset, 'utf-8'); - #iconv_strpos() deprecated, because slowly than self::strlen(substr()) - #if (function_exists('iconv_strpos')) return iconv_strpos($s, $needle, $offset, 'utf-8'); - $byte_pos = $offset; - do if (($byte_pos = strpos($s, $needle, $byte_pos)) === false) return false; - while (($char_pos = self::strlen(substr($s, 0, $byte_pos++))) < $offset); - return $char_pos; - } - - /** - * Find position of first occurrence of a case-insensitive string. - * - * @param string|null $s The entire string - * @param string|int $needle The searched substring - * @param int|null $offset The optional offset parameter specifies the position from which the search should be performed - * @return int|bool|null Returns the numeric position of the first occurrence of needle in haystack. - * If needle is not found, will return FALSE. - */ - public static function stripos($s, $needle, $offset = null) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - if ($offset === null || $offset < 0) $offset = 0; - if (function_exists('mb_stripos')) return mb_stripos($s, $needle, $offset, 'utf-8'); - - #optimization block (speed improve) - #{{{ - $ascii_int = intval(self::is_ascii($s)) + intval(self::is_ascii($needle)); - if ($ascii_int === 1) return false; - if ($ascii_int === 2) return stripos($s, $needle, $offset); - #}}} - - $s = self::convert_case($s, CASE_LOWER, false); - if ($s === false) return false; - $needle = self::convert_case($needle, CASE_LOWER, false); - if ($needle === false) return false; - return self::strpos($s, $needle, $offset); - } - - /** - * Implementation strrev() function for UTF-8 encoding string - * - * @param string|null $s - * @return string|bool|null Returns FALSE if error occurred - */ - public static function strrev($s) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - if (0) #TODO test speed - { - $s = self::_convert($s, 'UTF-8', 'UTF-32'); - if (! is_string($s)) return false; - $s = implode('', array_reverse(str_split($s, 4))); - return self::_convert($s, 'UTF-32', 'UTF-8'); - } - - if (! is_array($a = self::str_split($s))) return false; - return implode('', array_reverse($a)); - } - - /** - * Implementation substr() function for UTF-8 encoding string. - * - * @link http://www.w3.org/International/questions/qa-forms-utf-8.html - * @param string|null $s - * @param int|digit $offset - * @param int|null|digit $length - * @return string|bool|null Returns FALSE if error occurred - */ - public static function substr($s, $offset, $length = null) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - #since PHP-5.3.x mb_substr() faster then iconv_substr() - if (function_exists('mb_substr')) - { - if ($length === null) $length = self::strlen($s); - return mb_substr($s, $offset, $length, 'utf-8'); - } - if (function_exists('iconv_substr')) - { - if ($length === null) $length = self::strlen($s); - return iconv_substr($s, $offset, $length, 'utf-8'); - } - - static $_s = null; - static $_a = null; - - if ($_s !== $s) $_a = self::str_split($_s = $s); - if (! is_array($_a)) return false; - if ($length !== null) $a = array_slice($_a, $offset, $length); - else $a = array_slice($_a, $offset); - return implode('', $a); - } - - /** - * Implementation substr_replace() function for UTF-8 encoding string. - * - * @param string|null $s - * @param string|int $replacement - * @param int|digit $start - * @param int|null $length - * @return string|bool|null Returns FALSE if error occurred - */ - public static function substr_replace($s, $replacement, $start, $length = null) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - if (! is_array($a = self::str_split($s))) return false; - array_splice($a, $start, $length, $replacement); - return implode('', $a); - } - - /** - * Implementation ucfirst() function for UTF-8 encoding string. - * Преобразует первый символ строки в кодировке UTF-8 в верхний регистр. - * - * @param string|null $s - * @param bool $is_other_to_lowercase остальные символы преобразуются в нижний регистр? - * @return string|bool|null Returns FALSE if error occurred - */ - public static function ucfirst($s, $is_other_to_lowercase = true) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - if ($s === '' || ! is_string($s)) return $s; - if (! preg_match('/^(.)(.*)$/suSX', $s, $m)) return false; - return self::uppercase($m[1]) . ($is_other_to_lowercase ? self::lowercase($m[2]) : $m[2]); - } - - /** - * Implementation ucwords() function for UTF-8 encoding string. - * Преобразует в верхний регистр первый символ каждого слова в строке в кодировке UTF-8, - * остальные символы каждого слова преобразуются в нижний регистр. - * - * @param string|null $s - * @param bool $is_other_to_lowercase остальные символы преобразуются в нижний регистр? - * @param string $spaces_re - * @return string|bool|null Returns FALSE if error occurred - */ - public static function ucwords($s, $is_other_to_lowercase = true, $spaces_re = '~([\pZ\s]+)~suSX') #\pXps is POSIX space: property Z or tab, NL, VT, FF, CR - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_null($s)) return $s; - - $words = preg_split($spaces_re, $s, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); - foreach ($words as $k => $word) - { - $words[$k] = self::ucfirst($word, $is_other_to_lowercase = true); - if ($words[$k] === false) return false; - } - return implode('', $words); - } - - /** - * Decodes a string in the format %uXXXX or %u{XXXXXX} in the UTF-8 string. - * - * Используется для декодирования данных типа "%u0442%u0435%u0441%u0442", - * закодированных устаревшей функцией javascript://encode(). - * Рекомендуется использовать функцию javascript://encodeURIComponent(). - * - * NOTICE - * Устаревший формат %uXXXX позволяет использовать юникод только из диапазона UCS-2, т.е. от U+0 до U+FFFF - * - * @param scalar|array|null $data - * @param bool $is_rawurlencode - * @return scalar|array|null Returns FALSE if error occurred - */ - public static function unescape($data, $is_rawurlencode = false) - { - if (! ReflectionTypeHint::isValid()) return false; - if (is_array($data)) - { - $d = array(); - foreach ($data as $k => &$v) - { - $k = self::unescape($k, $is_rawurlencode); - if ($k === false) return false; - $d[$k] = self::unescape($v, $is_rawurlencode); - if ($d[$k] === false && ! is_bool($v)) return false; - } - return $d; - } - if (is_string($data)) - { - if (strpos($data, '%u') === false) return $data; #use strpos() for speed improving - return preg_replace_callback('/%u( [\da-fA-F]{4}+ #%uXXXX only UCS-2 - | \{ [\da-fA-F]{1,6}+ \} #%u{XXXXXX} extended form for all UNICODE charts - ) - /sxSX', - function (array $m) use ($is_rawurlencode) - { - $codepoint = hexdec(trim($m[1], '{}')); - $char = self::chr($codepoint); - return $is_rawurlencode ? rawurlencode($char) : $char; - }, - $data); - } - if (is_scalar($data) || is_null($data)) return $data; #~ null, integer, float, boolean - return false; #object or resource - } - - /** - * 1) Corrects the global arrays $_GET, $_POST, $_COOKIE, $_REQUEST - * decoded values ​​in the format %uXXXX and %u{XXXXXX}, encoded, - * for example, through an outdated javascript function escape(). - * Standard PHP5 cannot do it. - * 2) If in the HTTP_COOKIE there are parameters with the same name, - * takes the last value, not the first, as in the QUERY_STRING. - * 3) Creates an array of $_POST for non-standard Content-Type, for example, "Content-Type: application/octet-stream". - * Standard PHP5 creates an array for "Content-Type: application/x-www-form-urlencoded" and "Content-Type: multipart/form-data". - * - * Сессии, куки и независимая авторизация на поддоменах. - * - * ПРИМЕР 1 - * У рабочего сайта http://domain.com появились поддомены. - * Для кроссдоменной авторизации через механизм сессий имя хоста для COOKIE было изменено с "domain.com" на ".domain.com" - * В результате авторизация не работает. - * Помогает очистка COOKIE, но их принудительная очистка на тысячах пользовательских компьютеров проблематична. - * Проблема в следующем: если в HTTP_COOKIE есть параметры с одинаковым именем, то берётся последнее значение, - * а не первое, как в QUERY_STRING. - * Более подробное описание: - * PHP не правильно (?) обрабатывает заголовок HTTP_COOKIE, если там встречаются параметры с одинаковым именем, но разными значениями. - * Пример запроса HTTP-заголовка клиентом: "Cookie: sid=chpgs2fiak-330mzqza; sid=cmz5tnp5zz-xlbbgqp" - * В этом случае сервер берёт первое значение, а не последнее. - * Хотя если в QUERY_STRING есть такая ситуация, всегда берётся последний параметр. - * В HTTP_COOKIE два параметра с одинаковым именем могут появиться, если отправить клиенту следующие HTTP-заголовки: - * "Set-Cookie: sid=chpgs2fiak-330mzqza; expires=Thu, 15 Oct 2009 14:23:42 GMT; path=/; domain=domain.com" (только domain.com) - * "Set-Cookie: sid=cmz6uqorzv-1bn35110; expires=Thu, 15 Oct 2009 14:23:42 GMT; path=/; domain=.domain.com" (domain.com и все его поддомены) - * Решение: поменять имя сессии. - * - * ПРИМЕР 2 - * Есть рабочие сайты: http://domain.com (основной), http://admin.domain.com (админка), - * http://sub1.domain.com (подпроект 1), http://sub2.domain.com, (подпроект 2). - * Так же имеется сервер разработки http://dev.domain.com, на котором м. б. свои поддомены. - * Требуется сделать независимую кросс-доменную авторизацию для http://*.domain.com и http://*.dev.domain.com. - * Для сохранения статуса авторизации будем использовать сессию, имя и значение которой пишется в COOKIE. - * Т. к. домены http://*.dev.domain.com имеют пересечение с доменами http://*.domain.com, - * для независимой авторизации нужно использовать разные имена сессий. - * Пример HTTP заголовков ответа сервера: - * "Set-Cookie: sid=chpgs2fiak-330mzqza; expires=Thu, 15 Oct 2009 14:23:42 GMT; path=/; domain=.domain.com" (.domain.com и все его поддомены) - * "Set-Cookie: sid.dev=cmz6uqorzv-1bn35110; expires=Thu, 15 Oct 2009 14:23:42 GMT; path=/; domain=.dev.domain.com" (dev.domain.com и все его поддомены) - * - * @link http://tools.ietf.org/html/rfc2965 RFC 2965 - HTTP State Management Mechanism - * @return void - */ - public static function unescape_request() - { - $fixed = false; - #ATTENTION! HTTP_RAW_POST_DATA is only accessible when Content-Type of POST request is NOT default "application/x-www-form-urlencoded"! - $HTTP_RAW_POST_DATA = isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' ? (isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : @file_get_contents('php://input')) : null; - if (ini_get('always_populate_raw_post_data')) $GLOBALS['HTTP_RAW_POST_DATA'] = $HTTP_RAW_POST_DATA; - foreach (array( '_GET' => isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null, - '_POST' => $HTTP_RAW_POST_DATA, - '_COOKIE' => isset($_SERVER['HTTP_COOKIE']) ? $_SERVER['HTTP_COOKIE'] : null, - ) as $k => $v) - { - if (! is_string($v)) continue; - if ($k === '_COOKIE') - { - $v = preg_replace('/; *+/sSX', '&', $v); - unset($_COOKIE); #будем парсить HTTP_COOKIE сами, чтобы сделать обработку как у QUERY_STRING - } - if (strpos($v, '%u') !== false) - { - parse_str(self::unescape($v, $is_rawurlencode = true), $GLOBALS[$k]); - $fixed = true; - continue; - } - if (array_key_exists($k, $GLOBALS)) continue; - parse_str($v, $GLOBALS[$k]); - $fixed = true; - } - if ($fixed) - { - $_REQUEST = - (isset($_COOKIE) ? $_COOKIE : array()) + - (isset($_POST) ? $_POST : array()) + - (isset($_GET) ? $_GET : array()); - } - } - - /** - * Calculates the height of the edit text in - - - - - - - - - - - - -
        Правила оформления
        -
        {TPL_RULES_HTML}
        -
        -
        -
        - - - - - --- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        Создание шаблона для релиза
        -
        -
        - - -
        название: [?]
        - -
        - -
        - - - - -
        -
        -
        -
        -

        сообщение: [?]

        - -
        -
        -
        -
        -
        [ Инструкция ]
        - -
        -
        - - -
        -
        - - - - -
        -
        - - - - - - - - - - - - - - - -
        - -
        - - - - - -
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        - -
        - - - - -
        - + + + + +

        {FORUM_NAME}

        + + + + +
        + + + +
        + + + + + + + + + +
        Правила оформления
        +
        {TPL_RULES_HTML}
        +
        +
        +
        + + + + + +++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        Создание шаблона для релиза
        +
        +
        + + +
        название: [?]
        + +
        + +
        + + + + +
        +
        +
        +
        +

        сообщение: [?]

        + +
        +
        +
        +
        +
        [ Инструкция ]
        + +
        +
        + + +
        +
        + + + + +
        +
        + + + + + + + + + + + + + + + +
        + +
        + + + + + +
        + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        + +
        + + + + +
        + \ No newline at end of file diff --git a/upload/templates/default/usercp_bonus.tpl b/upload/templates/default/usercp_bonus.tpl index fb4f168b2..8cc1a7596 100644 --- a/upload/templates/default/usercp_bonus.tpl +++ b/upload/templates/default/usercp_bonus.tpl @@ -1,53 +1,53 @@ - -{PAGE_TITLE} - - - - - -
        - -
        - - - - - - - - - - - - - - - - - - - - - - -
        {MY_BONUS}
        {L_DESCRIPTION}{L_PRICE}{L_BONUS_SELECT}
        {bonus_upload.DESC}{bonus_upload.PRICE}
        - -
        - -
        - - -
        - -
        - -
        -

        {CURRENT_TIME}

        -

        {S_TIMEZONE}

        -
        -
        - + +{PAGE_TITLE} + + + + + +
        + +
        + + + + + + + + + + + + + + + + + + + + + + +
        {MY_BONUS}
        {L_DESCRIPTION}{L_PRICE}{L_BONUS_SELECT}
        {bonus_upload.DESC}{bonus_upload.PRICE}
        + +
        + +
        + + +
        + +
        + +
        +

        {CURRENT_TIME}

        +

        {S_TIMEZONE}

        +
        +
        +
        \ No newline at end of file diff --git a/upload/templates/default/usercp_topic_watch.tpl b/upload/templates/default/usercp_topic_watch.tpl index 1ba5e7ea4..be0c3c52c 100644 --- a/upload/templates/default/usercp_topic_watch.tpl +++ b/upload/templates/default/usercp_topic_watch.tpl @@ -1,127 +1,127 @@ - - - - - - - - - - - - - - - - - -
        -

        {PAGE_TITLE}

        - -
        {PAGINATION}
        - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +
        {L_FORUM}{L_TOPIC}{L_AUTHOR}{L_REPLIES}{L_LASTPOST}
        - {watch.TOPIC_ICON} - - {watch.FORUM_TITLE} - {watch.TOPIC_TITLE} -
         [{ICON_GOTOPOST}{L_GOTO_SHORT} {watch.PAGINATION} ] -
        {watch.AUTHOR}{watch.REPLIES} - {watch.LAST_POST}{ICON_NEWEST_REPLY} - {ICON_LATEST_REPLY} -
        - {L_DEL_LIST_INFO}{MATCHES} -
        +
        + +
        + +
        + + + + + + + + + + + + +
        +

        {PAGE_TITLE}

        + +
        {PAGINATION}
        + + + + + + + + + + + + + + + + + + + + + + + + + + +
        {L_FORUM}{L_TOPIC}{L_AUTHOR}{L_REPLIES}{L_LASTPOST}
        + {watch.TOPIC_ICON} + + {watch.FORUM_TITLE} + {watch.TOPIC_TITLE} +
         [{ICON_GOTOPOST}{L_GOTO_SHORT} {watch.PAGINATION} ] +
        {watch.AUTHOR}{watch.REPLIES} + {watch.LAST_POST}{ICON_NEWEST_REPLY} + {ICON_LATEST_REPLY} +
        + {L_DEL_LIST_INFO}{MATCHES} +
        \ No newline at end of file diff --git a/upload/templates/default/viewtopic.tpl b/upload/templates/default/viewtopic.tpl index 749c0d599..fadfed052 100644 --- a/upload/templates/default/viewtopic.tpl +++ b/upload/templates/default/viewtopic.tpl @@ -1,637 +1,637 @@ - - - - - - - - - - - - - - - -
        - -

        - {TOPIC_TITLE} - - - - - - -

        - - -

        {PAGINATION}

        - - - - - - - -
        - {T_POST_REPLY} -
        - - - - - - - - - - - - - - - - - - -
        - - - - - - - - - - - - - - - - - -
        - {L_MODERATE_TOPIC}{L_MODERATE_TOPIC} -  |  - {PIN_TITLE} - |{L_SELECT_POSTS_PER_PAGE} -
        {SELECT_PPP}
        -
        -   - - {L_SEARCH_SELF}  |  - {L_DISPLAYING_OPTIONS} - - -
        - - -
        -
        - -
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        {L_AUTHOR}{L_MESSAGE}
        - - -

        {postrow.POSTER_NAME}

        -

        {postrow.POSTER_AVATAR}

        - - -

        - {postrow.POSTER_NAME} ® -

        - -

        {postrow.POSTER_NAME} ®

        - - -

        {postrow.POSTER_RANK}

        -

        {postrow.RANK_IMAGE}

        -

        {postrow.POSTER_AVATAR}

        -

        {L_GENDER}: {postrow.POSTER_GENDER}

        -

        {L_LONGEVITY}: {postrow.POSTER_JOINED}

        -

        {L_POSTS}: {postrow.POSTER_POSTS}

        -

        {L_LOCATION}: {postrow.POSTER_FROM}

        - -

        {postrow.POSTER_BIRTHDAY}

        - - -

        - -
        - -
        -

        - {MINIPOST_IMG_NEW}{MINIPOST_IMG} - {postrow.POST_DATE} - - ({L_POSTED_AFTER} {postrow.POSTED_AFTER}) - -

        - - - -

        - {POLL_IMG} - {QUOTE_IMG}{POST_BTN_SPACER} - {EDIT_POST_IMG}{POST_BTN_SPACER} - {DELETE_POST_IMG}{POST_BTN_SPACER} - {IP_POST_IMG}{POST_BTN_SPACER} - {postrow.REPORT}{POST_BTN_SPACER} - - {MC_IMG}{POST_BTN_SPACER} - {MOD_POST_IMG}{POST_BTN_SPACER} - -

        -
        -
        - -
        -
        - - {postrow.MESSAGE} -
        style="display: none;"> -
        -

        {postrow.MC_TITLE}


        -
        {postrow.MC_COMMENT}
        -
        -
        - {postrow.ATTACHMENTS} -
        - {postrow.SIGNATURE} -
        {postrow.EDITED_MESSAGE}
        -
        - - - - - -
        - - -   - -
        - {PROFILE_IMG}{POST_BTN_SPACER} - {PM_IMG}{POST_BTN_SPACER} -
        - - -
        - - - - - - - - -
        - - -
        - - - - - - - - - - - - - -
        {L_QUICK_REPLY}
        - -
        - -

        {L_QR_USERNAME}:

        - -
        - -
        -
        - -
        - -
        - -
        - - - - - - -
        -
        - {L_DISPLAY_POSTS}: {S_SELECT_POST_DAYS}  - {S_SELECT_POST_ORDER}  - -
        -
        - - - - - - -
        - {T_POST_REPLY} -
        - - -
        - -
        - -
        -

        {CURRENT_TIME}

        -

        {S_TIMEZONE}

        -
        -
        - -
        - - - - - + + + + + + + + + + + + + + + +
        + +

        + {TOPIC_TITLE} + + + + + + +

        + + +

        {PAGINATION}

        + + +
        {S_WATCH_TOPIC}
        -
        - -
        -
        {S_TOPIC_ADMIN}
        - - -
        - Admin:  - {L_LOGS}  -
        - - -
        -
        {S_DL_DELETE}
        - -
        -
        {S_AUTH_LIST}
        -
        -
        + + + + +
        + {T_POST_REPLY} +
        + + + + + + + + + + + + + + + + + + +
        + + + + + + + + + + + + + + + + + +
        + {L_MODERATE_TOPIC}{L_MODERATE_TOPIC} +  |  + {PIN_TITLE} + |{L_SELECT_POSTS_PER_PAGE} +
        {SELECT_PPP}
        +
        +   + + {L_SEARCH_SELF}  |  + {L_DISPLAYING_OPTIONS} + + +
        + + +
        +
        + +
        + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        {L_AUTHOR}{L_MESSAGE}
        + + +

        {postrow.POSTER_NAME}

        +

        {postrow.POSTER_AVATAR}

        + + +

        + {postrow.POSTER_NAME} ® +

        + +

        {postrow.POSTER_NAME} ®

        + + +

        {postrow.POSTER_RANK}

        +

        {postrow.RANK_IMAGE}

        +

        {postrow.POSTER_AVATAR}

        +

        {L_GENDER}: {postrow.POSTER_GENDER}

        +

        {L_LONGEVITY}: {postrow.POSTER_JOINED}

        +

        {L_POSTS}: {postrow.POSTER_POSTS}

        +

        {L_LOCATION}: {postrow.POSTER_FROM}

        + +

        {postrow.POSTER_BIRTHDAY}

        + + +

        + +
        + +
        +

        + {MINIPOST_IMG_NEW}{MINIPOST_IMG} + {postrow.POST_DATE} + + ({L_POSTED_AFTER} {postrow.POSTED_AFTER}) + +

        + + + +

        + {POLL_IMG} + {QUOTE_IMG}{POST_BTN_SPACER} + {EDIT_POST_IMG}{POST_BTN_SPACER} + {DELETE_POST_IMG}{POST_BTN_SPACER} + {IP_POST_IMG}{POST_BTN_SPACER} + {postrow.REPORT}{POST_BTN_SPACER} + + {MC_IMG}{POST_BTN_SPACER} + {MOD_POST_IMG}{POST_BTN_SPACER} + +

        +
        +
        + +
        +
        + + {postrow.MESSAGE} +
        style="display: none;"> +
        +

        {postrow.MC_TITLE}


        +
        {postrow.MC_COMMENT}
        +
        +
        + {postrow.ATTACHMENTS} +
        + {postrow.SIGNATURE} +
        {postrow.EDITED_MESSAGE}
        +
        + + + + + +
        + + +   + +
        + {PROFILE_IMG}{POST_BTN_SPACER} + {PM_IMG}{POST_BTN_SPACER} +
        + + +
        + + + + + + + + +
        + + +
        + + + + + + + + + + + + + +
        {L_QUICK_REPLY}
        + +
        + +

        {L_QR_USERNAME}:

        + +
        + +
        +
        + +
        + +
        + +
        + + + + + + +
        +
        + {L_DISPLAY_POSTS}: {S_SELECT_POST_DAYS}  + {S_SELECT_POST_ORDER}  + +
        +
        + + + + + + +
        + {T_POST_REPLY} +
        + + +
        + +
        + +
        +

        {CURRENT_TIME}

        +

        {S_TIMEZONE}

        +
        +
        + +
        + + + + +
        {S_WATCH_TOPIC}
        +
        + +
        +
        {S_TOPIC_ADMIN}
        + + +
        + Admin:  + {L_LOGS}  +
        + + +
        +
        {S_DL_DELETE}
        + +
        +
        {S_AUTH_LIST}
        +
        +
        \ No newline at end of file diff --git a/upload/viewforum.php b/upload/viewforum.php index 6a76065bf..219e3aace 100644 --- a/upload/viewforum.php +++ b/upload/viewforum.php @@ -1,594 +1,594 @@ -session_start(); - -$lastvisit = (IS_GUEST) ? TIMENOW : $userdata['user_lastvisit']; - -// Caching output -$req_page = "forum_f{$forum_id}"; -$req_page .= ($start) ? "_start{$start}" : ''; - -define('REQUESTED_PAGE', $req_page); -caching_output(IS_GUEST, 'send', REQUESTED_PAGE .'_guest'); - -set_die_append_msg(); -if (!$forums = $datastore->get('cat_forums')) -{ - $datastore->update('cat_forums'); - $forums = $datastore->get('cat_forums'); -} -if (!$forum_id OR !$forum_data = @$forums['forum'][$forum_id]) -{ - bb_die($lang['FORUM_NOT_EXIST']); -} - -// Only new -$only_new = $user->opt_js['only_new']; -$only_new_sql = ''; -if ($only_new == ONLY_NEW_POSTS) -{ - $only_new_sql = "AND t.topic_last_post_time > $lastvisit"; -} -elseif ($only_new == ONLY_NEW_TOPICS) -{ - $only_new_sql = "AND t.topic_time > $lastvisit"; -} - -// Auth -$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_data); - -$moderation = (!empty($_REQUEST['mod']) && $is_auth['auth_mod']); - -if (!$is_auth['auth_view']) -{ - if (IS_GUEST) - { - $redirect = "f=$forum_id"; - $redirect .= ($start) ? "&start=$start" : ''; - redirect(LOGIN_URL . "?redirect=viewforum.php&$redirect"); - } - // The user is not authed to read this forum ... - $message = sprintf($lang['SORRY_AUTH_VIEW'], $is_auth['auth_view_type']); - bb_die($message); -} - -// Redirect to login page if not admin session -$mod_redirect_url = ''; - -// Filter by torrent status -$tor_status = -1; // all by default - -if ($is_auth['auth_mod']) -{ - $redirect = isset($_POST['redirect']) ? $_POST['redirect'] : @$_SERVER['REQUEST_URI']; - $redirect = url_arg($redirect, 'mod', 1, '&'); - $mod_redirect_url = LOGIN_URL . "?redirect=$redirect&admin=1"; - - if ($moderation && !$userdata['session_admin']) - { - redirect($mod_redirect_url); - } - if (isset($_REQUEST['tst']) && $_REQUEST['tst'] != -1) - { - $tor_status = (int) $_REQUEST['tst']; - // reset other req values - unset($_REQUEST['sort'], $_REQUEST['order'], $_REQUEST[$title_match_key]); - $show_type_separator = false; - } - $select_tst = array_merge(array($lang['TOR_STATUS_SELECT_ALL'] => -1), array_flip($lang['TOR_STATUS_NAME'])); - $template->assign_vars(array( - 'SELECT_TST' => build_select('tst', $select_tst, $tor_status), - )); - $select_st = array_merge(array($lang['TOR_STATUS_SELECT_ACTION'] => -1), array_flip($lang['TOR_STATUS_NAME'])); - $template->assign_vars(array( - 'SELECT_ST' => build_select('st', $select_st, -1), - )); -} - -// Topics read tracks -$tracking_topics = get_tracks('topic'); -$tracking_forums = get_tracks('forum'); - -if ($mark_read && !IS_GUEST) -{ - set_tracks(COOKIE_FORUM, $tracking_forums, $forum_id); - - set_die_append_msg($forum_id); - $message = $lang['TOPICS_MARKED_READ']; - bb_die($message); -} - -// Subforums -$show_subforums = ($bb_cfg['sf_on_first_page_only']) ? !$start : true; - -if (!$forums = $datastore->get('cat_forums')) -{ - $datastore->update('cat_forums'); - $forums = $datastore->get('cat_forums'); -} - -if($forums['forum'][$forum_id]['allow_porno_topic'] && bf($userdata['user_opt'], 'user_opt', 'user_porn_forums')) bb_die($lang['ERROR_PORNO_FORUM']); - -if (!$forum_data['forum_parent'] && isset($forums['f'][$forum_id]['subforums']) && $show_subforums) -{ - $not_auth_forums = $user->get_excluded_forums(AUTH_VIEW); - $ignore_forum_sql = ($not_auth_forums) ? "AND f.forum_id NOT IN($not_auth_forums)" : ''; - - $sql = " - SELECT - f.forum_id, f.forum_status, f.forum_last_post_id, f.forum_posts, f.forum_topics, - t.topic_last_post_time, t.topic_id AS last_topic_id, t.topic_title AS last_topic_title, - p.poster_id AS sf_last_user_id, IF(p.poster_id = $anon, p.post_username, u.username) AS sf_last_username, u.user_rank - FROM ". BB_FORUMS ." f - LEFT JOIN ". BB_TOPICS ." t ON(f.forum_last_post_id = t.topic_last_post_id) - LEFT JOIN ". BB_POSTS ." p ON(f.forum_last_post_id = p.post_id) - LEFT JOIN ". BB_USERS ." u ON(p.poster_id = u.user_id) - WHERE f.forum_parent = $forum_id - $only_new_sql - $ignore_forum_sql - GROUP BY f.forum_id - ORDER BY f.forum_order - "; - - if ($rowset = DB()->fetch_rowset($sql)) - { - $template->assign_vars(array( - 'SHOW_SUBFORUMS' => true, - 'FORUM_IMG' => $images['forum'], - 'FORUM_NEW_IMG' => $images['forum_new'], - 'FORUM_LOCKED_IMG' => $images['forum_locked'], - )); - } - foreach ($rowset as $sf_data) - { - $sf_forum_id = $sf_data['forum_id']; - $sf_last_tid = $sf_data['last_topic_id']; - $folder_image = $images['forum']; - $last_post = $lang['NO_POSTS']; - - if (!$fname_html =& $forums['forum_name_html'][$sf_forum_id]) - { - continue; - } - - if ($sf_data['forum_status'] == FORUM_LOCKED) - { - $folder_image = $images['forum_locked']; - } - elseif (is_unread($sf_data['topic_last_post_time'], $sf_last_tid, $sf_forum_id)) - { - $folder_image = $images['forum_new']; - } - - $last_post_user = profile_url(array('username' => $sf_data['sf_last_username'], 'user_id' => $sf_data['sf_last_user_id'], 'user_rank' => $sf_data['user_rank'])); - - if ($sf_data['forum_last_post_id']) - { - $last_post = bb_date($sf_data['topic_last_post_time'], $bb_cfg['last_post_date_format']); - $last_post .= "
        $last_post_user"; - $last_post .= 'latest'; - } - - $template->assign_block_vars('f', array( - 'FORUM_FOLDER_IMG' => $folder_image, - - 'FORUM_NAME' => $fname_html, - 'FORUM_DESC' => $forums['f'][$sf_forum_id]['forum_desc'], - 'U_VIEWFORUM' => FORUM_URL . $sf_forum_id, - 'TOPICS' => commify($sf_data['forum_topics']), - 'POSTS' => commify($sf_data['forum_posts']), - 'LAST_POST' => $last_post, - )); - - if ($sf_data['forum_last_post_id']) - { - $template->assign_block_vars('f.last', array( - 'FORUM_LAST_POST' => true, - 'SHOW_LAST_TOPIC' => $show_last_topic, - 'LAST_TOPIC_ID' => $sf_data['last_topic_id'], - 'LAST_TOPIC_TIP' => $sf_data['last_topic_title'], - 'LAST_TOPIC_TITLE' => str_short($sf_data['last_topic_title'], $last_topic_max_len), - 'LAST_POST_TIME' => bb_date($sf_data['topic_last_post_time'], $bb_cfg['last_post_date_format']), - 'LAST_POST_ID' => $sf_data['forum_last_post_id'], - 'LAST_POST_USER' => $last_post_user, - 'ICON_LATEST_REPLY' => $images['icon_latest_reply'], - )); - } - else - { - $template->assign_block_vars('f.last', array('FORUM_LAST_POST' => false)); - } - } -} -unset($rowset); -$datastore->rm('cat_forums'); - -// Topics per page -$topics_per_page = $bb_cfg['topics_per_page']; -$select_tpp = ''; - -if ($is_auth['auth_mod']) -{ - if ($req_tpp = abs(intval(@$_REQUEST['tpp'])) AND in_array($req_tpp, $bb_cfg['allowed_topics_per_page'])) - { - $topics_per_page = $req_tpp; - } - - $select_tpp = array(); - foreach ($bb_cfg['allowed_topics_per_page'] as $tpp) - { - $select_tpp[$tpp] = $tpp; - } -} - -// Generate a 'Show topics in previous x days' select box. -$topic_days = 0; // all the time -$forum_topics = $forum_data['forum_topics']; - -$sel_previous_days = array( - 0 => $lang['ALL_POSTS'], - 1 => $lang['1_DAY'], - 7 => $lang['7_DAYS'], - 14 => $lang['2_WEEKS'], - 30 => $lang['1_MONTH'], - 90 => $lang['3_MONTHS'], - 180 => $lang['6_MONTHS'], - 364 => $lang['1_YEAR'], -); - -if (!empty($_REQUEST['topicdays'])) -{ - if ($req_topic_days = abs(intval($_REQUEST['topicdays'])) AND isset($sel_previous_days[$req_topic_days])) - { - $sql = " - SELECT COUNT(*) AS forum_topics - FROM ". BB_TOPICS ." - WHERE forum_id = $forum_id - AND topic_last_post_time > ". (TIMENOW - 86400*$req_topic_days) ." - "; - - if ($row = DB()->fetch_row($sql)) - { - $topic_days = $req_topic_days; - $forum_topics = $row['forum_topics']; - } - } -} -// Correct $start value -if ($start > $forum_topics) -{ - redirect("viewforum.php?f=$forum_id"); -} - -// Generate SORT and ORDER selects -$sort_value = isset($_REQUEST['sort']) ? (int) $_REQUEST['sort'] : $forum_data['forum_display_sort']; -$order_value = isset($_REQUEST['order']) ? (int) $_REQUEST['order'] : $forum_data['forum_display_order']; -$sort_list = ''; -$order_list = ''; -$s_display_order = ' '. $lang['SORT_BY'] .': '. $sort_list .' '. $order_list .' '; - -// Selected SORT and ORDER methods -$sort_method = get_forum_display_sort_option($sort_value, 'field', 'sort'); -$order_method = get_forum_display_sort_option($order_value, 'field', 'order'); - -$order_sql = "ORDER BY t.topic_type DESC, $sort_method $order_method"; - -$limit_topics_time_sql = ($topic_days) ? "AND t.topic_last_post_time > ". (TIMENOW - 86400*$topic_days) : ''; - -$select_tor_sql = $join_tor_sql = ''; -$join_dl = ($bb_cfg['show_dl_status_in_forum'] && !IS_GUEST); - -$where_tor_sql = ''; -if ($forum_data['allow_reg_tracker']) -{ - if ($tor_status != -1) - { - $where_tor_sql = "AND tor.tor_status = $tor_status"; - } - - $select_tor_sql = ', - bt.auth_key, tor.info_hash, tor.size AS tor_size, tor.reg_time, tor.complete_count, tor.seeder_last_seen, tor.attach_id, tor.tor_status, tor.tor_type, - sn.seeders, sn.leechers - '; - $select_tor_sql .= ($join_dl) ? ', dl.user_status AS dl_status' : ''; - - $join_tor_sql = " - LEFT JOIN ". BB_BT_TORRENTS ." tor ON(t.topic_id = tor.topic_id) - LEFT JOIN ". BB_BT_USERS ." bt ON(bt.user_id = {$userdata['user_id']}) - LEFT JOIN ". BB_BT_TRACKER_SNAP ." sn ON(tor.topic_id = sn.topic_id) - "; - $join_tor_sql .= ($join_dl) ? " LEFT JOIN ". BB_BT_DLSTATUS ." dl ON(dl.user_id = {$userdata['user_id']} AND dl.topic_id = t.topic_id)" : ''; -} - -// Title match -$title_match_sql = ''; - -if ($title_match =& $_REQUEST[$title_match_key]) -{ - if ($tmp = mb_substr(trim($title_match), 0, $title_match_max_len)) - { - $title_match_val = clean_text_match($tmp, true, false, false); - $title_match_topics = get_title_match_topics($title_match_val, array(0 => $forum_id)); - - if ($search_match_topics_csv = join(',', $title_match_topics)) - { - $title_match_sql = "AND t.topic_id IN($search_match_topics_csv)"; - } - } -} - -// Get topics -$topic_ids = $topic_rowset = array(); - -// IDs -$sql = " - SELECT t.topic_id - FROM ". BB_TOPICS ." t - WHERE t.forum_id = $forum_id - $only_new_sql - $title_match_sql - $limit_topics_time_sql - $order_sql - LIMIT $start, $topics_per_page -"; -foreach (DB()->fetch_rowset($sql) as $row) -{ - $topic_ids[] = $row['topic_id']; -} - -// Titles, posters etc. -if ($topics_csv = join(',', $topic_ids)) -{ - $topic_rowset = DB()->fetch_rowset(" - SELECT - t.*, t.topic_poster AS first_user_id, u1.user_rank as first_user_rank, - IF(t.topic_poster = $anon, p1.post_username, u1.username) AS first_username, - p2.poster_id AS last_user_id, u2.user_rank as last_user_rank, - IF(p2.poster_id = $anon, p2.post_username, u2.username) AS last_username - $select_tor_sql - FROM ". BB_TOPICS ." t - LEFT JOIN ". BB_POSTS ." p1 ON(t.topic_first_post_id = p1.post_id) - LEFT JOIN ". BB_USERS ." u1 ON(t.topic_poster = u1.user_id) - LEFT JOIN ". BB_POSTS ." p2 ON(t.topic_last_post_id = p2.post_id) - LEFT JOIN ". BB_USERS ." u2 ON(p2.poster_id = u2.user_id) - $join_tor_sql - WHERE t.topic_id IN($topics_csv) - $where_tor_sql - GROUP BY t.topic_id - $order_sql - "); -} - -// Define censored word matches -$orig_word = $replacement_word = array(); -obtain_word_list($orig_word, $replacement_word); - -if($forum_data['allow_reg_tracker']) -{ - $post_new_topic_url = POSTING_URL . "?mode=new_rel&f=$forum_id"; - $post_img = $images['release_new']; - $post_new_topic = $lang['POST_NEW_RELEASE']; -} -else -{ - $post_new_topic_url = POSTING_URL . "?mode=newtopic&f=$forum_id"; - $post_img = $images['post_new']; - $post_new_topic = $lang['POST_NEW_TOPIC']; -} - -// Post URL generation for templating vars -$template->assign_vars(array( - 'U_POST_NEW_TOPIC' => $post_new_topic_url, - 'S_SELECT_TOPIC_DAYS' => build_select('topicdays', array_flip($sel_previous_days), $topic_days), - 'S_POST_DAYS_ACTION' => "viewforum.php?f=$forum_id&start=$start", - 'S_DISPLAY_ORDER' => $s_display_order, -)); - -// User authorisation levels output -$u_auth = array(); -$u_auth[] = ($is_auth['auth_post']) ? $lang['RULES_POST_CAN'] : $lang['RULES_POST_CANNOT']; -$u_auth[] = ($is_auth['auth_reply']) ? $lang['RULES_REPLY_CAN'] : $lang['RULES_REPLY_CANNOT']; -$u_auth[] = ($is_auth['auth_edit']) ? $lang['RULES_EDIT_CAN'] : $lang['RULES_EDIT_CANNOT']; -$u_auth[] = ($is_auth['auth_delete']) ? $lang['RULES_DELETE_CAN'] : $lang['RULES_DELETE_CANNOT']; -$u_auth[] = ($is_auth['auth_vote']) ? $lang['RULES_VOTE_CAN'] : $lang['RULES_VOTE_CANNOT']; -$u_auth[] = ($is_auth['auth_attachments']) ? $lang['RULES_ATTACH_CAN'] : $lang['RULES_ATTACH_CANNOT']; -$u_auth[] = ($is_auth['auth_download']) ? $lang['RULES_DOWNLOAD_CAN'] : $lang['RULES_DOWNLOAD_CANNOT']; -$u_auth[] = ($is_auth['auth_mod']) ? $lang['RULES_MODERATE'] : ''; -$u_auth = join("
        \n", $u_auth); - -$template->assign_vars(array( - 'SHOW_JUMPBOX' => true, - 'PAGE_TITLE' => htmlCHR($forum_data['forum_name']), - 'FORUM_ID' => $forum_id, - 'FORUM_NAME' => htmlCHR($forum_data['forum_name']), - 'TORRENTS' => $forum_data['allow_reg_tracker'], - 'POST_IMG' => ($forum_data['forum_status'] == FORUM_LOCKED) ? $images['post_locked'] : $post_img, - - 'FOLDER_IMG' => $images['folder'], - 'FOLDER_NEW_IMG' => $images['folder_new'], - 'FOLDER_LOCKED_IMG' => $images['folder_locked'], - 'FOLDER_STICKY_IMG' => $images['folder_sticky'], - 'FOLDER_ANNOUNCE_IMG' => $images['folder_announce'], - 'FOLDER_DOWNLOAD_IMG' => $images['folder_dl'], - - 'SHOW_ONLY_NEW_MENU' => true, - 'ONLY_NEW_POSTS_ON' => ($only_new == ONLY_NEW_POSTS), - 'ONLY_NEW_TOPICS_ON' => ($only_new == ONLY_NEW_TOPICS), - - 'TITLE_MATCH' => htmlCHR($title_match), - 'SELECT_TPP' => ($select_tpp) ? build_select('tpp', $select_tpp, $topics_per_page, null, null, 'onchange="$(\'#tpp\').submit();"') : '', - 'T_POST_NEW_TOPIC' => ($forum_data['forum_status'] == FORUM_LOCKED) ? $lang['FORUM_LOCKED'] : $post_new_topic, - 'S_AUTH_LIST' => $u_auth, - 'U_VIEW_FORUM' => FORUM_URL . $forum_id, - 'U_MARK_READ' => FORUM_URL . $forum_id ."&mark=topics", - 'U_SEARCH_SELF' => "search.php?uid={$userdata['user_id']}&f=$forum_id", -)); - -// Okay, lets dump out the page ... -$found_topics = 0; -foreach ($topic_rowset as $topic) -{ - $topic_id = $topic['topic_id']; - $moved = ($topic['topic_status'] == TOPIC_MOVED); - $replies = $topic['topic_replies']; - $t_hot = ($replies >= $bb_cfg['hot_threshold']); - $t_type = $topic['topic_type']; - $separator = ''; - $is_unread = is_unread($topic['topic_last_post_time'], $topic_id, $forum_id); - - if ($t_type == POST_ANNOUNCE && !defined('ANNOUNCE_SEP')) - { - define('ANNOUNCE_SEP', true); - $separator = $lang['TOPICS_ANNOUNCEMENT']; - } - elseif ($t_type == POST_STICKY && !defined('STICKY_SEP')) - { - define('STICKY_SEP', true); - $separator = $lang['TOPICS_STICKY']; - } - elseif ($t_type == POST_NORMAL && !defined('NORMAL_SEP')) - { - if (defined('ANNOUNCE_SEP') || defined('STICKY_SEP')) - { - define('NORMAL_SEP', true); - $separator = $lang['TOPICS_NORMAL']; - } - } - - // Gold/Silver releases mod - $is_gold = ''; - if ($tr_cfg['gold_silver_enabled'] && isset($topic['tor_type'])) - { - if ($topic['tor_type'] == TOR_TYPE_GOLD) - { - $is_gold = ' '; - } - elseif ($topic['tor_type'] == TOR_TYPE_SILVER) - { - $is_gold = ' '; - } - } - // END Gold/Silver releases mod - - $template->assign_block_vars('t', array( - 'FORUM_ID' => $forum_id, - 'TOPIC_ID' => $topic_id, - 'HREF_TOPIC_ID' => ($moved) ? $topic['topic_moved_id'] : $topic['topic_id'], - 'TOPIC_TITLE' => wbr($topic['topic_title']), - 'TOPICS_SEPARATOR' => $separator, - 'IS_UNREAD' => $is_unread, - 'TOPIC_ICON' => get_topic_icon($topic, $is_unread), - 'PAGINATION' => ($moved) ? '' : build_topic_pagination(TOPIC_URL . $topic_id, $replies, $bb_cfg['posts_per_page']), - 'REPLIES' => $replies, - 'VIEWS' => $topic['topic_views'], - 'TOR_STALED' => ($forum_data['allow_reg_tracker'] && !($t_type == POST_ANNOUNCE || $t_type == POST_STICKY || $topic['tor_size'])), - 'TOR_FROZEN' => isset($topic['tor_status']) ? ((!IS_AM) ? isset($bb_cfg['tor_frozen'][$topic['tor_status']]) : '') : '', - 'TOR_TYPE' => $is_gold, - - 'TOR_STATUS_ICON' => isset($topic['tor_status']) ? $bb_cfg['tor_icons'][$topic['tor_status']] : '', - 'TOR_STATUS_TEXT' => isset($topic['tor_status']) ? $lang['TOR_STATUS_NAME'][$topic['tor_status']] : '', - - 'ATTACH' => $topic['topic_attachment'], - 'STATUS' => $topic['topic_status'], - 'TYPE' => $topic['topic_type'], - 'DL' => ($topic['topic_dl_type'] == TOPIC_DL_TYPE_DL && !$forum_data['allow_reg_tracker']), - 'POLL' => $topic['topic_vote'], - 'DL_CLASS' => isset($topic['dl_status']) ? $dl_link_css[$topic['dl_status']] : '', - - 'TOPIC_AUTHOR' => profile_url(array('username' => str_short($topic['first_username'], 15), 'user_id' => $topic['first_user_id'], 'user_rank' => $topic['first_user_rank'])), - 'LAST_POSTER' => profile_url(array('username' => str_short($topic['last_username'], 15), 'user_id' => $topic['last_user_id'], 'user_rank' => $topic['last_user_rank'])), - 'LAST_POST_TIME' => bb_date($topic['topic_last_post_time']), - 'LAST_POST_ID' => $topic['topic_last_post_id'], - )); - - if (isset($topic['tor_size'])) - { - $tor_magnet = create_magnet($topic['info_hash'], $topic['auth_key'], $userdata['session_logged_in']); - - $template->assign_block_vars('t.tor', array( - 'SEEDERS' => (int) $topic['seeders'], - 'LEECHERS' => (int) $topic['leechers'], - 'TOR_SIZE' => humn_size($topic['tor_size']), - 'COMPL_CNT' => (int) $topic['complete_count'], - 'ATTACH_ID' => $topic['attach_id'], - 'MAGNET' => $tor_magnet, - )); - } - $found_topics++; -} -unset($topic_rowset); - -$pg_url = FORUM_URL . $forum_id; -$pg_url .= ($sort_value) ? "&sort=$sort_value" : ''; -$pg_url .= ($order_value) ? "&order=$order_value" : ''; -$template->assign_var('MOD_URL', $pg_url); -$pg_url = FORUM_URL . $forum_id; -$pg_url .= ($topic_days) ? "&topicdays=$topic_days" : ''; -$pg_url .= ($sort_value) ? "&sort=$sort_value" : ''; -$pg_url .= ($order_value) ? "&order=$order_value" : ''; -$pg_url .= ($moderation) ? "&mod=1" : ''; -$pg_url .= ($topics_per_page != $bb_cfg['topics_per_page']) ? "&tpp=$topics_per_page" : ''; - -if ($found_topics) -{ - generate_pagination($pg_url, $forum_topics, $topics_per_page, $start); -} -else -{ - if ($only_new) - { - $no_topics_msg = $lang['NO_NEW_POSTS']; - } - else - { - $no_topics_msg = ($topic_days || $title_match) ? $lang['NO_SEARCH_MATCH'] : $lang['NO_TOPICS_POST_ONE']; - } - $template->assign_vars(array( - 'NO_TOPICS' => $no_topics_msg, - )); -} - -$template->assign_vars(array( - 'PAGE_URL' => $pg_url, - 'PAGE_URL_TPP' => url_arg($pg_url, 'tpp', null), - 'FOUND_TOPICS' => $found_topics, - - 'AUTH_MOD' => $is_auth['auth_mod'], - 'SESSION_ADMIN' => $userdata['session_admin'], - 'MOD_REDIRECT_URL' => $mod_redirect_url, - 'MODERATION_ON' => $moderation, - 'PRUNE_DAYS' => $forum_data['prune_days'], - - 'CAT_ID' => $forum_data['cat_id'], - 'CAT_TITLE' => $forums['cat_title_html'][$forum_data['cat_id']], - 'U_VIEWCAT' => CAT_URL . $forum_data['cat_id'], - 'PARENT_FORUM_HREF' => ($parent_id = $forum_data['forum_parent']) ? FORUM_URL . $forum_data['forum_parent'] : '', - 'PARENT_FORUM_NAME' => ($parent_id = $forum_data['forum_parent']) ? $forums['forum_name_html'][$parent_id] : '', -)); - +session_start(); + +$lastvisit = (IS_GUEST) ? TIMENOW : $userdata['user_lastvisit']; + +// Caching output +$req_page = "forum_f{$forum_id}"; +$req_page .= ($start) ? "_start{$start}" : ''; + +define('REQUESTED_PAGE', $req_page); +caching_output(IS_GUEST, 'send', REQUESTED_PAGE .'_guest'); + +set_die_append_msg(); +if (!$forums = $datastore->get('cat_forums')) +{ + $datastore->update('cat_forums'); + $forums = $datastore->get('cat_forums'); +} +if (!$forum_id OR !$forum_data = @$forums['forum'][$forum_id]) +{ + bb_die($lang['FORUM_NOT_EXIST']); +} + +// Only new +$only_new = $user->opt_js['only_new']; +$only_new_sql = ''; +if ($only_new == ONLY_NEW_POSTS) +{ + $only_new_sql = "AND t.topic_last_post_time > $lastvisit"; +} +elseif ($only_new == ONLY_NEW_TOPICS) +{ + $only_new_sql = "AND t.topic_time > $lastvisit"; +} + +// Auth +$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_data); + +$moderation = (!empty($_REQUEST['mod']) && $is_auth['auth_mod']); + +if (!$is_auth['auth_view']) +{ + if (IS_GUEST) + { + $redirect = "f=$forum_id"; + $redirect .= ($start) ? "&start=$start" : ''; + redirect(LOGIN_URL . "?redirect=viewforum.php&$redirect"); + } + // The user is not authed to read this forum ... + $message = sprintf($lang['SORRY_AUTH_VIEW'], $is_auth['auth_view_type']); + bb_die($message); +} + +// Redirect to login page if not admin session +$mod_redirect_url = ''; + +// Filter by torrent status +$tor_status = -1; // all by default + +if ($is_auth['auth_mod']) +{ + $redirect = isset($_POST['redirect']) ? $_POST['redirect'] : @$_SERVER['REQUEST_URI']; + $redirect = url_arg($redirect, 'mod', 1, '&'); + $mod_redirect_url = LOGIN_URL . "?redirect=$redirect&admin=1"; + + if ($moderation && !$userdata['session_admin']) + { + redirect($mod_redirect_url); + } + if (isset($_REQUEST['tst']) && $_REQUEST['tst'] != -1) + { + $tor_status = (int) $_REQUEST['tst']; + // reset other req values + unset($_REQUEST['sort'], $_REQUEST['order'], $_REQUEST[$title_match_key]); + $show_type_separator = false; + } + $select_tst = array_merge(array($lang['TOR_STATUS_SELECT_ALL'] => -1), array_flip($lang['TOR_STATUS_NAME'])); + $template->assign_vars(array( + 'SELECT_TST' => build_select('tst', $select_tst, $tor_status), + )); + $select_st = array_merge(array($lang['TOR_STATUS_SELECT_ACTION'] => -1), array_flip($lang['TOR_STATUS_NAME'])); + $template->assign_vars(array( + 'SELECT_ST' => build_select('st', $select_st, -1), + )); +} + +// Topics read tracks +$tracking_topics = get_tracks('topic'); +$tracking_forums = get_tracks('forum'); + +if ($mark_read && !IS_GUEST) +{ + set_tracks(COOKIE_FORUM, $tracking_forums, $forum_id); + + set_die_append_msg($forum_id); + $message = $lang['TOPICS_MARKED_READ']; + bb_die($message); +} + +// Subforums +$show_subforums = ($bb_cfg['sf_on_first_page_only']) ? !$start : true; + +if (!$forums = $datastore->get('cat_forums')) +{ + $datastore->update('cat_forums'); + $forums = $datastore->get('cat_forums'); +} + +if($forums['forum'][$forum_id]['allow_porno_topic'] && bf($userdata['user_opt'], 'user_opt', 'user_porn_forums')) bb_die($lang['ERROR_PORNO_FORUM']); + +if (!$forum_data['forum_parent'] && isset($forums['f'][$forum_id]['subforums']) && $show_subforums) +{ + $not_auth_forums = $user->get_excluded_forums(AUTH_VIEW); + $ignore_forum_sql = ($not_auth_forums) ? "AND f.forum_id NOT IN($not_auth_forums)" : ''; + + $sql = " + SELECT + f.forum_id, f.forum_status, f.forum_last_post_id, f.forum_posts, f.forum_topics, + t.topic_last_post_time, t.topic_id AS last_topic_id, t.topic_title AS last_topic_title, + p.poster_id AS sf_last_user_id, IF(p.poster_id = $anon, p.post_username, u.username) AS sf_last_username, u.user_rank + FROM ". BB_FORUMS ." f + LEFT JOIN ". BB_TOPICS ." t ON(f.forum_last_post_id = t.topic_last_post_id) + LEFT JOIN ". BB_POSTS ." p ON(f.forum_last_post_id = p.post_id) + LEFT JOIN ". BB_USERS ." u ON(p.poster_id = u.user_id) + WHERE f.forum_parent = $forum_id + $only_new_sql + $ignore_forum_sql + GROUP BY f.forum_id + ORDER BY f.forum_order + "; + + if ($rowset = DB()->fetch_rowset($sql)) + { + $template->assign_vars(array( + 'SHOW_SUBFORUMS' => true, + 'FORUM_IMG' => $images['forum'], + 'FORUM_NEW_IMG' => $images['forum_new'], + 'FORUM_LOCKED_IMG' => $images['forum_locked'], + )); + } + foreach ($rowset as $sf_data) + { + $sf_forum_id = $sf_data['forum_id']; + $sf_last_tid = $sf_data['last_topic_id']; + $folder_image = $images['forum']; + $last_post = $lang['NO_POSTS']; + + if (!$fname_html =& $forums['forum_name_html'][$sf_forum_id]) + { + continue; + } + + if ($sf_data['forum_status'] == FORUM_LOCKED) + { + $folder_image = $images['forum_locked']; + } + elseif (is_unread($sf_data['topic_last_post_time'], $sf_last_tid, $sf_forum_id)) + { + $folder_image = $images['forum_new']; + } + + $last_post_user = profile_url(array('username' => $sf_data['sf_last_username'], 'user_id' => $sf_data['sf_last_user_id'], 'user_rank' => $sf_data['user_rank'])); + + if ($sf_data['forum_last_post_id']) + { + $last_post = bb_date($sf_data['topic_last_post_time'], $bb_cfg['last_post_date_format']); + $last_post .= "
        $last_post_user"; + $last_post .= 'latest'; + } + + $template->assign_block_vars('f', array( + 'FORUM_FOLDER_IMG' => $folder_image, + + 'FORUM_NAME' => $fname_html, + 'FORUM_DESC' => $forums['f'][$sf_forum_id]['forum_desc'], + 'U_VIEWFORUM' => FORUM_URL . $sf_forum_id, + 'TOPICS' => commify($sf_data['forum_topics']), + 'POSTS' => commify($sf_data['forum_posts']), + 'LAST_POST' => $last_post, + )); + + if ($sf_data['forum_last_post_id']) + { + $template->assign_block_vars('f.last', array( + 'FORUM_LAST_POST' => true, + 'SHOW_LAST_TOPIC' => $show_last_topic, + 'LAST_TOPIC_ID' => $sf_data['last_topic_id'], + 'LAST_TOPIC_TIP' => $sf_data['last_topic_title'], + 'LAST_TOPIC_TITLE' => str_short($sf_data['last_topic_title'], $last_topic_max_len), + 'LAST_POST_TIME' => bb_date($sf_data['topic_last_post_time'], $bb_cfg['last_post_date_format']), + 'LAST_POST_ID' => $sf_data['forum_last_post_id'], + 'LAST_POST_USER' => $last_post_user, + 'ICON_LATEST_REPLY' => $images['icon_latest_reply'], + )); + } + else + { + $template->assign_block_vars('f.last', array('FORUM_LAST_POST' => false)); + } + } +} +unset($rowset); +$datastore->rm('cat_forums'); + +// Topics per page +$topics_per_page = $bb_cfg['topics_per_page']; +$select_tpp = ''; + +if ($is_auth['auth_mod']) +{ + if ($req_tpp = abs(intval(@$_REQUEST['tpp'])) AND in_array($req_tpp, $bb_cfg['allowed_topics_per_page'])) + { + $topics_per_page = $req_tpp; + } + + $select_tpp = array(); + foreach ($bb_cfg['allowed_topics_per_page'] as $tpp) + { + $select_tpp[$tpp] = $tpp; + } +} + +// Generate a 'Show topics in previous x days' select box. +$topic_days = 0; // all the time +$forum_topics = $forum_data['forum_topics']; + +$sel_previous_days = array( + 0 => $lang['ALL_POSTS'], + 1 => $lang['1_DAY'], + 7 => $lang['7_DAYS'], + 14 => $lang['2_WEEKS'], + 30 => $lang['1_MONTH'], + 90 => $lang['3_MONTHS'], + 180 => $lang['6_MONTHS'], + 364 => $lang['1_YEAR'], +); + +if (!empty($_REQUEST['topicdays'])) +{ + if ($req_topic_days = abs(intval($_REQUEST['topicdays'])) AND isset($sel_previous_days[$req_topic_days])) + { + $sql = " + SELECT COUNT(*) AS forum_topics + FROM ". BB_TOPICS ." + WHERE forum_id = $forum_id + AND topic_last_post_time > ". (TIMENOW - 86400*$req_topic_days) ." + "; + + if ($row = DB()->fetch_row($sql)) + { + $topic_days = $req_topic_days; + $forum_topics = $row['forum_topics']; + } + } +} +// Correct $start value +if ($start > $forum_topics) +{ + redirect("viewforum.php?f=$forum_id"); +} + +// Generate SORT and ORDER selects +$sort_value = isset($_REQUEST['sort']) ? (int) $_REQUEST['sort'] : $forum_data['forum_display_sort']; +$order_value = isset($_REQUEST['order']) ? (int) $_REQUEST['order'] : $forum_data['forum_display_order']; +$sort_list = ''; +$order_list = ''; +$s_display_order = ' '. $lang['SORT_BY'] .': '. $sort_list .' '. $order_list .' '; + +// Selected SORT and ORDER methods +$sort_method = get_forum_display_sort_option($sort_value, 'field', 'sort'); +$order_method = get_forum_display_sort_option($order_value, 'field', 'order'); + +$order_sql = "ORDER BY t.topic_type DESC, $sort_method $order_method"; + +$limit_topics_time_sql = ($topic_days) ? "AND t.topic_last_post_time > ". (TIMENOW - 86400*$topic_days) : ''; + +$select_tor_sql = $join_tor_sql = ''; +$join_dl = ($bb_cfg['show_dl_status_in_forum'] && !IS_GUEST); + +$where_tor_sql = ''; +if ($forum_data['allow_reg_tracker']) +{ + if ($tor_status != -1) + { + $where_tor_sql = "AND tor.tor_status = $tor_status"; + } + + $select_tor_sql = ', + bt.auth_key, tor.info_hash, tor.size AS tor_size, tor.reg_time, tor.complete_count, tor.seeder_last_seen, tor.attach_id, tor.tor_status, tor.tor_type, + sn.seeders, sn.leechers + '; + $select_tor_sql .= ($join_dl) ? ', dl.user_status AS dl_status' : ''; + + $join_tor_sql = " + LEFT JOIN ". BB_BT_TORRENTS ." tor ON(t.topic_id = tor.topic_id) + LEFT JOIN ". BB_BT_USERS ." bt ON(bt.user_id = {$userdata['user_id']}) + LEFT JOIN ". BB_BT_TRACKER_SNAP ." sn ON(tor.topic_id = sn.topic_id) + "; + $join_tor_sql .= ($join_dl) ? " LEFT JOIN ". BB_BT_DLSTATUS ." dl ON(dl.user_id = {$userdata['user_id']} AND dl.topic_id = t.topic_id)" : ''; +} + +// Title match +$title_match_sql = ''; + +if ($title_match =& $_REQUEST[$title_match_key]) +{ + if ($tmp = mb_substr(trim($title_match), 0, $title_match_max_len)) + { + $title_match_val = clean_text_match($tmp, true, false, false); + $title_match_topics = get_title_match_topics($title_match_val, array(0 => $forum_id)); + + if ($search_match_topics_csv = join(',', $title_match_topics)) + { + $title_match_sql = "AND t.topic_id IN($search_match_topics_csv)"; + } + } +} + +// Get topics +$topic_ids = $topic_rowset = array(); + +// IDs +$sql = " + SELECT t.topic_id + FROM ". BB_TOPICS ." t + WHERE t.forum_id = $forum_id + $only_new_sql + $title_match_sql + $limit_topics_time_sql + $order_sql + LIMIT $start, $topics_per_page +"; +foreach (DB()->fetch_rowset($sql) as $row) +{ + $topic_ids[] = $row['topic_id']; +} + +// Titles, posters etc. +if ($topics_csv = join(',', $topic_ids)) +{ + $topic_rowset = DB()->fetch_rowset(" + SELECT + t.*, t.topic_poster AS first_user_id, u1.user_rank as first_user_rank, + IF(t.topic_poster = $anon, p1.post_username, u1.username) AS first_username, + p2.poster_id AS last_user_id, u2.user_rank as last_user_rank, + IF(p2.poster_id = $anon, p2.post_username, u2.username) AS last_username + $select_tor_sql + FROM ". BB_TOPICS ." t + LEFT JOIN ". BB_POSTS ." p1 ON(t.topic_first_post_id = p1.post_id) + LEFT JOIN ". BB_USERS ." u1 ON(t.topic_poster = u1.user_id) + LEFT JOIN ". BB_POSTS ." p2 ON(t.topic_last_post_id = p2.post_id) + LEFT JOIN ". BB_USERS ." u2 ON(p2.poster_id = u2.user_id) + $join_tor_sql + WHERE t.topic_id IN($topics_csv) + $where_tor_sql + GROUP BY t.topic_id + $order_sql + "); +} + +// Define censored word matches +$orig_word = $replacement_word = array(); +obtain_word_list($orig_word, $replacement_word); + +if($forum_data['allow_reg_tracker']) +{ + $post_new_topic_url = POSTING_URL . "?mode=new_rel&f=$forum_id"; + $post_img = $images['release_new']; + $post_new_topic = $lang['POST_NEW_RELEASE']; +} +else +{ + $post_new_topic_url = POSTING_URL . "?mode=newtopic&f=$forum_id"; + $post_img = $images['post_new']; + $post_new_topic = $lang['POST_NEW_TOPIC']; +} + +// Post URL generation for templating vars +$template->assign_vars(array( + 'U_POST_NEW_TOPIC' => $post_new_topic_url, + 'S_SELECT_TOPIC_DAYS' => build_select('topicdays', array_flip($sel_previous_days), $topic_days), + 'S_POST_DAYS_ACTION' => "viewforum.php?f=$forum_id&start=$start", + 'S_DISPLAY_ORDER' => $s_display_order, +)); + +// User authorisation levels output +$u_auth = array(); +$u_auth[] = ($is_auth['auth_post']) ? $lang['RULES_POST_CAN'] : $lang['RULES_POST_CANNOT']; +$u_auth[] = ($is_auth['auth_reply']) ? $lang['RULES_REPLY_CAN'] : $lang['RULES_REPLY_CANNOT']; +$u_auth[] = ($is_auth['auth_edit']) ? $lang['RULES_EDIT_CAN'] : $lang['RULES_EDIT_CANNOT']; +$u_auth[] = ($is_auth['auth_delete']) ? $lang['RULES_DELETE_CAN'] : $lang['RULES_DELETE_CANNOT']; +$u_auth[] = ($is_auth['auth_vote']) ? $lang['RULES_VOTE_CAN'] : $lang['RULES_VOTE_CANNOT']; +$u_auth[] = ($is_auth['auth_attachments']) ? $lang['RULES_ATTACH_CAN'] : $lang['RULES_ATTACH_CANNOT']; +$u_auth[] = ($is_auth['auth_download']) ? $lang['RULES_DOWNLOAD_CAN'] : $lang['RULES_DOWNLOAD_CANNOT']; +$u_auth[] = ($is_auth['auth_mod']) ? $lang['RULES_MODERATE'] : ''; +$u_auth = join("
        \n", $u_auth); + +$template->assign_vars(array( + 'SHOW_JUMPBOX' => true, + 'PAGE_TITLE' => htmlCHR($forum_data['forum_name']), + 'FORUM_ID' => $forum_id, + 'FORUM_NAME' => htmlCHR($forum_data['forum_name']), + 'TORRENTS' => $forum_data['allow_reg_tracker'], + 'POST_IMG' => ($forum_data['forum_status'] == FORUM_LOCKED) ? $images['post_locked'] : $post_img, + + 'FOLDER_IMG' => $images['folder'], + 'FOLDER_NEW_IMG' => $images['folder_new'], + 'FOLDER_LOCKED_IMG' => $images['folder_locked'], + 'FOLDER_STICKY_IMG' => $images['folder_sticky'], + 'FOLDER_ANNOUNCE_IMG' => $images['folder_announce'], + 'FOLDER_DOWNLOAD_IMG' => $images['folder_dl'], + + 'SHOW_ONLY_NEW_MENU' => true, + 'ONLY_NEW_POSTS_ON' => ($only_new == ONLY_NEW_POSTS), + 'ONLY_NEW_TOPICS_ON' => ($only_new == ONLY_NEW_TOPICS), + + 'TITLE_MATCH' => htmlCHR($title_match), + 'SELECT_TPP' => ($select_tpp) ? build_select('tpp', $select_tpp, $topics_per_page, null, null, 'onchange="$(\'#tpp\').submit();"') : '', + 'T_POST_NEW_TOPIC' => ($forum_data['forum_status'] == FORUM_LOCKED) ? $lang['FORUM_LOCKED'] : $post_new_topic, + 'S_AUTH_LIST' => $u_auth, + 'U_VIEW_FORUM' => FORUM_URL . $forum_id, + 'U_MARK_READ' => FORUM_URL . $forum_id ."&mark=topics", + 'U_SEARCH_SELF' => "search.php?uid={$userdata['user_id']}&f=$forum_id", +)); + +// Okay, lets dump out the page ... +$found_topics = 0; +foreach ($topic_rowset as $topic) +{ + $topic_id = $topic['topic_id']; + $moved = ($topic['topic_status'] == TOPIC_MOVED); + $replies = $topic['topic_replies']; + $t_hot = ($replies >= $bb_cfg['hot_threshold']); + $t_type = $topic['topic_type']; + $separator = ''; + $is_unread = is_unread($topic['topic_last_post_time'], $topic_id, $forum_id); + + if ($t_type == POST_ANNOUNCE && !defined('ANNOUNCE_SEP')) + { + define('ANNOUNCE_SEP', true); + $separator = $lang['TOPICS_ANNOUNCEMENT']; + } + elseif ($t_type == POST_STICKY && !defined('STICKY_SEP')) + { + define('STICKY_SEP', true); + $separator = $lang['TOPICS_STICKY']; + } + elseif ($t_type == POST_NORMAL && !defined('NORMAL_SEP')) + { + if (defined('ANNOUNCE_SEP') || defined('STICKY_SEP')) + { + define('NORMAL_SEP', true); + $separator = $lang['TOPICS_NORMAL']; + } + } + + // Gold/Silver releases mod + $is_gold = ''; + if ($tr_cfg['gold_silver_enabled'] && isset($topic['tor_type'])) + { + if ($topic['tor_type'] == TOR_TYPE_GOLD) + { + $is_gold = ' '; + } + elseif ($topic['tor_type'] == TOR_TYPE_SILVER) + { + $is_gold = ' '; + } + } + // END Gold/Silver releases mod + + $template->assign_block_vars('t', array( + 'FORUM_ID' => $forum_id, + 'TOPIC_ID' => $topic_id, + 'HREF_TOPIC_ID' => ($moved) ? $topic['topic_moved_id'] : $topic['topic_id'], + 'TOPIC_TITLE' => wbr($topic['topic_title']), + 'TOPICS_SEPARATOR' => $separator, + 'IS_UNREAD' => $is_unread, + 'TOPIC_ICON' => get_topic_icon($topic, $is_unread), + 'PAGINATION' => ($moved) ? '' : build_topic_pagination(TOPIC_URL . $topic_id, $replies, $bb_cfg['posts_per_page']), + 'REPLIES' => $replies, + 'VIEWS' => $topic['topic_views'], + 'TOR_STALED' => ($forum_data['allow_reg_tracker'] && !($t_type == POST_ANNOUNCE || $t_type == POST_STICKY || $topic['tor_size'])), + 'TOR_FROZEN' => isset($topic['tor_status']) ? ((!IS_AM) ? isset($bb_cfg['tor_frozen'][$topic['tor_status']]) : '') : '', + 'TOR_TYPE' => $is_gold, + + 'TOR_STATUS_ICON' => isset($topic['tor_status']) ? $bb_cfg['tor_icons'][$topic['tor_status']] : '', + 'TOR_STATUS_TEXT' => isset($topic['tor_status']) ? $lang['TOR_STATUS_NAME'][$topic['tor_status']] : '', + + 'ATTACH' => $topic['topic_attachment'], + 'STATUS' => $topic['topic_status'], + 'TYPE' => $topic['topic_type'], + 'DL' => ($topic['topic_dl_type'] == TOPIC_DL_TYPE_DL && !$forum_data['allow_reg_tracker']), + 'POLL' => $topic['topic_vote'], + 'DL_CLASS' => isset($topic['dl_status']) ? $dl_link_css[$topic['dl_status']] : '', + + 'TOPIC_AUTHOR' => profile_url(array('username' => str_short($topic['first_username'], 15), 'user_id' => $topic['first_user_id'], 'user_rank' => $topic['first_user_rank'])), + 'LAST_POSTER' => profile_url(array('username' => str_short($topic['last_username'], 15), 'user_id' => $topic['last_user_id'], 'user_rank' => $topic['last_user_rank'])), + 'LAST_POST_TIME' => bb_date($topic['topic_last_post_time']), + 'LAST_POST_ID' => $topic['topic_last_post_id'], + )); + + if (isset($topic['tor_size'])) + { + $tor_magnet = create_magnet($topic['info_hash'], $topic['auth_key'], $userdata['session_logged_in']); + + $template->assign_block_vars('t.tor', array( + 'SEEDERS' => (int) $topic['seeders'], + 'LEECHERS' => (int) $topic['leechers'], + 'TOR_SIZE' => humn_size($topic['tor_size']), + 'COMPL_CNT' => (int) $topic['complete_count'], + 'ATTACH_ID' => $topic['attach_id'], + 'MAGNET' => $tor_magnet, + )); + } + $found_topics++; +} +unset($topic_rowset); + +$pg_url = FORUM_URL . $forum_id; +$pg_url .= ($sort_value) ? "&sort=$sort_value" : ''; +$pg_url .= ($order_value) ? "&order=$order_value" : ''; +$template->assign_var('MOD_URL', $pg_url); +$pg_url = FORUM_URL . $forum_id; +$pg_url .= ($topic_days) ? "&topicdays=$topic_days" : ''; +$pg_url .= ($sort_value) ? "&sort=$sort_value" : ''; +$pg_url .= ($order_value) ? "&order=$order_value" : ''; +$pg_url .= ($moderation) ? "&mod=1" : ''; +$pg_url .= ($topics_per_page != $bb_cfg['topics_per_page']) ? "&tpp=$topics_per_page" : ''; + +if ($found_topics) +{ + generate_pagination($pg_url, $forum_topics, $topics_per_page, $start); +} +else +{ + if ($only_new) + { + $no_topics_msg = $lang['NO_NEW_POSTS']; + } + else + { + $no_topics_msg = ($topic_days || $title_match) ? $lang['NO_SEARCH_MATCH'] : $lang['NO_TOPICS_POST_ONE']; + } + $template->assign_vars(array( + 'NO_TOPICS' => $no_topics_msg, + )); +} + +$template->assign_vars(array( + 'PAGE_URL' => $pg_url, + 'PAGE_URL_TPP' => url_arg($pg_url, 'tpp', null), + 'FOUND_TOPICS' => $found_topics, + + 'AUTH_MOD' => $is_auth['auth_mod'], + 'SESSION_ADMIN' => $userdata['session_admin'], + 'MOD_REDIRECT_URL' => $mod_redirect_url, + 'MODERATION_ON' => $moderation, + 'PRUNE_DAYS' => $forum_data['prune_days'], + + 'CAT_ID' => $forum_data['cat_id'], + 'CAT_TITLE' => $forums['cat_title_html'][$forum_data['cat_id']], + 'U_VIEWCAT' => CAT_URL . $forum_data['cat_id'], + 'PARENT_FORUM_HREF' => ($parent_id = $forum_data['forum_parent']) ? FORUM_URL . $forum_data['forum_parent'] : '', + 'PARENT_FORUM_NAME' => ($parent_id = $forum_data['forum_parent']) ? $forums['forum_name_html'][$parent_id] : '', +)); + print_page('viewforum.tpl'); \ No newline at end of file diff --git a/upload/viewtopic.php b/upload/viewtopic.php index 83f2bb049..2049efab9 100644 --- a/upload/viewtopic.php +++ b/upload/viewtopic.php @@ -1,945 +1,945 @@ -enqueue(array( - 'ranks', -)); - -$page_cfg['load_tpl_vars'] = array( - 'post_buttons', - 'post_icons', - 'topic_icons', -); - -$newest = $next_topic_id = 0; -$start = isset($_GET['start']) ? abs(intval($_GET['start'])) : 0; -$topic_id = isset($_GET[POST_TOPIC_URL]) ? (int) $_GET[POST_TOPIC_URL] : 0; -$post_id = (!$topic_id && isset($_GET[POST_POST_URL])) ? (int) $_GET[POST_POST_URL] : 0; - -// Start session -$user->session_start(); - -set_die_append_msg(); - -// Posts per page -$posts_per_page = $bb_cfg['posts_per_page']; -$select_ppp = ''; - -if ($userdata['session_admin']) -{ - if ($req_ppp = abs(intval(@$_REQUEST['ppp'])) AND in_array($req_ppp, $bb_cfg['allowed_posts_per_page'])) - { - $posts_per_page = $req_ppp; - } - - $select_ppp = array(); - foreach ($bb_cfg['allowed_posts_per_page'] as $ppp) - { - $select_ppp[$ppp] = $ppp; - } -} - -if (isset($_REQUEST['single'])) -{ - $posts_per_page = 1; -} -else -{ - $start = floor($start/$posts_per_page) * $posts_per_page; -} - -if (!$topic_id && !$post_id) -{ - bb_die($lang['TOPIC_POST_NOT_EXIST']); -} - -$tracking_topics = get_tracks('topic'); -$tracking_forums = get_tracks('forum'); - -// Find topic id if user requested a newer or older topic -if ($topic_id && isset($_GET['view']) && ($_GET['view'] == 'next' || $_GET['view'] == 'previous')) -{ - $sql_condition = ($_GET['view'] == 'next') ? '>' : '<'; - $sql_ordering = ($_GET['view'] == 'next') ? 'ASC' : 'DESC'; - - $sql = "SELECT t.topic_id - FROM ". BB_TOPICS ." t, ". BB_TOPICS ." t2 - WHERE t2.topic_id = $topic_id - AND t.forum_id = t2.forum_id - AND t.topic_moved_id = 0 - AND t.topic_last_post_id $sql_condition t2.topic_last_post_id - ORDER BY t.topic_last_post_id $sql_ordering - LIMIT 1"; - - if ($row = DB()->fetch_row($sql)) - { - $next_topic_id = $topic_id = $row['topic_id']; - } - else - { - $message = ($_GET['view'] == 'next') ? $lang['NO_NEWER_TOPICS'] : $lang['NO_OLDER_TOPICS']; - bb_die($message); - } -} - -// Get forum/topic data -if ($topic_id) -{ - $sql = "SELECT t.*, f.*, tw.notify_status - FROM ". BB_TOPICS ." t - LEFT JOIN ". BB_FORUMS ." f USING(forum_id) - LEFT JOIN ". BB_TOPICS_WATCH ." tw ON(tw.topic_id = t.topic_id AND user_id = {$userdata['user_id']}) - WHERE t.topic_id = $topic_id - "; -} -elseif ($post_id) -{ - $sql = "SELECT t.*, f.*, p.post_time, tw.notify_status - FROM ". BB_TOPICS ." t - LEFT JOIN ". BB_FORUMS ." f USING(forum_id) - LEFT JOIN ". BB_POSTS ." p USING(topic_id) - LEFT JOIN ". BB_TOPICS_WATCH ." tw ON(tw.topic_id = t.topic_id AND user_id = {$userdata['user_id']}) - WHERE p.post_id = $post_id - "; -} -else -{ - bb_die($lang['TOPIC_POST_NOT_EXIST']); -} - -if (!$t_data = DB()->fetch_row($sql)) -{ - bb_die($lang['TOPIC_POST_NOT_EXIST']); -} - -$forum_topic_data =& $t_data; -$topic_id = $t_data['topic_id']; -$forum_id = $t_data['forum_id']; - -if($t_data['allow_porno_topic'] && bf($userdata['user_opt'], 'user_opt', 'user_porn_forums')) bb_die($lang['ERROR_PORNO_FORUM']); - -if ($userdata['session_admin'] && !empty($_REQUEST['mod'])) -{ - if (IS_ADMIN) - { - $datastore->enqueue(array('viewtopic_forum_select')); - } -} -if ($t_data['topic_attachment']) -{ - $datastore->enqueue(array( - 'attach_extensions', - )); -} - -// Find newest post -if (($next_topic_id || @$_GET['view'] === 'newest') && !IS_GUEST && $topic_id) -{ - $post_time = 'post_time >= '. get_last_read($topic_id, $forum_id); - $post_id_altern = ($next_topic_id) ? '' : ' OR post_id = '. $t_data['topic_last_post_id']; - - $sql = "SELECT post_id, post_time - FROM ". BB_POSTS ." - WHERE topic_id = $topic_id - AND ($post_time $post_id_altern) - ORDER BY post_time ASC - LIMIT 1"; - - if ($row = DB()->fetch_row($sql)) - { - $post_id = $newest = $row['post_id']; - $t_data['post_time'] = $row['post_time']; - } -} - -if ($post_id && !empty($t_data['post_time']) && ($t_data['topic_replies'] + 1) > $posts_per_page) -{ - $sql = "SELECT COUNT(post_id) AS prev_posts - FROM ". BB_POSTS ." - WHERE topic_id = $topic_id - AND post_time <= {$t_data['post_time']}"; - - if ($row = DB()->fetch_row($sql)) - { - $t_data['prev_posts'] = $row['prev_posts']; - } -} - -// Auth check -$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $t_data); - -if (!$is_auth['auth_read']) -{ - if (IS_GUEST) - { - $redirect = ($post_id) ? POST_URL ."$post_id#$post_id" : TOPIC_URL . $topic_id; - $redirect .= ($start && !$post_id) ? "&start=$start" : ''; - redirect(LOGIN_URL . "?redirect=viewtopic.php&$redirect"); - } - bb_die($lang['TOPIC_POST_NOT_EXIST']); -} - -$forum_name = $t_data['forum_name']; -$topic_title = $t_data['topic_title']; -$topic_id = $t_data['topic_id']; -$topic_time = $t_data['topic_time']; - -$moderation = (!empty($_REQUEST['mod']) && $is_auth['auth_mod']); - -// Redirect to login page if not admin session -$mod_redirect_url = ''; - -if ($is_auth['auth_mod']) -{ - $redirect = isset($_POST['redirect']) ? $_POST['redirect'] : @$_SERVER['REQUEST_URI']; - $redirect = url_arg($redirect, 'mod', 1, '&'); - $mod_redirect_url = LOGIN_URL . "?redirect=$redirect&admin=1"; - - if ($moderation && !$userdata['session_admin']) - { - redirect($mod_redirect_url); - } -} - -if ($moderation) -{ - if (IS_ADMIN) - { - if (!$forum_select = $datastore->get('viewtopic_forum_select')) - { - $datastore->update('viewtopic_forum_select'); - $forum_select = $datastore->get('viewtopic_forum_select'); - } - $forum_select_html = $forum_select['viewtopic_forum_select']; - } - else - { - $not_auth_forums_csv = $user->get_not_auth_forums(AUTH_VIEW); - $forum_select_html = get_forum_select(explode(',', $not_auth_forums_csv), 'new_forum_id'); - } - $template->assign_vars(array( - 'S_FORUM_SELECT' => $forum_select_html, - )); -} - -if (!$forums = $datastore->get('cat_forums')) -{ - $datastore->update('cat_forums'); - $forums = $datastore->get('cat_forums'); -} - -$template->assign_vars(array( - 'CAT_TITLE' => $forums['cat_title_html'][$t_data['cat_id']], - 'U_VIEWCAT' => CAT_URL . $t_data['cat_id'], - 'PARENT_FORUM_HREF' => ($parent_id = $t_data['forum_parent']) ? FORUM_URL . $parent_id : '', - 'PARENT_FORUM_NAME' => ($parent_id = $t_data['forum_parent']) ? htmlCHR($forums['f'][$parent_id]['forum_name']) : '', -)); -unset($forums); -$datastore->rm('cat_forums'); - -if ($post_id && !empty($t_data['prev_posts'])) -{ - $start = floor(($t_data['prev_posts'] - 1) / $posts_per_page) * $posts_per_page; -} - -// -// Is user watching this thread? -// -$can_watch_topic = $is_watching_topic = false; - -if ($bb_cfg['topic_notify_enabled']) -{ - if ($userdata['session_logged_in']) - { - $can_watch_topic = TRUE; - - if (!empty($t_data['notify_status']) && $t_data['notify_status']) - { - if (isset($_GET['unwatch'])) - { - if ($_GET['unwatch'] == 'topic') - { - $is_watching_topic = 0; - - DB()->query("DELETE FROM ". BB_TOPICS_WATCH ." WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}"); - } - - set_die_append_msg($forum_id, $topic_id); - bb_die($lang['NO_LONGER_WATCHING']); - - } - else - { - $is_watching_topic = TRUE; - - if (!$t_data['notify_status']) - { - DB()->query("UPDATE ". BB_TOPICS_WATCH ." SET notify_status = ". TOPIC_WATCH_NOTIFIED ." WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}"); - } - } - } - else - { - if (isset($_GET['watch'])) - { - if ($_GET['watch'] == 'topic') - { - $is_watching_topic = TRUE; - - DB()->query(" - INSERT INTO ". BB_TOPICS_WATCH ." (user_id, topic_id, notify_status) - VALUES (". $userdata['user_id'] .", $topic_id, ". TOPIC_WATCH_NOTIFIED .") - "); - } - - set_die_append_msg($forum_id, $topic_id); - bb_die($lang['YOU_ARE_WATCHING']); - - } - else - { - $is_watching_topic = 0; - } - } - } - else - { - if (isset($_GET['unwatch'])) - { - if ($_GET['unwatch'] == 'topic') - { - redirect(LOGIN_URL . "?redirect=viewtopic.php&t=$topic_id&unwatch=topic"); - } - } - } -} - -// Generate a 'Show posts in previous x days' select box. If the postdays var is POSTed -// then get it's value, find the number of topics with dates newer than it (to properly -// handle pagination) and alter the main query -$post_days = 0; -$limit_posts_time = ''; -$total_replies = $t_data['topic_replies'] + 1; - -if (!empty($_REQUEST['postdays'])) -{ - if ($post_days = abs(intval($_REQUEST['postdays']))) - { - if (!empty($_POST['postdays'])) - { - $start = 0; - } - $min_post_time = TIMENOW - ($post_days*86400); - - $sql = "SELECT COUNT(p.post_id) AS num_posts - FROM " . BB_TOPICS . " t, " . BB_POSTS . " p - WHERE t.topic_id = $topic_id - AND p.topic_id = t.topic_id - AND p.post_time > $min_post_time"; - - $total_replies = ($row = DB()->fetch_row($sql)) ? $row['num_posts'] : 0; - $limit_posts_time = "AND p.post_time >= $min_post_time "; - } -} - -// Decide how to order the post display -$post_order = (isset($_POST['postorder']) && $_POST['postorder'] !== 'asc') ? 'desc' : 'asc'; - -// -// Go ahead and pull all data for this topic -// -// 1. Add first post of topic if it pinned and page of topic not first -$first_post = false; -if ($t_data['topic_show_first_post'] && $start) -{ - $first_post = DB()->fetch_rowset(" - SELECT - u.username, u.user_id, u.user_rank, u.user_posts, u.user_from, - u.user_regdate, u.user_sig, - u.avatar_ext_id, - u.user_opt, u.user_gender, u.user_birthday, - p.*, - u2.username as mc_username, u2.user_rank as mc_user_rank, - h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text - FROM ". BB_POSTS ." p - LEFT JOIN ". BB_USERS ." u ON(u.user_id = p.poster_id) - LEFT JOIN ". BB_POSTS_TEXT ." pt ON(pt.post_id = p.post_id) - LEFT JOIN ". BB_POSTS_HTML ." h ON(h.post_id = p.post_id) - LEFT JOIN ". BB_USERS ." u2 ON(u2.user_id = p.mc_user_id) - WHERE - p.post_id = {$t_data['topic_first_post_id']} - LIMIT 1 - "); -} -// 2. All others posts -$sql = " - SELECT - u.username, u.user_id, u.user_rank, u.user_posts, u.user_from, - u.user_regdate, u.user_sig, - u.avatar_ext_id, - u.user_opt, u.user_gender, u.user_birthday, - p.*, - u2.username as mc_username, u2.user_rank as mc_user_rank, - h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text - FROM ". BB_POSTS ." p - LEFT JOIN ". BB_USERS ." u ON(u.user_id = p.poster_id) - LEFT JOIN ". BB_POSTS_TEXT ." pt ON(pt.post_id = p.post_id) - LEFT JOIN ". BB_POSTS_HTML ." h ON(h.post_id = p.post_id) - LEFT JOIN ". BB_USERS ." u2 ON(u2.user_id = p.mc_user_id) - WHERE p.topic_id = $topic_id - $limit_posts_time - GROUP BY p.post_id - ORDER BY p.post_time $post_order - LIMIT $start, $posts_per_page -"; - -if ($postrow = DB()->fetch_rowset($sql)) -{ - if ($first_post) $postrow = array_merge($first_post, $postrow); - $total_posts = count($postrow); -} -else -{ - bb_die($lang['NO_POSTS_TOPIC']); -} - -if (!$ranks = $datastore->get('ranks')) -{ - $datastore->update('ranks'); - $ranks = $datastore->get('ranks'); -} - -// -// Define censored word matches -// -$orig_word = $replacement_word = array(); -obtain_word_list($orig_word, $replacement_word); - -// -// Censor topic title -// -if ( count($orig_word) ) -{ - $topic_title = preg_replace($orig_word, $replacement_word, $topic_title); -} - -// -// Post, reply and other URL generation for -// templating vars -// -$new_topic_url = POSTING_URL . "?mode=newtopic&f=$forum_id"; -$reply_topic_url = POSTING_URL . "?mode=reply&t=$topic_id"; -$view_forum_url = "viewforum.php?f=$forum_id"; -$view_prev_topic_url = "viewtopic.php?t=$topic_id&view=previous#newest"; -$view_next_topic_url = "viewtopic.php?t=$topic_id&view=next#newest"; - -$reply_img = ( $t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] == TOPIC_LOCKED) ? $images['reply_locked'] : $images['reply_new']; -$reply_alt = ( $t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] == TOPIC_LOCKED) ? $lang['TOPIC_LOCKED_SHORT'] : $lang['REPLY_TO_TOPIC']; - -// Set 'body' template for attach_mod -$template->set_filenames(array('body' => 'viewtopic.tpl')); - -// -// User authorisation levels output -// -$s_auth_can = ( ( $is_auth['auth_post'] ) ? $lang['RULES_POST_CAN'] : $lang['RULES_POST_CANNOT'] ) . '
        '; -$s_auth_can .= ( ( $is_auth['auth_reply'] ) ? $lang['RULES_REPLY_CAN'] : $lang['RULES_REPLY_CANNOT'] ) . '
        '; -$s_auth_can .= ( ( $is_auth['auth_edit'] ) ? $lang['RULES_EDIT_CAN'] : $lang['RULES_EDIT_CANNOT'] ) . '
        '; -$s_auth_can .= ( ( $is_auth['auth_delete'] ) ? $lang['RULES_DELETE_CAN'] : $lang['RULES_DELETE_CANNOT'] ) . '
        '; -$s_auth_can .= ( ( $is_auth['auth_vote'] ) ? $lang['RULES_VOTE_CAN'] : $lang['RULES_VOTE_CANNOT'] ) . '
        '; -$s_auth_can .= ( ($is_auth['auth_attachments'] ) ? $lang['RULES_ATTACH_CAN'] : $lang['RULES_ATTACH_CANNOT'] ) . '
        '; -$s_auth_can .= ( ($is_auth['auth_download'] ) ? $lang['RULES_DOWNLOAD_CAN'] : $lang['RULES_DOWNLOAD_CANNOT'] ) . '
        '; - -$topic_mod = ''; - -if ( $is_auth['auth_mod'] ) -{ - $s_auth_can .= $lang['RULES_MODERATE']; - $topic_mod .= "' . $lang['DELETE_TOPIC'] . ' '; - $topic_mod .= "' . $lang['MOVE_TOPIC'] . ' '; - $topic_mod .= ( $t_data['topic_status'] == TOPIC_UNLOCKED ) ? "' . $lang['LOCK_TOPIC'] . ' ' : "' . $lang['UNLOCK_TOPIC'] . ' '; - $topic_mod .= "' . $lang['SPLIT_TOPIC'] . ' '; - - if ($t_data['allow_reg_tracker'] || $t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL || IS_ADMIN) - { - if ($t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL) - { - $topic_mod .= "' . $lang['UNSET_DL_STATUS'] . ''; - } - else - { - $topic_mod .= "' . $lang['SET_DL_STATUS'] . ''; - } - } -} -elseif (($t_data['topic_poster'] == $userdata['user_id']) && $userdata['session_logged_in'] && $t_data['self_moderated']) -{ - $topic_mod .= "' . $lang['MOVE_TOPIC'] . ' '; -} - -// Get report topic module and create report link -require_once(INC_DIR ."functions_report.php"); -$report_topic = report_modules('name', 'report_topic'); - -if ($report_topic && $report_topic->auth_check('auth_write')) -{ - if ($forum_topic_data['topic_reported']) - { - $report_auth = ($userdata['user_level'] == ADMIN || (!$bb_cfg['report_list_admin'] && (!$bb_cfg['report_subject_auth'] || $is_auth['auth_mod']))); - if ($report_topic->auth_check('auth_view') && $is_auth) - { - $target = ($bb_cfg['report_new_window']) ? ' target="_blank"' : ''; - $s_report_topic =' ' . $report_topic->lang['DUPLICATE_REPORT'] . ' '; - } - else - { - $s_report_topic = ' ' . $report_topic->lang['DUPLICATE_REPORT'] . ' '; - } - } - else - { - $s_report_topic = ' ' . $report_topic->lang['WRITE_REPORT'] . ' '; - } - - $topic_mod .= $s_report_topic; - $template->assign_var('S_REPORT_TOPIC', $s_report_topic); -} - -// -// Topic watch information -// -$s_watching_topic = $s_watching_topic_img = ''; -if ( $can_watch_topic ) -{ - if ( $is_watching_topic ) - { - $s_watching_topic = "' . $lang['STOP_WATCHING_TOPIC'] . ''; - $s_watching_topic_img = ( isset($images['topic_un_watch']) ) ? "' . $lang['STOP_WATCHING_TOPIC'] . '' : ''; - } - else - { - $s_watching_topic = "' . $lang['START_WATCHING_TOPIC'] . ''; - $s_watching_topic_img = ( isset($images['Topic_watch']) ) ? "' . $lang['START_WATCHING_TOPIC'] . '' : ''; - } -} - -// If we've got a hightlight set pass it on to pagination, -$pg_url = TOPIC_URL . $topic_id; -$pg_url .= ($post_days) ? "&postdays=$post_days" : ''; -$pg_url .= ($post_order != 'asc') ? "&postorder=$post_order" : ''; -$pg_url .= isset($_REQUEST['single']) ? "&single=1" : ''; -$pg_url .= ($moderation) ? "&mod=1" : ''; -$pg_url .= ($posts_per_page != $bb_cfg['posts_per_page']) ? "&ppp=$posts_per_page" : ''; - -generate_pagination($pg_url, $total_replies, $posts_per_page, $start); - -// -// Selects -// -$sel_previous_days = array( - 0 => $lang['ALL_POSTS'], - 1 => $lang['1_DAY'], - 7 => $lang['7_DAYS'], - 14 => $lang['2_WEEKS'], - 30 => $lang['1_MONTH'], - 90 => $lang['3_MONTHS'], - 180 => $lang['6_MONTHS'], - 364 => $lang['1_YEAR'], -); - -$sel_post_order_ary = array( - $lang['OLDEST_FIRST'] => 'asc', - $lang['NEWEST_FIRST'] => 'desc', -); - -$topic_has_poll = ($t_data['topic_vote'] && !IS_GUEST); -$poll_time_expired = ($t_data['topic_time'] < TIMENOW - $bb_cfg['poll_max_days']*86400); -$can_manage_poll = ($t_data['topic_poster'] == $userdata['user_id'] || $is_auth['auth_mod']); -$can_add_poll = ($can_manage_poll && !$topic_has_poll && !$poll_time_expired && !$start); - -// -// Send vars to template -// -$template->assign_vars(array( - 'PAGE_URL' => $pg_url, - 'PAGE_URL_PPP' => url_arg($pg_url, 'ppp', null), - 'PAGE_START' => $start, - 'SHOW_JUMPBOX' => true, - - 'FORUM_ID' => $forum_id, - 'FORUM_NAME' => htmlCHR($forum_name), - 'TOPIC_ID' => $topic_id, - 'PAGE_TITLE' => $topic_title, - 'TOPIC_TITLE' => wbr($topic_title), - 'PORNO_FORUM' => $t_data['allow_porno_topic'], - 'REPLY_IMG' => $reply_img, - 'SHOW_BOT_NICK' => $bb_cfg['show_bot_nick'], - 'T_POST_REPLY' => $reply_alt, - - 'HIDE_AVATAR' => $user->opt_js['h_av'], - 'HIDE_RANK_IMG' => ($user->opt_js['h_rnk_i'] && $bb_cfg['show_rank_image']), - 'HIDE_POST_IMG' => $user->opt_js['h_post_i'], - 'HIDE_SMILE' => $user->opt_js['h_smile'], - 'HIDE_SIGNATURE' => $user->opt_js['h_sig'], - 'SPOILER_OPENED' => $user->opt_js['sp_op'], - 'SHOW_IMG_AFTER_LOAD' => $user->opt_js['i_aft_l'], - - 'HIDE_RANK_IMG_DIS' => !$bb_cfg['show_rank_image'], - - 'PINNED_FIRST_POST' => $t_data['topic_show_first_post'], - 'PIN_HREF' => $t_data['topic_show_first_post'] ? "modcp.php?t=$topic_id&mode=post_unpin" : "modcp.php?t=$topic_id&mode=post_pin", - 'PIN_TITLE' => $t_data['topic_show_first_post'] ? $lang['POST_UNPIN'] : $lang['POST_PIN'], - - 'AUTH_MOD' => $is_auth['auth_mod'], - 'IN_MODERATION' => $moderation, - 'SELECT_PPP' => ($moderation && $select_ppp && $total_replies > $posts_per_page) ? build_select('ppp', $select_ppp, $posts_per_page, null, null, 'onchange="$(\'#ppp\').submit();"') : '', - - 'S_SELECT_POST_DAYS' => build_select('postdays', array_flip($sel_previous_days), $post_days), - 'S_SELECT_POST_ORDER' => build_select('postorder', $sel_post_order_ary, $post_order), - 'S_POST_DAYS_ACTION' => "viewtopic.php?t=$topic_id&start=$start", - 'S_AUTH_LIST' => $s_auth_can, - 'S_TOPIC_ADMIN' => $topic_mod, - 'S_WATCH_TOPIC' => $s_watching_topic, - 'S_WATCH_TOPIC_IMG' => $s_watching_topic_img, - 'U_VIEW_TOPIC' => TOPIC_URL . $topic_id, - 'U_VIEW_FORUM' => $view_forum_url, - 'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url, - 'U_VIEW_NEWER_TOPIC' => $view_next_topic_url, - 'U_POST_NEW_TOPIC' => $new_topic_url, - 'U_POST_REPLY_TOPIC' => $reply_topic_url, - 'U_SEARCH_SELF' => "search.php?uid={$userdata['user_id']}&t=$topic_id&dm=1", - - 'TOPIC_HAS_POLL' => $topic_has_poll, - 'POLL_IS_EDITABLE' => (!$poll_time_expired), - 'POLL_IS_FINISHED' => ($t_data['topic_vote'] == POLL_FINISHED), - 'CAN_MANAGE_POLL' => $can_manage_poll, - 'CAN_ADD_POLL' => $can_add_poll, -)); - -// Does this topic contain DL-List? -$template->assign_vars(array( - 'SHOW_TOR_ACT' => false, - 'PEERS_FULL_LINK' => false, - 'DL_LIST_HREF' => TOPIC_URL ."$topic_id&dl=names&spmode=full", -)); -require(INC_DIR .'torrent_show_dl_list.php'); - -if ($t_data['topic_attachment']) -{ - require(BB_ROOT .'attach_mod/attachment_mod.php'); - init_display_post_attachments($t_data['topic_attachment']); -} - -// -// Update the topic view counter -// -$sql = "INSERT INTO ". BUF_TOPIC_VIEW ." (topic_id, topic_views) VALUES ($topic_id, 1) ON DUPLICATE KEY UPDATE topic_views = topic_views + 1"; -if (!DB()->sql_query($sql)) -{ - bb_die('Could not update topic views'); -} - -// -// Does this topic contain a poll? -// -if ($topic_has_poll) -{ - $poll_votes_js = get_poll_data_items_js($topic_id); - - if (!$poll_votes_js) - { - $template->assign_vars(array( - 'TOPIC_HAS_POLL' => false, - )); - } - else - { - $template->assign_vars(array( - 'SHOW_VOTE_BTN' => poll_is_active($t_data), - 'POLL_VOTES_JS' => $poll_votes_js, - )); - } -} - -$prev_post_time = $max_post_time = 0; - -// Report -require_once(INC_DIR ."functions_report.php"); -$report_post = report_modules('name', 'report_post'); - -$this_date = bb_date(TIMENOW ,'md', false); - -for($i = 0; $i < $total_posts; $i++) -{ - $poster_id = $postrow[$i]['user_id']; - $poster = ($poster_id == GUEST_UID) ? $lang['GUEST'] : $postrow[$i]['username']; - $poster_birthday = ($poster_id != GUEST_UID) ? date('md', strtotime($postrow[$i]['user_birthday'])) : ''; - $post_date = bb_date($postrow[$i]['post_time'], $bb_cfg['post_date_format']); - $max_post_time = max($max_post_time, $postrow[$i]['post_time']); - $poster_posts = ($poster_id != GUEST_UID) ? $postrow[$i]['user_posts'] : ''; - $poster_from = ($postrow[$i]['user_from'] && $poster_id != GUEST_UID ) ? $postrow[$i]['user_from'] : ''; - $poster_joined = ($poster_id != GUEST_UID) ? $lang['JOINED'] . ': ' . bb_date($postrow[$i]['user_regdate'], $bb_cfg['date_format']) : ''; - $poster_longevity = ($poster_id != GUEST_UID) ? delta_time($postrow[$i]['user_regdate']) : ''; - $post_id = $postrow[$i]['post_id']; - $mc_type = $postrow[$i]['mc_type']; - $mc_comment = $postrow[$i]['mc_comment']; - $mc_user_id = profile_url(array('username' => $postrow[$i]['mc_username'], 'user_id' => $postrow[$i]['mc_user_id'], 'user_rank' => $postrow[$i]['mc_user_rank'])); - - $poster_avatar = ''; - if ( !$user->opt_js['h_av'] && $poster_id != GUEST_UID ) - { - $poster_avatar = get_avatar($poster_id, $postrow[$i]['avatar_ext_id'], !bf($postrow[$i]['user_opt'], 'user_opt', 'dis_avatar')); - } - - $poster_rank = $rank_image = ''; - $user_rank = $postrow[$i]['user_rank']; - if (!$user->opt_js['h_rnk_i'] AND isset($ranks[$user_rank])) - { - $rank_image = ($bb_cfg['show_rank_image'] && $ranks[$user_rank]['rank_image']) ? '' : ''; - $poster_rank = ($bb_cfg['show_rank_text']) ? $ranks[$user_rank]['rank_title'] : ''; - } - - // Handle anon users posting with usernames - if ($poster_id == GUEST_UID && $postrow[$i]['post_username'] != '') - { - $poster = $postrow[$i]['post_username']; - } - - // Buttons - $pm_btn = $profile_btn = $delpost_btn = $edit_btn = $ip_btn = $quote_btn = ''; - - if ($poster_id != GUEST_UID) - { - $profile_btn = true; - $pm_btn = true; - } - - if ($poster_id != BOT_UID) - { - $quote_btn = true; - $edit_btn = (($userdata['user_id'] == $poster_id && $is_auth['auth_edit']) || $is_auth['auth_mod']); - $ip_btn = ($is_auth['auth_mod'] || IS_MOD); - } - $delpost_btn = ($post_id != $t_data['topic_first_post_id'] && ($is_auth['auth_mod'] || ($userdata['user_id'] == $poster_id && $is_auth['auth_delete'] && $t_data['topic_last_post_id'] == $post_id && $postrow[$i]['post_time'] + 3600*3 > TIMENOW))); - - // Parse message and sig - $message = get_parsed_post($postrow[$i]); - - $user_sig = ($bb_cfg['allow_sig'] && !$user->opt_js['h_sig'] && $postrow[$i]['user_sig']) ? $postrow[$i]['user_sig'] : ''; - - if (bf($postrow[$i]['user_opt'], 'user_opt', 'dis_sig')) - { - $user_sig = $lang['SIGNATURE_DISABLE']; - } - elseif ($user_sig) - { - $user_sig = bbcode2html($user_sig); - } - - // Replace naughty words - if (count($orig_word)) - { - if ($user_sig) - { - $user_sig = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $user_sig . '<'), 1, -1)); - } - - $message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $message . '<'), 1, -1)); - } - - // Replace newlines (we use this rather than nl2br because till recently it wasn't XHTML compliant) - if ($user_sig) - { - $user_sig = $bb_cfg['user_signature_start'] . $user_sig . $bb_cfg['user_signature_end']; - } - - // Editing information - if ($postrow[$i]['post_edit_count']) - { - $l_edit_time_total = ($postrow[$i]['post_edit_count'] == 1) ? $lang['EDITED_TIME_TOTAL'] : $lang['EDITED_TIMES_TOTAL']; - $l_edited_by = '

        ' . sprintf($l_edit_time_total, $poster, bb_date($postrow[$i]['post_edit_time']), $postrow[$i]['post_edit_count']); - } - else - { - $l_edited_by = ''; - } - - // Again this will be handled by the templating code at some point - $pg_row_class = !($i % 2) ? 'row2' : 'row1'; - - // Create report links - if ($report_post && $report_post->auth_check('auth_write')) - { - if ($postrow[$i]['post_reported']) - { - $report_auth = ($userdata['user_level'] == ADMIN || (!$bb_cfg['report_list_admin'] && (!$bb_cfg['report_subject_auth'] || $is_auth['auth_mod']))); - if ($report_post->auth_check('auth_view') && $report_auth) - { - $temp_url = "report.php?mode=reported&" . POST_CAT_URL . '=' . $report_post->id . '&id=' . $post_id; - $target = ($bb_cfg['report_new_window']) ? ' target="_blank"' : ''; - $report_img = '' . $report_post->lang['DUPLICATE_REPORT'] . ''; - $report = '[' . $report_post->lang['DUPLICATE_REPORT'] . ']'; - } - else - { - $report_img = '' . $report_post->lang['DUPLICATE_REPORT'] . ''; - $report = '['. $report_post->lang['DUPLICATE_REPORT'] .']'; - } - } - else - { - $temp_url = "report.php?mode=" . $report_post->mode . '&id=' . $post_id; - $report_img = '' . $report_post->lang['WRITE_REPORT'] . ''; - $report = '[' . $report_post->lang['WRITE_REPORT'] . ']'; - } - } - else - { - $report_img = $report = ''; - } - - // Mod comment - switch($mc_type) - { - case 1: // Комментарий - $mc_class = 'success'; - break; - case 2: // Информация - $mc_class = 'info'; - break; - case 3: // Предупреждение - $mc_class = 'warning'; - break; - case 4: // Нарушение - $mc_class = 'danger'; - break; - default: - $mc_class = ''; - break; - } - $mc_select_type = array(); - foreach ($lang['MC_COMMENT'] as $key => $value) - { - $mc_select_type[$key] = $value['type']; - } - - $template->assign_block_vars('postrow', array( - 'ROW_CLASS' => !($i % 2) ? 'row1' : 'row2', - 'POST_ID' => $post_id, - 'IS_NEWEST' => ($post_id == $newest), - 'POSTER_NAME' => profile_url(array('username' => $poster, 'user_rank' => $user_rank)), - 'POSTER_NAME_JS' => addslashes($poster), - 'POSTER_RANK' => $poster_rank, - 'RANK_IMAGE' => $rank_image, - 'POSTER_JOINED' => ($bb_cfg['show_poster_joined']) ? $poster_longevity : '', - - 'POSTER_JOINED_DATE' => $poster_joined, - 'POSTER_POSTS' => ($bb_cfg['show_poster_posts']) ? $poster_posts : '', - 'POSTER_FROM' => ($bb_cfg['show_poster_from']) ? wbr($poster_from) : '', - 'POSTER_BOT' => ($poster_id == BOT_UID), - 'POSTER_ID' => $poster_id, - 'POSTER_AUTHOR' => ($poster_id == $t_data['topic_poster']), - 'POSTER_GENDER' => ($bb_cfg['gender']) ? gender_image($postrow[$i]['user_gender']) : '', - 'POSTED_AFTER' => ($prev_post_time) ? delta_time($postrow[$i]['post_time'], $prev_post_time) : '', - 'IS_UNREAD' => is_unread($postrow[$i]['post_time'], $topic_id, $forum_id), - 'IS_FIRST_POST' => (!$start && ($post_id == $t_data['topic_first_post_id'])), - 'MOD_CHECKBOX' => ($moderation && ($start || defined('SPLIT_FORM_START'))), - 'POSTER_AVATAR' => $poster_avatar, - 'POST_NUMBER' => ($i + $start + 1), - 'POST_DATE' => $post_date, - 'MESSAGE' => $message, - 'SIGNATURE' => $user_sig, - 'EDITED_MESSAGE' => $l_edited_by, - - 'PM' => $pm_btn, - 'PROFILE' => $profile_btn, - - 'QUOTE' => $quote_btn, - 'EDIT' => $edit_btn, - 'DELETE' => $delpost_btn, - 'IP' => $ip_btn, - - 'REPORT' => ($bb_cfg['text_buttons']) ? $report : $report_img, - 'POSTER_BIRTHDAY' => ($bb_cfg['birthday_enabled'] && $this_date == $poster_birthday) ? '' : '', - - 'MC_COMMENT' => ($mc_type) ? bbcode2html($mc_comment) : '', - 'MC_BBCODE' => ($mc_type) ? $mc_comment : '', - 'MC_CLASS' => $mc_class, - 'MC_TITLE' => sprintf($lang['MC_COMMENT'][$mc_type]['title'], $mc_user_id), - 'MC_SELECT_TYPE' => build_select("mc_type_$post_id", array_flip($mc_select_type), $mc_type), - )); - - if ($postrow[$i]['post_attachment'] && $is_auth['auth_download'] && function_exists('display_post_attachments')) - { - display_post_attachments($post_id, $postrow[$i]['post_attachment']); - } - - if ($moderation && !defined('SPLIT_FORM_START') && ($start || $post_id == $t_data['topic_first_post_id'])) - { - define('SPLIT_FORM_START', TRUE); - } - - if ($poster_id != BOT_UID) - { - $prev_post_time = $postrow[$i]['post_time']; - } -} - -set_tracks(COOKIE_TOPIC, $tracking_topics, $topic_id, $max_post_time); - -if (defined('SPLIT_FORM_START')) -{ - $template->assign_vars(array( - 'SPLIT_FORM' => true, - 'START' => $start, - 'S_SPLIT_ACTION' => "modcp.php", - 'POST_FORUM_URL' => POST_FORUM_URL, - 'POST_TOPIC_URL' => POST_TOPIC_URL, - )); -} - -// Quick Reply -if ($bb_cfg['show_quick_reply']) -{ - if ($is_auth['auth_reply'] && !($t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] == TOPIC_LOCKED)) - { - $template->assign_vars(array( - 'QUICK_REPLY' => true, - 'QR_POST_ACTION' => POSTING_URL, - 'QR_TOPIC_ID' => $topic_id, - 'CAPTCHA_HTML' => (IS_GUEST) ? CAPTCHA()->get_html() : '', - )); - - if (!IS_GUEST) - { - $notify_user = bf($userdata['user_opt'], 'user_opt', 'user_notify'); - - $template->assign_vars(array( - 'QR_NOTIFY_CHECKED' => ($notify_user) ? $notify_user && $is_watching_topic : $is_watching_topic, - )); - } - } -} - -foreach($is_auth as $name => $is) -{ - $template->assign_vars(array(strtoupper($name) => $is)); -} - -$template->assign_vars(array( - 'PG_ROW_CLASS' => isset($pg_row_class) ? $pg_row_class : 'row1', -)); - -if (IS_ADMIN) -{ - $template->assign_vars(array( - 'U_LOGS' => "admin/admin_log.php?sid={$userdata['session_id']}&t=$topic_id&db=900", - )); -} - +enqueue(array( + 'ranks', +)); + +$page_cfg['load_tpl_vars'] = array( + 'post_buttons', + 'post_icons', + 'topic_icons', +); + +$newest = $next_topic_id = 0; +$start = isset($_GET['start']) ? abs(intval($_GET['start'])) : 0; +$topic_id = isset($_GET[POST_TOPIC_URL]) ? (int) $_GET[POST_TOPIC_URL] : 0; +$post_id = (!$topic_id && isset($_GET[POST_POST_URL])) ? (int) $_GET[POST_POST_URL] : 0; + +// Start session +$user->session_start(); + +set_die_append_msg(); + +// Posts per page +$posts_per_page = $bb_cfg['posts_per_page']; +$select_ppp = ''; + +if ($userdata['session_admin']) +{ + if ($req_ppp = abs(intval(@$_REQUEST['ppp'])) AND in_array($req_ppp, $bb_cfg['allowed_posts_per_page'])) + { + $posts_per_page = $req_ppp; + } + + $select_ppp = array(); + foreach ($bb_cfg['allowed_posts_per_page'] as $ppp) + { + $select_ppp[$ppp] = $ppp; + } +} + +if (isset($_REQUEST['single'])) +{ + $posts_per_page = 1; +} +else +{ + $start = floor($start/$posts_per_page) * $posts_per_page; +} + +if (!$topic_id && !$post_id) +{ + bb_die($lang['TOPIC_POST_NOT_EXIST']); +} + +$tracking_topics = get_tracks('topic'); +$tracking_forums = get_tracks('forum'); + +// Find topic id if user requested a newer or older topic +if ($topic_id && isset($_GET['view']) && ($_GET['view'] == 'next' || $_GET['view'] == 'previous')) +{ + $sql_condition = ($_GET['view'] == 'next') ? '>' : '<'; + $sql_ordering = ($_GET['view'] == 'next') ? 'ASC' : 'DESC'; + + $sql = "SELECT t.topic_id + FROM ". BB_TOPICS ." t, ". BB_TOPICS ." t2 + WHERE t2.topic_id = $topic_id + AND t.forum_id = t2.forum_id + AND t.topic_moved_id = 0 + AND t.topic_last_post_id $sql_condition t2.topic_last_post_id + ORDER BY t.topic_last_post_id $sql_ordering + LIMIT 1"; + + if ($row = DB()->fetch_row($sql)) + { + $next_topic_id = $topic_id = $row['topic_id']; + } + else + { + $message = ($_GET['view'] == 'next') ? $lang['NO_NEWER_TOPICS'] : $lang['NO_OLDER_TOPICS']; + bb_die($message); + } +} + +// Get forum/topic data +if ($topic_id) +{ + $sql = "SELECT t.*, f.*, tw.notify_status + FROM ". BB_TOPICS ." t + LEFT JOIN ". BB_FORUMS ." f USING(forum_id) + LEFT JOIN ". BB_TOPICS_WATCH ." tw ON(tw.topic_id = t.topic_id AND user_id = {$userdata['user_id']}) + WHERE t.topic_id = $topic_id + "; +} +elseif ($post_id) +{ + $sql = "SELECT t.*, f.*, p.post_time, tw.notify_status + FROM ". BB_TOPICS ." t + LEFT JOIN ". BB_FORUMS ." f USING(forum_id) + LEFT JOIN ". BB_POSTS ." p USING(topic_id) + LEFT JOIN ". BB_TOPICS_WATCH ." tw ON(tw.topic_id = t.topic_id AND user_id = {$userdata['user_id']}) + WHERE p.post_id = $post_id + "; +} +else +{ + bb_die($lang['TOPIC_POST_NOT_EXIST']); +} + +if (!$t_data = DB()->fetch_row($sql)) +{ + bb_die($lang['TOPIC_POST_NOT_EXIST']); +} + +$forum_topic_data =& $t_data; +$topic_id = $t_data['topic_id']; +$forum_id = $t_data['forum_id']; + +if($t_data['allow_porno_topic'] && bf($userdata['user_opt'], 'user_opt', 'user_porn_forums')) bb_die($lang['ERROR_PORNO_FORUM']); + +if ($userdata['session_admin'] && !empty($_REQUEST['mod'])) +{ + if (IS_ADMIN) + { + $datastore->enqueue(array('viewtopic_forum_select')); + } +} +if ($t_data['topic_attachment']) +{ + $datastore->enqueue(array( + 'attach_extensions', + )); +} + +// Find newest post +if (($next_topic_id || @$_GET['view'] === 'newest') && !IS_GUEST && $topic_id) +{ + $post_time = 'post_time >= '. get_last_read($topic_id, $forum_id); + $post_id_altern = ($next_topic_id) ? '' : ' OR post_id = '. $t_data['topic_last_post_id']; + + $sql = "SELECT post_id, post_time + FROM ". BB_POSTS ." + WHERE topic_id = $topic_id + AND ($post_time $post_id_altern) + ORDER BY post_time ASC + LIMIT 1"; + + if ($row = DB()->fetch_row($sql)) + { + $post_id = $newest = $row['post_id']; + $t_data['post_time'] = $row['post_time']; + } +} + +if ($post_id && !empty($t_data['post_time']) && ($t_data['topic_replies'] + 1) > $posts_per_page) +{ + $sql = "SELECT COUNT(post_id) AS prev_posts + FROM ". BB_POSTS ." + WHERE topic_id = $topic_id + AND post_time <= {$t_data['post_time']}"; + + if ($row = DB()->fetch_row($sql)) + { + $t_data['prev_posts'] = $row['prev_posts']; + } +} + +// Auth check +$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $t_data); + +if (!$is_auth['auth_read']) +{ + if (IS_GUEST) + { + $redirect = ($post_id) ? POST_URL ."$post_id#$post_id" : TOPIC_URL . $topic_id; + $redirect .= ($start && !$post_id) ? "&start=$start" : ''; + redirect(LOGIN_URL . "?redirect=viewtopic.php&$redirect"); + } + bb_die($lang['TOPIC_POST_NOT_EXIST']); +} + +$forum_name = $t_data['forum_name']; +$topic_title = $t_data['topic_title']; +$topic_id = $t_data['topic_id']; +$topic_time = $t_data['topic_time']; + +$moderation = (!empty($_REQUEST['mod']) && $is_auth['auth_mod']); + +// Redirect to login page if not admin session +$mod_redirect_url = ''; + +if ($is_auth['auth_mod']) +{ + $redirect = isset($_POST['redirect']) ? $_POST['redirect'] : @$_SERVER['REQUEST_URI']; + $redirect = url_arg($redirect, 'mod', 1, '&'); + $mod_redirect_url = LOGIN_URL . "?redirect=$redirect&admin=1"; + + if ($moderation && !$userdata['session_admin']) + { + redirect($mod_redirect_url); + } +} + +if ($moderation) +{ + if (IS_ADMIN) + { + if (!$forum_select = $datastore->get('viewtopic_forum_select')) + { + $datastore->update('viewtopic_forum_select'); + $forum_select = $datastore->get('viewtopic_forum_select'); + } + $forum_select_html = $forum_select['viewtopic_forum_select']; + } + else + { + $not_auth_forums_csv = $user->get_not_auth_forums(AUTH_VIEW); + $forum_select_html = get_forum_select(explode(',', $not_auth_forums_csv), 'new_forum_id'); + } + $template->assign_vars(array( + 'S_FORUM_SELECT' => $forum_select_html, + )); +} + +if (!$forums = $datastore->get('cat_forums')) +{ + $datastore->update('cat_forums'); + $forums = $datastore->get('cat_forums'); +} + +$template->assign_vars(array( + 'CAT_TITLE' => $forums['cat_title_html'][$t_data['cat_id']], + 'U_VIEWCAT' => CAT_URL . $t_data['cat_id'], + 'PARENT_FORUM_HREF' => ($parent_id = $t_data['forum_parent']) ? FORUM_URL . $parent_id : '', + 'PARENT_FORUM_NAME' => ($parent_id = $t_data['forum_parent']) ? htmlCHR($forums['f'][$parent_id]['forum_name']) : '', +)); +unset($forums); +$datastore->rm('cat_forums'); + +if ($post_id && !empty($t_data['prev_posts'])) +{ + $start = floor(($t_data['prev_posts'] - 1) / $posts_per_page) * $posts_per_page; +} + +// +// Is user watching this thread? +// +$can_watch_topic = $is_watching_topic = false; + +if ($bb_cfg['topic_notify_enabled']) +{ + if ($userdata['session_logged_in']) + { + $can_watch_topic = TRUE; + + if (!empty($t_data['notify_status']) && $t_data['notify_status']) + { + if (isset($_GET['unwatch'])) + { + if ($_GET['unwatch'] == 'topic') + { + $is_watching_topic = 0; + + DB()->query("DELETE FROM ". BB_TOPICS_WATCH ." WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}"); + } + + set_die_append_msg($forum_id, $topic_id); + bb_die($lang['NO_LONGER_WATCHING']); + + } + else + { + $is_watching_topic = TRUE; + + if (!$t_data['notify_status']) + { + DB()->query("UPDATE ". BB_TOPICS_WATCH ." SET notify_status = ". TOPIC_WATCH_NOTIFIED ." WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}"); + } + } + } + else + { + if (isset($_GET['watch'])) + { + if ($_GET['watch'] == 'topic') + { + $is_watching_topic = TRUE; + + DB()->query(" + INSERT INTO ". BB_TOPICS_WATCH ." (user_id, topic_id, notify_status) + VALUES (". $userdata['user_id'] .", $topic_id, ". TOPIC_WATCH_NOTIFIED .") + "); + } + + set_die_append_msg($forum_id, $topic_id); + bb_die($lang['YOU_ARE_WATCHING']); + + } + else + { + $is_watching_topic = 0; + } + } + } + else + { + if (isset($_GET['unwatch'])) + { + if ($_GET['unwatch'] == 'topic') + { + redirect(LOGIN_URL . "?redirect=viewtopic.php&t=$topic_id&unwatch=topic"); + } + } + } +} + +// Generate a 'Show posts in previous x days' select box. If the postdays var is POSTed +// then get it's value, find the number of topics with dates newer than it (to properly +// handle pagination) and alter the main query +$post_days = 0; +$limit_posts_time = ''; +$total_replies = $t_data['topic_replies'] + 1; + +if (!empty($_REQUEST['postdays'])) +{ + if ($post_days = abs(intval($_REQUEST['postdays']))) + { + if (!empty($_POST['postdays'])) + { + $start = 0; + } + $min_post_time = TIMENOW - ($post_days*86400); + + $sql = "SELECT COUNT(p.post_id) AS num_posts + FROM " . BB_TOPICS . " t, " . BB_POSTS . " p + WHERE t.topic_id = $topic_id + AND p.topic_id = t.topic_id + AND p.post_time > $min_post_time"; + + $total_replies = ($row = DB()->fetch_row($sql)) ? $row['num_posts'] : 0; + $limit_posts_time = "AND p.post_time >= $min_post_time "; + } +} + +// Decide how to order the post display +$post_order = (isset($_POST['postorder']) && $_POST['postorder'] !== 'asc') ? 'desc' : 'asc'; + +// +// Go ahead and pull all data for this topic +// +// 1. Add first post of topic if it pinned and page of topic not first +$first_post = false; +if ($t_data['topic_show_first_post'] && $start) +{ + $first_post = DB()->fetch_rowset(" + SELECT + u.username, u.user_id, u.user_rank, u.user_posts, u.user_from, + u.user_regdate, u.user_sig, + u.avatar_ext_id, + u.user_opt, u.user_gender, u.user_birthday, + p.*, + u2.username as mc_username, u2.user_rank as mc_user_rank, + h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text + FROM ". BB_POSTS ." p + LEFT JOIN ". BB_USERS ." u ON(u.user_id = p.poster_id) + LEFT JOIN ". BB_POSTS_TEXT ." pt ON(pt.post_id = p.post_id) + LEFT JOIN ". BB_POSTS_HTML ." h ON(h.post_id = p.post_id) + LEFT JOIN ". BB_USERS ." u2 ON(u2.user_id = p.mc_user_id) + WHERE + p.post_id = {$t_data['topic_first_post_id']} + LIMIT 1 + "); +} +// 2. All others posts +$sql = " + SELECT + u.username, u.user_id, u.user_rank, u.user_posts, u.user_from, + u.user_regdate, u.user_sig, + u.avatar_ext_id, + u.user_opt, u.user_gender, u.user_birthday, + p.*, + u2.username as mc_username, u2.user_rank as mc_user_rank, + h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text + FROM ". BB_POSTS ." p + LEFT JOIN ". BB_USERS ." u ON(u.user_id = p.poster_id) + LEFT JOIN ". BB_POSTS_TEXT ." pt ON(pt.post_id = p.post_id) + LEFT JOIN ". BB_POSTS_HTML ." h ON(h.post_id = p.post_id) + LEFT JOIN ". BB_USERS ." u2 ON(u2.user_id = p.mc_user_id) + WHERE p.topic_id = $topic_id + $limit_posts_time + GROUP BY p.post_id + ORDER BY p.post_time $post_order + LIMIT $start, $posts_per_page +"; + +if ($postrow = DB()->fetch_rowset($sql)) +{ + if ($first_post) $postrow = array_merge($first_post, $postrow); + $total_posts = count($postrow); +} +else +{ + bb_die($lang['NO_POSTS_TOPIC']); +} + +if (!$ranks = $datastore->get('ranks')) +{ + $datastore->update('ranks'); + $ranks = $datastore->get('ranks'); +} + +// +// Define censored word matches +// +$orig_word = $replacement_word = array(); +obtain_word_list($orig_word, $replacement_word); + +// +// Censor topic title +// +if ( count($orig_word) ) +{ + $topic_title = preg_replace($orig_word, $replacement_word, $topic_title); +} + +// +// Post, reply and other URL generation for +// templating vars +// +$new_topic_url = POSTING_URL . "?mode=newtopic&f=$forum_id"; +$reply_topic_url = POSTING_URL . "?mode=reply&t=$topic_id"; +$view_forum_url = "viewforum.php?f=$forum_id"; +$view_prev_topic_url = "viewtopic.php?t=$topic_id&view=previous#newest"; +$view_next_topic_url = "viewtopic.php?t=$topic_id&view=next#newest"; + +$reply_img = ( $t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] == TOPIC_LOCKED) ? $images['reply_locked'] : $images['reply_new']; +$reply_alt = ( $t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] == TOPIC_LOCKED) ? $lang['TOPIC_LOCKED_SHORT'] : $lang['REPLY_TO_TOPIC']; + +// Set 'body' template for attach_mod +$template->set_filenames(array('body' => 'viewtopic.tpl')); + +// +// User authorisation levels output +// +$s_auth_can = ( ( $is_auth['auth_post'] ) ? $lang['RULES_POST_CAN'] : $lang['RULES_POST_CANNOT'] ) . '
        '; +$s_auth_can .= ( ( $is_auth['auth_reply'] ) ? $lang['RULES_REPLY_CAN'] : $lang['RULES_REPLY_CANNOT'] ) . '
        '; +$s_auth_can .= ( ( $is_auth['auth_edit'] ) ? $lang['RULES_EDIT_CAN'] : $lang['RULES_EDIT_CANNOT'] ) . '
        '; +$s_auth_can .= ( ( $is_auth['auth_delete'] ) ? $lang['RULES_DELETE_CAN'] : $lang['RULES_DELETE_CANNOT'] ) . '
        '; +$s_auth_can .= ( ( $is_auth['auth_vote'] ) ? $lang['RULES_VOTE_CAN'] : $lang['RULES_VOTE_CANNOT'] ) . '
        '; +$s_auth_can .= ( ($is_auth['auth_attachments'] ) ? $lang['RULES_ATTACH_CAN'] : $lang['RULES_ATTACH_CANNOT'] ) . '
        '; +$s_auth_can .= ( ($is_auth['auth_download'] ) ? $lang['RULES_DOWNLOAD_CAN'] : $lang['RULES_DOWNLOAD_CANNOT'] ) . '
        '; + +$topic_mod = ''; + +if ( $is_auth['auth_mod'] ) +{ + $s_auth_can .= $lang['RULES_MODERATE']; + $topic_mod .= "' . $lang['DELETE_TOPIC'] . ' '; + $topic_mod .= "' . $lang['MOVE_TOPIC'] . ' '; + $topic_mod .= ( $t_data['topic_status'] == TOPIC_UNLOCKED ) ? "' . $lang['LOCK_TOPIC'] . ' ' : "' . $lang['UNLOCK_TOPIC'] . ' '; + $topic_mod .= "' . $lang['SPLIT_TOPIC'] . ' '; + + if ($t_data['allow_reg_tracker'] || $t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL || IS_ADMIN) + { + if ($t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL) + { + $topic_mod .= "' . $lang['UNSET_DL_STATUS'] . ''; + } + else + { + $topic_mod .= "' . $lang['SET_DL_STATUS'] . ''; + } + } +} +elseif (($t_data['topic_poster'] == $userdata['user_id']) && $userdata['session_logged_in'] && $t_data['self_moderated']) +{ + $topic_mod .= "' . $lang['MOVE_TOPIC'] . ' '; +} + +// Get report topic module and create report link +require_once(INC_DIR ."functions_report.php"); +$report_topic = report_modules('name', 'report_topic'); + +if ($report_topic && $report_topic->auth_check('auth_write')) +{ + if ($forum_topic_data['topic_reported']) + { + $report_auth = ($userdata['user_level'] == ADMIN || (!$bb_cfg['report_list_admin'] && (!$bb_cfg['report_subject_auth'] || $is_auth['auth_mod']))); + if ($report_topic->auth_check('auth_view') && $is_auth) + { + $target = ($bb_cfg['report_new_window']) ? ' target="_blank"' : ''; + $s_report_topic =' ' . $report_topic->lang['DUPLICATE_REPORT'] . ' '; + } + else + { + $s_report_topic = ' ' . $report_topic->lang['DUPLICATE_REPORT'] . ' '; + } + } + else + { + $s_report_topic = ' ' . $report_topic->lang['WRITE_REPORT'] . ' '; + } + + $topic_mod .= $s_report_topic; + $template->assign_var('S_REPORT_TOPIC', $s_report_topic); +} + +// +// Topic watch information +// +$s_watching_topic = $s_watching_topic_img = ''; +if ( $can_watch_topic ) +{ + if ( $is_watching_topic ) + { + $s_watching_topic = "' . $lang['STOP_WATCHING_TOPIC'] . ''; + $s_watching_topic_img = ( isset($images['topic_un_watch']) ) ? "' . $lang['STOP_WATCHING_TOPIC'] . '' : ''; + } + else + { + $s_watching_topic = "' . $lang['START_WATCHING_TOPIC'] . ''; + $s_watching_topic_img = ( isset($images['Topic_watch']) ) ? "' . $lang['START_WATCHING_TOPIC'] . '' : ''; + } +} + +// If we've got a hightlight set pass it on to pagination, +$pg_url = TOPIC_URL . $topic_id; +$pg_url .= ($post_days) ? "&postdays=$post_days" : ''; +$pg_url .= ($post_order != 'asc') ? "&postorder=$post_order" : ''; +$pg_url .= isset($_REQUEST['single']) ? "&single=1" : ''; +$pg_url .= ($moderation) ? "&mod=1" : ''; +$pg_url .= ($posts_per_page != $bb_cfg['posts_per_page']) ? "&ppp=$posts_per_page" : ''; + +generate_pagination($pg_url, $total_replies, $posts_per_page, $start); + +// +// Selects +// +$sel_previous_days = array( + 0 => $lang['ALL_POSTS'], + 1 => $lang['1_DAY'], + 7 => $lang['7_DAYS'], + 14 => $lang['2_WEEKS'], + 30 => $lang['1_MONTH'], + 90 => $lang['3_MONTHS'], + 180 => $lang['6_MONTHS'], + 364 => $lang['1_YEAR'], +); + +$sel_post_order_ary = array( + $lang['OLDEST_FIRST'] => 'asc', + $lang['NEWEST_FIRST'] => 'desc', +); + +$topic_has_poll = ($t_data['topic_vote'] && !IS_GUEST); +$poll_time_expired = ($t_data['topic_time'] < TIMENOW - $bb_cfg['poll_max_days']*86400); +$can_manage_poll = ($t_data['topic_poster'] == $userdata['user_id'] || $is_auth['auth_mod']); +$can_add_poll = ($can_manage_poll && !$topic_has_poll && !$poll_time_expired && !$start); + +// +// Send vars to template +// +$template->assign_vars(array( + 'PAGE_URL' => $pg_url, + 'PAGE_URL_PPP' => url_arg($pg_url, 'ppp', null), + 'PAGE_START' => $start, + 'SHOW_JUMPBOX' => true, + + 'FORUM_ID' => $forum_id, + 'FORUM_NAME' => htmlCHR($forum_name), + 'TOPIC_ID' => $topic_id, + 'PAGE_TITLE' => $topic_title, + 'TOPIC_TITLE' => wbr($topic_title), + 'PORNO_FORUM' => $t_data['allow_porno_topic'], + 'REPLY_IMG' => $reply_img, + 'SHOW_BOT_NICK' => $bb_cfg['show_bot_nick'], + 'T_POST_REPLY' => $reply_alt, + + 'HIDE_AVATAR' => $user->opt_js['h_av'], + 'HIDE_RANK_IMG' => ($user->opt_js['h_rnk_i'] && $bb_cfg['show_rank_image']), + 'HIDE_POST_IMG' => $user->opt_js['h_post_i'], + 'HIDE_SMILE' => $user->opt_js['h_smile'], + 'HIDE_SIGNATURE' => $user->opt_js['h_sig'], + 'SPOILER_OPENED' => $user->opt_js['sp_op'], + 'SHOW_IMG_AFTER_LOAD' => $user->opt_js['i_aft_l'], + + 'HIDE_RANK_IMG_DIS' => !$bb_cfg['show_rank_image'], + + 'PINNED_FIRST_POST' => $t_data['topic_show_first_post'], + 'PIN_HREF' => $t_data['topic_show_first_post'] ? "modcp.php?t=$topic_id&mode=post_unpin" : "modcp.php?t=$topic_id&mode=post_pin", + 'PIN_TITLE' => $t_data['topic_show_first_post'] ? $lang['POST_UNPIN'] : $lang['POST_PIN'], + + 'AUTH_MOD' => $is_auth['auth_mod'], + 'IN_MODERATION' => $moderation, + 'SELECT_PPP' => ($moderation && $select_ppp && $total_replies > $posts_per_page) ? build_select('ppp', $select_ppp, $posts_per_page, null, null, 'onchange="$(\'#ppp\').submit();"') : '', + + 'S_SELECT_POST_DAYS' => build_select('postdays', array_flip($sel_previous_days), $post_days), + 'S_SELECT_POST_ORDER' => build_select('postorder', $sel_post_order_ary, $post_order), + 'S_POST_DAYS_ACTION' => "viewtopic.php?t=$topic_id&start=$start", + 'S_AUTH_LIST' => $s_auth_can, + 'S_TOPIC_ADMIN' => $topic_mod, + 'S_WATCH_TOPIC' => $s_watching_topic, + 'S_WATCH_TOPIC_IMG' => $s_watching_topic_img, + 'U_VIEW_TOPIC' => TOPIC_URL . $topic_id, + 'U_VIEW_FORUM' => $view_forum_url, + 'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url, + 'U_VIEW_NEWER_TOPIC' => $view_next_topic_url, + 'U_POST_NEW_TOPIC' => $new_topic_url, + 'U_POST_REPLY_TOPIC' => $reply_topic_url, + 'U_SEARCH_SELF' => "search.php?uid={$userdata['user_id']}&t=$topic_id&dm=1", + + 'TOPIC_HAS_POLL' => $topic_has_poll, + 'POLL_IS_EDITABLE' => (!$poll_time_expired), + 'POLL_IS_FINISHED' => ($t_data['topic_vote'] == POLL_FINISHED), + 'CAN_MANAGE_POLL' => $can_manage_poll, + 'CAN_ADD_POLL' => $can_add_poll, +)); + +// Does this topic contain DL-List? +$template->assign_vars(array( + 'SHOW_TOR_ACT' => false, + 'PEERS_FULL_LINK' => false, + 'DL_LIST_HREF' => TOPIC_URL ."$topic_id&dl=names&spmode=full", +)); +require(INC_DIR .'torrent_show_dl_list.php'); + +if ($t_data['topic_attachment']) +{ + require(BB_ROOT .'attach_mod/attachment_mod.php'); + init_display_post_attachments($t_data['topic_attachment']); +} + +// +// Update the topic view counter +// +$sql = "INSERT INTO ". BUF_TOPIC_VIEW ." (topic_id, topic_views) VALUES ($topic_id, 1) ON DUPLICATE KEY UPDATE topic_views = topic_views + 1"; +if (!DB()->sql_query($sql)) +{ + bb_die('Could not update topic views'); +} + +// +// Does this topic contain a poll? +// +if ($topic_has_poll) +{ + $poll_votes_js = get_poll_data_items_js($topic_id); + + if (!$poll_votes_js) + { + $template->assign_vars(array( + 'TOPIC_HAS_POLL' => false, + )); + } + else + { + $template->assign_vars(array( + 'SHOW_VOTE_BTN' => poll_is_active($t_data), + 'POLL_VOTES_JS' => $poll_votes_js, + )); + } +} + +$prev_post_time = $max_post_time = 0; + +// Report +require_once(INC_DIR ."functions_report.php"); +$report_post = report_modules('name', 'report_post'); + +$this_date = bb_date(TIMENOW ,'md', false); + +for($i = 0; $i < $total_posts; $i++) +{ + $poster_id = $postrow[$i]['user_id']; + $poster = ($poster_id == GUEST_UID) ? $lang['GUEST'] : $postrow[$i]['username']; + $poster_birthday = ($poster_id != GUEST_UID) ? date('md', strtotime($postrow[$i]['user_birthday'])) : ''; + $post_date = bb_date($postrow[$i]['post_time'], $bb_cfg['post_date_format']); + $max_post_time = max($max_post_time, $postrow[$i]['post_time']); + $poster_posts = ($poster_id != GUEST_UID) ? $postrow[$i]['user_posts'] : ''; + $poster_from = ($postrow[$i]['user_from'] && $poster_id != GUEST_UID ) ? $postrow[$i]['user_from'] : ''; + $poster_joined = ($poster_id != GUEST_UID) ? $lang['JOINED'] . ': ' . bb_date($postrow[$i]['user_regdate'], $bb_cfg['date_format']) : ''; + $poster_longevity = ($poster_id != GUEST_UID) ? delta_time($postrow[$i]['user_regdate']) : ''; + $post_id = $postrow[$i]['post_id']; + $mc_type = $postrow[$i]['mc_type']; + $mc_comment = $postrow[$i]['mc_comment']; + $mc_user_id = profile_url(array('username' => $postrow[$i]['mc_username'], 'user_id' => $postrow[$i]['mc_user_id'], 'user_rank' => $postrow[$i]['mc_user_rank'])); + + $poster_avatar = ''; + if ( !$user->opt_js['h_av'] && $poster_id != GUEST_UID ) + { + $poster_avatar = get_avatar($poster_id, $postrow[$i]['avatar_ext_id'], !bf($postrow[$i]['user_opt'], 'user_opt', 'dis_avatar')); + } + + $poster_rank = $rank_image = ''; + $user_rank = $postrow[$i]['user_rank']; + if (!$user->opt_js['h_rnk_i'] AND isset($ranks[$user_rank])) + { + $rank_image = ($bb_cfg['show_rank_image'] && $ranks[$user_rank]['rank_image']) ? '' : ''; + $poster_rank = ($bb_cfg['show_rank_text']) ? $ranks[$user_rank]['rank_title'] : ''; + } + + // Handle anon users posting with usernames + if ($poster_id == GUEST_UID && $postrow[$i]['post_username'] != '') + { + $poster = $postrow[$i]['post_username']; + } + + // Buttons + $pm_btn = $profile_btn = $delpost_btn = $edit_btn = $ip_btn = $quote_btn = ''; + + if ($poster_id != GUEST_UID) + { + $profile_btn = true; + $pm_btn = true; + } + + if ($poster_id != BOT_UID) + { + $quote_btn = true; + $edit_btn = (($userdata['user_id'] == $poster_id && $is_auth['auth_edit']) || $is_auth['auth_mod']); + $ip_btn = ($is_auth['auth_mod'] || IS_MOD); + } + $delpost_btn = ($post_id != $t_data['topic_first_post_id'] && ($is_auth['auth_mod'] || ($userdata['user_id'] == $poster_id && $is_auth['auth_delete'] && $t_data['topic_last_post_id'] == $post_id && $postrow[$i]['post_time'] + 3600*3 > TIMENOW))); + + // Parse message and sig + $message = get_parsed_post($postrow[$i]); + + $user_sig = ($bb_cfg['allow_sig'] && !$user->opt_js['h_sig'] && $postrow[$i]['user_sig']) ? $postrow[$i]['user_sig'] : ''; + + if (bf($postrow[$i]['user_opt'], 'user_opt', 'dis_sig')) + { + $user_sig = $lang['SIGNATURE_DISABLE']; + } + elseif ($user_sig) + { + $user_sig = bbcode2html($user_sig); + } + + // Replace naughty words + if (count($orig_word)) + { + if ($user_sig) + { + $user_sig = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $user_sig . '<'), 1, -1)); + } + + $message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $message . '<'), 1, -1)); + } + + // Replace newlines (we use this rather than nl2br because till recently it wasn't XHTML compliant) + if ($user_sig) + { + $user_sig = $bb_cfg['user_signature_start'] . $user_sig . $bb_cfg['user_signature_end']; + } + + // Editing information + if ($postrow[$i]['post_edit_count']) + { + $l_edit_time_total = ($postrow[$i]['post_edit_count'] == 1) ? $lang['EDITED_TIME_TOTAL'] : $lang['EDITED_TIMES_TOTAL']; + $l_edited_by = '

        ' . sprintf($l_edit_time_total, $poster, bb_date($postrow[$i]['post_edit_time']), $postrow[$i]['post_edit_count']); + } + else + { + $l_edited_by = ''; + } + + // Again this will be handled by the templating code at some point + $pg_row_class = !($i % 2) ? 'row2' : 'row1'; + + // Create report links + if ($report_post && $report_post->auth_check('auth_write')) + { + if ($postrow[$i]['post_reported']) + { + $report_auth = ($userdata['user_level'] == ADMIN || (!$bb_cfg['report_list_admin'] && (!$bb_cfg['report_subject_auth'] || $is_auth['auth_mod']))); + if ($report_post->auth_check('auth_view') && $report_auth) + { + $temp_url = "report.php?mode=reported&" . POST_CAT_URL . '=' . $report_post->id . '&id=' . $post_id; + $target = ($bb_cfg['report_new_window']) ? ' target="_blank"' : ''; + $report_img = '' . $report_post->lang['DUPLICATE_REPORT'] . ''; + $report = '[' . $report_post->lang['DUPLICATE_REPORT'] . ']'; + } + else + { + $report_img = '' . $report_post->lang['DUPLICATE_REPORT'] . ''; + $report = '['. $report_post->lang['DUPLICATE_REPORT'] .']'; + } + } + else + { + $temp_url = "report.php?mode=" . $report_post->mode . '&id=' . $post_id; + $report_img = '' . $report_post->lang['WRITE_REPORT'] . ''; + $report = '[' . $report_post->lang['WRITE_REPORT'] . ']'; + } + } + else + { + $report_img = $report = ''; + } + + // Mod comment + switch($mc_type) + { + case 1: // Комментарий + $mc_class = 'success'; + break; + case 2: // Информация + $mc_class = 'info'; + break; + case 3: // Предупреждение + $mc_class = 'warning'; + break; + case 4: // Нарушение + $mc_class = 'danger'; + break; + default: + $mc_class = ''; + break; + } + $mc_select_type = array(); + foreach ($lang['MC_COMMENT'] as $key => $value) + { + $mc_select_type[$key] = $value['type']; + } + + $template->assign_block_vars('postrow', array( + 'ROW_CLASS' => !($i % 2) ? 'row1' : 'row2', + 'POST_ID' => $post_id, + 'IS_NEWEST' => ($post_id == $newest), + 'POSTER_NAME' => profile_url(array('username' => $poster, 'user_rank' => $user_rank)), + 'POSTER_NAME_JS' => addslashes($poster), + 'POSTER_RANK' => $poster_rank, + 'RANK_IMAGE' => $rank_image, + 'POSTER_JOINED' => ($bb_cfg['show_poster_joined']) ? $poster_longevity : '', + + 'POSTER_JOINED_DATE' => $poster_joined, + 'POSTER_POSTS' => ($bb_cfg['show_poster_posts']) ? $poster_posts : '', + 'POSTER_FROM' => ($bb_cfg['show_poster_from']) ? wbr($poster_from) : '', + 'POSTER_BOT' => ($poster_id == BOT_UID), + 'POSTER_ID' => $poster_id, + 'POSTER_AUTHOR' => ($poster_id == $t_data['topic_poster']), + 'POSTER_GENDER' => ($bb_cfg['gender']) ? gender_image($postrow[$i]['user_gender']) : '', + 'POSTED_AFTER' => ($prev_post_time) ? delta_time($postrow[$i]['post_time'], $prev_post_time) : '', + 'IS_UNREAD' => is_unread($postrow[$i]['post_time'], $topic_id, $forum_id), + 'IS_FIRST_POST' => (!$start && ($post_id == $t_data['topic_first_post_id'])), + 'MOD_CHECKBOX' => ($moderation && ($start || defined('SPLIT_FORM_START'))), + 'POSTER_AVATAR' => $poster_avatar, + 'POST_NUMBER' => ($i + $start + 1), + 'POST_DATE' => $post_date, + 'MESSAGE' => $message, + 'SIGNATURE' => $user_sig, + 'EDITED_MESSAGE' => $l_edited_by, + + 'PM' => $pm_btn, + 'PROFILE' => $profile_btn, + + 'QUOTE' => $quote_btn, + 'EDIT' => $edit_btn, + 'DELETE' => $delpost_btn, + 'IP' => $ip_btn, + + 'REPORT' => ($bb_cfg['text_buttons']) ? $report : $report_img, + 'POSTER_BIRTHDAY' => ($bb_cfg['birthday_enabled'] && $this_date == $poster_birthday) ? '' : '', + + 'MC_COMMENT' => ($mc_type) ? bbcode2html($mc_comment) : '', + 'MC_BBCODE' => ($mc_type) ? $mc_comment : '', + 'MC_CLASS' => $mc_class, + 'MC_TITLE' => sprintf($lang['MC_COMMENT'][$mc_type]['title'], $mc_user_id), + 'MC_SELECT_TYPE' => build_select("mc_type_$post_id", array_flip($mc_select_type), $mc_type), + )); + + if ($postrow[$i]['post_attachment'] && $is_auth['auth_download'] && function_exists('display_post_attachments')) + { + display_post_attachments($post_id, $postrow[$i]['post_attachment']); + } + + if ($moderation && !defined('SPLIT_FORM_START') && ($start || $post_id == $t_data['topic_first_post_id'])) + { + define('SPLIT_FORM_START', TRUE); + } + + if ($poster_id != BOT_UID) + { + $prev_post_time = $postrow[$i]['post_time']; + } +} + +set_tracks(COOKIE_TOPIC, $tracking_topics, $topic_id, $max_post_time); + +if (defined('SPLIT_FORM_START')) +{ + $template->assign_vars(array( + 'SPLIT_FORM' => true, + 'START' => $start, + 'S_SPLIT_ACTION' => "modcp.php", + 'POST_FORUM_URL' => POST_FORUM_URL, + 'POST_TOPIC_URL' => POST_TOPIC_URL, + )); +} + +// Quick Reply +if ($bb_cfg['show_quick_reply']) +{ + if ($is_auth['auth_reply'] && !($t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] == TOPIC_LOCKED)) + { + $template->assign_vars(array( + 'QUICK_REPLY' => true, + 'QR_POST_ACTION' => POSTING_URL, + 'QR_TOPIC_ID' => $topic_id, + 'CAPTCHA_HTML' => (IS_GUEST) ? CAPTCHA()->get_html() : '', + )); + + if (!IS_GUEST) + { + $notify_user = bf($userdata['user_opt'], 'user_opt', 'user_notify'); + + $template->assign_vars(array( + 'QR_NOTIFY_CHECKED' => ($notify_user) ? $notify_user && $is_watching_topic : $is_watching_topic, + )); + } + } +} + +foreach($is_auth as $name => $is) +{ + $template->assign_vars(array(strtoupper($name) => $is)); +} + +$template->assign_vars(array( + 'PG_ROW_CLASS' => isset($pg_row_class) ? $pg_row_class : 'row1', +)); + +if (IS_ADMIN) +{ + $template->assign_vars(array( + 'U_LOGS' => "admin/admin_log.php?sid={$userdata['session_id']}&t=$topic_id&db=900", + )); +} + print_page('viewtopic.tpl'); \ No newline at end of file From cd40f62cd6b0490c440c27f853c3734742371488 Mon Sep 17 00:00:00 2001 From: Exile Date: Sat, 2 Aug 2014 22:42:17 +0400 Subject: [PATCH 07/19] r593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Завершаем с форматированием. --- upload/admin/admin_groups.php | 19 ++-- upload/ajax/edit_group_profile.php | 37 +++---- upload/group_config.php | 107 ++++++++++----------- upload/groupcp.php | 12 +-- upload/templates/admin/admin_groups.tpl | 13 ++- upload/templates/default/group_config.tpl | 112 +++++++++++----------- upload/templates/default/groupcp.tpl | 32 +++---- 7 files changed, 164 insertions(+), 168 deletions(-) diff --git a/upload/admin/admin_groups.php b/upload/admin/admin_groups.php index 81c3be58a..5d86807b3 100644 --- a/upload/admin/admin_groups.php +++ b/upload/admin/admin_groups.php @@ -30,7 +30,7 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'group_moderator' => $row['group_moderator'], 'group_mod_name' => $row['moderator_name'], 'group_type' => $row['group_type'], - 'release_group' => $row['release_group'], + 'release_group' => $row['release_group'], ); $mode = 'editgroup'; $template->assign_block_vars('group_edit', array()); @@ -43,7 +43,7 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'group_moderator' => '', 'group_mod_name' => '', 'group_type' => GROUP_OPEN, - 'release_group' => 0, + 'release_group' => 0, ); $mode = 'newgroup'; } @@ -68,7 +68,7 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) 'S_GROUP_OPEN_CHECKED' => ($group_info['group_type'] == GROUP_OPEN) ? HTML_CHECKED : '', 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? HTML_CHECKED : '', 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN ) ? HTML_CHECKED : '', - 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, + 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, 'S_GROUP_ACTION' => "admin_groups.php", 'S_HIDDEN_FIELDS' => $s_hidden_fields, )); @@ -92,11 +92,10 @@ else if (!empty($_POST['group_update'])) } else { - $group_type = isset($_POST['group_type']) ? intval($_POST['group_type']) : GROUP_OPEN; - $release_group = isset($_POST['release_group']) ? intval($_POST['release_group']) : 0; - $group_name = isset($_POST['group_name']) ? trim($_POST['group_name']) : ''; - $group_desc = isset($_POST['group_description']) ? trim($_POST['group_description']) : ''; - + $group_type = isset($_POST['group_type']) ? intval($_POST['group_type']) : GROUP_OPEN; + $release_group = isset($_POST['release_group']) ? intval($_POST['release_group']) : 0; + $group_name = isset($_POST['group_name']) ? trim($_POST['group_name']) : ''; + $group_desc = isset($_POST['group_description']) ? trim($_POST['group_description']) : ''; $group_moderator = isset($_POST['username']) ? $_POST['username'] : ''; if ($group_name === '') @@ -116,7 +115,7 @@ else if (!empty($_POST['group_update'])) $sql_ary = array( 'group_type' => (int) $group_type, - 'release_group' => (int) $release_group, + 'release_group' => (int) $release_group, 'group_name' => (string) $group_name, 'group_description' => (string) $group_desc, 'group_moderator' => (int) $group_moderator, @@ -134,7 +133,7 @@ else if (!empty($_POST['group_update'])) { // Create user_group for new group's moderator add_user_into_group($group_id, $group_moderator); - $sql_ary['group_time'] = TIMENOW; + $sql_ary['group_time'] = TIMENOW; // Delete old moderator's user_group if (isset($_POST['delete_old_moderator'])) diff --git a/upload/ajax/edit_group_profile.php b/upload/ajax/edit_group_profile.php index 1b6356d04..8d659a090 100644 --- a/upload/ajax/edit_group_profile.php +++ b/upload/ajax/edit_group_profile.php @@ -6,38 +6,40 @@ global $bb_cfg, $userdata, $lang; if (!$group_id = intval($this->request['group_id']) OR !$group_info = get_group_data($group_id)) { - $this->ajax_die($lang['NO_GROUP_ID_SPECIFIED']); + $this->ajax_die($lang['NO_GROUP_ID_SPECIFIED']); } if (!$mode = (string) $this->request['mode']) { - $this->ajax_die('No mode specified'); + $this->ajax_die('No mode specified'); } $value = $this->request['value'] = (string) (isset($this->request['value'])) ? $this->request['value'] : 0; if (!IS_ADMIN && $userdata['user_id'] != $group_info['group_moderator']) { - $this->ajax_die($lang['ONLY_FOR_MOD']); + $this->ajax_die($lang['ONLY_FOR_MOD']); } switch ($mode) { - case 'group_name': - case 'group_description': - $value = htmlCHR($value); - $this->response['new_value'] = $value; - break; - case 'group_type': - $this->response['new_value'] = $value; - break; - case 'release_group': - $this->response['new_value'] = $value; - break; - default: - $this->ajax_die('Unknown mode'); + case 'group_name': + case 'group_description': + $value = htmlCHR($value); + $this->response['new_value'] = $value; + break; + case 'group_type': + $this->response['new_value'] = $value; + break; + case 'release_group': + $this->response['new_value'] = $value; + break; + + default: + $this->ajax_die('Unknown mode'); } + $value_sql = DB()->escape($value, true); DB()->query("UPDATE ". BB_GROUPS ." SET $mode = $value_sql WHERE group_id = $group_id LIMIT 1"); @@ -46,5 +48,4 @@ DB()->query("UPDATE ". BB_GROUPS ." SET $mode = $value_sql WHERE group_id = $gro $this->response['new_value'] = $value; $this->response['group_id'] = $group_id; $this->response['mode'] = $mode; -*/ - +*/ \ No newline at end of file diff --git a/upload/group_config.php b/upload/group_config.php index 45a44c030..1016873f8 100644 --- a/upload/group_config.php +++ b/upload/group_config.php @@ -17,75 +17,72 @@ $is_moderator = false; if ($group_id) { - if (!$group_info = get_group_data($group_id)) - { - bb_die($lang['GROUP_NOT_EXIST']); - } - if (!$group_info['group_id'] || !$group_info['group_moderator'] || !$group_info['moderator_name']) - { - bb_die("Invalid group data [group_id: $group_id]"); - } - $is_moderator = ($userdata['user_id'] == $group_info['group_moderator'] || IS_ADMIN); + if (!$group_info = get_group_data($group_id)) + { + bb_die($lang['GROUP_NOT_EXIST']); + } + if (!$group_info['group_id'] || !$group_info['group_moderator'] || !$group_info['moderator_name']) + { + bb_die("Invalid group data [group_id: $group_id]"); + } + $is_moderator = ($userdata['user_id'] == $group_info['group_moderator'] || IS_ADMIN); } if ($is_moderator) { - // TODO Creation Date, Admin panel, Avatar, Some tasty features + // TODO Creation Date, Admin panel, Avatar, Some tasty features - $group_type = ''; - if ($group_info['group_type'] == GROUP_OPEN) - { - $group_type = $lang['GROUP_OPEN']; - } - elseif ($group_info['group_type'] == GROUP_CLOSED) - { - $group_type = $lang['GROUP_CLOSED']; - } - elseif ($group_info['group_type'] == GROUP_HIDDEN) - { - $group_type = $lang['GROUP_HIDDEN']; - } + $group_type = ''; + if ($group_info['group_type'] == GROUP_OPEN) + { + $group_type = $lang['GROUP_OPEN']; + } + elseif ($group_info['group_type'] == GROUP_CLOSED) + { + $group_type = $lang['GROUP_CLOSED']; + } + elseif ($group_info['group_type'] == GROUP_HIDDEN) + { + $group_type = $lang['GROUP_HIDDEN']; + } - $s_hidden_fields = ''; + $s_hidden_fields = ''; - $template->assign_vars(array( - 'PAGE_TITLE' => $lang['GROUP_CONTROL_PANEL'], - 'GROUP_NAME' => htmlCHR($group_info['group_name']), - 'GROUP_ID' => $group_id, - 'GROUP_DESCRIPTION' => htmlCHR($group_info['group_description']), + $template->assign_vars(array( + 'PAGE_TITLE' => $lang['GROUP_CONTROL_PANEL'], + 'GROUP_NAME' => htmlCHR($group_info['group_name']), + 'GROUP_ID' => $group_id, + 'GROUP_DESCRIPTION' => htmlCHR($group_info['group_description']), + 'U_GROUP_URL' => GROUP_URL . $group_id, + 'GROUP_TYPE' => $group_type, + 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, + 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED, + 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN, + 'S_GROUP_OPEN_CHECKED' => ($group_info['group_type'] == GROUP_OPEN) ? ' checked="checked"' : '', + 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? ' checked="checked"' : '', + 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN) ? ' checked="checked"' : '', + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_GROUPCP_ACTION' => "groupcp.php?" . POST_GROUPS_URL . "=$group_id", + 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, + )); - 'U_GROUP_URL' => GROUP_URL . $group_id, + $template->set_filenames(array('body' => 'group_config.tpl')); + $template->assign_vars(array('PAGE_TITLE' => $lang['GROUP_CONFIGURATION'])); - 'GROUP_TYPE' => $group_type, - 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, - 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED, - 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN, - 'S_GROUP_OPEN_CHECKED' => ($group_info['group_type'] == GROUP_OPEN) ? ' checked="checked"' : '', - 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? ' checked="checked"' : '', - 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN) ? ' checked="checked"' : '', - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - 'S_GROUPCP_ACTION' => "groupcp.php?" . POST_GROUPS_URL . "=$group_id", - 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, - )); + require(PAGE_HEADER); - $template->set_filenames(array('body' => 'group_config.tpl')); + $template->pparse('body'); - $template->assign_vars(array('PAGE_TITLE' => $lang['GROUP_CONFIGURATION'])); - - require(PAGE_HEADER); - - $template->pparse('body'); - - require(PAGE_FOOTER); + require(PAGE_FOOTER); } else { - $redirect = 'index.php'; + $redirect = 'index.php'; - if ($group_id) - { - $redirect = GROUP_URL . $group_id; - } - redirect($redirect); + if ($group_id) + { + $redirect = GROUP_URL . $group_id; + } + redirect($redirect); } \ No newline at end of file diff --git a/upload/groupcp.php b/upload/groupcp.php index af56db610..b4672599a 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -145,11 +145,11 @@ if (!$group_id) { $text = htmlCHR(str_short(rtrim($name), HTML_SELECT_MAX_LENGTH)); - $members = ($data['m']) ? $lang['MEMBERS_IN_GROUP'] .': '. $data['m'] : $lang['NO_GROUP_MEMBERS']; + $members = ($data['m']) ? $lang['MEMBERS_IN_GROUP'] .': '. $data['m'] : $lang['NO_GROUP_MEMBERS']; $candidates = ($data['c']) ? $lang['PENDING_MEMBERS'] .': '. $data['c'] : $lang['NO_PENDING_GROUP_MEMBERS']; - $options .= '
      • '. $text .'
      • '; - $options .= ($data['rg']) ? '
        • '. $lang['RELEASE_GROUP'] .'
        • ' : ''; + $options .= '
        • '. $text .'
        • '; + $options .= ($data['rg']) ? '
          • '. $lang['RELEASE_GROUP'] .'
          • ' : ''; $options .= '
          • '. $members .'
          • '; if (IS_AM) { @@ -525,9 +525,9 @@ else 'MOD_TIME' => (!empty($group_info['group_time'])) ? bb_date($group_info['group_time']) : $lang['NONE'], 'U_SEARCH_USER' => "search.php?mode=searchuser", - 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", + 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, - 'GROUP_TYPE' => $group_type, + 'GROUP_TYPE' => $group_type, 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED, @@ -604,7 +604,7 @@ else $template->assign_block_vars('pending', array( 'ROW_CLASS' => $row_class, - 'AVATAR_IMG'=> $avatar, + 'AVATAR_IMG'=> $avatar, 'USER' => profile_url($member), 'FROM' => $from, 'JOINED' => $joined, diff --git a/upload/templates/admin/admin_groups.tpl b/upload/templates/admin/admin_groups.tpl index dbf4bfd00..313d94669 100644 --- a/upload/templates/admin/admin_groups.tpl +++ b/upload/templates/admin/admin_groups.tpl @@ -34,11 +34,11 @@ - {L_RELEASE_GROUP} - -    - - + {L_RELEASE_GROUP} + +    + + @@ -106,5 +106,4 @@



            - - + \ No newline at end of file diff --git a/upload/templates/default/group_config.tpl b/upload/templates/default/group_config.tpl index f204536d8..b161ed2f8 100644 --- a/upload/templates/default/group_config.tpl +++ b/upload/templates/default/group_config.tpl @@ -1,63 +1,63 @@

            {PAGE_TITLE} :: {GROUP_NAME}

            - {S_HIDDEN_FIELDS} - - - - - - - - - - - - - - - - - - - - - - - - - - -
            {L_GROUP_INFORMATION}
            {L_GROUP_NAME}:
            {L_GROUP_DESCRIPTION}:
            -

            - -

            -

            - - -

            -
            {L_GROUP_TYPE}: -

            -    -    - -

            -
            {L_RELEASE_GROUP} -    - -
            {L_AVATAR} 
            + {S_HIDDEN_FIELDS} + + + + + + + + + + + + + + + + + + + + + + + + + + +
            {L_GROUP_INFORMATION}
            {L_GROUP_NAME}:
            {L_GROUP_DESCRIPTION}:
            +

            + +

            +

            + + +

            +
            {L_GROUP_TYPE}: +

            +    +    + +

            +
            {L_RELEASE_GROUP} +    + +
            {L_AVATAR} 
            \ No newline at end of file diff --git a/upload/templates/default/groupcp.tpl b/upload/templates/default/groupcp.tpl index 5fe2cd091..9d7e8e655 100644 --- a/upload/templates/default/groupcp.tpl +++ b/upload/templates/default/groupcp.tpl @@ -56,19 +56,19 @@

            {GROUP_NAME}

            - -
             
            - - - -
            {GROUP_DESCRIPTION}
            - - + +
             
            + + + +
            {GROUP_DESCRIPTION}
            + + - {L_GROUP_TYPE} - {L_RELEASE_GROUP} + {L_GROUP_TYPE} + {L_RELEASE_GROUP} @@ -89,8 +89,8 @@ - {L_GROUP_CONFIGURATION}: - {L_GROUP_GOTO_CONFIG} + {L_GROUP_CONFIGURATION}: + {L_GROUP_GOTO_CONFIG} @@ -203,8 +203,8 @@ - - + + @@ -214,13 +214,13 @@ - + - + From f992d730fde7f9b0b25a7fdab9df319def7393e6 Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Sun, 3 Aug 2014 14:00:24 +0600 Subject: [PATCH 08/19] R593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit +Добавлены аватары к группам Signed-off-by: Dark Nightmare --- upload/ajax/edit_group_profile.php | 7 ++ upload/group_config.php | 42 ++++++++- upload/groupcp.php | 1 + upload/includes/init_bb.php | 2 + upload/templates/default/group_config.tpl | 108 +++++++++++++--------- upload/templates/default/groupcp.tpl | 2 +- 6 files changed, 113 insertions(+), 49 deletions(-) diff --git a/upload/ajax/edit_group_profile.php b/upload/ajax/edit_group_profile.php index 8d659a090..52ca3c502 100644 --- a/upload/ajax/edit_group_profile.php +++ b/upload/ajax/edit_group_profile.php @@ -36,6 +36,13 @@ switch ($mode) $this->response['new_value'] = $value; break; + case 'delete_avatar': + delete_avatar(GROUP_AVATAR_MASK . $group_id, $group_info['avatar_ext_id']); + $value = 0; + $mode = 'avatar_ext_id'; + $this->response['act'] = $value; + break; + default: $this->ajax_die('Unknown mode'); } diff --git a/upload/group_config.php b/upload/group_config.php index 1016873f8..bdd079d5b 100644 --- a/upload/group_config.php +++ b/upload/group_config.php @@ -15,6 +15,8 @@ $group_id = isset($_REQUEST[POST_GROUPS_URL]) ? intval($_REQUEST[POST_GROUPS_URL $group_info = array(); $is_moderator = false; +$submit = !empty($_POST['submit']); + if ($group_id) { if (!$group_info = get_group_data($group_id)) @@ -31,9 +33,37 @@ if ($group_id) if ($is_moderator) { - // TODO Creation Date, Admin panel, Avatar, Some tasty features + // TODO Creation Date, Admin panel, Some tasty features - $group_type = ''; + // Avatar + if ($submit) + { + + if (isset($_POST['delete_avatar'])) + { + delete_avatar(GROUP_AVATAR_MASK . $group_id, $group_info['avatar_ext_id']); + $avatar_ext_id = 0; + } + else if (!empty($_FILES['avatar']['name']) && $bb_cfg['avatars']['up_allowed']) + { + require(INC_DIR .'functions_upload.php'); + $upload = new upload_common(); + + if ($upload->init($bb_cfg['avatars'], $_FILES['avatar']) AND $upload->store('avatar', array("user_id" => GROUP_AVATAR_MASK . $group_id, "avatar_ext_id" => $group_info['avatar_ext_id']))) + { + $avatar_ext_id = (int) $upload->file_ext_id; + } + else + { + bb_die(implode($upload->errors)); + } + } + + DB()->query("UPDATE ". BB_GROUPS ." SET avatar_ext_id = $avatar_ext_id WHERE group_id = $group_id LIMIT 1"); + + } + + $group_type = ''; if ($group_info['group_type'] == GROUP_OPEN) { $group_type = $lang['GROUP_OPEN']; @@ -63,8 +93,12 @@ if ($is_moderator) 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? ' checked="checked"' : '', 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN) ? ' checked="checked"' : '', 'S_HIDDEN_FIELDS' => $s_hidden_fields, - 'S_GROUPCP_ACTION' => "groupcp.php?" . POST_GROUPS_URL . "=$group_id", - 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, + 'S_GROUP_CONFIG_ACTION' => "group_config.php?" . POST_GROUPS_URL . "=$group_id", + + 'AVATAR_EXPLAIN' => sprintf($lang['AVATAR_EXPLAIN'], $bb_cfg['avatars']['max_width'], $bb_cfg['avatars']['max_height'], (round($bb_cfg['avatars']['max_size'] / 1024))), + 'AVATAR_URL_PATH' => ($group_info['avatar_ext_id']) ? get_avatar_path(GROUP_AVATAR_MASK . $group_id, $group_info['avatar_ext_id']) : '', + + 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, )); $template->set_filenames(array('body' => 'group_config.tpl')); diff --git a/upload/groupcp.php b/upload/groupcp.php index b4672599a..4e94f85ac 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -513,6 +513,7 @@ else 'PAGE_TITLE' => $lang['GROUP_CONTROL_PANEL'], 'GROUP_NAME' => htmlCHR($group_info['group_name']), 'GROUP_DESCRIPTION' => bbcode2html($group_info['group_description']), + 'GROUP_AVATAR' => get_avatar(GROUP_AVATAR_MASK . $group_id, $group_info['avatar_ext_id'], true), 'GROUP_DETAILS' => $group_details, 'MOD_USER' => profile_url($group_moderator), 'MOD_AVATAR' => $avatar, diff --git a/upload/includes/init_bb.php b/upload/includes/init_bb.php index 46cf5c51a..5dad02c1a 100644 --- a/upload/includes/init_bb.php +++ b/upload/includes/init_bb.php @@ -246,6 +246,8 @@ define('NOGENDER', 0); # 1 - обычный опрос define('POLL_FINISHED', 2); +define('GROUP_AVATAR_MASK', 9999900); + // Torrents (reserved: -1) define('TOR_NOT_APPROVED', 0); // не проверено define('TOR_CLOSED', 1); // закрыто diff --git a/upload/templates/default/group_config.tpl b/upload/templates/default/group_config.tpl index b161ed2f8..412d2537d 100644 --- a/upload/templates/default/group_config.tpl +++ b/upload/templates/default/group_config.tpl @@ -6,7 +6,8 @@ function manage_group(mode, value) { group_id : {GROUP_ID}, value : value }); - ajax.callback.manage_group = function(data){ + ajax.callback.manage_group = function(data) { + if (data.act == 0) $('div#avatar').hide(100); console.log(data); } } @@ -14,50 +15,69 @@ function manage_group(mode, value) {

            {PAGE_TITLE} :: {GROUP_NAME}

            -
            - {S_HIDDEN_FIELDS} -
            #{L_AVATAR}#{L_AVATAR} {L_USERNAME} {L_PM} {L_EMAIL}{L_WEBSITE}
            {L_PENDING_MEMBERS}{L_PENDING_MEMBERS}
            {pending.AVATAR_IMG}{pending.AVATAR_IMG} {pending.USER} {pending.PM} {pending.EMAIL}
            - - - - - - - - - - - - + + +
            {L_GROUP_INFORMATION}
            {L_GROUP_NAME}:
            {L_GROUP_DESCRIPTION}:
            + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - -
            {L_GROUP_INFORMATION}
            {L_GROUP_NAME}:
            {L_GROUP_DESCRIPTION}:
            +

            + +

            +

            + + +

            +
            {L_GROUP_TYPE}: +

            +    +    + +

            +
            {L_RELEASE_GROUP} +    + +
            + {L_AVATAR} + +

            - + avatar

            - - +

            -
            {L_GROUP_TYPE}: -

            -    -    - -

            -
            {L_RELEASE_GROUP} -    - -
            {L_AVATAR} 
            - \ No newline at end of file + + +
            +
            {AVATAR_EXPLAIN}

            + +
            + {S_HIDDEN_FIELDS} + + + +
            + +
            \ No newline at end of file diff --git a/upload/templates/default/groupcp.tpl b/upload/templates/default/groupcp.tpl index 9d7e8e655..2e8236c56 100644 --- a/upload/templates/default/groupcp.tpl +++ b/upload/templates/default/groupcp.tpl @@ -57,7 +57,7 @@

            {GROUP_NAME}

            -
             
            + {GROUP_AVATAR} From 179baf854303130601889d53f54f0987c8036d28 Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Sun, 3 Aug 2014 14:07:49 +0600 Subject: [PATCH 09/19] R593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Обновлен дамп базы Signed-off-by: Dark Nightmare --- install/sql/mysql.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index 1c419c05a..39159af8b 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -788,6 +788,7 @@ INSERT INTO `bb_forums` VALUES (1, 1, 'Ваш первый форум', 'Опи CREATE TABLE IF NOT EXISTS `bb_groups` ( `group_id` mediumint(8) NOT NULL AUTO_INCREMENT, + `avatar_ext_id` int(15) NOT NULL DEFAULT '0', `group_time` int(11) NOT NULL DEFAULT '0', `group_type` tinyint(4) NOT NULL DEFAULT '1', `release_group` tinyint(4) NOT NULL DEFAULT '0', From 89521020f236d28adcfb4a797bcf23efc7176769 Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Sun, 3 Aug 2014 20:15:38 +0600 Subject: [PATCH 10/19] R593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Добавлены конфиги для изображений групп в config.php - Удален не используемый код Signed-off-by: Dark Nightmare --- upload/config.php | 10 ++++++++++ upload/group_config.php | 9 ++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/upload/config.php b/upload/config.php index b92071297..4748b5b78 100644 --- a/upload/config.php +++ b/upload/config.php @@ -553,6 +553,16 @@ $bb_cfg['avatars'] = array( 'up_allowed' => true, // разрешить загрузку аватар ); +$bb_cfg['group_avatars'] = array( + 'allowed_ext' => array('gif','jpg','jpeg','png'), // разрешенные форматы файлов + 'max_size' => 50*1024, // размер аватары в байтах + 'max_height' => 300, // высота аватара в px + 'max_width' => 250, // ширина аватара в px + 'no_avatar' => 'gallery/noavatar.png', // дефолтная аватара + 'upload_path' => BB_ROOT . 'images/avatars/', // путь к директории с аватарами + 'up_allowed' => true, // разрешить загрузку аватар +); + // Misc define('MEM_USAGE', function_exists('memory_get_usage')); diff --git a/upload/group_config.php b/upload/group_config.php index bdd079d5b..9ef7dc181 100644 --- a/upload/group_config.php +++ b/upload/group_config.php @@ -39,17 +39,12 @@ if ($is_moderator) if ($submit) { - if (isset($_POST['delete_avatar'])) - { - delete_avatar(GROUP_AVATAR_MASK . $group_id, $group_info['avatar_ext_id']); - $avatar_ext_id = 0; - } - else if (!empty($_FILES['avatar']['name']) && $bb_cfg['avatars']['up_allowed']) + if (!empty($_FILES['avatar']['name']) && $bb_cfg['avatars']['up_allowed']) { require(INC_DIR .'functions_upload.php'); $upload = new upload_common(); - if ($upload->init($bb_cfg['avatars'], $_FILES['avatar']) AND $upload->store('avatar', array("user_id" => GROUP_AVATAR_MASK . $group_id, "avatar_ext_id" => $group_info['avatar_ext_id']))) + if ($upload->init($bb_cfg['group_avatars'], $_FILES['avatar']) AND $upload->store('avatar', array("user_id" => GROUP_AVATAR_MASK . $group_id, "avatar_ext_id" => $group_info['avatar_ext_id']))) { $avatar_ext_id = (int) $upload->file_ext_id; } From a3a8cd548b87245066af1b616cf6a0856ae21a65 Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Sun, 3 Aug 2014 20:49:37 +0600 Subject: [PATCH 11/19] R593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Фикс использования конфигов Signed-off-by: Dark Nightmare --- upload/group_config.php | 4 ++-- upload/templates/default/group_config.tpl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/upload/group_config.php b/upload/group_config.php index 9ef7dc181..4df9850ce 100644 --- a/upload/group_config.php +++ b/upload/group_config.php @@ -39,7 +39,7 @@ if ($is_moderator) if ($submit) { - if (!empty($_FILES['avatar']['name']) && $bb_cfg['avatars']['up_allowed']) + if (!empty($_FILES['avatar']['name']) && $bb_cfg['group_avatars']['up_allowed']) { require(INC_DIR .'functions_upload.php'); $upload = new upload_common(); @@ -90,7 +90,7 @@ if ($is_moderator) 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_GROUP_CONFIG_ACTION' => "group_config.php?" . POST_GROUPS_URL . "=$group_id", - 'AVATAR_EXPLAIN' => sprintf($lang['AVATAR_EXPLAIN'], $bb_cfg['avatars']['max_width'], $bb_cfg['avatars']['max_height'], (round($bb_cfg['avatars']['max_size'] / 1024))), + 'AVATAR_EXPLAIN' => sprintf($lang['AVATAR_EXPLAIN'], $bb_cfg['group_avatars']['max_width'], $bb_cfg['group_avatars']['max_height'], (round($bb_cfg['group_avatars']['max_size'] / 1024))), 'AVATAR_URL_PATH' => ($group_info['avatar_ext_id']) ? get_avatar_path(GROUP_AVATAR_MASK . $group_id, $group_info['avatar_ext_id']) : '', 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, diff --git a/upload/templates/default/group_config.tpl b/upload/templates/default/group_config.tpl index 412d2537d..7e45ddfec 100644 --- a/upload/templates/default/group_config.tpl +++ b/upload/templates/default/group_config.tpl @@ -70,7 +70,7 @@ function manage_group(mode, value) {
            {AVATAR_EXPLAIN}

            - +
            {S_HIDDEN_FIELDS} From 090b886dc163a41dff3a735b53c87d45d3e5a038 Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Tue, 5 Aug 2014 00:45:47 +0600 Subject: [PATCH 12/19] R593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Добавлена возможность указать от какой релиз группы создана раздача + Добавлена возможность присоединить подпись релиз группы при создании раздачи + Добавленна подпись релиз группы Необходимый SQL запрос: ALTER TABLE `bb_posts` ADD `poster_rg_id` mediumint(8) NOT NULL DEFAULT '0' ADD `attach_poster_rg_sig` tinyint(4) NOT NULL DEFAULT '0'; ALTER TABLE `bb_posts` ADD `group_signature` text NOT NULL DEFAULT ''; Signed-off-by: Dark Nightmare --- install/sql/mysql.sql | 3 ++ upload/ajax/edit_group_profile.php | 17 +++--- upload/group_config.php | 1 + upload/includes/functions_post.php | 6 +-- upload/language/en/main.php | 6 +++ upload/language/ru/main.php | 6 +++ upload/language/ua/main.php | 6 +++ upload/posting.php | 63 +++++++++++++++++------ upload/templates/default/group_config.tpl | 16 +++++- upload/templates/default/posting.tpl | 16 +++++- upload/templates/default/viewtopic.tpl | 12 +++++ upload/viewtopic.php | 16 +++++- 12 files changed, 134 insertions(+), 34 deletions(-) diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index 39159af8b..c504b4165 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -794,6 +794,7 @@ CREATE TABLE IF NOT EXISTS `bb_groups` ( `release_group` tinyint(4) NOT NULL DEFAULT '0', `group_name` varchar(40) NOT NULL DEFAULT '', `group_description` text NOT NULL DEFAULT '', + `group_signature` text NOT NULL DEFAULT '', `group_moderator` mediumint(8) NOT NULL DEFAULT '0', `group_single_user` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`group_id`), @@ -864,6 +865,8 @@ CREATE TABLE IF NOT EXISTS `bb_posts` ( `poster_id` mediumint(8) NOT NULL DEFAULT '0', `post_time` int(11) NOT NULL DEFAULT '0', `poster_ip` char(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', + `poster_rg_id` mediumint(8) NOT NULL DEFAULT '0', + `attach_poster_rg_sig` tinyint(4) NOT NULL DEFAULT '0', `post_username` varchar(25) NOT NULL DEFAULT '', `post_edit_time` int(11) NOT NULL DEFAULT '0', `post_edit_count` smallint(5) unsigned NOT NULL DEFAULT '0', diff --git a/upload/ajax/edit_group_profile.php b/upload/ajax/edit_group_profile.php index 52ca3c502..bc9a4f453 100644 --- a/upload/ajax/edit_group_profile.php +++ b/upload/ajax/edit_group_profile.php @@ -6,27 +6,28 @@ global $bb_cfg, $userdata, $lang; if (!$group_id = intval($this->request['group_id']) OR !$group_info = get_group_data($group_id)) { - $this->ajax_die($lang['NO_GROUP_ID_SPECIFIED']); + $this->ajax_die($lang['NO_GROUP_ID_SPECIFIED']); } if (!$mode = (string) $this->request['mode']) { - $this->ajax_die('No mode specified'); + $this->ajax_die('No mode specified'); } $value = $this->request['value'] = (string) (isset($this->request['value'])) ? $this->request['value'] : 0; if (!IS_ADMIN && $userdata['user_id'] != $group_info['group_moderator']) { - $this->ajax_die($lang['ONLY_FOR_MOD']); + $this->ajax_die($lang['ONLY_FOR_MOD']); } switch ($mode) { - case 'group_name': - case 'group_description': - $value = htmlCHR($value); - $this->response['new_value'] = $value; - break; + case 'group_name': + case 'group_signature': + case 'group_description': + $value = htmlCHR($value); + $this->response['new_value'] = $value; + break; case 'group_type': $this->response['new_value'] = $value; diff --git a/upload/group_config.php b/upload/group_config.php index 4df9850ce..831c1462f 100644 --- a/upload/group_config.php +++ b/upload/group_config.php @@ -79,6 +79,7 @@ if ($is_moderator) 'GROUP_NAME' => htmlCHR($group_info['group_name']), 'GROUP_ID' => $group_id, 'GROUP_DESCRIPTION' => htmlCHR($group_info['group_description']), + 'GROUP_SIGNATURE' => htmlCHR($group_info['group_signature']), 'U_GROUP_URL' => GROUP_URL . $group_id, 'GROUP_TYPE' => $group_type, 'S_GROUP_OPEN_TYPE' => GROUP_OPEN, diff --git a/upload/includes/functions_post.php b/upload/includes/functions_post.php index 04129124c..4fae0ee6f 100644 --- a/upload/includes/functions_post.php +++ b/upload/includes/functions_post.php @@ -69,7 +69,7 @@ function prepare_post(&$mode, &$post_data, &$error_msg, &$username, &$subject, & // // Post a new topic/reply or edit existing post/poll // -function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$topic_type, $post_username, $post_subject, $post_message, $update_post_time) +function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$topic_type, $post_username, $post_subject, $post_message, $update_post_time, $poster_rg_id, $attach_poster_rg_sig) { global $userdata, $post_info, $is_auth, $bb_cfg, $lang, $datastore; @@ -154,7 +154,7 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_ } } - $edited_sql = ($mode == 'editpost' && !$post_data['last_post'] && $post_data['poster_post']) ? ", post_edit_time = $current_time, post_edit_count = post_edit_count + 1 " : ""; + $edited_sql = ($mode == 'editpost' && !$post_data['last_post'] && $post_data['poster_post']) ? ", post_edit_time = $current_time, post_edit_count = post_edit_count + 1" : ""; if ($update_post_time && $mode == 'editpost' && $post_data['last_post'] && !$post_data['first_post']) { @@ -163,7 +163,7 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_ DB()->sql_query("UPDATE ". BB_TOPICS ." SET topic_last_post_time = $current_time WHERE topic_id = $topic_id LIMIT 1"); } - $sql = ($mode != "editpost") ? "INSERT INTO " . BB_POSTS . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip) VALUES ($topic_id, $forum_id, " . $userdata['user_id'] . ", '$post_username', $current_time, '". USER_IP ."')" : "UPDATE " . BB_POSTS . " SET post_username = '$post_username'" . $edited_sql . " WHERE post_id = $post_id"; + $sql = ($mode != "editpost") ? "INSERT INTO " . BB_POSTS . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, poster_rg_id, attach_poster_rg_sig) VALUES ($topic_id, $forum_id, " . $userdata['user_id'] . ", '$post_username', $current_time, '". USER_IP ."', $poster_rg_id, $attach_poster_rg_sig)" : "UPDATE " . BB_POSTS . " SET post_username = '$post_username'" . $edited_sql . ", poster_rg_id = $poster_rg_id, attach_poster_rg_sig = $attach_poster_rg_sig WHERE post_id = $post_id"; if (!DB()->sql_query($sql)) { bb_die('Error in posting #2'); diff --git a/upload/language/en/main.php b/upload/language/en/main.php index 974fa5801..714b543c1 100644 --- a/upload/language/en/main.php +++ b/upload/language/en/main.php @@ -773,6 +773,12 @@ $lang['UNSUBSCRIBE_GROUP'] = 'Unsubscribe'; $lang['VIEW_INFORMATION'] = 'View Information'; $lang['MEMBERS_IN_GROUP'] = 'Members in group'; +// Release Groups +$lang['POST_RELEASE_FROM_GROUP'] = 'Post release from group'; +$lang['CHOOSE_RELEASE_GROUP'] = 'Select release group'; +$lang['ATTACH_RG_SIG'] = 'Attach release group signature'; +$lang['RELEASE_FROM_RG'] = 'Release was prepared by'; + // // Search // diff --git a/upload/language/ru/main.php b/upload/language/ru/main.php index 68da460a0..cd140982d 100644 --- a/upload/language/ru/main.php +++ b/upload/language/ru/main.php @@ -773,6 +773,12 @@ $lang['UNSUBSCRIBE_GROUP'] = 'Выйти из группы'; $lang['VIEW_INFORMATION'] = 'Просмотреть информацию'; $lang['MEMBERS_IN_GROUP'] = 'Кол-во участников'; +// Release Groups +$lang['POST_RELEASE_FROM_GROUP'] = 'Создать релиз от группы'; +$lang['CHOOSE_RELEASE_GROUP'] = 'Выбрать релиз группу'; +$lang['ATTACH_RG_SIG'] = 'Добавить подпись релиз группы'; +$lang['RELEASE_FROM_RG'] = 'Релиз подготовлен'; + // // Search // diff --git a/upload/language/ua/main.php b/upload/language/ua/main.php index 3bde9dcf0..fb5b9cd84 100644 --- a/upload/language/ua/main.php +++ b/upload/language/ua/main.php @@ -773,6 +773,12 @@ $lang['UNSUBSCRIBE_GROUP'] = 'Вийти з групи'; $lang['VIEW_INFORMATION'] = 'Переглянути інформацію'; $lang['MEMBERS_IN_GROUP'] = 'Кількість учасників'; +// Release Groups +$lang['POST_RELEASE_FROM_GROUP'] = 'Создать релиз от группы'; +$lang['CHOOSE_RELEASE_GROUP'] = 'Выбрать релиз группу'; +$lang['ATTACH_RG_SIG'] = 'Добавить подпись релиз группы'; +$lang['RELEASE_FROM_RG'] = 'Релиз подготовлен'; + // // Search // diff --git a/upload/posting.php b/upload/posting.php index 82b42e45c..57a8bf5dd 100644 --- a/upload/posting.php +++ b/upload/posting.php @@ -29,6 +29,8 @@ $orig_word = $replacement_word = array(); $topic_type = (@$_POST['topictype']) ? (int) $_POST['topictype'] : POST_NORMAL; $topic_type = in_array($topic_type, array(POST_NORMAL, POST_STICKY, POST_ANNOUNCE)) ? $topic_type : POST_NORMAL; +$selected_rg = 0; + if ($mode == 'smilies') { generate_smilies('window'); @@ -178,6 +180,9 @@ if ($post_info = DB()->fetch_row($sql)) $post_data['topic_type'] = $post_info['topic_type']; $post_data['poster_id'] = $post_info['poster_id']; + $selected_rg = $post_info['poster_rg_id']; + $switch_poster_rg_sig = ($post_info['attach_poster_rg_sig']) ? true : false; + // Can this user edit/delete the post? if ($post_info['poster_id'] != $userdata['user_id'] && !$is_auth['auth_mod']) { @@ -361,6 +366,8 @@ elseif ( ($submit || $confirm) && !$topic_has_new_posts ) $username = ( !empty($_POST['username']) ) ? clean_username($_POST['username']) : ''; $subject = ( !empty($_POST['subject']) ) ? clean_title($_POST['subject']) : ''; $message = ( !empty($_POST['message']) ) ? prepare_message($_POST['message']) : ''; + $attach_poster_rg_sig = (isset($_POST['attach_poster_rg_sig']) && isset($_POST['poster_release_group']) && $_POST['poster_release_group'] != -1) ? 1 : 0; + $poster_rg_id = (isset($_POST['poster_release_group']) && $_POST['poster_release_group'] != -1) ? (int) $_POST['poster_release_group'] : 0; prepare_post($mode, $post_data, $error_msg, $username, $subject, $message); @@ -368,7 +375,7 @@ elseif ( ($submit || $confirm) && !$topic_has_new_posts ) { $topic_type = ( isset($post_data['topic_type']) && $topic_type != $post_data['topic_type'] && !$is_auth['auth_sticky'] && !$is_auth['auth_announce'] ) ? $post_data['topic_type'] : $topic_type; - submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $topic_type, DB()->escape($username), DB()->escape($subject), DB()->escape($message), $update_post_time); + submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $topic_type, DB()->escape($username), DB()->escape($subject), DB()->escape($message), $update_post_time, $poster_rg_id, $attach_poster_rg_sig); $post_url = POST_URL ."$post_id#$post_id"; $post_msg = ($mode == 'editpost') ? $lang['EDITED']: $lang['STORED']; @@ -630,6 +637,25 @@ if ($post_info['allow_reg_tracker'] && $post_data['first_post'] && ($topic_dl_ty } //bt end +// Get poster release group data +if ($userdata['user_level'] == GROUP_MEMBER || IS_AM) +{ + $poster_release_groups = ''; + + $sql = "SELECT ug.group_id, g.group_name, g.release_group + FROM ". BB_USER_GROUP ." ug + INNER JOIN ". BB_GROUPS ." g ON(g.group_id = ug.group_id) + WHERE ug.user_id = {$userdata['user_id']} + AND g.release_group = 1 + ORDER BY g.group_name"; + + foreach (DB()->fetch_rowset($sql) as $row) + { + $selected_opt = ($row['group_id'] == $selected_rg) ? 'selected' : ''; + $poster_release_groups .= ''; + } +} + $hidden_form_fields = ''; switch( $mode ) @@ -659,25 +685,28 @@ $template->set_filenames(array( // Output the data to the template $template->assign_vars(array( - 'FORUM_NAME' => htmlCHR($forum_name), - 'PAGE_TITLE' => $page_title, - 'POSTING_TYPE_TITLE' => $page_title, - 'POSTING_TOPIC_ID' => ($mode != 'newtopic') ? $topic_id : '', - 'POSTING_TOPIC_TITLE' => ($mode != 'newtopic') ? wbr($post_info['topic_title']) : '', - 'U_VIEW_FORUM' => "viewforum.php?" . POST_FORUM_URL . "=$forum_id", + 'FORUM_NAME' => htmlCHR($forum_name), + 'PAGE_TITLE' => $page_title, + 'POSTING_TYPE_TITLE' => $page_title, + 'POSTING_TOPIC_ID' => ($mode != 'newtopic') ? $topic_id : '', + 'POSTING_TOPIC_TITLE' => ($mode != 'newtopic') ? wbr($post_info['topic_title']) : '', + 'U_VIEW_FORUM' => "viewforum.php?" . POST_FORUM_URL . "=$forum_id", - 'USERNAME' => @$username, - 'CAPTCHA_HTML' => (IS_GUEST) ? CAPTCHA()->get_html() : '', - 'SUBJECT' => $subject, - 'MESSAGE' => $message, + 'USERNAME' => @$username, + 'CAPTCHA_HTML' => (IS_GUEST) ? CAPTCHA()->get_html() : '', + 'SUBJECT' => $subject, + 'MESSAGE' => $message, - 'U_VIEWTOPIC' => ( $mode == 'reply' ) ? "viewtopic.php?" . POST_TOPIC_URL . "=$topic_id&postorder=desc" : '', + 'POSTER_RELEASE_GROUPS' => ($poster_release_groups) ? $poster_release_groups : '', + 'ATTACH_POSTER_RG_SIG' => $switch_poster_rg_sig, - 'S_NOTIFY_CHECKED' => ( $notify_user ) ? 'checked="checked"' : '', - 'S_TYPE_TOGGLE' => $topic_type_toggle, - 'S_TOPIC_ID' => $topic_id, - 'S_POST_ACTION' => POSTING_URL, - 'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields, + 'U_VIEWTOPIC' => ( $mode == 'reply' ) ? "viewtopic.php?" . POST_TOPIC_URL . "=$topic_id&postorder=desc" : '', + + 'S_NOTIFY_CHECKED' => ( $notify_user ) ? 'checked="checked"' : '', + 'S_TYPE_TOGGLE' => $topic_type_toggle, + 'S_TOPIC_ID' => $topic_id, + 'S_POST_ACTION' => POSTING_URL, + 'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields, )); if ($mode == 'newtopic' || $post_data['first_post']) diff --git a/upload/templates/default/group_config.tpl b/upload/templates/default/group_config.tpl index 7e45ddfec..4e0b646f5 100644 --- a/upload/templates/default/group_config.tpl +++ b/upload/templates/default/group_config.tpl @@ -27,16 +27,28 @@ function manage_group(mode, value) { {L_GROUP_DESCRIPTION}: -
            +

            - +

            + + {L_SIGNATURE}: +
            +

            + +

            +

            + + +

            + + {L_GROUP_TYPE}: diff --git a/upload/templates/default/posting.tpl b/upload/templates/default/posting.tpl index 8a71e6de8..ae901b47c 100644 --- a/upload/templates/default/posting.tpl +++ b/upload/templates/default/posting.tpl @@ -116,7 +116,7 @@ -

            {L_OPTIONS}

            +

            {L_OPTIONS}:

            @@ -138,14 +138,26 @@ + + + {L_POST_RELEASE_FROM_GROUP}: + + + + + + + {S_TYPE_TOGGLE} - diff --git a/upload/templates/default/viewtopic.tpl b/upload/templates/default/viewtopic.tpl index fadfed052..1aba2e3d9 100644 --- a/upload/templates/default/viewtopic.tpl +++ b/upload/templates/default/viewtopic.tpl @@ -408,6 +408,18 @@ function build_poll_add_form (src_el)
            {postrow.MESSAGE} + +
            + + + + + + +
            {L_RELEASE_FROM_RG}:
            {postrow.RG_AVATAR}

            {postrow.RG_NAME}

            +
            + +
            {postrow.RG_SIG}
            style="display: none;">

            {postrow.MC_TITLE}


            diff --git a/upload/viewtopic.php b/upload/viewtopic.php index 2049efab9..525be8499 100644 --- a/upload/viewtopic.php +++ b/upload/viewtopic.php @@ -363,7 +363,7 @@ if ($t_data['topic_show_first_post'] && $start) u.user_regdate, u.user_sig, u.avatar_ext_id, u.user_opt, u.user_gender, u.user_birthday, - p.*, + p.*, g.group_name, g.group_id, g.group_signature, g.avatar_ext_id as rg_avatar_id, u2.username as mc_username, u2.user_rank as mc_user_rank, h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text FROM ". BB_POSTS ." p @@ -371,6 +371,7 @@ if ($t_data['topic_show_first_post'] && $start) LEFT JOIN ". BB_POSTS_TEXT ." pt ON(pt.post_id = p.post_id) LEFT JOIN ". BB_POSTS_HTML ." h ON(h.post_id = p.post_id) LEFT JOIN ". BB_USERS ." u2 ON(u2.user_id = p.mc_user_id) + LEFT JOIN ". BB_GROUPS ." g ON(g.group_id = p.poster_rg_id) WHERE p.post_id = {$t_data['topic_first_post_id']} LIMIT 1 @@ -383,7 +384,7 @@ $sql = " u.user_regdate, u.user_sig, u.avatar_ext_id, u.user_opt, u.user_gender, u.user_birthday, - p.*, + p.*, g.group_name, g.group_id, g.group_signature, g.avatar_ext_id as rg_avatar_id, u2.username as mc_username, u2.user_rank as mc_user_rank, h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text FROM ". BB_POSTS ." p @@ -391,6 +392,7 @@ $sql = " LEFT JOIN ". BB_POSTS_TEXT ." pt ON(pt.post_id = p.post_id) LEFT JOIN ". BB_POSTS_HTML ." h ON(h.post_id = p.post_id) LEFT JOIN ". BB_USERS ." u2 ON(u2.user_id = p.mc_user_id) + LEFT JOIN ". BB_GROUPS ." g ON(g.group_id = p.poster_rg_id) WHERE p.topic_id = $topic_id $limit_posts_time GROUP BY p.post_id @@ -690,6 +692,11 @@ for($i = 0; $i < $total_posts; $i++) $mc_comment = $postrow[$i]['mc_comment']; $mc_user_id = profile_url(array('username' => $postrow[$i]['mc_username'], 'user_id' => $postrow[$i]['mc_user_id'], 'user_rank' => $postrow[$i]['mc_user_rank'])); + $rg_id = ($postrow[$i]['poster_rg_id']) ? $postrow[$i]['poster_rg_id'] : 0; + $rg_avatar = get_avatar(GROUP_AVATAR_MASK . $rg_id, $postrow[$i]['rg_avatar_id'], true, 100, 100); + $rg_name = ($postrow[$i]['group_name']) ? htmlCHR($postrow[$i]['group_name']) : ''; + $rg_signature = ($postrow[$i]['group_signature']) ? bbcode2html(htmlCHR($postrow[$i]['group_signature'])) : ''; + $poster_avatar = ''; if ( !$user->opt_js['h_av'] && $poster_id != GUEST_UID ) { @@ -872,6 +879,11 @@ for($i = 0; $i < $total_posts; $i++) 'MC_CLASS' => $mc_class, 'MC_TITLE' => sprintf($lang['MC_COMMENT'][$mc_type]['title'], $mc_user_id), 'MC_SELECT_TYPE' => build_select("mc_type_$post_id", array_flip($mc_select_type), $mc_type), + + 'RG_AVATAR' => $rg_avatar, + 'RG_NAME' => $rg_name, + 'RG_URL' => GROUP_URL . $rg_id, + 'RG_SIG' => $rg_signature, )); if ($postrow[$i]['post_attachment'] && $is_auth['auth_download'] && function_exists('display_post_attachments')) From ee26088b163ccc1f6ba9948e4c4ed818ccce8a9f Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Tue, 5 Aug 2014 01:11:03 +0600 Subject: [PATCH 13/19] R593 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hot Fix Удаление группы Обнуляйте переменные Signed-off-by: Dark Nightmare --- upload/includes/functions_group.php | 2 ++ upload/posting.php | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/upload/includes/functions_group.php b/upload/includes/functions_group.php index 026fd065e..bc74edcac 100644 --- a/upload/includes/functions_group.php +++ b/upload/includes/functions_group.php @@ -72,6 +72,8 @@ function delete_group ($group_id) WHERE ug.group_id = $group_id "); + DB()->query("UPDATE ". BB_POSTS . " SET attach_poster_rg_sig = 0, poster_rg_id = 0 WHERE poster_rg_id = ". $group_id); + update_user_level('all'); } diff --git a/upload/posting.php b/upload/posting.php index 57a8bf5dd..b80ac989e 100644 --- a/upload/posting.php +++ b/upload/posting.php @@ -30,6 +30,7 @@ $topic_type = (@$_POST['topictype']) ? (int) $_POST['topictype'] : POST_NORMAL; $topic_type = in_array($topic_type, array(POST_NORMAL, POST_STICKY, POST_ANNOUNCE)) ? $topic_type : POST_NORMAL; $selected_rg = 0; +$switch_poster_rg_sig = 0; if ($mode == 'smilies') { @@ -698,7 +699,7 @@ $template->assign_vars(array( 'MESSAGE' => $message, 'POSTER_RELEASE_GROUPS' => ($poster_release_groups) ? $poster_release_groups : '', - 'ATTACH_POSTER_RG_SIG' => $switch_poster_rg_sig, + 'ATTACH_POSTER_RG_SIG' => ($switch_poster_rg_sig) ? $switch_poster_rg_sig : false, 'U_VIEWTOPIC' => ( $mode == 'reply' ) ? "viewtopic.php?" . POST_TOPIC_URL . "=$topic_id&postorder=desc" : '', From 0f1c93f166811062106f2991f19fd0b1a184ad7c Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Tue, 5 Aug 2014 13:57:04 +0600 Subject: [PATCH 14/19] R594 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Не выводить блок если пользователь не состоит ни в одной релиз группе Signed-off-by: Dark Nightmare --- upload/templates/default/posting.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upload/templates/default/posting.tpl b/upload/templates/default/posting.tpl index ae901b47c..b7d0e1241 100644 --- a/upload/templates/default/posting.tpl +++ b/upload/templates/default/posting.tpl @@ -138,7 +138,7 @@ - + {L_POST_RELEASE_FROM_GROUP}: From d3b9b0ca2bd7dea180dacb2f533d0b372d479fd9 Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Tue, 5 Aug 2014 22:18:55 +0600 Subject: [PATCH 15/19] R594 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Исправлено выполнение запроса при пустом поле avatar Signed-off-by: Dark Nightmare --- upload/group_config.php | 5 ++--- upload/templates/default/viewtopic.tpl | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/upload/group_config.php b/upload/group_config.php index 831c1462f..4604389a8 100644 --- a/upload/group_config.php +++ b/upload/group_config.php @@ -52,10 +52,9 @@ if ($is_moderator) { bb_die(implode($upload->errors)); } + + DB()->query("UPDATE ". BB_GROUPS ." SET avatar_ext_id = $avatar_ext_id WHERE group_id = $group_id LIMIT 1"); } - - DB()->query("UPDATE ". BB_GROUPS ." SET avatar_ext_id = $avatar_ext_id WHERE group_id = $group_id LIMIT 1"); - } $group_type = ''; diff --git a/upload/templates/default/viewtopic.tpl b/upload/templates/default/viewtopic.tpl index 1aba2e3d9..e815366f0 100644 --- a/upload/templates/default/viewtopic.tpl +++ b/upload/templates/default/viewtopic.tpl @@ -410,11 +410,11 @@ function build_poll_add_form (src_el) {postrow.MESSAGE}
            - +
            - +
            {L_RELEASE_FROM_RG}:
            {postrow.RG_AVATAR}

            {postrow.RG_NAME}

            {postrow.RG_NAME}

            From 5c355fd027167b8cdfcc4dd7a9e4958ecd3d5cab Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Wed, 6 Aug 2014 12:19:10 +0600 Subject: [PATCH 16/19] R594 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Добавлена дата создания группы Signed-off-by: Dark Nightmare --- install/sql/mysql.sql | 3 ++- upload/admin/admin_groups.php | 6 +++--- upload/group_config.php | 2 +- upload/groupcp.php | 3 ++- upload/templates/default/groupcp.tpl | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index c504b4165..e4965a3a6 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -789,7 +789,8 @@ INSERT INTO `bb_forums` VALUES (1, 1, 'Ваш первый форум', 'Опи CREATE TABLE IF NOT EXISTS `bb_groups` ( `group_id` mediumint(8) NOT NULL AUTO_INCREMENT, `avatar_ext_id` int(15) NOT NULL DEFAULT '0', - `group_time` int(11) NOT NULL DEFAULT '0', + `group_time` INT(11) NOT NULL DEFAULT '0', + `mod_time` INT(11) NOT NULL DEFAULT '0', `group_type` tinyint(4) NOT NULL DEFAULT '1', `release_group` tinyint(4) NOT NULL DEFAULT '0', `group_name` varchar(40) NOT NULL DEFAULT '', diff --git a/upload/admin/admin_groups.php b/upload/admin/admin_groups.php index 5d86807b3..d84ddf853 100644 --- a/upload/admin/admin_groups.php +++ b/upload/admin/admin_groups.php @@ -133,7 +133,7 @@ else if (!empty($_POST['group_update'])) { // Create user_group for new group's moderator add_user_into_group($group_id, $group_moderator); - $sql_ary['group_time'] = TIMENOW; + $sql_ary['mod_time'] = TIMENOW; // Delete old moderator's user_group if (isset($_POST['delete_old_moderator'])) @@ -155,8 +155,8 @@ else if (!empty($_POST['group_update'])) } else if ($mode == 'newgroup') { - $sql_ary['group_time'] = TIMENOW; - $sql_args = DB()->build_array('INSERT', $sql_ary); + $sql_ary['group_time'] = $sql_ary['mod_time'] = TIMENOW; + $sql_args = DB()->build_array('INSERT', $sql_ary); // Create new group DB()->query("INSERT INTO ". BB_GROUPS ." $sql_args"); diff --git a/upload/group_config.php b/upload/group_config.php index 4604389a8..d65f72dbf 100644 --- a/upload/group_config.php +++ b/upload/group_config.php @@ -33,7 +33,7 @@ if ($group_id) if ($is_moderator) { - // TODO Creation Date, Admin panel, Some tasty features + // TODO Admin panel, Some tasty features // Avatar if ($submit) diff --git a/upload/groupcp.php b/upload/groupcp.php index 4e94f85ac..718042fdc 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -515,6 +515,7 @@ else 'GROUP_DESCRIPTION' => bbcode2html($group_info['group_description']), 'GROUP_AVATAR' => get_avatar(GROUP_AVATAR_MASK . $group_id, $group_info['avatar_ext_id'], true), 'GROUP_DETAILS' => $group_details, + 'GROUP_TIME' => (!empty($group_info['group_time'])) ? sprintf('%s (%s)', bb_date($group_info['group_time']), delta_time($group_info['group_time'])) : $lang['NONE'], 'MOD_USER' => profile_url($group_moderator), 'MOD_AVATAR' => $avatar, 'MOD_FROM' => $from, @@ -523,7 +524,7 @@ else 'MOD_PM' => $pm, 'MOD_EMAIL' => $email, 'MOD_WWW' => $www, - 'MOD_TIME' => (!empty($group_info['group_time'])) ? bb_date($group_info['group_time']) : $lang['NONE'], + 'MOD_TIME' => (!empty($group_info['mod_time'])) ? bb_date($group_info['mod_time']) : $lang['NONE'], 'U_SEARCH_USER' => "search.php?mode=searchuser", 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", diff --git a/upload/templates/default/groupcp.tpl b/upload/templates/default/groupcp.tpl index 2e8236c56..83760cc52 100644 --- a/upload/templates/default/groupcp.tpl +++ b/upload/templates/default/groupcp.tpl @@ -73,7 +73,7 @@ {L_GROUP_TIME} - {MOD_TIME} + {GROUP_TIME} {L_GROUP_MEMBERSHIP}: From 8691ad0751587b76da4cef2411faad2810bd09fd Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Thu, 7 Aug 2014 12:11:50 +0600 Subject: [PATCH 17/19] R594 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Добавлены релизы группы на страницу группы + Исправлена проблема спойлера с названием Signed-off-by: Dark Nightmare --- upload/ajax/edit_group_profile.php | 2 +- upload/groupcp.php | 288 ++++++++++++++++----------- upload/language/en/main.php | 1 + upload/language/ru/main.php | 1 + upload/language/ua/main.php | 1 + upload/templates/default/groupcp.tpl | 49 ++++- 6 files changed, 228 insertions(+), 114 deletions(-) diff --git a/upload/ajax/edit_group_profile.php b/upload/ajax/edit_group_profile.php index bc9a4f453..5a0ac6912 100644 --- a/upload/ajax/edit_group_profile.php +++ b/upload/ajax/edit_group_profile.php @@ -25,7 +25,7 @@ switch ($mode) case 'group_name': case 'group_signature': case 'group_description': - $value = htmlCHR($value); + $value = htmlCHR($value, false, ENT_NOQUOTES); $this->response['new_value'] = $value; break; diff --git a/upload/groupcp.php b/upload/groupcp.php index 718042fdc..11866e252 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -22,7 +22,7 @@ function generate_user_info(&$row, $date_format, $group_mod, &$from, &$posts, &$ $user_time = ( !empty($row['user_time']) ) ? bb_date($row['user_time']) : $lang['NONE']; $posts = ( $row['user_posts'] ) ? $row['user_posts'] : 0; $pm = ($bb_cfg['text_buttons']) ? ''. $lang['SEND_PM_TXTB'] .'' : '' . $lang['SEND_PRIVATE_MESSAGE'] . ''; - $avatar = get_avatar($row['user_id'], $row['avatar_ext_id'], !bf($row['user_opt'], 'user_opt', 'dis_avatar'), true, 50, 50); + $avatar = get_avatar($row['user_id'], $row['avatar_ext_id'], !bf($row['user_opt'], 'user_opt', 'dis_avatar'), 50, 50); if (bf($row['user_opt'], 'user_opt', 'user_viewemail') || $group_mod) { @@ -47,6 +47,7 @@ set_die_append_msg(); $group_id = isset($_REQUEST[POST_GROUPS_URL]) ? intval($_REQUEST[POST_GROUPS_URL]) : null; $start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; $per_page = $bb_cfg['groupcp_members_per_page']; +$view_mode = isset($_REQUEST['view']) ? $_REQUEST['view'] : null; $group_info = array(); $is_moderator = false; @@ -380,51 +381,6 @@ else WHERE user_id = ". $group_info['group_moderator'] ." "); - // Members - $count_members = DB()->fetch_rowset(" - SELECT u.username, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time - FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u - WHERE ug.group_id = $group_id - AND ug.user_pending = 0 - AND ug.user_id <> ". $group_moderator['user_id'] ." - AND u.user_id = ug.user_id - ORDER BY u.username - "); - $count_members = count($count_members); - - // Get user information for this group - $modgroup_pending_count = 0; - - // Members - $group_members = DB()->fetch_rowset(" - SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time - FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u - WHERE ug.group_id = $group_id - AND ug.user_pending = 0 - AND ug.user_id <> ". $group_moderator['user_id'] ." - AND u.user_id = ug.user_id - ORDER BY u.username - LIMIT $start, $per_page - "); - $members_count = count($group_members); - - generate_pagination(GROUP_URL . $group_id, $count_members, $per_page, $start); - - // Pending - if ($is_moderator) - { - $modgroup_pending_list = DB()->fetch_rowset(" - SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email - FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u - WHERE ug.group_id = $group_id - AND ug.user_pending = 1 - AND u.user_id = ug.user_id - ORDER BY u.username - LIMIT 200 - "); - $modgroup_pending_count = count($modgroup_pending_list); - } - // Current user membership $is_group_member = $is_group_pending_member = false; @@ -527,6 +483,9 @@ else 'MOD_TIME' => (!empty($group_info['mod_time'])) ? bb_date($group_info['mod_time']) : $lang['NONE'], 'U_SEARCH_USER' => "search.php?mode=searchuser", + 'U_GROUP_RELEASES' => "groupcp.php?view=releases&". POST_GROUPS_URL ."=$group_id", + 'U_GROUP_MEMBERS' => "groupcp.php?view=members&". POST_GROUPS_URL ."=$group_id", + 'U_GROUP_CONFIG' => "group_config.php?g=$group_id", 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false, 'GROUP_TYPE' => $group_type, @@ -543,84 +502,189 @@ else 'S_GROUPCP_ACTION' => "groupcp.php?" . POST_GROUPS_URL . "=$group_id", )); - // Dump out the remaining users - foreach ($group_members as $i => $member) - { - $user_id = $member['user_id']; + switch($view_mode) + { + case 'releases': - generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); + // TODO Correct SQL to posts with attach and limit them, optimization - if ($group_info['group_type'] != GROUP_HIDDEN || $is_group_member || $is_moderator) - { - $row_class = !($i % 2) ? 'row1' : 'row2'; + // Count releases for pagination + $all_releases = DB()->fetch_rowset(" + SELECT p.topic_id, p.forum_id, p.poster_id, t.topic_title, t.topic_time, f.forum_name, u.username, u.avatar_ext_id, u.user_opt, u.user_rank + FROM ". BB_POSTS ." p + LEFT JOIN ". BB_TOPICS ." t ON(p.topic_id = t.topic_id) + LEFT JOIN ". BB_FORUMS ." f ON(p.forum_id= f.forum_id) + LEFT JOIN ". BB_USERS ." u ON(p.poster_id = u.user_id) + WHERE p.poster_rg_id = $group_id + ORDER BY t.topic_time DESC + "); - $template->assign_block_vars('member', array( - 'ROW_NUMBER' => $i + ( $start + 1 ), - 'ROW_CLASS' => $row_class, - 'USER' => profile_url($member), - 'AVATAR_IMG' => $avatar, - 'FROM' => $from, - 'JOINED' => $joined, - 'POSTS' => $posts, - 'USER_ID' => $user_id, - 'PM' => $pm, - 'EMAIL' => $email, - 'WWW' => $www, - 'TIME' => $user_time, - )); + $count_releases = count($all_releases); - if ($is_moderator) - { - $template->assign_block_vars('member.switch_mod_option', array()); - } - } - } + generate_pagination(GROUP_URL . $group_id ."&view=releases", $count_releases, $per_page, $start); - // No group members - if (!$members_count) - { - $template->assign_block_vars('switch_no_members', array()); - } + $sql = "SELECT p.topic_id, p.forum_id, p.poster_id, t.topic_title, t.topic_time, f.forum_name, u.username, u.avatar_ext_id, u.user_opt, u.user_rank + FROM ". BB_POSTS ." p + LEFT JOIN ". BB_TOPICS ." t ON(p.topic_id = t.topic_id) + LEFT JOIN ". BB_FORUMS ." f ON(p.forum_id= f.forum_id) + LEFT JOIN ". BB_USERS ." u ON(p.poster_id = u.user_id) + WHERE p.poster_rg_id = $group_id + ORDER BY t.topic_time DESC + LIMIT $start, $per_page"; - // No group members - if ($group_info['group_type'] == GROUP_HIDDEN && !$is_group_member && !$is_moderator) - { - $template->assign_block_vars('switch_hidden_group', array()); - } + if (!$releases = DB()->fetch_rowset($sql)) + { + bb_die('Could not get releases data'); + } - // - // We've displayed the members who belong to the group, now we - // do that pending memebers... - // - if ($is_moderator && $modgroup_pending_list) - { - foreach ($modgroup_pending_list as $i => $member) - { - $user_id = $member['user_id']; + foreach ($releases as $i => $release) + { + $row_class = !($i % 2) ? 'row1' : 'row2'; - generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); + $template->assign_block_vars('releases', array( + 'ROW_NUMBER' => $i + ( $start + 1 ), + 'ROW_CLASS' => $row_class, + 'RELEASER' => profile_url(array('user_id' => $release['poster_id'], 'username' => $release['username'], 'user_rank' => $release['user_rank'])), + 'AVATAR_IMG' => get_avatar($release['poster_id'], $release['avatar_ext_id'], !bf($release['user_opt'], 'user_opt', 'dis_avatar'), 50, 50), + 'RELEASE_NAME' => sprintf('%s', TOPIC_URL . $release['topic_id'], htmlCHR($release['topic_title'])), + 'RELEASE_TIME' => bb_date($release['topic_time']), + 'RELEASE_FORUM' => sprintf('%s', FORUM_URL . $release['forum_id'], htmlCHR($release['forum_name'])), + )); + } - $row_class = !($i % 2) ? 'row1' : 'row2'; + $template->assign_vars(array('RELEASES' => true)); - $user_select = ''; + break; + case 'members': + default: - $template->assign_block_vars('pending', array( - 'ROW_CLASS' => $row_class, - 'AVATAR_IMG'=> $avatar, - 'USER' => profile_url($member), - 'FROM' => $from, - 'JOINED' => $joined, - 'POSTS' => $posts, - 'USER_ID' => $user_id, - 'PM' => $pm, - 'EMAIL' => $email, - )); - } + // Members + $count_members = DB()->fetch_rowset(" + SELECT u.username, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time + FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u + WHERE ug.group_id = $group_id + AND ug.user_pending = 0 + AND ug.user_id <> ". $group_moderator['user_id'] ." + AND u.user_id = ug.user_id + ORDER BY u.username + "); + $count_members = count($count_members); - $template->assign_vars(array( - 'PENDING_USERS' => true, - )); - } + // Get user information for this group + $modgroup_pending_count = 0; + + // Members + $group_members = DB()->fetch_rowset(" + SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time + FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u + WHERE ug.group_id = $group_id + AND ug.user_pending = 0 + AND ug.user_id <> ". $group_moderator['user_id'] ." + AND u.user_id = ug.user_id + ORDER BY u.username + LIMIT $start, $per_page + "); + $members_count = count($group_members); + + generate_pagination(GROUP_URL . $group_id, $count_members, $per_page, $start); + + // Dump out the remaining users + foreach ($group_members as $i => $member) + { + $user_id = $member['user_id']; + + generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); + + if ($group_info['group_type'] != GROUP_HIDDEN || $is_group_member || $is_moderator) + { + $row_class = !($i % 2) ? 'row1' : 'row2'; + + $template->assign_block_vars('member', array( + 'ROW_NUMBER' => $i + ( $start + 1 ), + 'ROW_CLASS' => $row_class, + 'USER' => profile_url($member), + 'AVATAR_IMG' => $avatar, + 'FROM' => $from, + 'JOINED' => $joined, + 'POSTS' => $posts, + 'USER_ID' => $user_id, + 'PM' => $pm, + 'EMAIL' => $email, + 'WWW' => $www, + 'TIME' => $user_time, + )); + + if ($is_moderator) + { + $template->assign_block_vars('member.switch_mod_option', array()); + } + } + } + + // No group members + if (!$members_count) + { + $template->assign_block_vars('switch_no_members', array()); + } + + // No group members + if ($group_info['group_type'] == GROUP_HIDDEN && !$is_group_member && !$is_moderator) + { + $template->assign_block_vars('switch_hidden_group', array()); + } + + // + // We've displayed the members who belong to the group, now we + // do that pending memebers... + // + + // Pending + if ($is_moderator) + { + $modgroup_pending_list = DB()->fetch_rowset(" + SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email + FROM ". BB_USER_GROUP ." ug, ". BB_USERS ." u + WHERE ug.group_id = $group_id + AND ug.user_pending = 1 + AND u.user_id = ug.user_id + ORDER BY u.username + LIMIT 200 + "); + $modgroup_pending_count = count($modgroup_pending_list); + } + + if ($is_moderator && $modgroup_pending_list) + { + foreach ($modgroup_pending_list as $i => $member) + { + $user_id = $member['user_id']; + + generate_user_info($member, $bb_cfg['default_dateformat'], $is_moderator, $from, $posts, $joined, $pm, $email, $www, $user_time, $avatar); + + $row_class = !($i % 2) ? 'row1' : 'row2'; + + $user_select = ''; + + $template->assign_block_vars('pending', array( + 'ROW_CLASS' => $row_class, + 'AVATAR_IMG'=> $avatar, + 'USER' => profile_url($member), + 'FROM' => $from, + 'JOINED' => $joined, + 'POSTS' => $posts, + 'USER_ID' => $user_id, + 'PM' => $pm, + 'EMAIL' => $email, + )); + } + + $template->assign_vars(array( + 'PENDING_USERS' => true, + )); + } + + $template->assign_vars(array('MEMBERS' => true)); + } if ($is_moderator) { diff --git a/upload/language/en/main.php b/upload/language/en/main.php index 714b543c1..8b6289bd4 100644 --- a/upload/language/en/main.php +++ b/upload/language/en/main.php @@ -778,6 +778,7 @@ $lang['POST_RELEASE_FROM_GROUP'] = 'Post release from group'; $lang['CHOOSE_RELEASE_GROUP'] = 'Select release group'; $lang['ATTACH_RG_SIG'] = 'Attach release group signature'; $lang['RELEASE_FROM_RG'] = 'Release was prepared by'; +$lang['GROUPS_RELEASES'] = 'Group\'s releases'; // // Search diff --git a/upload/language/ru/main.php b/upload/language/ru/main.php index cd140982d..8c6d3f859 100644 --- a/upload/language/ru/main.php +++ b/upload/language/ru/main.php @@ -778,6 +778,7 @@ $lang['POST_RELEASE_FROM_GROUP'] = 'Создать релиз от группы' $lang['CHOOSE_RELEASE_GROUP'] = 'Выбрать релиз группу'; $lang['ATTACH_RG_SIG'] = 'Добавить подпись релиз группы'; $lang['RELEASE_FROM_RG'] = 'Релиз подготовлен'; +$lang['GROUPS_RELEASES'] = 'Релизы группы'; // // Search diff --git a/upload/language/ua/main.php b/upload/language/ua/main.php index fb5b9cd84..f9222b787 100644 --- a/upload/language/ua/main.php +++ b/upload/language/ua/main.php @@ -778,6 +778,7 @@ $lang['POST_RELEASE_FROM_GROUP'] = 'Создать релиз от группы' $lang['CHOOSE_RELEASE_GROUP'] = 'Выбрать релиз группу'; $lang['ATTACH_RG_SIG'] = 'Добавить подпись релиз группы'; $lang['RELEASE_FROM_RG'] = 'Релиз подготовлен'; +$lang['GROUPS_RELEASES'] = 'Релизы групи'; // // Search diff --git a/upload/templates/default/groupcp.tpl b/upload/templates/default/groupcp.tpl index 83760cc52..1732aa940 100644 --- a/upload/templates/default/groupcp.tpl +++ b/upload/templates/default/groupcp.tpl @@ -93,12 +93,15 @@ {L_GROUP_GOTO_CONFIG} +
            + +
            {S_HIDDEN_FIELDS} @@ -241,8 +244,52 @@ - +
            + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            #{L_AVATAR}{L_USERNAME}{L_TOPIC}{L_FORUM}{L_BT_CREATED}
            {L_GROUPS_RELEASES}
            {releases.ROW_NUMBER}{releases.AVATAR_IMG}{releases.RELEASER}{releases.RELEASE_NAME}{releases.RELEASE_FORUM}{releases.RELEASE_TIME}
             
            + +
            + + + +
            + From 82092388d559949be05804d505f00891198c4344 Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Thu, 7 Aug 2014 12:32:51 +0600 Subject: [PATCH 18/19] R594 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Небольшие фиксы Signed-off-by: Dark Nightmare --- upload/groupcp.php | 2 +- upload/posting.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/upload/groupcp.php b/upload/groupcp.php index 11866e252..6bb033593 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -47,7 +47,7 @@ set_die_append_msg(); $group_id = isset($_REQUEST[POST_GROUPS_URL]) ? intval($_REQUEST[POST_GROUPS_URL]) : null; $start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; $per_page = $bb_cfg['groupcp_members_per_page']; -$view_mode = isset($_REQUEST['view']) ? $_REQUEST['view'] : null; +$view_mode = isset($_REQUEST['view']) ? (string) $_REQUEST['view'] : null; $group_info = array(); $is_moderator = false; diff --git a/upload/posting.php b/upload/posting.php index b80ac989e..011dca4ec 100644 --- a/upload/posting.php +++ b/upload/posting.php @@ -698,7 +698,7 @@ $template->assign_vars(array( 'SUBJECT' => $subject, 'MESSAGE' => $message, - 'POSTER_RELEASE_GROUPS' => ($poster_release_groups) ? $poster_release_groups : '', + 'POSTER_RELEASE_GROUPS' => isset($poster_release_groups) && !empty($poster_release_groups) ? $poster_release_groups : '', 'ATTACH_POSTER_RG_SIG' => ($switch_poster_rg_sig) ? $switch_poster_rg_sig : false, 'U_VIEWTOPIC' => ( $mode == 'reply' ) ? "viewtopic.php?" . POST_TOPIC_URL . "=$topic_id&postorder=desc" : '', From 1635224764397248c5e557b5ab685b7f1e507266 Mon Sep 17 00:00:00 2001 From: Dark Nightmare Date: Sat, 9 Aug 2014 22:24:15 +0600 Subject: [PATCH 19/19] Search release groups releases in tracker.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Поиск раздач релиз групп в tracker.php + Вывод ссылки "Релизы группы" если группа является релиз группой + Проверка является ли группа релиз группой --- upload/config.php | 2 +- upload/groupcp.php | 6 +++ upload/language/en/main.php | 2 + upload/language/ru/main.php | 2 + upload/language/ua/main.php | 2 + upload/templates/default/groupcp.tpl | 4 +- upload/templates/default/tracker.tpl | 6 +++ upload/tracker.php | 71 +++++++++++++++++++++------- 8 files changed, 76 insertions(+), 19 deletions(-) diff --git a/upload/config.php b/upload/config.php index 4748b5b78..c24e45cfa 100644 --- a/upload/config.php +++ b/upload/config.php @@ -498,7 +498,7 @@ $bb_cfg['user_not_activated_days_keep'] = 7; // "not activated" == "not fi $bb_cfg['user_not_active_days_keep'] = 180; // inactive users but only with no posts // GroupCP -$bb_cfg['groupcp_members_per_page'] = 300; +$bb_cfg['groupcp_members_per_page'] = 50; // Tidy $bb_cfg['tidy_post'] = (!extension_loaded('tidy')) ? false : true; diff --git a/upload/groupcp.php b/upload/groupcp.php index 6bb033593..9f1d527a4 100644 --- a/upload/groupcp.php +++ b/upload/groupcp.php @@ -49,6 +49,8 @@ $start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; $per_page = $bb_cfg['groupcp_members_per_page']; $view_mode = isset($_REQUEST['view']) ? (string) $_REQUEST['view'] : null; +$releases_limit = 50; + $group_info = array(); $is_moderator = false; @@ -482,6 +484,7 @@ else 'MOD_WWW' => $www, 'MOD_TIME' => (!empty($group_info['mod_time'])) ? bb_date($group_info['mod_time']) : $lang['NONE'], 'U_SEARCH_USER' => "search.php?mode=searchuser", + 'U_SEARCH_RELEASES' => "tracker.php?srg=$group_id", 'U_GROUP_RELEASES' => "groupcp.php?view=releases&". POST_GROUPS_URL ."=$group_id", 'U_GROUP_MEMBERS' => "groupcp.php?view=members&". POST_GROUPS_URL ."=$group_id", @@ -508,6 +511,8 @@ else // TODO Correct SQL to posts with attach and limit them, optimization + if (!$group_info['release_group']) bb_die($lang['NOT_A_RELEASE_GROUP']); + // Count releases for pagination $all_releases = DB()->fetch_rowset(" SELECT p.topic_id, p.forum_id, p.poster_id, t.topic_title, t.topic_time, f.forum_name, u.username, u.avatar_ext_id, u.user_opt, u.user_rank @@ -517,6 +522,7 @@ else LEFT JOIN ". BB_USERS ." u ON(p.poster_id = u.user_id) WHERE p.poster_rg_id = $group_id ORDER BY t.topic_time DESC + LIMIT $releases_limit "); $count_releases = count($all_releases); diff --git a/upload/language/en/main.php b/upload/language/en/main.php index 8b6289bd4..e9f0e0ea2 100644 --- a/upload/language/en/main.php +++ b/upload/language/en/main.php @@ -779,6 +779,8 @@ $lang['CHOOSE_RELEASE_GROUP'] = 'Select release group'; $lang['ATTACH_RG_SIG'] = 'Attach release group signature'; $lang['RELEASE_FROM_RG'] = 'Release was prepared by'; $lang['GROUPS_RELEASES'] = 'Group\'s releases'; +$lang['MORE_RELEASES'] = 'All releases'; +$lang['NOT_A_RELEASE_GROUP'] = 'This group is not a release group'; // // Search diff --git a/upload/language/ru/main.php b/upload/language/ru/main.php index 8c6d3f859..cccba160d 100644 --- a/upload/language/ru/main.php +++ b/upload/language/ru/main.php @@ -779,6 +779,8 @@ $lang['CHOOSE_RELEASE_GROUP'] = 'Выбрать релиз группу'; $lang['ATTACH_RG_SIG'] = 'Добавить подпись релиз группы'; $lang['RELEASE_FROM_RG'] = 'Релиз подготовлен'; $lang['GROUPS_RELEASES'] = 'Релизы группы'; +$lang['MORE_RELEASES'] = 'Все релизы'; +$lang['NOT_A_RELEASE_GROUP'] = 'Эта группа не является релиз группой'; // // Search diff --git a/upload/language/ua/main.php b/upload/language/ua/main.php index f9222b787..7edc46046 100644 --- a/upload/language/ua/main.php +++ b/upload/language/ua/main.php @@ -779,6 +779,8 @@ $lang['CHOOSE_RELEASE_GROUP'] = 'Выбрать релиз группу'; $lang['ATTACH_RG_SIG'] = 'Добавить подпись релиз группы'; $lang['RELEASE_FROM_RG'] = 'Релиз подготовлен'; $lang['GROUPS_RELEASES'] = 'Релизы групи'; +$lang['MORE_RELEASES'] = 'Всi релизы'; +$lang['NOT_A_RELEASE_GROUP'] = 'Эта группа не является релиз группой'; // // Search diff --git a/upload/templates/default/groupcp.tpl b/upload/templates/default/groupcp.tpl index 1732aa940..015ac36ba 100644 --- a/upload/templates/default/groupcp.tpl +++ b/upload/templates/default/groupcp.tpl @@ -99,7 +99,7 @@
            - +
            @@ -275,7 +275,7 @@ -   + {L_MORE_RELEASES} diff --git a/upload/templates/default/tracker.tpl b/upload/templates/default/tracker.tpl index 353470f6c..98bb97036 100644 --- a/upload/templates/default/tracker.tpl +++ b/upload/templates/default/tracker.tpl @@ -266,6 +266,12 @@ $(function(){

            style="color: red" class="post" type="text" size="16" maxlength="{POSTER_NAME_MAX}" name="{POSTER_NAME_NAME}" value="{POSTER_NAME_VAL}" />

            +
            + {L_GROUPS_RELEASES} +
            +

            {S_RG_SELECT}

            +
            +
            {L_TITLE_MATCH}
            diff --git a/upload/tracker.php b/upload/tracker.php index f41b402dc..2510eb0c5 100644 --- a/upload/tracker.php +++ b/upload/tracker.php @@ -7,6 +7,7 @@ require(BB_ROOT .'common.php'); require(INC_DIR .'class.utf8.php'); require(INC_DIR .'class.correct.php'); require(INC_DIR .'class.reflection.php'); +require(INC_DIR .'functions_group.php'); // Page config $page_cfg['include_bbcode_js'] = true; @@ -21,7 +22,7 @@ $user->session_start(array('req_login' => $bb_cfg['bt_tor_browse_only_reg'])); set_die_append_msg(); $tor_search_limit = (IS_AM) ? 2000 : 500; -$forum_select_size = 24; // forum select box max rows +$forum_select_size = 26; // forum select box max rows $max_forum_name_len = 60; // inside forum select box $max_forums_selected = 50; $title_match_max_len = 60; @@ -51,6 +52,7 @@ $row_num = $tor_count = 0; $torrents_tbl = BB_BT_TORRENTS .' tor'; $cat_tbl = BB_CATEGORIES .' c'; $forums_tbl = BB_FORUMS .' f'; +$posts_tbl = BB_POSTS .' p'; $topics_tbl = BB_TOPICS .' t'; $users_tbl = BB_USERS .' u'; $tracker_tbl = BB_BT_TRACKER .' tr'; @@ -219,6 +221,30 @@ foreach ($s_not_seen_opt as $val => $opt) $s_not_seen_select[$opt['lang']] = $val; } +if ($release_groups = get_group_data('all')) +{ + $s_rg_opt = array( + $search_all => array( + 'lang' => $lang['GROUPS_RELEASES'], + 'sql' => 0, + )); + foreach ($release_groups as $rg) + { + + if ($rg['release_group']) + { + $s_rg_opt[$rg['group_id']] = array( + 'lang' => $rg['group_name'], + 'sql' => $rg['group_id'], + ); + } + } + foreach ($s_rg_opt as $val => $opt) + { + $s_release_group_select[$opt['lang']] = $val; + } +} + $GPC = array( # var_name key_name def_value GPC type 'all_words' => array('allw', 1, CHBOX), @@ -239,12 +265,13 @@ $GPC = array( 'sort' => array('s', $sort_desc, SELECT), 'seed_exist' => array('sd', 0, CHBOX), 'show_author' => array('da', 1, CHBOX), + 's_rg' => array('srg', $search_all, SELECT), 'show_cat' => array('dc', 0, CHBOX), 'show_forum' => array('df', 1, CHBOX), 'show_speed' => array('ds', 0, CHBOX), 's_not_seen' => array('sns', $search_all, SELECT), 'time' => array('tm', $search_all, SELECT), - 'tor_type' => array('tor_type', 0, CHBOX), + 'tor_type' => array('tor_type', 0, CHBOX), ); // Define all GPC vars with default values @@ -445,21 +472,22 @@ if ($dl_will_val) $dl_status[] = DL_STATUS_WILL; $dl_status_csv = join(',', $dl_status); // Switches -$only_new = ($new_val && !IS_GUEST); -$seed_exist = (bool) $seed_exist_val; -$only_active = ($active_val || $seed_exist); -$dl_search = ($dl_status && !IS_GUEST); -$only_my = ($my_val && !IS_GUEST && !$dl_search); -$prev_days = ($time_val != $search_all); -$poster_id = (bool) $poster_id_val; -$title_match = (bool) $title_match_sql; -$s_not_seen = ($s_not_seen_val != $search_all); -$tor_type = (bool) $tor_type_val; +$only_new = ($new_val && !IS_GUEST); +$seed_exist = (bool) $seed_exist_val; +$only_active = ($active_val || $seed_exist); +$dl_search = ($dl_status && !IS_GUEST); +$only_my = ($my_val && !IS_GUEST && !$dl_search); +$prev_days = ($time_val != $search_all); +$poster_id = (bool) $poster_id_val; +$s_release_group = ($s_rg_val != $search_all); +$title_match = (bool) $title_match_sql; +$s_not_seen = ($s_not_seen_val != $search_all); +$tor_type = (bool) $tor_type_val; -$hide_cat = intval(!$show_cat_val); -$hide_forum = intval(!$show_forum_val); -$hide_author = intval(!$show_author_val); -$hide_speed = intval(!$show_speed_val); +$hide_cat = intval(!$show_cat_val); +$hide_forum = intval(!$show_forum_val); +$hide_author = intval(!$show_author_val); +$hide_speed = intval(!$show_speed_val); if ($s_not_seen_val != $search_all) { @@ -490,6 +518,7 @@ if ($allowed_forums) 'order', 'poster_id', 'poster_name', + 's_rg', 's_not_seen', 'seed_exist', 'show_author', @@ -528,6 +557,7 @@ if ($allowed_forums) { $reg_time = $time_opt[$time_val]['sql']; $poster_id_sql = (int) $poster_id_val; + $rg_id_sql = (int) $s_rg_val; $s_seen_time = $s_not_seen_opt[$s_not_seen_val]['sql']; $s_seen_sign = ($s_not_seen_val == $never) ? '=' : '<'; $s_seen_exclude = ($s_not_seen_val == $never) ? '' : "AND tor.seeder_last_seen != 0"; @@ -563,6 +593,10 @@ if ($allowed_forums) AND dl.user_status IN($dl_status_csv) )"; } + if ($s_release_group) + { + $SQL['LEFT JOIN'][] = "$posts_tbl ON(p.topic_id = tor.topic_id)"; + } // WHERE $title_match_notfound_flag = false; @@ -582,6 +616,10 @@ if ($allowed_forums) { $SQL['WHERE'][] = "tor.poster_id = $poster_id_sql"; } + if ($s_release_group) + { + $SQL['WHERE'][] = "p.poster_rg_id = $rg_id_sql"; + } if ($only_new) { $SQL['WHERE'][] = "tor.reg_time > $lastvisit"; @@ -926,6 +964,7 @@ $template->assign_vars(array( 'ORDER_SELECT' => build_select($order_key, $order_select, $order_val), 'TIME_SELECT' => build_select($time_key, $time_select, $time_val), 'S_NOT_SEEN_SELECT' => build_select($s_not_seen_key, $s_not_seen_select, $s_not_seen_val), + 'S_RG_SELECT' => build_select($s_rg_key, $s_release_group_select, $s_rg_val), 'TOR_SEARCH_ACTION' => $tracker_url, 'TOR_COLSPAN' => $tor_colspan, 'TITLE_MATCH_MAX' => $title_match_max_len,