[geeklog-cvs] geeklog: Fixed Topic and Block permission issue when a parent to...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Wed Oct 19 10:40:13 EDT 2011


changeset 8446:d4f90d7462cd
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/d4f90d7462cd
user: Tom <websitemaster at cogeco.net>
date: Wed Oct 19 10:39:21 2011 -0400
description:
Fixed Topic and Block permission issue when a parent topic is not accessible by a user but the child topic is still viewed.
Updated Directory to use proper function to display topics. All fixed issue of no 'No articles' message being displayed.
In multilanguage enviroment, only the topics specifically for that language are displayed. (before topics without language also displayed)

diffstat:

 public_html/admin/topic.php |    2 +-
 public_html/directory.php   |   24 +++----
 public_html/lib-common.php  |    7 +-
 system/lib-topic.php        |  133 ++++++++++++++++++++++++++++---------------
 4 files changed, 101 insertions(+), 65 deletions(-)

diffs (truncated from 311 to 300 lines):

diff -r 8df047460283 -r d4f90d7462cd public_html/admin/topic.php
--- a/public_html/admin/topic.php	Thu Oct 13 13:57:28 2011 -0400
+++ b/public_html/admin/topic.php	Wed Oct 19 10:39:21 2011 -0400
@@ -140,7 +140,7 @@
     
     $topic_templates->set_var('lang_parent_id', $LANG27[32]);
     $topic_templates->set_var('parent_id_options',
-                              TOPIC_getTopicListSelect($A['parent_id'], true, $A['tid']));
+                              TOPIC_getTopicListSelect($A['parent_id'], 1, false, $A['tid']));
     
     $topic_templates->set_var('lang_inherit', $LANG27[33]);
     $topic_templates->set_var('lang_inherit_info', $LANG27[34]);
diff -r 8df047460283 -r d4f90d7462cd public_html/directory.php
--- a/public_html/directory.php	Thu Oct 13 13:57:28 2011 -0400
+++ b/public_html/directory.php	Wed Oct 19 10:39:21 2011 -0400
@@ -100,12 +100,7 @@
     }
     $retval .= '><div>' . LB;
     $retval .= '<select name="topic" onchange="this.form.submit()">' . LB;
-    $retval .= '<option value="all"';
-    if ($topic == 'all') {
-        $retval .= ' selected="selected"';
-    }
-    $retval .= '>' . $LANG21[7] . '</option>' . LB;
-    $retval .= COM_topicList ('tid,topic', $topic);
+    $retval .= TOPIC_getTopicListSelect($topic, 2, true);
     $retval .= '</select>' . LB;
     $retval .= '<input type="hidden" name="year" value="' . $year . '"' . XHTML . '>';
     $retval .= '<input type="hidden" name="month" value="' . $month . '"' . XHTML . '>';
@@ -264,7 +259,7 @@
     $sql['mysql'] = "SELECT sid,title,UNIX_TIMESTAMP(date) AS day,DATE_FORMAT(date, '%e') AS mday FROM {$_TABLES['stories']} WHERE (date >= '$start') AND (date <= '$end') AND (draft_flag = 0) AND (date <= NOW())";
     $sql['mssql'] = "SELECT sid,title,UNIX_TIMESTAMP(date) AS day,DATE_FORMAT(date, '%e') AS mday FROM {$_TABLES['stories']} WHERE (date >= '$start') AND (date <= '$end') AND (draft_flag = 0) AND (date <= NOW())";
     $sql['pgsql'] = "SELECT sid,title,UNIX_TIMESTAMP(date) AS day,EXTRACT(day from date) AS mday FROM {$_TABLES['stories']} WHERE (date >= '$start') AND (date <= '$end') AND (draft_flag = 0) AND (date <= NOW())";
-        if ($topic != 'all') {
+    if ($topic != 'all') {
         $sql['mysql'] .= " AND (tid = '$topic')";
         $sql['mssql'] .= " AND (tid = '$topic')";
         $sql['pgsql'] .= " AND (tid = '$topic')";
@@ -449,12 +444,15 @@
 
     $yresult = DB_query ($ysql);
     $numyears = DB_numRows ($yresult);
-
-    for ($i = 0; $i < $numyears; $i++) {
-        $Y = DB_fetchArray ($yresult);
-
-        $retval .= DIR_displayYear ($topic, $Y['year']);
-    }
+    if ($numyears > 0) {
+        for ($i = 0; $i < $numyears; $i++) {
+            $Y = DB_fetchArray ($yresult);
+    
+            $retval .= DIR_displayYear ($topic, $Y['year']);
+        }
+    } else {
+        $retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>';
+    }    
 
     return $retval;
 }
diff -r 8df047460283 -r d4f90d7462cd public_html/lib-common.php
--- a/public_html/lib-common.php	Thu Oct 13 13:57:28 2011 -0400
+++ b/public_html/lib-common.php	Wed Oct 19 10:39:21 2011 -0400
@@ -2280,7 +2280,8 @@
         
         if ($branch_level_skip == 0) {
             // Make sure to show topics for proper language only
-            if (!$_TOPICS[$count_topic]['hidden'] && (($lang_id == '') || ($lang_id != '' && ($_TOPICS[$count_topic]['language_id'] == $lang_id || $_TOPICS[$count_topic]['language_id'] == '')))) {  
+            //if ($_TOPICS[$count_topic]['access'] > 0 && !$_TOPICS[$count_topic]['hidden'] && (($lang_id == '') || ($lang_id != '' && ($_TOPICS[$count_topic]['language_id'] == $lang_id || $_TOPICS[$count_topic]['language_id'] == '')))) {
+            if ($_TOPICS[$count_topic]['access'] > 0 && !$_TOPICS[$count_topic]['hidden'] && (($lang_id == '') || ($lang_id != '' && ($_TOPICS[$count_topic]['language_id'] == $lang_id)))) {
                 $branch_spaces = "";
                 for ($branch_count = $start_branch; $branch_count <= $_TOPICS[$count_topic]['branch_level'] ; $branch_count++) {
                     $branch_spaces .= "   ";
@@ -3568,7 +3569,7 @@
 
 function COM_showBlocks( $side, $topic='', $name='all' )
 {
-    global $_CONF, $_TABLES, $_USER, $LANG21, $topic, $page;
+    global $_CONF, $_TABLES, $_USER, $LANG21, $topic, $page, $_TOPICS;
 
     $retval = '';
 
@@ -3605,7 +3606,7 @@
         $commonsql .= " AND onleft = 0";
     }
 
-    if(!empty($topic)) {
+    if(!empty($topic) && $topic != TOPIC_ALL_OPTION && $topic != TOPIC_HOMEONLY_OPTION && $_TOPICS[TOPIC_getIndex($topic)]['access'] > 0) {
         // Retrieve list of inherited topics
         $tid_list = TOPIC_getChildList($topic);
         // Get list of blocks to display (except for dynamic). This includes blocks for all topics, and child blocks that are inherited
diff -r 8df047460283 -r d4f90d7462cd system/lib-topic.php
--- a/system/lib-topic.php	Thu Oct 13 13:57:28 2011 -0400
+++ b/system/lib-topic.php	Wed Oct 19 10:39:21 2011 -0400
@@ -64,7 +64,8 @@
       $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]['hidden'] = 0;
+      $tree_array[$total_topic]['access'] = 2;  // Read Access
       
       $branch_level = $branch_level + 1;
 	}    
@@ -75,9 +76,11 @@
         $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}' " . 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}' " . COM_getPermSQL ('AND') . $sql_sort;
+		$sql = "SELECT * FROM {$_TABLES['topics']} WHERE tid = '{$id}' " . $sql_sort;
 	}
 
 	$result = DB_query ($sql);
@@ -94,6 +97,7 @@
             $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]['access'] = SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']);
             
             // See if this topic has any children
             $tree_array = TOPIC_buildTree($tree_array[$total_topic]['id'], true, $branch_level, $tree_array);
@@ -103,23 +107,34 @@
     return $tree_array;
 }
 
+function TOPIC_getIndex($id)
+{
+	global $_TOPICS;
+	
+	$index = 0;
+	
+	// Find id in $_TOPICS
+    $total_topic = count($_TOPICS);
+    for ($count_topic = 1; $count_topic <= $total_topic ; $count_topic++) {
+        if ($_TOPICS[$count_topic]['id'] == $id) {
+            $index = $count_topic;
+            break;
+        }
+    }
+    
+    return $index;
+}
+
 function TOPIC_getChildList($id)
 {
 	global $_TOPICS;
 	
 	$retval = '';
-	// Find id in $_TOPICS
-	$id_found = false;
+
+    $start_topic = TOPIC_getIndex($id);
     $total_topic = count($_TOPICS);
-    for ($count_topic = 1; $count_topic <= $total_topic ; $count_topic++) {
-        if ($_TOPICS[$count_topic]['id'] == $id) {
-            $start_topic = $count_topic;
-            $id_found = true;
-            break;
-        }
-    }
-	
-    if ($id_found) {
+    
+    if ($start_topic > 0) {
         $retval = "'{$_TOPICS[$start_topic]['id']}'";
     
         $min_branch_level = $_TOPICS[$start_topic]['branch_level'];
@@ -133,8 +148,8 @@
             }        
             
             if ($branch_level_skip == 0) {
-                // Make sure to show topics for proper language only
-                if (($min_branch_level < $_TOPICS[$count_topic]['branch_level']) && (($lang_id == '') || ($lang_id != '' && ($_TOPICS[$count_topic]['language_id'] == $lang_id || $_TOPICS[$count_topic]['language_id'] == '')))) {
+                // 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 ($_TOPICS[$count_topic]['inherit'] == 1) {
                         $retval .= ", '" . $_TOPICS[$count_topic]['id'] . "'";
@@ -143,7 +158,7 @@
                         $branch_level_skip = $_TOPICS[$count_topic]['branch_level'];
                     }
                 } else {
-                    // Nothing inherited beyond this point because of language or beyond passed id
+                    // Nothing inherited beyond this point because of language or access beyond passed id
                     $branch_level_skip = $_TOPICS[$count_topic]['branch_level'];
                 }
             }
@@ -211,57 +226,80 @@
 /**
 * 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   Include Root in list
-* @param    string          $remove_id      Id of topic to not include (includes any children) (used for selection of parent id)
+* @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    string          $remove_id          Id of topic to not include (includes any children) (used for selection of parent id)
 * @return   HTML string
 *
 */
-function TOPIC_getTopicListSelect ($selected_ids = array(), $include_root = true, $remove_id = '')
+function TOPIC_getTopicListSelect ($selected_ids = array(), $include_root_all = 1, $language_specific = false, $remove_id = '')
 {
-    global $_TOPICS, $_TABLES, $LANG_CAT;
+    global $_TOPICS, $_TABLES, $LANG21;
 
     $retval = '';
     
     if (!is_array($selected_ids)) {
         $selected_ids = array($selected_ids);   
     }
-    if ($include_root) {
+    if ($include_root_all > 0) {
         $start_topic = 1;
     } else {
         $start_topic = 2;
     }
     $total_topic = count($_TOPICS);
     $branch_level_skip = 0;
+    $lang_id = '';
+    if ($language_specific) {
+        $lang_id = COM_getLanguageId();
+    }
 
     for ($count_topic = $start_topic; $count_topic <= $total_topic ; $count_topic++) {
-
-        // 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']) {
-            $branch_level_skip = 0;
-        }        
-
-        if ($branch_level_skip == 0) {
-            $id =  $_TOPICS[$count_topic]['id'];
-            
-            if ($id != $remove_id) {
+        
+        if ($count_topic == 1) {
+            // Deal with Root or All
+            if ($include_root_all == 1) {
+                $id =  $_TOPICS[$count_topic]['id'];
                 $title =  $_TOPICS[$count_topic]['title'];
                 
-                $branch_spaces = "";
-                for ($branch_count = $start_topic; $branch_count <= $_TOPICS[$count_topic]['branch_level'] ; $branch_count++) {
-                    $branch_spaces .= "   ";
+            } else {
+                $id = TOPIC_ALL_OPTION;
+                $title = $LANG21[7];
+            }
+            $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']) {
+                $branch_level_skip = 0;
+            }        
+    
+            if ($branch_level_skip == 0) {
+                $id =  $_TOPICS[$count_topic]['id'];
+                
+                if ($_TOPICS[$count_topic]['access'] > 0 && $id != $remove_id && (($lang_id == '') || ($lang_id != '' && $_TOPICS[$count_topic]['language_id'] == $lang_id))) {
+                    $title =  $_TOPICS[$count_topic]['title'];
+                    
+                    $branch_spaces = "";
+                    for ($branch_count = $start_topic; $branch_count <= $_TOPICS[$count_topic]['branch_level'] ; $branch_count++) {
+                        $branch_spaces .= "   ";
+                    }
+                    
+                    $retval .= '<option value="' . $id . '"';
+                    
+                    if (in_array($id, $selected_ids)) {
+                        $retval .= ' selected="selected"';
+                    }
+                    
+                    $retval .= '>' . $branch_spaces . $title . '</option>';
+                } else {
+                    // Cannot pick child as parent so skip
+                    $branch_level_skip = $_TOPICS[$count_topic]['branch_level'];            
                 }
-                
-                $retval .= '<option value="' . $id . '"';
-                
-                if (in_array($id, $selected_ids)) {
-                    $retval .= ' selected="selected"';
-                }
-                
-                $retval .= '>' . $branch_spaces . $title . '</option>';
-            } else {
-                // Cannot pick child as parent so skip
-                $branch_level_skip = $_TOPICS[$count_topic]['branch_level'];            



More information about the geeklog-cvs mailing list