/** * Return the topic tree structure in an array. * id ID of topic parent_id ID of parent topic branch_level Level of branch in tree structure title Title of topic language_id Language of topic inherit If topic inherits objects from child topics hidden If topic is hidden exclude If topic is in current users exclude list (1), (0) if not in list access Access current user has with topic owner_id ID of the owner of the topic group_id ID of group topic belongs to perm_owner Permissions the owner has perm_group Permissions the group has perm_members Permissions logged in members have perm_anon Permissions anonymous users have * * @return array * */ function TOPIC_buildTree($id, $parent = '', $branch_level = -1, $tree_array = array()) { global $_TABLES, $_CONF, $_USER, $LANG27; $branch_level = $branch_level + 1; $total_topic = count($tree_array) + 1; if ($id == TOPIC_ROOT) { // Root $tree_array[$total_topic]['id'] = TOPIC_ROOT; $tree_array[$total_topic]['parent_id'] = ''; $tree_array[$total_topic]['branch_level'] = $branch_level; $tree_array[$total_topic]['title'] = $LANG27[37]; $tree_array[$total_topic]['language_id'] = ''; $tree_array[$total_topic]['inherit'] = 1; $tree_array[$total_topic]['hidden'] = 0; $tree_array[$total_topic]['exclude'] = 0; $tree_array[$total_topic]['access'] = 2; // Read Access $tree_array[$total_topic]['owner_id'] = SEC_getDefaultRootUser(); $tree_array[$total_topic]['group_id'] = 1; $tree_array[$total_topic]['perm_owner'] = 2; $tree_array[$total_topic]['perm_group'] = 2; $tree_array[$total_topic]['perm_members'] = 2; $tree_array[$total_topic]['perm_anon'] = 2; $branch_level = $branch_level + 1; } if ($_CONF['sortmethod'] != 'alpha') { $sql_sort = " ORDER BY sortnum"; } else { $sql_sort = " ORDER BY topic ASC"; } if ($parent) { $sql = "SELECT * FROM {$_TABLES['topics']} WHERE parent_id = '{$id}' " . $sql_sort; } else { $sql = "SELECT * FROM {$_TABLES['topics']} WHERE tid = '{$id}' " . $sql_sort; } $result = DB_query($sql); $nrows = DB_numRows($result); if ($nrows > 0) { // Figure out if any excluded topics $excluded_tids = ''; if (!COM_isAnonUser()) { $excluded_tids = DB_getItem($_TABLES['userindex'], 'tids', "uid = '{$_USER['uid']}'"); if (!empty($excluded_tids)) { $excluded_tids = "'" . str_replace(' ', "','", $excluded_tids) . "'"; } } for ($i = 0; $i < $nrows; $i++) { $A = DB_fetchArray($result); $total_topic = count($tree_array) + 1; $tree_array[$total_topic]['id'] = $A['tid']; $tree_array[$total_topic]['parent_id'] = $A['parent_id']; $tree_array[$total_topic]['branch_level'] = $branch_level; $tree_array[$total_topic]['title'] = stripslashes($A['topic']); $tree_array[$total_topic]['language_id'] = COM_getLanguageIdForObject($A['tid']); // figure out language if need be $tree_array[$total_topic]['inherit'] = $A['inherit']; $tree_array[$total_topic]['hidden'] = $A['hidden']; $tree_array[$total_topic]['exclude'] = 0; if (!empty($excluded_tids)) { if (MBYTE_strpos($excluded_tids, $A['tid']) !== false) { $tree_array[$total_topic]['exclude'] = 1; } } $tree_array[$total_topic]['access'] = SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']); // Current User Access $tree_array[$total_topic]['owner_id'] = $A['owner_id']; $tree_array[$total_topic]['group_id'] = $A['group_id']; $tree_array[$total_topic]['perm_owner'] = $A['perm_owner']; $tree_array[$total_topic]['perm_group'] = $A['perm_group']; $tree_array[$total_topic]['perm_members'] = $A['perm_members']; $tree_array[$total_topic]['perm_anon'] = $A['perm_anon']; // See if this topic has any children $tree_array = TOPIC_buildTree($tree_array[$total_topic]['id'], true, $branch_level, $tree_array); } } return $tree_array; }
/** * Switch the language ID of the object id * * @param string $id object id that the language ID is attached to the end * @return string id that is overwritten with the current language ID * */ function COM_switchLanguageIdForObject($id) { global $_CONF; if (!empty($_CONF['languages']) && !empty($_CONF['language_files'])) { $new_id = COM_getLanguageId(); $old_id = COM_getLanguageIdForObject($id); if (!empty($new_id) && !empty($old_id)) { $id = substr_replace($id, $new_id, -strlen($old_id)); } } return $id; }