/** * 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; }
/** * Re-order all topics in steps of 10 * * @return void */ function reorderTopics() { global $_TABLES, $_TOPICS; $order = 0; $A = getTopicChildTreeArray(); foreach ($A as $B) { $order += 10; if ($B['sortnum'] != $order) { DB_query("UPDATE {$_TABLES['topics']} SET sortnum = '{$order}' WHERE tid = '{$B['tid']}'"); } } // Delete topic cache info since topics have changed $cacheInstance = 'topicsblock__'; CACHE_remove_instance($cacheInstance); $cacheInstance = 'topic_tree__'; CACHE_remove_instance($cacheInstance); // Update Topics Array to reflect any changes since not sure what is called after $_TOPICS = TOPIC_buildTree(TOPIC_ROOT, true); }
* */ $relLinks = array(); /** * Build global array of Topics current user has access to * * @global array $_TOPICS * */ // Figure out if we need to update topic tree or retrieve it from the cache // For anonymous users topic tree data can be shared $cacheInstance = 'topic_tree__' . CACHE_security_hash(); $serialized_topic_tree = CACHE_check_instance($cacheInstance, true); // See if Topic Tree cache exists if (empty($serialized_topic_tree)) { $_TOPICS = TOPIC_buildTree(TOPIC_ROOT, true); // Need this check since this variable is not set correctly when Geeklog is being install if (isset($GLOBALS['TEMPLATE_OPTIONS']) && is_array($TEMPLATE_OPTIONS) && isset($TEMPLATE_OPTIONS['path_cache'])) { // Save updated topic tree and date CACHE_create_instance($cacheInstance, serialize($_TOPICS), true); } } else { $_TOPICS = unserialize($serialized_topic_tree); } // Figure out if we need to update article feeds. Check last article date punlished in feed $sql = "SELECT date FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW() AND perm_anon > 0 ORDER BY date DESC LIMIT 1"; $result = DB_query($sql); $A = DB_fetchArray($result); if (DB_getItem($_TABLES['vars'], 'value', "name='last_article_publish'") != $A['date']) { //Set new latest article published DB_query("UPDATE {$_TABLES['vars']} SET value='{$A['date']}' WHERE name='last_article_publish'");