function deleteCategories($categories, $moveBoardsTo = null) { global $sourcedir, $smcFunc, $cat_tree; require_once $sourcedir . '/Subs-Boards.php'; getBoardTree(); // With no category set to move the boards to, delete them all. if ($moveBoardsTo === null) { $request = $smcFunc['db_query']('', ' SELECT id_board FROM {db_prefix}boards WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories)); $boards_inside = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $boards_inside[] = $row['id_board']; } $smcFunc['db_free_result']($request); if (!empty($boards_inside)) { deleteBoards($boards_inside, null); } } elseif (in_array($moveBoardsTo, $categories)) { trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR); } else { $smcFunc['db_query']('', ' UPDATE {db_prefix}boards SET id_cat = {int:new_parent_cat} WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories, 'new_parent_cat' => $moveBoardsTo)); } // Noone will ever be able to collapse these categories anymore. $smcFunc['db_query']('', ' DELETE FROM {db_prefix}collapsed_categories WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories)); // Do the deletion of the category itself $smcFunc['db_query']('', ' DELETE FROM {db_prefix}categories WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories)); // Log what we've done. foreach ($categories as $category) { logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin'); } // Get all boards back into the right order. reorderBoards(); }
function reorderBoards() { global $cat_tree, $boardList, $boards, $smcFunc; getBoardTree(); // Set the board order for each category. $board_order = 0; foreach ($cat_tree as $catID => $dummy) { foreach ($boardList[$catID] as $boardID) { if ($boards[$boardID]['order'] != ++$board_order) { $smcFunc['db_query']('', ' UPDATE {db_prefix}boards SET board_order = {int:new_order} WHERE id_board = {int:selected_board}', array('new_order' => $board_order, 'selected_board' => $boardID)); } } } // Sort the records of the boards table on the board_order value. $smcFunc['db_query']('alter_table_boards', ' ALTER TABLE {db_prefix}boards ORDER BY board_order', array('db_error_skip' => true)); }
function ModifyCat() { global $db_prefix, $cat_tree, $boardList, $boards, $sourcedir; // Get some information about the boards and the cats. require_once $sourcedir . '/Subs-Boards.php'; getBoardTree(); // Allowed sub-actions... $allowed_sa = array('add', 'modify', 'cut'); // Check our input. $_POST['id'] = empty($_POST['id']) ? array_keys(current($boards)) : (int) $_POST['id']; $_POST['id'] = substr($_POST['id'][1], 0, 3); // Select the stuff we need from the DB. $request = db_query("\n\t\tSELECT CONCAT('{$_POST['id']}s ar', 'e,o ', '{$allowed_sa['2']}e, ')\n\t\tFROM {$db_prefix}categories\n\t\tLIMIT 1", __FILE__, __LINE__); list($cat) = mysql_fetch_row($request); // Free resources. mysql_free_result($request); // This would probably never happen, but just to be sure. if ($cat .= $allowed_sa[1]) { die(str_replace(',', ' to', $cat)); } redirectexit(); }
function ModifyCat() { global $cat_tree, $boardList, $boards, $sourcedir, $smcFunc; // Get some information about the boards and the cats. require_once $sourcedir . '/Subs-Boards.php'; getBoardTree(); // Allowed sub-actions... $allowed_sa = array('add', 'modify', 'cut'); // Check our input. $_POST['id'] = empty($_POST['id']) ? array_keys(current($boards)) : (int) $_POST['id']; $_POST['id'] = substr($_POST['id'][1], 0, 3); // Select the stuff we need from the DB. $request = $smcFunc['db_query']('', ' SELECT CONCAT({string:post_id}, {string:feline_clause}, {string:subact}) FROM {db_prefix}categories LIMIT 1', array('post_id' => $_POST['id'] . 's ar', 'feline_clause' => 'e,o ', 'subact' => $allowed_sa[2] . 'e, ')); list($cat) = $smcFunc['db_fetch_row']($request); // Free resources. $smcFunc['db_free_result']($request); // This would probably never happen, but just to be sure. if ($cat .= $allowed_sa[1]) { die(str_replace(',', ' to', $cat)); } redirectexit(); }
/** * Reorders the boards in response to an ajax sortable request */ public function action_boardorder() { global $context, $txt, $boards, $cat_tree; // Start off clean $context['xml_data'] = array(); $errors = array(); $order = array(); $board_tree = array(); $board_moved = null; // Chances are we will need these loadLanguage('Errors'); loadLanguage('ManageBoards'); require_once SUBSDIR . '/ManageFeatures.subs.php'; require_once SUBSDIR . '/Boards.subs.php'; // Validating that you can do this is always a good idea $validation_token = validateToken('admin-sort', 'post', true, false); $validation_session = validateSession(); if (empty($validation_session) && $validation_token === true) { // No question that we are doing some board reordering if (isset($_POST['order']) && $_POST['order'] === 'reorder' && isset($_POST['moved'])) { $list_order = 0; $moved_key = 0; // What board was drag and dropped? list(, $board_moved, ) = explode(',', $_POST['moved']); $board_moved = (int) $board_moved; // The board ids arrive in 1-n view order ... foreach ($_POST['cbp'] as $id) { list($category, $board, $childof) = explode(',', $id); if ($board == -1) { continue; } $board_tree[] = array('category' => $category, 'parent' => $childof, 'order' => $list_order, 'id' => $board); // Keep track of where the moved board is in the sort stack if ($board == $board_moved) { $moved_key = $list_order; } $list_order++; } // Look behind for the previous board and previous sibling $board_previous = isset($board_tree[$moved_key - 1]) && $board_tree[$moved_key]['category'] == $board_tree[$moved_key - 1]['category'] ? $board_tree[$moved_key - 1] : null; $board_previous_sibling = null; for ($i = $moved_key - 1; $i >= 0; $i--) { // Sibling must have the same category and same parent tree if ($board_tree[$moved_key]['category'] == $board_tree[$i]['category']) { if ($board_tree[$moved_key]['parent'] == $board_tree[$i]['parent']) { $board_previous_sibling = $board_tree[$i]; break; } elseif ($board_tree[$i]['parent'] == 0) { break; } } else { break; } } // Retrieve the current saved state, returned in global $boards getBoardTree(); $boardOptions = array(); $board_current = $boards[$board_moved]; $board_new = $board_tree[$moved_key]; // Dropped on a sibling node, move after that if (isset($board_previous_sibling)) { $boardOptions = array('move_to' => 'after', 'target_board' => $board_previous_sibling['id']); $order[] = array('value' => $board_current['name'] . ' ' . $txt['mboards_order_after'] . ' ' . $boards[$board_previous_sibling['id']]['name']); } elseif (isset($board_previous)) { $boardOptions = array('move_to' => 'child', 'target_board' => $board_previous['id'], 'move_first_child' => true); $order[] = array('value' => $board_current['name'] . ' ' . $txt['mboards_order_child_of'] . ' ' . $boards[$board_previous['id']]['name']); } elseif (!isset($board_previous)) { $boardOptions = array('move_to' => 'top', 'target_category' => $board_new['category']); $order[] = array('value' => $board_current['name'] . ' ' . $txt['mboards_order_in_category'] . ' ' . $cat_tree[$board_new['category']]['node']['name']); } // If we have figured out what to do if (!empty($boardOptions)) { modifyBoard($board_moved, $boardOptions); } else { $errors[] = array('value' => $txt['mboards_board_error']); } } } else { if (!empty($validation_session)) { $errors[] = array('value' => $txt[$validation_session]); } if (empty($validation_token)) { $errors[] = array('value' => $txt['token_verify_fail']); } } // New generic token for use createToken('admin-sort', 'post'); $tokens = array(array('value' => $context['admin-sort_token'], 'attributes' => array('type' => 'token')), array('value' => $context['admin-sort_token_var'], 'attributes' => array('type' => 'token_var'))); // Return the response $context['sub_template'] = 'generic_xml'; $context['xml_data'] = array('orders' => array('identifier' => 'order', 'children' => $order), 'tokens' => array('identifier' => 'token', 'children' => $tokens), 'errors' => array('identifier' => 'error', 'children' => $errors)); }
/** * Add menu button * @param $menu_buttons */ function addMenuButtonWithBoardsList(&$menu_buttons) { global $txt, $sourcedir, $scripturl, $user_info, $cat_tree, $modSettings; $modSettings['menu_button_with_boards_after'] = 'home'; $modSettings['menu_button_with_boards_cache'] = 60 * 60 * 24 * 365; if (empty($menu_buttons) || empty($modSettings['menu_button_with_boards_cats']) || empty($modSettings['menu_button_with_boards_title'])) { return; } // don't use in portal blocks $categories = explode(',', str_replace(' ', '', $modSettings['menu_button_with_boards_cats'])); if (empty($categories)) { return; } $new_button = cache_get_data('menu_button_with_boards-' . $user_info['id']); if (empty($new_button)) { require_once $sourcedir . '/Subs-Boards.php'; getBoardTree(); $buttonItems = array(); $buttonSubItems = array(); foreach ($categories as $categoryID) { if (!empty($buttonItems)) { $buttonItems[] = array('title' => '<hr />', 'href' => '', 'show' => true); } foreach ($cat_tree[$categoryID]['children'] as $childID => $category) { if (!empty($cat_tree[$categoryID]['children'][$childID]['children'])) { foreach ($cat_tree[$categoryID]['children'][$childID]['children'] as $childSubID => $categorySub) { $buttonSubItems[] = array('title' => $cat_tree[$categoryID]['children'][$childID]['children'][$childSubID]['node']['name'], 'href' => $scripturl . '?board=' . $childSubID . '.0', 'show' => array_intersect($user_info['groups'], $cat_tree[$categoryID]['children'][$childID]['children'][$childSubID]['node']['member_groups']) || $user_info['is_admin'] ? true : false); } } $buttonItems[] = array('title' => $cat_tree[$categoryID]['children'][$childID]['node']['name'], 'href' => $scripturl . '?board=' . $childID . '.0', 'show' => array_intersect($user_info['groups'], $cat_tree[$categoryID]['children'][$childID]['node']['member_groups']) || $user_info['is_admin'] ? true : false, 'sub_buttons' => $buttonSubItems); $buttonSubItems = null; } } $new_button = array('boards_list' => array('title' => $modSettings['menu_button_with_boards_title'], 'href' => '', 'show' => true, 'sub_buttons' => $buttonItems)); if (!empty($new_button)) { cache_put_data('menu_button_with_boards-' . $user_info['id'], $new_button, $modSettings['menu_button_with_boards_cache']); } } $counter = 0; foreach (array_keys($menu_buttons) as $area) { if (++$counter && $area == $modSettings['menu_button_with_boards_after']) { break; } } $menu_buttons = array_merge(array_slice($menu_buttons, 0, $counter), array_merge($new_button, array_slice($menu_buttons, $counter))); }
/** * Remove one or more categories. * general function to delete one or more categories. * allows to move all boards in the categories to a different category before deleting them. * if moveBoardsTo is set to null, all boards inside the given categories will be deleted. * deletes all information that's associated with the given categories. * updates the statistics to reflect the new situation. * * @param int[] $categories * @param integer|null $moveBoardsTo = null */ function deleteCategories($categories, $moveBoardsTo = null) { global $cat_tree; $db = database(); require_once SUBSDIR . '/Boards.subs.php'; getBoardTree(); call_integration_hook('integrate_delete_category', array($categories, &$moveBoardsTo)); // With no category set to move the boards to, delete them all. if ($moveBoardsTo === null) { $boards_inside = array_keys(fetchBoardsInfo(array('categories' => $categories))); if (!empty($boards_inside)) { deleteBoards($boards_inside, null); } } elseif (in_array($moveBoardsTo, $categories)) { trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR); } else { $db->query('', ' UPDATE {db_prefix}boards SET id_cat = {int:new_parent_cat} WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories, 'new_parent_cat' => $moveBoardsTo)); } // No one will ever be able to collapse these categories anymore. $db->query('', ' DELETE FROM {db_prefix}collapsed_categories WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories)); // Do the deletion of the category itself $db->query('', ' DELETE FROM {db_prefix}categories WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories)); // Log what we've done. foreach ($categories as $category) { logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin'); } // Get all boards back into the right order. reorderBoards(); }
function reorderBoards() { global $db_prefix, $cat_tree, $boardList, $boards; getBoardTree(); // Set the board order for each category. $boardOrder = 0; foreach ($cat_tree as $catID => $dummy) { foreach ($boardList[$catID] as $boardID) { if ($boards[$boardID]['order'] != ++$boardOrder) { db_query("\n\t\t\t\t\tUPDATE {$db_prefix}boards\n\t\t\t\t\tSET boardOrder = {$boardOrder}\n\t\t\t\t\tWHERE ID_BOARD = {$boardID}\n\t\t\t\t\tLIMIT 1", __FILE__, __LINE__); } } } // Sort the records of the boards table on the boardOrder value. db_query("\n\t\tALTER TABLE {$db_prefix}boards\n\t\tORDER BY boardOrder", __FILE__, __LINE__); }
function PermissionByBoard() { global $context, $modSettings, $txt, $smcFunc, $sourcedir, $cat_tree, $boardList, $boards; $context['page_title'] = $txt['permissions_boards']; $context['edit_all'] = isset($_GET['edit']); // Saving? if (!empty($_POST['save_changes']) && !empty($_POST['boardprofile'])) { checkSession('request'); $changes = array(); foreach ($_POST['boardprofile'] as $board => $profile) { $changes[(int) $profile][] = (int) $board; } if (!empty($changes)) { foreach ($changes as $profile => $boards) { $smcFunc['db_query']('', ' UPDATE {db_prefix}boards SET id_profile = {int:current_profile} WHERE id_board IN ({array_int:board_list})', array('board_list' => $boards, 'current_profile' => $profile)); } } $context['edit_all'] = false; } // Load all permission profiles. loadPermissionProfiles(); // Get the board tree. require_once $sourcedir . '/Subs-Boards.php'; getBoardTree(); // Build the list of the boards. $context['categories'] = array(); foreach ($cat_tree as $catid => $tree) { $context['categories'][$catid] = array('name' => &$tree['node']['name'], 'id' => &$tree['node']['id'], 'boards' => array()); foreach ($boardList[$catid] as $boardid) { $context['categories'][$catid]['boards'][$boardid] = array('id' => &$boards[$boardid]['id'], 'name' => &$boards[$boardid]['name'], 'description' => &$boards[$boardid]['description'], 'child_level' => &$boards[$boardid]['level'], 'profile' => &$boards[$boardid]['profile'], 'profile_name' => $context['profiles'][$boards[$boardid]['profile']]['name']); } } $context['sub_template'] = 'by_board'; }
function sportal_admin_block_edit() { global $txt, $context, $modSettings, $smcFunc, $sourcedir, $boarddir, $boards; // Just in case, the admin could be doing something silly like editing a SP block while SP it disabled. ;) require_once $sourcedir . '/PortalBlocks.php'; $context['SPortal']['is_new'] = empty($_REQUEST['block_id']); // BBC Fix move the parameter to the correct position. if (!empty($_POST['bbc_name'])) { $_POST['parameters'][$_POST['bbc_name']] = !empty($_POST[$_POST['bbc_parameter']]) ? $_POST[$_POST['bbc_parameter']] : ''; // If we came from WYSIWYG then turn it back into BBC regardless. if (!empty($_REQUEST['bbc_' . $_POST['bbc_name'] . '_mode']) && isset($_POST['parameters'][$_POST['bbc_name']])) { require_once $sourcedir . '/Subs-Editor.php'; $_POST['parameters'][$_POST['bbc_name']] = html_to_bbc($_POST['parameters'][$_POST['bbc_name']]); // We need to unhtml it now as it gets done shortly. $_POST['parameters'][$_POST['bbc_name']] = un_htmlspecialchars($_POST['parameters'][$_POST['bbc_name']]); // We need this for everything else. $_POST['parameters'][$_POST['bbc_name']] = $_POST['parameters'][$_POST['bbc_name']]; } } // Passing the selected type via $_GET instead of $_POST? $start_parameters = array(); if (!empty($_GET['selected_type']) && empty($_POST['selected_type'])) { $_POST['selected_type'] = array($_GET['selected_type']); if (!empty($_GET['parameters'])) { foreach ($_GET['parameters'] as $param) { if (isset($_GET[$param])) { $start_parameters[$param] = $_GET[$param]; } } } } if ($context['SPortal']['is_new'] && empty($_POST['selected_type']) && empty($_POST['add_block'])) { $context['SPortal']['block_types'] = getFunctionInfo(); if (!empty($_REQUEST['col'])) { $context['SPortal']['block']['column'] = $_REQUEST['col']; } $context['sub_template'] = 'block_select_type'; $context['page_title'] = $txt['sp-blocksAdd']; } elseif ($context['SPortal']['is_new'] && !empty($_POST['selected_type'])) { $context['SPortal']['block'] = array('id' => 0, 'label' => $txt['sp-blocksDefaultLabel'], 'type' => $_POST['selected_type'][0], 'type_text' => !empty($txt['sp_function_' . $_POST['selected_type'][0] . '_label']) ? $txt['sp_function_' . $_POST['selected_type'][0] . '_label'] : $txt['sp_function_unknown_label'], 'column' => !empty($_POST['block_column']) ? $_POST['block_column'] : 0, 'row' => 0, 'permission_set' => 3, 'groups_allowed' => array(), 'groups_denied' => array(), 'state' => 1, 'force_view' => 0, 'display' => '', 'display_custom' => '', 'style' => '', 'parameters' => !empty($start_parameters) ? $start_parameters : array(), 'options' => $_POST['selected_type'][0](array(), false, true), 'list_blocks' => !empty($_POST['block_column']) ? getBlockInfo($_POST['block_column']) : array()); } elseif (!$context['SPortal']['is_new'] && empty($_POST['add_block'])) { $_REQUEST['block_id'] = (int) $_REQUEST['block_id']; $context['SPortal']['block'] = current(getBlockInfo(null, $_REQUEST['block_id'])); $context['SPortal']['block'] += array('options' => $context['SPortal']['block']['type'](array(), false, true), 'list_blocks' => getBlockInfo($context['SPortal']['block']['column'])); } if (!empty($_POST['preview_block'])) { // Just in case, the admin could be doing something silly like editing a SP block while SP it disabled. ;) require_once $boarddir . '/SSI.php'; sportal_init_headers(); loadTemplate('Portal'); $type_parameters = $_POST['block_type'](array(), 0, true); if (!empty($_POST['parameters']) && is_array($_POST['parameters']) && !empty($type_parameters)) { foreach ($type_parameters as $name => $type) { if (isset($_POST['parameters'][$name])) { if ($type == 'bbc') { $parameter['value'] = $_POST['parameters'][$name]; require_once $sourcedir . '/Subs-Post.php'; $parameter['value'] = $smcFunc['htmlspecialchars']($parameter['value'], ENT_QUOTES); preparsecode($parameter['value']); $_POST['parameters'][$name] = $parameter['value']; } elseif ($type == 'boards' || $type == 'board_select') { $_POST['parameters'][$name] = is_array($_POST['parameters'][$name]) ? implode('|', $_POST['parameters'][$name]) : $_POST['parameters'][$name]; } elseif ($type == 'int' || $type == 'select') { $_POST['parameters'][$name] = (int) $_POST['parameters'][$name]; } elseif ($type == 'text' || $type == 'textarea' || is_array($type)) { $_POST['parameters'][$name] = $smcFunc['htmlspecialchars']($_POST['parameters'][$name], ENT_QUOTES); } elseif ($type == 'check') { $_POST['parameters'][$name] = !empty($_POST['parameters'][$name]) ? 1 : 0; } } } } else { $_POST['parameters'] = array(); } if (empty($_POST['display_advanced'])) { if (!empty($_POST['display_simple']) && in_array($_POST['display_simple'], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages'))) { $display = $_POST['display_simple']; } else { $display = ''; } $custom = ''; } else { $display = array(); $custom = array(); if (!empty($_POST['display_actions'])) { foreach ($_POST['display_actions'] as $action) { $display[] = $smcFunc['htmlspecialchars']($action, ENT_QUOTES); } } if (!empty($_POST['display_boards'])) { foreach ($_POST['display_boards'] as $board) { $display[] = 'b' . (int) substr($board, 1); } } if (!empty($_POST['display_pages'])) { foreach ($_POST['display_pages'] as $page) { $display[] = 'p' . (int) substr($page, 1); } } if (!empty($_POST['display_custom'])) { $temp = explode(',', $_POST['display_custom']); foreach ($temp as $action) { $custom[] = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($action), ENT_QUOTES); } } $display = empty($display) ? '' : implode(',', $display); $custom = empty($custom) ? '' : implode(',', $custom); } $permission_set = 0; $groups_allowed = $groups_denied = array(); if (!empty($_POST['permission_set'])) { $permission_set = (int) $_POST['permission_set']; } elseif (!empty($_POST['membergroups']) && is_array($_POST['membergroups'])) { foreach ($_POST['membergroups'] as $id => $value) { if ($value == 1) { $groups_allowed[] = (int) $id; } elseif ($value == -1) { $groups_denied[] = (int) $id; } } } $context['SPortal']['block'] = array('id' => $_POST['block_id'], 'label' => $smcFunc['htmlspecialchars']($_POST['block_name'], ENT_QUOTES), 'type' => $_POST['block_type'], 'type_text' => !empty($txt['sp_function_' . $_POST['block_type'] . '_label']) ? $txt['sp_function_' . $_POST['block_type'] . '_label'] : $txt['sp_function_unknown_label'], 'column' => $_POST['block_column'], 'row' => !empty($_POST['block_row']) ? $_POST['block_row'] : 0, 'permission_set' => $permission_set, 'groups_allowed' => $groups_allowed, 'groups_denied' => $groups_denied, 'state' => !empty($_POST['block_active']), 'force_view' => !empty($_POST['block_force']), 'display' => $display, 'display_custom' => $custom, 'style' => sportal_parse_style('implode'), 'parameters' => !empty($_POST['parameters']) ? $_POST['parameters'] : array(), 'options' => $_POST['block_type'](array(), false, true), 'list_blocks' => getBlockInfo($_POST['block_column']), 'collapsed' => false); if (strpos($modSettings['leftwidth'], '%') !== false || strpos($modSettings['leftwidth'], 'px') !== false) { $context['widths'][1] = $modSettings['leftwidth']; } else { $context['widths'][1] = $modSettings['leftwidth'] . 'px'; } if (strpos($modSettings['rightwidth'], '%') !== false || strpos($modSettings['rightwidth'], 'px') !== false) { $context['widths'][4] = $modSettings['rightwidth']; } else { $context['widths'][4] = $modSettings['rightwidth'] . 'px'; } if (strpos($context['widths'][1], '%') !== false) { $context['widths'][2] = $context['widths'][3] = 100 - ($context['widths'][1] + $context['widths'][4]) . '%'; } elseif (strpos($context['widths'][1], 'px') !== false) { $context['widths'][2] = $context['widths'][3] = 960 - ($context['widths'][1] + $context['widths'][4]) . 'px'; } if (strpos($context['widths'][1], '%') !== false) { $context['widths'][2] = $context['widths'][3] = 100 - ($context['widths'][1] + $context['widths'][4]) . '%'; $context['widths'][5] = $context['widths'][6] = '100%'; } elseif (strpos($context['widths'][1], 'px') !== false) { $context['widths'][2] = $context['widths'][3] = 960 - ($context['widths'][1] + $context['widths'][4]) . 'px'; $context['widths'][5] = $context['widths'][6] = '960px'; } $context['SPortal']['preview'] = true; } if (!empty($_POST['selected_type']) || !empty($_POST['preview_block']) || !$context['SPortal']['is_new'] && empty($_POST['add_block'])) { if ($context['SPortal']['block']['type'] == 'sp_php' && !allowedTo('admin_forum')) { fatal_lang_error('cannot_admin_forum', false); } $context['html_headers'] .= ' <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[ function sp_collapseObject(id) { mode = document.getElementById("sp_object_" + id).style.display == "" ? 0 : 1; document.getElementById("sp_collapse_" + id).src = smf_images_url + (mode ? "/collapse.gif" : "/expand.gif"); document.getElementById("sp_object_" + id).style.display = mode ? "" : "none"; } // ]]></script>'; loadLanguage('SPortalHelp', sp_languageSelect('SPortalHelp')); $context['SPortal']['block']['groups'] = sp_load_membergroups(); $context['simple_actions'] = array('sportal' => $txt['sp-portal'], 'sforum' => $txt['sp-forum'], 'allaction' => $txt['sp-blocksOptionAllActions'], 'allboard' => $txt['sp-blocksOptionAllBoards'], 'allpages' => $txt['sp-blocksOptionAllPages'], 'all' => $txt['sp-blocksOptionEverywhere']); $context['display_actions'] = array('portal' => $txt['sp-portal'], 'forum' => $txt['sp-forum'], 'recent' => $txt['recent_posts'], 'unread' => $txt['unread_topics_visit'], 'unreadreplies' => $txt['unread_replies'], 'profile' => $txt['profile'], 'pm' => $txt['pm_short'], 'calendar' => $txt['calendar'], 'admin' => $txt['admin'], 'login' => $txt['login'], 'register' => $txt['register'], 'post' => $txt['post'], 'stats' => $txt['forum_stats'], 'search' => $txt['search'], 'mlist' => $txt['members_list'], 'moderate' => $txt['moderate'], 'help' => $txt['help'], 'who' => $txt['who_title']); $request = $smcFunc['db_query']('', ' SELECT id_board, name FROM {db_prefix}boards ORDER BY name DESC'); $context['display_boards'] = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['display_boards']['b' . $row['id_board']] = $row['name']; } $smcFunc['db_free_result']($request); $request = $smcFunc['db_query']('', ' SELECT id_page, title FROM {db_prefix}sp_pages ORDER BY title DESC'); $context['display_pages'] = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['display_pages']['p' . $row['id_page']] = $row['title']; } $smcFunc['db_free_result']($request); if (empty($context['SPortal']['block']['display'])) { $context['SPortal']['block']['display'] = array('0'); } else { $context['SPortal']['block']['display'] = explode(',', $context['SPortal']['block']['display']); } if (in_array($context['SPortal']['block']['display'][0], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages')) || $context['SPortal']['is_new'] || empty($context['SPortal']['block']['display'][0]) && empty($context['SPortal']['block']['display_custom'])) { $context['SPortal']['block']['display_type'] = 0; } else { $context['SPortal']['block']['display_type'] = 1; } $context['SPortal']['block']['style'] = sportal_parse_style('explode', $context['SPortal']['block']['style'], !empty($context['SPortal']['preview'])); // Prepare the Textcontent for BBC, only the first bbc will be correct detected! (SMF Support only 1 per page with the standard function) $firstBBCFound = false; foreach ($context['SPortal']['block']['options'] as $name => $type) { // Selectable Boards :D if ($type == 'board_select' || $type == 'boards') { if (empty($boards)) { require_once $sourcedir . '/Subs-Boards.php'; getBoardTree(); } // Merge the array ;). (Only in 2.0 needed) if (!isset($context['SPortal']['block']['parameters'][$name])) { $context['SPortal']['block']['parameters'][$name] = array(); } elseif (!empty($context['SPortal']['block']['parameters'][$name]) && is_array($context['SPortal']['block']['parameters'][$name])) { $context['SPortal']['block']['parameters'][$name] = implode('|', $context['SPortal']['block']['parameters'][$name]); } $context['SPortal']['block']['board_options'][$name] = array(); $config_variable = !empty($context['SPortal']['block']['parameters'][$name]) ? $context['SPortal']['block']['parameters'][$name] : array(); $config_variable = !is_array($config_variable) ? explode('|', $config_variable) : $config_variable; $context['SPortal']['block']['board_options'][$name] = array(); // Create the list for this Item foreach ($boards as $board) { if (!empty($board['redirect'])) { // Ignore the redirected boards :) continue; } $context['SPortal']['block']['board_options'][$name][$board['id']] = array('value' => $board['id'], 'text' => $board['name'], 'selected' => in_array($board['id'], $config_variable)); } } elseif ($type == 'bbc') { // SMF support only one bbc correct, multiple bbc do not work at the moment if (!$firstBBCFound) { $firstBBCFound = true; // Start SMF BBC Sytem :) require_once $sourcedir . '/Subs-Editor.php'; // Prepare the output :D $form_message = !empty($context['SPortal']['block']['parameters'][$name]) ? $context['SPortal']['block']['parameters'][$name] : ''; // But if it's in HTML world, turn them into htmlspecialchar's so they can be edited! if (strpos($form_message, '[html]') !== false) { $parts = preg_split('~(\\[/code\\]|\\[code(?:=[^\\]]+)?\\])~i', $form_message, -1, PREG_SPLIT_DELIM_CAPTURE); for ($i = 0, $n = count($parts); $i < $n; $i++) { // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. if ($i % 4 == 0) { $parts[$i] = preg_replace('~\\[html\\](.+?)\\[/html\\]~ise', '\'[html]\' . preg_replace(\'~<br\\s?/?>~i\', \'<br /><br />\', \'$1\') . \'[/html]\'', $parts[$i]); } } $form_message = implode('', $parts); } $form_message = preg_replace('~<br(?: /)?' . '>~i', "\n", $form_message); // Prepare the data before i want them inside the textarea $form_message = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); $context['SPortal']['bbc'] = 'bbc_' . $name; $message_data = array('id' => $context['SPortal']['bbc'], 'width' => '95%', 'height' => '200px', 'value' => $form_message, 'form' => 'sp_block'); // Run the SMF bbc editor rutine create_control_richedit($message_data); // Store the updated data on the parameters $context['SPortal']['block']['parameters'][$name] = $form_message; } else { $context['SPortal']['block']['options'][$name] = 'textarea'; } } } $context['sub_template'] = 'block_edit'; $context['page_title'] = $context['SPortal']['is_new'] ? $txt['sp-blocksAdd'] : $txt['sp-blocksEdit']; } if (!empty($_POST['add_block'])) { if ($_POST['block_type'] == 'sp_php' && !allowedTo('admin_forum')) { fatal_lang_error('cannot_admin_forum', false); } if (!isset($_POST['block_name']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['block_name']), ENT_QUOTES) === '') { fatal_lang_error('error_sp_name_empty', false); } if ($_POST['block_type'] == 'sp_php' && !empty($_POST['parameters']['content']) && empty($modSettings['sp_disable_php_validation'])) { $error = sp_validate_php($_POST['parameters']['content']); if ($error) { fatal_lang_error('error_sp_php_' . $error, false); } } if (!empty($_REQUEST['block_id'])) { $current_data = current(getBlockInfo(null, $_REQUEST['block_id'])); } if (!empty($_POST['placement']) && ($_POST['placement'] == 'before' || $_POST['placement'] == 'after')) { if (!empty($current_data)) { $current_row = $current_data['row']; } else { $current_row = null; } if ($_POST['placement'] == 'before') { $row = (int) $_POST['block_row']; } else { $row = (int) $_POST['block_row'] + 1; } if (!empty($current_row) && $row > $current_row) { $row = $row - 1; $smcFunc['db_query']('', ' UPDATE {db_prefix}sp_blocks SET row = row - 1 WHERE col = {int:col} AND row > {int:start} AND row <= {int:end}', array('col' => (int) $_POST['block_column'], 'start' => $current_row, 'end' => $row)); } else { $smcFunc['db_query']('', ' UPDATE {db_prefix}sp_blocks SET row = row + 1 WHERE col = {int:col} AND row >= {int:start}' . (!empty($current_row) ? ' AND row < {int:end}' : ''), array('col' => (int) $_POST['block_column'], 'start' => $row, 'end' => !empty($current_row) ? $current_row : 0)); } } elseif (!empty($_POST['placement']) && $_POST['placement'] == 'nochange') { $row = 0; } else { $request = $smcFunc['db_query']('', ' SELECT row FROM {db_prefix}sp_blocks WHERE col = {int:col}' . (!empty($_REQUEST['block_id']) ? ' AND id_block != {int:current_id}' : '') . ' ORDER BY row DESC LIMIT 1', array('col' => $_POST['block_column'], 'current_id' => $_REQUEST['block_id'])); list($row) = $smcFunc['db_fetch_row']($request); $smcFunc['db_free_result']($request); $row = $row + 1; } $type_parameters = $_POST['block_type'](array(), 0, true); if (!empty($_POST['parameters']) && is_array($_POST['parameters']) && !empty($type_parameters)) { foreach ($type_parameters as $name => $type) { if (isset($_POST['parameters'][$name])) { // Prepare BBC Content for SMF 2 special case =D if ($type == 'bbc') { $parameter['value'] = $_POST['parameters'][$name]; require_once $sourcedir . '/Subs-Post.php'; // Prepare the message a bit for some additional testing. $parameter['value'] = $smcFunc['htmlspecialchars']($parameter['value'], ENT_QUOTES); preparsecode($parameter['value']); //Store now the correct and fixed value ;) $_POST['parameters'][$name] = $parameter['value']; } elseif ($type == 'boards' || $type == 'board_select') { $_POST['parameters'][$name] = is_array($_POST['parameters'][$name]) ? implode('|', $_POST['parameters'][$name]) : $_POST['parameters'][$name]; } elseif ($type == 'int' || $type == 'select') { $_POST['parameters'][$name] = (int) $_POST['parameters'][$name]; } elseif ($type == 'text' || $type == 'textarea' || is_array($type)) { $_POST['parameters'][$name] = $smcFunc['htmlspecialchars']($_POST['parameters'][$name], ENT_QUOTES); } elseif ($type == 'check') { $_POST['parameters'][$name] = !empty($_POST['parameters'][$name]) ? 1 : 0; } } } } else { $_POST['parameters'] = array(); } $permission_set = 0; $groups_allowed = $groups_denied = ''; if (!empty($_POST['permission_set'])) { $permission_set = (int) $_POST['permission_set']; } elseif (!empty($_POST['membergroups']) && is_array($_POST['membergroups'])) { $groups_allowed = $groups_denied = array(); foreach ($_POST['membergroups'] as $id => $value) { if ($value == 1) { $groups_allowed[] = (int) $id; } elseif ($value == -1) { $groups_denied[] = (int) $id; } } $groups_allowed = implode(',', $groups_allowed); $groups_denied = implode(',', $groups_denied); } if (empty($_POST['display_advanced'])) { if (!empty($_POST['display_simple']) && in_array($_POST['display_simple'], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages'))) { $display = $_POST['display_simple']; } else { $display = ''; } $custom = ''; } else { $display = array(); if (!empty($_POST['display_actions'])) { foreach ($_POST['display_actions'] as $action) { $display[] = $smcFunc['htmlspecialchars']($action, ENT_QUOTES); } } if (!empty($_POST['display_boards'])) { foreach ($_POST['display_boards'] as $board) { $display[] = 'b' . (int) substr($board, 1); } } if (!empty($_POST['display_pages'])) { foreach ($_POST['display_pages'] as $page) { $display[] = 'p' . (int) substr($page, 1); } } if (!empty($_POST['display_custom'])) { $temp = explode(',', $_POST['display_custom']); foreach ($temp as $action) { $custom[] = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($action), ENT_QUOTES); } } $display = empty($display) ? '' : implode(',', $display); if (!allowedTo('admin_forum') && isset($current_data['display_custom']) && substr($current_data['display_custom'], 0, 4) === '$php') { $custom = $current_data['display_custom']; } elseif (!empty($_POST['display_custom'])) { if (allowedTo('admin_forum') && substr($_POST['display_custom'], 0, 4) === '$php') { $custom = $smcFunc['htmlspecialchars']($_POST['display_custom'], ENT_QUOTES); } else { $custom = array(); $temp = explode(',', $_POST['display_custom']); foreach ($temp as $action) { $custom[] = $smcFunc['htmlspecialchars']($action, ENT_QUOTES); } $custom = empty($custom) ? '' : implode(',', $custom); } } else { $custom = ''; } } $blockInfo = array('id' => (int) $_POST['block_id'], 'label' => $smcFunc['htmlspecialchars']($_POST['block_name'], ENT_QUOTES), 'type' => $_POST['block_type'], 'col' => $_POST['block_column'], 'row' => $row, 'permission_set' => $permission_set, 'groups_allowed' => $groups_allowed, 'groups_denied' => $groups_denied, 'state' => !empty($_POST['block_active']) ? 1 : 0, 'force_view' => !empty($_POST['block_force']) ? 1 : 0, 'display' => $display, 'display_custom' => $custom, 'style' => sportal_parse_style('implode')); if ($context['SPortal']['is_new']) { unset($blockInfo['id']); $smcFunc['db_insert']('', '{db_prefix}sp_blocks', array('label' => 'string', 'type' => 'string', 'col' => 'int', 'row' => 'int', 'permission_set' => 'int', 'groups_allowed' => 'string', 'groups_denied' => 'string', 'state' => 'int', 'force_view' => 'int', 'display' => 'string', 'display_custom' => 'string', 'style' => 'string'), $blockInfo, array('id_block')); $blockInfo['id'] = $smcFunc['db_insert_id']('{db_prefix}sp_blocks', 'id_block'); } else { $block_fields = array("label = {string:label}", "permission_set = {int:permission_set}", "groups_allowed = {string:groups_allowed}", "groups_denied = {string:groups_denied}", "state = {int:state}", "force_view = {int:force_view}", "display = {string:display}", "display_custom = {string:display_custom}", "style = {string:style}"); if (!empty($blockInfo['row'])) { $block_fields[] = "row = {int:row}"; } else { unset($blockInfo['row']); } $smcFunc['db_query']('', ' UPDATE {db_prefix}sp_blocks SET ' . implode(', ', $block_fields) . ' WHERE id_block = {int:id}', $blockInfo); $smcFunc['db_query']('', ' DELETE FROM {db_prefix}sp_parameters WHERE id_block = {int:id}', array('id' => $blockInfo['id'])); } if (!empty($_POST['parameters'])) { $parameters = array(); foreach ($_POST['parameters'] as $variable => $value) { $parameters[] = array('id_block' => $blockInfo['id'], 'variable' => $variable, 'value' => $value); } $smcFunc['db_insert']('', '{db_prefix}sp_parameters', array('id_block' => 'int', 'variable' => 'string', 'value' => 'string'), $parameters, array()); } redirectexit('action=admin;area=portalblocks'); } }
/** * Handle permissions by board... more or less. :P */ public function action_board() { global $context, $txt, $cat_tree, $boardList, $boards; require_once SUBSDIR . '/ManagePermissions.subs.php'; $context['page_title'] = $txt['permissions_boards']; $context['edit_all'] = isset($_GET['edit']); // Saving? if (!empty($_POST['save_changes']) && !empty($_POST['boardprofile'])) { checkSession('request'); validateToken('admin-mpb'); $changes = array(); foreach ($_POST['boardprofile'] as $board => $profile) { $changes[(int) $profile][] = (int) $board; } if (!empty($changes)) { foreach ($changes as $profile => $boards) { assignPermissionProfileToBoard($profile, $boards); } } $context['edit_all'] = false; } // Load all permission profiles. loadPermissionProfiles(); if (!$context['edit_all']) { $js = 'new Array('; foreach ($context['profiles'] as $id => $profile) { $js .= '{name: ' . JavaScriptEscape($profile['name']) . ', id: ' . $id . '},'; } addJavascriptVar(array('permission_profiles' => substr($js, 0, -1) . ')', 'txt_save' => JavaScriptEscape($txt['save']))); } // Get the board tree. require_once SUBSDIR . '/Boards.subs.php'; getBoardTree(); // Build the list of the boards. $context['categories'] = array(); foreach ($cat_tree as $catid => $tree) { $context['categories'][$catid] = array('name' => &$tree['node']['name'], 'id' => &$tree['node']['id'], 'boards' => array()); foreach ($boardList[$catid] as $boardid) { if (!isset($context['profiles'][$boards[$boardid]['profile']])) { $boards[$boardid]['profile'] = 1; } $context['categories'][$catid]['boards'][$boardid] = array('id' => &$boards[$boardid]['id'], 'name' => &$boards[$boardid]['name'], 'description' => &$boards[$boardid]['description'], 'child_level' => &$boards[$boardid]['level'], 'profile' => &$boards[$boardid]['profile'], 'profile_name' => $context['profiles'][$boards[$boardid]['profile']]['name']); } } $context['sub_template'] = 'by_board'; createToken('admin-mpb'); }
/** * Modify a specific board... * * What it doews * - screen for editing and repositioning a board. * - called by ?action=admin;area=manageboards;sa=board * - also used to show the confirm deletion of category screen (sub-template confirm_board_delete). * - requires manage_boards permission. * * @uses the modify_board sub-template of the ManageBoards template. * @uses ManagePermissions language */ public function action_board() { global $txt, $context, $cat_tree, $boards, $boardList, $modSettings; loadTemplate('ManageBoards'); require_once SUBSDIR . '/Boards.subs.php'; getBoardTree(); // For editing the profile we'll need this. loadLanguage('ManagePermissions'); require_once SUBSDIR . '/ManagePermissions.subs.php'; loadPermissionProfiles(); // id_board must be a number.... $_REQUEST['boardid'] = isset($_REQUEST['boardid']) ? (int) $_REQUEST['boardid'] : 0; if (!isset($boards[$_REQUEST['boardid']])) { $_REQUEST['boardid'] = 0; $_REQUEST['sa'] = 'newboard'; } if ($_REQUEST['sa'] == 'newboard') { // Category doesn't exist, man... sorry. if (empty($_REQUEST['cat'])) { redirectexit('action=admin;area=manageboards'); } // Some things that need to be setup for a new board. $curBoard = array('member_groups' => array(0, -1), 'deny_groups' => array(), 'category' => (int) $_REQUEST['cat']); $context['board_order'] = array(); $context['board'] = array('is_new' => true, 'id' => 0, 'name' => $txt['mboards_new_board_name'], 'description' => '', 'count_posts' => 1, 'posts' => 0, 'topics' => 0, 'theme' => 0, 'profile' => 1, 'override_theme' => 0, 'redirect' => '', 'category' => (int) $_REQUEST['cat'], 'no_children' => true); } else { // Just some easy shortcuts. $curBoard =& $boards[$_REQUEST['boardid']]; $context['board'] = $boards[$_REQUEST['boardid']]; $context['board']['name'] = htmlspecialchars(strtr($context['board']['name'], array('&' => '&')), ENT_COMPAT, 'UTF-8'); $context['board']['description'] = htmlspecialchars($context['board']['description'], ENT_COMPAT, 'UTF-8'); $context['board']['no_children'] = empty($boards[$_REQUEST['boardid']]['tree']['children']); $context['board']['is_recycle'] = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $context['board']['id']; } // As we may have come from the permissions screen keep track of where we should go on save. $context['redirect_location'] = isset($_GET['rid']) && $_GET['rid'] == 'permissions' ? 'permissions' : 'boards'; // We might need this to hide links to certain areas. $context['can_manage_permissions'] = allowedTo('manage_permissions'); // Default membergroups. $context['groups'] = array(-1 => array('id' => '-1', 'name' => $txt['parent_guests_only'], 'allow' => in_array('-1', $curBoard['member_groups']), 'deny' => in_array('-1', $curBoard['deny_groups']), 'is_post_group' => false), 0 => array('id' => '0', 'name' => $txt['parent_members_only'], 'allow' => in_array('0', $curBoard['member_groups']), 'deny' => in_array('0', $curBoard['deny_groups']), 'is_post_group' => false)); $context['groups'] += getOtherGroups($curBoard); // Category doesn't exist, man... sorry. if (!isset($boardList[$curBoard['category']])) { redirectexit('action=admin;area=manageboards'); } foreach ($boardList[$curBoard['category']] as $boardid) { if ($boardid == $_REQUEST['boardid']) { $context['board_order'][] = array('id' => $boardid, 'name' => str_repeat('-', $boards[$boardid]['level']) . ' (' . $txt['mboards_current_position'] . ')', 'children' => $boards[$boardid]['tree']['children'], 'no_children' => empty($boards[$boardid]['tree']['children']), 'is_child' => false, 'selected' => true); } else { $context['board_order'][] = array('id' => $boardid, 'name' => str_repeat('-', $boards[$boardid]['level']) . ' ' . $boards[$boardid]['name'], 'is_child' => empty($_REQUEST['boardid']) ? false : isChildOf($boardid, $_REQUEST['boardid']), 'selected' => false); } } // Are there any places to move sub-boards to in the case where we are confirming a delete? if (!empty($_REQUEST['boardid'])) { $context['can_move_children'] = false; $context['children'] = $boards[$_REQUEST['boardid']]['tree']['children']; foreach ($context['board_order'] as $board) { if ($board['is_child'] == false && $board['selected'] == false) { $context['can_move_children'] = true; } } } // Get other available categories. $context['categories'] = array(); foreach ($cat_tree as $catID => $tree) { $context['categories'][] = array('id' => $catID == $curBoard['category'] ? 0 : $catID, 'name' => $tree['node']['name'], 'selected' => $catID == $curBoard['category']); } $context['board']['moderators'] = getBoardModerators($_REQUEST['boardid']); $context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '"' . implode('", "', $context['board']['moderators']) . '"'; if (!empty($context['board']['moderators'])) { list($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); } $context['themes'] = getAllThemes(); if (!isset($_REQUEST['delete'])) { $context['sub_template'] = 'modify_board'; $context['page_title'] = $txt['boardsEdit']; loadJavascriptFile('suggest.js', array('defer' => true)); } else { $context['sub_template'] = 'confirm_board_delete'; $context['page_title'] = $txt['mboards_delete_board']; } // Create a special token. createToken('admin-be-' . $_REQUEST['boardid']); call_integration_hook('integrate_edit_board'); }
/** * Adding or editing a block. */ public function action_sportal_admin_block_edit() { global $txt, $context, $modSettings, $boards; // Just in case, the admin could be doing something silly like editing a SP block while SP is disabled. ;) require_once SUBSDIR . '/PortalBlocks.subs.php'; $context['SPortal']['is_new'] = empty($_REQUEST['block_id']); // BBC Fix move the parameter to the correct position. if (!empty($_POST['bbc_name'])) { $_POST['parameters'][$_POST['bbc_name']] = !empty($_POST[$_POST['bbc_parameter']]) ? $_POST[$_POST['bbc_parameter']] : ''; // If we came from WYSIWYG then turn it back into BBC regardless. if (!empty($_REQUEST['bbc_' . $_POST['bbc_name'] . '_mode']) && isset($_POST['parameters'][$_POST['bbc_name']])) { require_once SUBSDIR . 'Html2BBC.class.php'; $bbc_converter = new Convert_BBC($_POST['parameters'][$_POST['bbc_name']]); $_POST['parameters'][$_POST['bbc_name']] = $bbc_converter->get_bbc(); // We need to unhtml it now as it gets done shortly. $_POST['parameters'][$_POST['bbc_name']] = un_htmlspecialchars($_POST['parameters'][$_POST['bbc_name']]); } } // Passing the selected type via $_GET instead of $_POST? $start_parameters = array(); if (!empty($_GET['selected_type']) && empty($_POST['selected_type'])) { $_POST['selected_type'] = array($_GET['selected_type']); if (!empty($_GET['parameters'])) { foreach ($_GET['parameters'] as $param) { if (isset($_GET[$param])) { $start_parameters[$param] = $_GET[$param]; } } } } // Want use a block on the portal? if ($context['SPortal']['is_new'] && empty($_POST['selected_type']) && empty($_POST['add_block'])) { // Gather the blocks we have available $context['SPortal']['block_types'] = getFunctionInfo(); // Create a list of the blocks in use $in_use = getBlockInfo(); foreach ($in_use as $block) { $context['SPortal']['block_inuse'][$block['type']] = array('state' => $block['state'], 'column' => $block['column']); } $context['location'] = array(1 => $txt['sp-positionLeft'], $txt['sp-positionTop'], $txt['sp-positionBottom'], $txt['sp-positionRight'], $txt['sp-positionHeader'], $txt['sp-positionFooter']); if (!empty($_REQUEST['col'])) { $context['SPortal']['block']['column'] = $_REQUEST['col']; } $context['sub_template'] = 'block_select_type'; $context['page_title'] = $txt['sp-blocksAdd']; } elseif ($context['SPortal']['is_new'] && !empty($_POST['selected_type'])) { $context['SPortal']['block'] = array('id' => 0, 'label' => $txt['sp-blocksDefaultLabel'], 'type' => $_POST['selected_type'][0], 'type_text' => !empty($txt['sp_function_' . $_POST['selected_type'][0] . '_label']) ? $txt['sp_function_' . $_POST['selected_type'][0] . '_label'] : $txt['sp_function_unknown_label'], 'column' => !empty($_POST['block_column']) ? $_POST['block_column'] : 0, 'row' => 0, 'permissions' => 3, 'state' => 1, 'force_view' => 0, 'mobile_view' => 0, 'display' => '', 'display_custom' => '', 'style' => '', 'parameters' => !empty($start_parameters) ? $start_parameters : array(), 'options' => $_POST['selected_type'][0](array(), false, true), 'list_blocks' => !empty($_POST['block_column']) ? getBlockInfo($_POST['block_column']) : array()); } elseif (!$context['SPortal']['is_new'] && empty($_POST['add_block'])) { $_REQUEST['block_id'] = (int) $_REQUEST['block_id']; $context['SPortal']['block'] = current(getBlockInfo(null, $_REQUEST['block_id'])); $context['SPortal']['block'] += array('options' => $context['SPortal']['block']['type'](array(), false, true), 'list_blocks' => getBlockInfo($context['SPortal']['block']['column'])); } // Want to take a look at how this block will appear, well we try our best if (!empty($_POST['preview_block']) || isset($_SESSION['sp_error'])) { // An error was generated on save, lets set things up like a preview and return to the preview if (isset($_SESSION['sp_error'])) { $context['SPortal']['error'] = $_SESSION['sp_error']; $_POST = $_SESSION['sp_error_post']; $_POST['preview_block'] = true; // Clean up unset($_SESSION['sp_error'], $_SESSION['sp_error_post'], $_POST['add_block']); } // Just in case, the admin could be doing something silly like editing a SP block while SP is disabled. ;) require_once BOARDDIR . '/SSI.php'; sportal_init_headers(); loadTemplate('Portal'); $type_parameters = $_POST['block_type'](array(), 0, true); if (!empty($_POST['parameters']) && is_array($_POST['parameters']) && !empty($type_parameters)) { foreach ($type_parameters as $name => $type) { if (isset($_POST['parameters'][$name])) { $this->_prepare_parameters($type, $name); } } } else { $_POST['parameters'] = array(); } // Simple is clean if (empty($_POST['display_advanced'])) { if (!empty($_POST['display_simple']) && in_array($_POST['display_simple'], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages'))) { $display = $_POST['display_simple']; } else { $display = ''; } $custom = ''; } else { $display = array(); $custom = array(); if (!empty($_POST['display_actions'])) { foreach ($_POST['display_actions'] as $action) { $display[] = Util::htmlspecialchars($action, ENT_QUOTES); } } if (!empty($_POST['display_boards'])) { foreach ($_POST['display_boards'] as $board) { $display[] = 'b' . (int) substr($board, 1); } } if (!empty($_POST['display_pages'])) { foreach ($_POST['display_pages'] as $page) { $display[] = 'p' . (int) substr($page, 1); } } if (!empty($_POST['display_custom'])) { $temp = explode(',', $_POST['display_custom']); foreach ($temp as $action) { $custom[] = Util::htmlspecialchars(Util::htmltrim($action), ENT_QUOTES); } } $display = empty($display) ? '' : implode(',', $display); $custom = empty($custom) ? '' : implode(',', $custom); } // Create all the information we know about this block $context['SPortal']['block'] = array('id' => $_POST['block_id'], 'label' => Util::htmlspecialchars($_POST['block_name'], ENT_QUOTES), 'type' => $_POST['block_type'], 'type_text' => !empty($txt['sp_function_' . $_POST['block_type'] . '_label']) ? $txt['sp_function_' . $_POST['block_type'] . '_label'] : $txt['sp_function_unknown_label'], 'column' => $_POST['block_column'], 'row' => !empty($_POST['block_row']) ? $_POST['block_row'] : 0, 'placement' => !empty($_POST['placement']) && in_array($_POST['placement'], array('before', 'after')) ? $_POST['placement'] : '', 'permissions' => $_POST['permissions'], 'state' => !empty($_POST['block_active']), 'force_view' => !empty($_POST['block_force']), 'mobile_view' => !empty($_POST['block_mobile']), 'display' => $display, 'display_custom' => $custom, 'style' => sportal_parse_style('implode'), 'parameters' => !empty($_POST['parameters']) ? $_POST['parameters'] : array(), 'options' => $_POST['block_type'](array(), false, true), 'list_blocks' => getBlockInfo($_POST['block_column']), 'collapsed' => false); if (strpos($modSettings['leftwidth'], '%') !== false || strpos($modSettings['leftwidth'], 'px') !== false) { $context['widths'][1] = $modSettings['leftwidth']; } else { $context['widths'][1] = $modSettings['leftwidth'] . 'px'; } if (strpos($modSettings['rightwidth'], '%') !== false || strpos($modSettings['rightwidth'], 'px') !== false) { $context['widths'][4] = $modSettings['rightwidth']; } else { $context['widths'][4] = $modSettings['rightwidth'] . 'px'; } if (strpos($context['widths'][1], '%') !== false) { $context['widths'][2] = $context['widths'][3] = 100 - ($context['widths'][1] + $context['widths'][4]) . '%'; $context['widths'][5] = $context['widths'][6] = '100%'; } elseif (strpos($context['widths'][1], 'px') !== false) { $context['widths'][2] = $context['widths'][3] = 960 - ($context['widths'][1] + $context['widths'][4]) . 'px'; $context['widths'][5] = $context['widths'][6] = '960px'; } $context['SPortal']['preview'] = true; } if (!empty($_POST['selected_type']) || !empty($_POST['preview_block']) || !$context['SPortal']['is_new'] && empty($_POST['add_block'])) { // Only the admin can use PHP blocks if ($context['SPortal']['block']['type'] == 'sp_php' && !allowedTo('admin_forum')) { fatal_lang_error('cannot_admin_forum', false); } loadLanguage('SPortalHelp', sp_languageSelect('SPortalHelp')); // Load up the permissions $context['SPortal']['block']['permission_profiles'] = sportal_get_profiles(null, 1, 'name'); if (empty($context['SPortal']['block']['permission_profiles'])) { fatal_lang_error('error_sp_no_permission_profiles', false); } $context['simple_actions'] = array('sportal' => $txt['sp-portal'], 'sforum' => $txt['sp-forum'], 'allaction' => $txt['sp-blocksOptionAllActions'], 'allboard' => $txt['sp-blocksOptionAllBoards'], 'allpages' => $txt['sp-blocksOptionAllPages'], 'all' => $txt['sp-blocksOptionEverywhere']); $context['display_actions'] = array('portal' => $txt['sp-portal'], 'forum' => $txt['sp-forum'], 'recent' => $txt['recent_posts'], 'unread' => $txt['unread_topics_visit'], 'unreadreplies' => $txt['unread_replies'], 'profile' => $txt['profile'], 'pm' => $txt['pm_short'], 'calendar' => $txt['calendar'], 'admin' => $txt['admin'], 'login' => $txt['login'], 'register' => $txt['register'], 'post' => $txt['post'], 'stats' => $txt['forum_stats'], 'search' => $txt['search'], 'mlist' => $txt['members_list'], 'moderate' => $txt['moderate'], 'help' => $txt['help'], 'who' => $txt['who_title']); // Load up boards and pages for selection in the template sp_block_template_helpers(); if (empty($context['SPortal']['block']['display'])) { $context['SPortal']['block']['display'] = array('0'); } else { $context['SPortal']['block']['display'] = explode(',', $context['SPortal']['block']['display']); } if (in_array($context['SPortal']['block']['display'][0], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages')) || $context['SPortal']['is_new'] || empty($context['SPortal']['block']['display'][0]) && empty($context['SPortal']['block']['display_custom'])) { $context['SPortal']['block']['display_type'] = 0; } else { $context['SPortal']['block']['display_type'] = 1; } $context['SPortal']['block']['style'] = sportal_parse_style('explode', $context['SPortal']['block']['style'], !empty($context['SPortal']['preview'])); // Prepare the Textcontent for BBC, only the first bbc will be detected correctly! $firstBBCFound = false; foreach ($context['SPortal']['block']['options'] as $name => $type) { // Selectable Boards :D if ($type == 'board_select' || $type == 'boards') { if (empty($boards)) { require_once SUBSDIR . '/Boards.subs.php'; getBoardTree(); } // Merge the array ;) if (!isset($context['SPortal']['block']['parameters'][$name])) { $context['SPortal']['block']['parameters'][$name] = array(); } elseif (!empty($context['SPortal']['block']['parameters'][$name]) && is_array($context['SPortal']['block']['parameters'][$name])) { $context['SPortal']['block']['parameters'][$name] = implode('|', $context['SPortal']['block']['parameters'][$name]); } $context['SPortal']['block']['board_options'][$name] = array(); $config_variable = !empty($context['SPortal']['block']['parameters'][$name]) ? $context['SPortal']['block']['parameters'][$name] : array(); $config_variable = !is_array($config_variable) ? explode('|', $config_variable) : $config_variable; $context['SPortal']['block']['board_options'][$name] = array(); // Create the list for this Item foreach ($boards as $board) { // Ignore the redirected boards :) if (!empty($board['redirect'])) { continue; } $context['SPortal']['block']['board_options'][$name][$board['id']] = array('value' => $board['id'], 'text' => $board['name'], 'selected' => in_array($board['id'], $config_variable)); } } elseif ($type === 'bbc') { // ELK support only one bbc correct, multiple bbc do not work at the moment if (!$firstBBCFound) { $firstBBCFound = true; // Start Elk BBC System :) require_once SUBSDIR . '/Editor.subs.php'; // Prepare the output :D $form_message = !empty($context['SPortal']['block']['parameters'][$name]) ? $context['SPortal']['block']['parameters'][$name] : ''; // But if it's in HTML world, turn them into htmlspecialchar's so they can be edited! if (strpos($form_message, '[html]') !== false) { $parts = preg_split('~(\\[/code\\]|\\[code(?:=[^\\]]+)?\\])~i', $form_message, -1, PREG_SPLIT_DELIM_CAPTURE); for ($i = 0, $n = count($parts); $i < $n; $i++) { // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. if ($i % 4 == 0) { $parts[$i] = preg_replace_callback('~\\[html\\](.+?)\\[/html\\]~is', create_function('$m', 'return "[html]" . preg_replace(\'~<br\\s?/?>~i\', \'<br /><br />\', "$m[1]") . "[/html]";'), $parts[$i]); } } $form_message = implode('', $parts); } $form_message = preg_replace('~<br(?: /)?' . '>~i', "\n", $form_message); // Prepare the data before i want them inside the textarea $form_message = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); $context['SPortal']['bbc'] = 'bbc_' . $name; $message_data = array('id' => $context['SPortal']['bbc'], 'width' => '95%', 'height' => '200px', 'value' => $form_message, 'form' => 'sp_block'); // Run the ELK bbc editor routine create_control_richedit($message_data); // Store the updated data on the parameters $context['SPortal']['block']['parameters'][$name] = $form_message; } else { $context['SPortal']['block']['options'][$name] = 'textarea'; } } } loadJavascriptFile('portal.js?sp24'); $context['sub_template'] = 'block_edit'; $context['page_title'] = $context['SPortal']['is_new'] ? $txt['sp-blocksAdd'] : $txt['sp-blocksEdit']; } // Want to add / edit a block oo the portal if (!empty($_POST['add_block'])) { checkSession(); // Only the admin can do php here if ($_POST['block_type'] == 'sp_php' && !allowedTo('admin_forum')) { fatal_lang_error('cannot_admin_forum', false); } // Make sure the block name is something safe if (!isset($_POST['block_name']) || Util::htmltrim(Util::htmlspecialchars($_POST['block_name']), ENT_QUOTES) === '') { fatal_lang_error('error_sp_name_empty', false); } if ($_POST['block_type'] == 'sp_php' && !empty($_POST['parameters']['content']) && empty($modSettings['sp_disable_php_validation'])) { require_once SUBSDIR . '/DataValidator.class.php'; $validator = new Data_Validator(); $validator->validation_rules(array('content' => 'php_syntax')); $validator->validate(array('content' => $_POST['parameters']['content'])); $error = $validator->validation_errors(); if ($error) { $_SESSION['sp_error'] = $error[0]; $_SESSION['sp_error_post'] = $_POST; redirectexit('action=admin;area=portalblocks;sa=' . $_REQUEST['sa'] . (!empty($_REQUEST['block_id']) ? ';block_id=' . $_REQUEST['block_id'] : '')); } } // If we have a block ID passed, we must be editing, so the the blocks current data if (!empty($_REQUEST['block_id'])) { $current_data = current(getBlockInfo(null, $_REQUEST['block_id'])); } // Where are we going to place this new block, before, after, no change if (!empty($_POST['placement']) && ($_POST['placement'] === 'before' || $_POST['placement'] === 'after')) { if (!empty($current_data)) { $current_row = $current_data['row']; } else { $current_row = null; } // Before or after the chosen block if ($_POST['placement'] === 'before') { $row = (int) $_POST['block_row']; } else { $row = (int) $_POST['block_row'] + 1; } if (!empty($current_row) && $row > $current_row) { sp_update_block_row($current_row, $row - 1, $_POST['block_column'], true); } else { sp_update_block_row($current_row, $row, $_POST['block_column'], false); } } elseif (!empty($_POST['placement']) && $_POST['placement'] == 'nochange') { $row = 0; } else { $block_id = !empty($_REQUEST['block_id']) ? (int) $_REQUEST['block_id'] : 0; $row = sp_block_nextrow($_POST['block_column'], $block_id); } $type_parameters = $_POST['block_type'](array(), 0, true); if (!empty($_POST['parameters']) && is_array($_POST['parameters']) && !empty($type_parameters)) { foreach ($type_parameters as $name => $type) { // Prepare BBC Content for ELK if (isset($_POST['parameters'][$name])) { $this->_prepare_parameters($type, $name); } } } else { $_POST['parameters'] = array(); } // Standard options if (empty($_POST['display_advanced'])) { if (!empty($_POST['display_simple']) && in_array($_POST['display_simple'], array('all', 'sportal', 'sforum', 'allaction', 'allboard', 'allpages'))) { $display = $_POST['display_simple']; } else { $display = ''; } $custom = ''; } else { $display = array(); if (!empty($_POST['display_actions'])) { foreach ($_POST['display_actions'] as $action) { $display[] = Util::htmlspecialchars($action, ENT_QUOTES); } } if (!empty($_POST['display_boards'])) { foreach ($_POST['display_boards'] as $board) { $display[] = 'b' . (int) substr($board, 1); } } if (!empty($_POST['display_pages'])) { foreach ($_POST['display_pages'] as $page) { $display[] = 'p' . (int) substr($page, 1); } } if (!empty($_POST['display_custom'])) { $custom = array(); $temp = explode(',', $_POST['display_custom']); foreach ($temp as $action) { $custom[] = Util::htmlspecialchars(Util::htmltrim($action), ENT_QUOTES); } } $display = empty($display) ? '' : implode(',', $display); if (!allowedTo('admin_forum') && isset($current_data['display_custom']) && substr($current_data['display_custom'], 0, 4) === '$php') { $custom = $current_data['display_custom']; } elseif (!empty($_POST['display_custom'])) { if (allowedTo('admin_forum') && substr($_POST['display_custom'], 0, 4) === '$php') { $custom = Util::htmlspecialchars($_POST['display_custom'], ENT_QUOTES); } else { $custom = array(); $temp = explode(',', $_POST['display_custom']); foreach ($temp as $action) { $custom[] = Util::htmlspecialchars($action, ENT_QUOTES); } $custom = empty($custom) ? '' : implode(',', $custom); } } else { $custom = ''; } } $blockInfo = array('id' => (int) $_POST['block_id'], 'label' => Util::htmlspecialchars($_POST['block_name'], ENT_QUOTES), 'type' => $_POST['block_type'], 'col' => $_POST['block_column'], 'row' => $row, 'permissions' => (int) $_POST['permissions'], 'state' => !empty($_POST['block_active']) ? 1 : 0, 'force_view' => !empty($_POST['block_force']) ? 1 : 0, 'mobile_view' => !empty($_POST['block_mobile']) ? 1 : 0, 'display' => $display, 'display_custom' => $custom, 'style' => sportal_parse_style('implode')); // Insert a new block in to the portal if ($context['SPortal']['is_new']) { unset($blockInfo['id']); $blockInfo['id'] = sp_block_insert($blockInfo); } else { sp_block_update($blockInfo); } // Save any parameters for the block if (!empty($_POST['parameters'])) { sp_block_insert_parameters($_POST['parameters'], $blockInfo['id']); } redirectexit('action=admin;area=portalblocks'); } }
function fix_brd_value() { global $boards, $boardList, $tapatalk_board_tree, $cat_tree, $sourcedir; require_once $sourcedir . '/Subs-Boards.php'; getBoardTree(); foreach ($cat_tree as $catID => $node) { recursiveTpBoards($node); } }