<commit_before><?php

/**
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * This software is a derived product, based on:
 *
 * Simple Machines Forum (SMF)
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
 * license:  	BSD, See included LICENSE.TXT for terms and conditions.
 *
 * @version 1.0 Alpha
 *
 * Manage and maintain the boards and categories of the forum.
 *
 */

if (!defined('ELK'))
	die('No access...');

class ManageBoards_Controller extends Action_Controller
{
	/**
	 * Boards settings form.
	 * @var Settings_Form
	 */
	protected $_boardSettings;

	/**
	 * The main dispatcher; doesn't do anything, just delegates.
	 * This is the main entry point for all the manageboards admin screens.
	 * Called by ?action=admin;area=manageboards.
	 * It checks the permissions, based on the sub-action, and calls a function based on the sub-action.
	 *
	 * uses ManageBoards language file.
	 */
	public function action_index()
	{
		global $context, $txt;

		// Everything's gonna need this.
		loadLanguage('ManageBoards');

		// We're working with them settings here.
		require_once(SUBSDIR . '/Settings.class.php');

		// Format: 'sub-action' => array('function', 'permission')
		$subActions = array(
			'board' => array(
				'controller' => $this,
				'function' => 'action_board',
				'permission' => 'manage_boards'),
			'board2' => array(
				'controller' => $this,
				'function' => 'action_board2',
				'permission' => 'manage_boards'),
			'cat' => array(
				'controller' => $this,
				'function' => 'action_cat',
				'permission' => 'manage_boards'),
			'cat2' => array(
				'controller' => $this,
				'function' => 'action_cat2',
				'permission' => 'manage_boards'),
			'main' => array(
				'controller' => $this,
				'function' => 'action_main',
				'permission' => 'manage_boards'),
			'move' => array(
				'controller' => $this,
				'function' => 'action_main',
				'permission' => 'manage_boards'),
			'newcat' => array(
				'controller' => $this,
				'function' => 'action_cat',
				'permission' => 'manage_boards'),
			'newboard' => array(
				'controller' => $this,
				'function' => 'action_board',
				'permission' => 'manage_boards'),
			'settings' => array(
				'controller' => $this,
				'function' => 'action_boardSettings_display',
				'permission' => 'admin_forum'),
		);

		call_integration_hook('integrate_manage_boards', array(&$subActions));

		// Default to sub-action 'main' or 'settings' depending on permissions.
		$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_boards') ? 'main' : 'settings');

		// Set up action/subaction stuff.
		$action = new Action();
		$action->initialize($subActions);

		// You way will end here if you don't have permission.
		$action->isAllowedTo($subAction);

		// Create the tabs for the template.
		$context[$context['admin_menu_name']]['tab_data'] = array(
			'title' => $txt['boards_and_cats'],
			'help' => 'manage_boards',
			'description' => $txt['boards_and_cats_desc'],
			'tabs' => array(
				'main' => array(
				),
				'newcat' => array(
				),
				'settings' => array(
					'description' => $txt['mboards_settings_desc'],
				),
			),
		);

		// Call the right function for this sub-action.
		$action->dispatch($subAction);
	}

	/**
	 * The main control panel thing, the screen showing all boards and categories.
	 * Called by ?action=admin;area=manageboards or ?action=admin;area=manageboards;sa=move.
	 * Requires manage_boards permission.
	 * It also handles the interface for moving boards.
	 *
	 * @uses ManageBoards template, main sub-template.
	 */
	public function action_main()
	{
		global $txt, $context, $cat_tree, $boards, $boardList, $scripturl, $txt;

		loadTemplate('ManageBoards');

		require_once(SUBSDIR . '/Boards.subs.php');

		if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'move' && in_array($_REQUEST['move_to'], array('child', 'before', 'after', 'top')))
		{
			checkSession('get');
			validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request');

			if ($_REQUEST['move_to'] === 'top')
				$boardOptions = array(
					'move_to' => $_REQUEST['move_to'],
					'target_category' => (int) $_REQUEST['target_cat'],
					'move_first_child' => true,
				);
			else
				$boardOptions = array(
					'move_to' => $_REQUEST['move_to'],
					'target_board' => (int) $_REQUEST['target_board'],
					'move_first_child' => true,
				);
			modifyBoard((int) $_REQUEST['src_board'], $boardOptions);
		}

		getBoardTree();

		$context['move_board'] = !empty($_REQUEST['move']) && isset($boards[(int) $_REQUEST['move']]) ? (int) $_REQUEST['move'] : 0;

		$context['categories'] = array();
		foreach ($cat_tree as $catid => $tree)
		{
			$context['categories'][$catid] = array(
				'name' => &$tree['node']['name'],
				'id' => &$tree['node']['id'],
				'boards' => array()
			);
			$move_cat = !empty($context['move_board']) && $boards[$context['move_board']]['category'] == $catid;
			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'],
					'move' => $move_cat && ($boardid == $context['move_board'] || isChildOf($boardid, $context['move_board'])),
					'permission_profile' => &$boards[$boardid]['profile'],
				);
			}
		}

		if (!empty($context['move_board']))
		{
			createToken('admin-bm-' . $context['move_board'], 'request');
<commit_msg>! add token for use in ajax board reorder<commit_after><?php

/**
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * This software is a derived product, based on:
 *
 * Simple Machines Forum (SMF)
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
 * license:  	BSD, See included LICENSE.TXT for terms and conditions.
 *
 * @version 1.0 Alpha
 *
 * Manage and maintain the boards and categories of the forum.
 *
 */

if (!defined('ELK'))
	die('No access...');

class ManageBoards_Controller extends Action_Controller
{
	/**
	 * Boards settings form.
	 * @var Settings_Form
	 */
	protected $_boardSettings;

	/**
	 * The main dispatcher; doesn't do anything, just delegates.
	 * This is the main entry point for all the manageboards admin screens.
	 * Called by ?action=admin;area=manageboards.
	 * It checks the permissions, based on the sub-action, and calls a function based on the sub-action.
	 *
	 * uses ManageBoards language file.
	 */
	public function action_index()
	{
		global $context, $txt;

		// Everything's gonna need this.
		loadLanguage('ManageBoards');

		// We're working with them settings here.
		require_once(SUBSDIR . '/Settings.class.php');

		// Format: 'sub-action' => array('function', 'permission')
		$subActions = array(
			'board' => array(
				'controller' => $this,
				'function' => 'action_board',
				'permission' => 'manage_boards'),
			'board2' => array(
				'controller' => $this,
				'function' => 'action_board2',
				'permission' => 'manage_boards'),
			'cat' => array(
				'controller' => $this,
				'function' => 'action_cat',
				'permission' => 'manage_boards'),
			'cat2' => array(
				'controller' => $this,
				'function' => 'action_cat2',
				'permission' => 'manage_boards'),
			'main' => array(
				'controller' => $this,
				'function' => 'action_main',
				'permission' => 'manage_boards'),
			'move' => array(
				'controller' => $this,
				'function' => 'action_main',
				'permission' => 'manage_boards'),
			'newcat' => array(
				'controller' => $this,
				'function' => 'action_cat',
				'permission' => 'manage_boards'),
			'newboard' => array(
				'controller' => $this,
				'function' => 'action_board',
				'permission' => 'manage_boards'),
			'settings' => array(
				'controller' => $this,
				'function' => 'action_boardSettings_display',
				'permission' => 'admin_forum'),
		);

		call_integration_hook('integrate_manage_boards', array(&$subActions));

		// Default to sub-action 'main' or 'settings' depending on permissions.
		$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_boards') ? 'main' : 'settings');

		// Set up action/subaction stuff.
		$action = new Action();
		$action->initialize($subActions);

		// You way will end here if you don't have permission.
		$action->isAllowedTo($subAction);

		// Create the tabs for the template.
		$context[$context['admin_menu_name']]['tab_data'] = array(
			'title' => $txt['boards_and_cats'],
			'help' => 'manage_boards',
			'description' => $txt['boards_and_cats_desc'],
			'tabs' => array(
				'main' => array(
				),
				'newcat' => array(
				),
				'settings' => array(
					'description' => $txt['mboards_settings_desc'],
				),
			),
		);

		// Call the right function for this sub-action.
		$action->dispatch($subAction);
	}

	/**
	 * The main control panel thing, the screen showing all boards and categories.
	 * Called by ?action=admin;area=manageboards or ?action=admin;area=manageboards;sa=move.
	 * Requires manage_boards permission.
	 * It also handles the interface for moving boards.
	 *
	 * @uses ManageBoards template, main sub-template.
	 */
	public function action_main()
	{
		global $txt, $context, $cat_tree, $boards, $boardList, $scripturl, $txt;

		loadTemplate('ManageBoards');

		require_once(SUBSDIR . '/Boards.subs.php');

		if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'move' && in_array($_REQUEST['move_to'], array('child', 'before', 'after', 'top')))
		{
			checkSession('get');
			validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request');

			if ($_REQUEST['move_to'] === 'top')
				$boardOptions = array(
					'move_to' => $_REQUEST['move_to'],
					'target_category' => (int) $_REQUEST['target_cat'],
					'move_first_child' => true,
				);
			else
				$boardOptions = array(
					'move_to' => $_REQUEST['move_to'],
					'target_board' => (int) $_REQUEST['target_board'],
					'move_first_child' => true,
				);
			modifyBoard((int) $_REQUEST['src_board'], $boardOptions);
		}

		getBoardTree();

		createToken('admin-sort');
		$context['move_board'] = !empty($_REQUEST['move']) && isset($boards[(int) $_REQUEST['move']]) ? (int) $_REQUEST['move'] : 0;

		$context['categories'] = array();
		foreach ($cat_tree as $catid => $tree)
		{
			$context['categories'][$catid] = array(
				'name' => &$tree['node']['name'],
				'id' => &$tree['node']['id'],
				'boards' => array()
			);
			$move_cat = !empty($context['move_board']) && $boards[$context['move_board']]['category'] == $catid;
			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'],
					'move' => $move_cat && ($boardid == $context['move_board'] || isChildOf($boardid, $context['move_board'])),
					'permission_profile' => &$boards[$boardid]['profile'],
				);
			}
		}

		if (!empty($context['move_board']))
		{
			createToken('admin-bm-' . $context['move_board'], 'request');

{'fraction_non_alphanumeric': 0.1901624945103206, 'fraction_numerical': 0.002108036890645586, 'mean_word_length': 4.022496691662991, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3421255', 'n_tokens_mistral': 4301, 'n_tokens_neox': 3628, 'n_words': 839}