[geeklog-cvs] geeklog: Now store all of topic permissions in topic array.
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Mon Dec 5 11:46:59 EST 2011
changeset 8450:8703014a4baa
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/8703014a4baa
user: Tom <websitemaster at cogeco.net>
date: Mon Dec 05 11:30:31 2011 -0500
description:
Now store all of topic permissions in topic array.
With TOPIC_getChildList and TOPIC_getTopicListSelect you can now specify a user other than current (will be used by syndication and digest).
Added restriced topic id for none option.
diffstat:
public_html/admin/topic.php | 2 +-
system/lib-topic.php | 137 ++++++++++++++++++++++++++++++++++---------
2 files changed, 107 insertions(+), 32 deletions(-)
diffs (243 lines):
diff -r c4210524c6d2 -r 8703014a4baa public_html/admin/topic.php
--- a/public_html/admin/topic.php Mon Dec 05 11:22:42 2011 -0500
+++ b/public_html/admin/topic.php Mon Dec 05 11:30:31 2011 -0500
@@ -367,7 +367,7 @@
// Check if tid is a restricted name
$restricted_tid = false;
- if ($tid == TOPIC_ALL_OPTION || $tid == TOPIC_HOMEONLY_OPTION || $tid == TOPIC_SELECTED_OPTION || $tid == TOPIC_ROOT) {
+ if ($tid == TOPIC_ALL_OPTION || $tid == TOPIC_NONE_OPTION || $tid == TOPIC_HOMEONLY_OPTION || $tid == TOPIC_SELECTED_OPTION || $tid == TOPIC_ROOT) {
$restricted_tid = true;
}
diff -r c4210524c6d2 -r 8703014a4baa system/lib-topic.php
--- a/system/lib-topic.php Mon Dec 05 11:22:42 2011 -0500
+++ b/system/lib-topic.php Mon Dec 05 11:30:31 2011 -0500
@@ -37,6 +37,7 @@
$_TOPIC_DEBUG = false;
define("TOPIC_ALL_OPTION", 'all');
+define("TOPIC_NONE_OPTION", 'none');
define("TOPIC_HOMEONLY_OPTION", 'homeonly');
define("TOPIC_SELECTED_OPTION", 'selectedtopics');
define("TOPIC_ROOT", 'root');
@@ -46,9 +47,31 @@
+/**
+* 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 gorup has
+perm_members Permissions logged in members have
+perm_anon Permissions anonymous users have
-
+*
+* @param int $uid user id or 0 = current user
+* @return array
+*
+*/
function TOPIC_buildTree($id, $parent = '', $branch_level = -1, $tree_array = array())
{
global $_TABLES, $_CONF, $_USER, $LANG27;
@@ -58,15 +81,21 @@
$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]['exclude'] = 0;
- $tree_array[$total_topic]['inherit'] = 1;
- $tree_array[$total_topic]['hidden'] = 0;
- $tree_array[$total_topic]['access'] = 2; // Read Access
+ $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;
}
@@ -77,10 +106,8 @@
$sql_sort = " ORDER BY topic ASC";
}
if ($parent) {
- // $sql = "SELECT * FROM {$_TABLES['topics']} WHERE parent_id = '{$id}' " . COM_getPermSQL ('AND') . $sql_sort;
$sql = "SELECT * FROM {$_TABLES['topics']} WHERE parent_id = '{$id}' " . $sql_sort;
} else {
- //$sql = "SELECT * FROM {$_TABLES['topics']} WHERE tid = '{$id}' " . COM_getPermSQL ('AND') . $sql_sort;
$sql = "SELECT * FROM {$_TABLES['topics']} WHERE tid = '{$id}' " . $sql_sort;
}
@@ -105,15 +132,22 @@
$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]['inherit'] = $A['inherit'];
- $tree_array[$total_topic]['hidden'] = $A['hidden'];
- $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']);
+ $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);
@@ -141,7 +175,15 @@
return $index;
}
-function TOPIC_getChildList($id)
+/**
+* Return a list of child topic ids that the user has access to
+*
+* @param string $id The id of the parent topic
+* @param int $uid user id or 0 = current user
+* @return string
+*
+*/
+function TOPIC_getChildList($id, $uid = 0)
{
global $_TOPICS;
@@ -164,8 +206,15 @@
}
if ($branch_level_skip == 0) {
+ // Figure out acces to topic
+ if ($uid == 0) {// Current User
+ $specified_user_access = $_TOPICS[$count_topic]['access'];
+ } else {
+ $specified_user_access = SEC_hasAccess($_TOPICS[$count_topic]['owner_id'], $_TOPICS[$count_topic]['group_id'], $_TOPICS[$count_topic]['perm_owner'], $_TOPICS[$count_topic]['perm_group'], $_TOPICS[$count_topic]['perm_members'], $_TOPICS[$count_topic]['perm_anon'], $uid);
+ }
+
// Make sure to show topics for proper language and access level only
- if ($_TOPICS[$count_topic]['access'] > 0 && (($min_branch_level < $_TOPICS[$count_topic]['branch_level']) && (($lang_id == '') || ($lang_id != '' && ($_TOPICS[$count_topic]['language_id'] == $lang_id || $_TOPICS[$count_topic]['language_id'] == ''))))) {
+ if ($specified_user_access > 0 && (($min_branch_level < $_TOPICS[$count_topic]['branch_level']) && (($lang_id == '') || ($lang_id != '' && ($_TOPICS[$count_topic]['language_id'] == $lang_id || $_TOPICS[$count_topic]['language_id'] == ''))))) {
if ($_TOPICS[$count_topic]['inherit'] == 1) {
$retval .= ", '" . $_TOPICS[$count_topic]['id'] . "'";
@@ -262,13 +311,14 @@
* This function creates html options for Topics, for a single or multi select box
*
* @param string/array $selected_ids Topics Ids to mark as selected
-* @param boolean $include_root_all Include Nothing (0) or Root (1) or All (2) in list.
+* @param boolean $include_root_all Include Nothing (0) or Root (1) or All (2) or None (4) in list.
* @param string $remove_id Id of topic to not include (includes any children) (used for selection of parent id)
-* @param boolean $remove_archive Remove archive topic from list if any
+* @param boolean $remove_archive Remove archive topic from list if any
+* @param int $uid User id or 0 = current user
* @return HTML string
*
*/
-function TOPIC_getTopicListSelect($selected_ids = array(), $include_root_all = 1, $language_specific = false, $remove_id = '', $remove_archive = false)
+function TOPIC_getTopicListSelect($selected_ids = array(), $include_root_all = 1, $language_specific = false, $remove_id = '', $remove_archive = false, $uid = 0)
{
global $_TOPICS, $_TABLES, $LANG21;
@@ -298,22 +348,40 @@
for ($count_topic = $start_topic; $count_topic <= $total_topic ; $count_topic++) {
if ($count_topic == 1) {
- // Deal with Root or All
+ // Deal with Root or All and None
if ($include_root_all == 1) {
$id = $_TOPICS[$count_topic]['id'];
$title = $_TOPICS[$count_topic]['title'];
+ $retval .= '<option value="' . $id . '"';
+ if (in_array($id, $selected_ids)) {
+ $retval .= ' selected="selected"';
+ }
+ $retval .= '>' . $title . '</option>';
} else {
- $id = TOPIC_ALL_OPTION;
- $title = $LANG21[7];
+ // Check for None
+ if ($include_root_all == 4 || $include_root_all == 6) {
+ $id = TOPIC_NONE_OPTION;
+ $title = $LANG21[47];
+
+ $retval .= '<option value="' . $id . '"';
+ if (in_array($id, $selected_ids)) {
+ $retval .= ' selected="selected"';
+ }
+ $retval .= '>' . $title . '</option>';
+ }
+ // Check for All
+ if ($include_root_all == 2 || $include_root_all == 6) {
+ $id = TOPIC_ALL_OPTION;
+ $title = $LANG21[7];
+
+ $retval .= '<option value="' . $id . '"';
+ if (in_array($id, $selected_ids)) {
+ $retval .= ' selected="selected"';
+ }
+ $retval .= '>' . $title . '</option>';
+ }
}
- $retval .= '<option value="' . $id . '"';
-
- if (in_array($id, $selected_ids)) {
- $retval .= ' selected="selected"';
- }
-
- $retval .= '>' . $title . '</option>';
} else {
// Check to see if we need to include id (this is done for stuff like topic edits that cannot include themselves or child as parent
if ($branch_level_skip >= $_TOPICS[$count_topic]['branch_level']) {
@@ -323,7 +391,14 @@
if ($branch_level_skip == 0) {
$id = $_TOPICS[$count_topic]['id'];
- if ($archive_tid != $id && $_TOPICS[$count_topic]['access'] > 0 && $id != $remove_id && (($lang_id == '') || ($lang_id != '' && $_TOPICS[$count_topic]['language_id'] == $lang_id))) {
+ if ($uid == 0) {// Current User
+ $specified_user_access = $_TOPICS[$count_topic]['access'];
+ } else {
+ $specified_user_access = SEC_hasAccess($_TOPICS[$count_topic]['owner_id'], $_TOPICS[$count_topic]['group_id'], $_TOPICS[$count_topic]['perm_owner'], $_TOPICS[$count_topic]['perm_group'], $_TOPICS[$count_topic]['perm_members'], $_TOPICS[$count_topic]['perm_anon'], $uid);
+ }
+
+ // Make sure to show topics for proper language and access level only
+ if ($archive_tid != $id && $specified_user_access > 0 && $id != $remove_id && (($lang_id == '') || ($lang_id != '' && $_TOPICS[$count_topic]['language_id'] == $lang_id))) {
$title = $_TOPICS[$count_topic]['title'];
$branch_spaces = "";
More information about the geeklog-cvs
mailing list