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: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254:
<?php
if (!defined('SMF'))
die('No direct access...');
function modifyCategory($category_id, $catOptions)
{
global $sourcedir, $smcFunc;
$catUpdates = array();
$catParameters = array();
$cat_id = $category_id;
call_integration_hook('integrate_pre_modify_category', array($cat_id, &$catOptions));
if (isset($catOptions['move_after']))
{
$cats = array();
$cat_order = array();
if ($catOptions['move_after'] == 0)
$cats[] = $category_id;
$request = $smcFunc['db_query']('', '
SELECT id_cat, cat_order
FROM {db_prefix}categories
ORDER BY cat_order',
array(
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['id_cat'] != $category_id)
$cats[] = $row['id_cat'];
if ($row['id_cat'] == $catOptions['move_after'])
$cats[] = $category_id;
$cat_order[$row['id_cat']] = $row['cat_order'];
}
$smcFunc['db_free_result']($request);
foreach ($cats as $index => $cat)
if ($index != $cat_order[$cat])
$smcFunc['db_query']('', '
UPDATE {db_prefix}categories
SET cat_order = {int:new_order}
WHERE id_cat = {int:current_category}',
array(
'new_order' => $index,
'current_category' => $cat,
)
);
require_once($sourcedir . '/Subs-Boards.php');
reorderBoards();
}
if (isset($catOptions['cat_name']))
{
$catUpdates[] = 'name = {string:cat_name}';
$catParameters['cat_name'] = $catOptions['cat_name'];
}
if (isset($catOptions['cat_desc']))
{
$catUpdates[] = 'description = {string:cat_desc}';
$catParameters['cat_desc'] = $catOptions['cat_desc'];
}
if (isset($catOptions['is_collapsible']))
{
$catUpdates[] = 'can_collapse = {int:is_collapsible}';
$catParameters['is_collapsible'] = $catOptions['is_collapsible'] ? 1 : 0;
}
$cat_id = $category_id;
call_integration_hook('integrate_modify_category', array($cat_id, &$catUpdates, &$catParameters));
if (!empty($catUpdates))
{
$smcFunc['db_query']('', '
UPDATE {db_prefix}categories
SET
' . implode(',
', $catUpdates) . '
WHERE id_cat = {int:current_category}',
array_merge($catParameters, array(
'current_category' => $category_id,
))
);
if (empty($catOptions['dont_log']))
logAction('edit_cat', array('catname' => isset($catOptions['cat_name']) ? $catOptions['cat_name'] : $category_id), 'admin');
}
}
function createCategory($catOptions)
{
global $smcFunc;
if (!isset($catOptions['cat_name']) || trim($catOptions['cat_name']) == '')
trigger_error('createCategory(): A category name is required', E_USER_ERROR);
if (!isset($catOptions['cat_desc']))
$catOptions['cat_desc'] = '';
if (!isset($catOptions['move_after']))
$catOptions['move_after'] = 0;
if (!isset($catOptions['is_collapsible']))
$catOptions['is_collapsible'] = true;
$catOptions['dont_log'] = true;
$cat_columns = array(
'name' => 'string-48',
'description' => 'string',
);
$cat_parameters = array(
$catOptions['cat_name'],
$catOptions['cat_desc'],
);
call_integration_hook('integrate_create_category', array(&$catOptions, &$cat_columns, &$cat_parameters));
$category_id = $smcFunc['db_insert']('',
'{db_prefix}categories',
$cat_columns,
$cat_parameters,
array('id_cat'),
1
);
modifyCategory($category_id, $catOptions);
logAction('add_cat', array('catname' => $catOptions['cat_name']), 'admin');
return $category_id;
}
function deleteCategories($categories, $moveBoardsTo = null)
{
global $sourcedir, $smcFunc, $cat_tree;
require_once($sourcedir . '/Subs-Boards.php');
getBoardTree();
call_integration_hook('integrate_delete_category', array($categories, &$moveBoardsTo));
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,
)
);
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}categories
WHERE id_cat IN ({array_int:category_list})',
array(
'category_list' => $categories,
)
);
foreach ($categories as $category)
logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin');
reorderBoards();
}
?>